~aleteoryx/muditaos

ref: a405cad694b867fcd2498984830bd97d4b9bde2f muditaos/module-bluetooth/Bluetooth/interface/profiles/HFP/HFPImpl.hpp -rw-r--r-- 3.2 KiB
a405cad6Aleteoryx trim readme 7 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include "HFP.hpp"
#include "Result.hpp"
#include <interface/profiles/SCO/SCO.hpp>
#include <Audio/AudioCommon.hpp>

namespace bluetooth
{
    class HFP::HFPImpl
    {
      public:
        static void packetHandler(std::uint8_t packetType,
                                  std::uint16_t channel,
                                  std::uint8_t *event,
                                  std::uint16_t eventSize);
        auto init() -> Result::Code;
        void deInit() noexcept;
        [[nodiscard]] auto incomingCallStarted() const noexcept -> Result::Code;
        [[nodiscard]] auto outgoingCallStarted(const std::string &number) const noexcept -> Result::Code;
        [[nodiscard]] auto incomingCallAnswered() const noexcept -> Result::Code;
        [[nodiscard]] auto outgoingCallAnswered() const noexcept -> Result::Code;
        [[nodiscard]] auto callTerminated() const noexcept -> Result::Code;
        [[nodiscard]] auto callMissed() const noexcept -> Result::Code;
        void connect();
        void disconnect();
        void setDevice(Devicei device);
        void setOwnerService(sys::Service *service);
        void setAudioDevice(std::shared_ptr<bluetooth::BluetoothAudioDevice> audioDevice);
        [[nodiscard]] auto setIncomingCallNumber(const std::string &num) const noexcept -> Result::Code;
        [[nodiscard]] auto setSignalStrength(int bars) const noexcept -> Result::Code;
        [[nodiscard]] auto setOperatorName(const std::string_view &name) const noexcept -> Result::Code;
        [[nodiscard]] auto setBatteryLevel(const BatteryLevel &level) const noexcept -> Result::Code;
        [[nodiscard]] auto setNetworkRegistrationStatus(bool registered) const noexcept -> Result::Code;
        [[nodiscard]] auto setRoamingStatus(bool enabled) const noexcept -> Result::Code;

      private:
        static void sendAudioEvent(audio::EventType event, audio::Event::DeviceState state);
        static void processHCIEvent(std::uint8_t *event);
        static void processHFPEvent(std::uint8_t *event);
        static void initCodecs();
        static void logSupportedCodecs();

        static constexpr auto serviceBufferSize           = 150;
        static constexpr std::uint8_t rfcommChannelNr     = 1;
        static constexpr std::uint32_t hfpSdpRecordHandle = 0x10004;

        static hci_con_handle_t scoHandle;
        static hci_con_handle_t aclHandle;

        static std::uint8_t serviceBuffer[serviceBufferSize];

        static const char *agServiceName;

        static std::unique_ptr<SCO> sco;
        static SCOCodec codec;
        static std::shared_ptr<CVSDAudioDevice> audioDevice;

        static std::unique_ptr<CellularInterface> cellularInterface;
        static std::unique_ptr<AudioInterface> audioInterface;

        static sys::Service *ownerService;
        static Devicei device;

        static btstack_packet_callback_registration_t hciEventCallbackRegistration;
        static hfp_ag_indicator_t agIndicators[];
        static const char *callHoldServices[];
        static hfp_generic_status_indicator_t hfIndicators[];
    };
} // namespace bluetooth