~aleteoryx/muditaos

ref: 6e69eb6aa629aeef8d64d84c26804c2bf4e9d72d muditaos/module-bluetooth/Bluetooth/interface/profiles/GAP/GAP.hpp -rw-r--r-- 2.4 KiB
6e69eb6a — Wojtek Rzepecki [BH-990] Adjist CPU frequency chages 4 years 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include <vector>
#include <Bluetooth/Device.hpp>
#include <Bluetooth/Error.hpp>
#include <Service/Service.hpp>
extern "C"
{
#include "btstack_defines.h"
}
namespace bluetooth
{
    enum ScanState
    {
        init,
        active,
        done
    };
    class GAP
    {
        static std::vector<Devicei> devices;
        static sys::Service *ownerService;
        static btstack_packet_callback_registration_t cb_handler;
        static constexpr auto inquiryIntervalSeconds = 5;
        static ScanState state;
        static void sendDevices();
        static auto startScan() -> int;
        static auto remoteNameToFetch() -> bool;
        static void fetchRemoteName();
        static void continueScanning();
        static auto updateDeviceName(std::uint8_t *packet, bd_addr_t &addr) -> bool;
        static void addNewDevice(std::uint8_t *packet, bd_addr_t &addr);
        static void activeStateHandler(std::uint8_t eventType, std::uint8_t *packet, bd_addr_t &addr);
        static void packetHandler(std::uint8_t packet_type,
                                  std::uint16_t channel,
                                  std::uint8_t *packet,
                                  std::uint16_t size);
        static void processInquiryResult(std::uint8_t *packet, bd_addr_t &addr);
        static void processInquiryComplete();
        static void processNameRequestComplete(std::uint8_t *packet, bd_addr_t &addr);
        static void processDedicatedBondingCompleted(std::uint8_t *packet, bd_addr_t &addr);
        static void initStateHandler(std::uint8_t eventType, std::uint8_t *packet);
        static auto getDeviceIndexForAddress(const std::vector<Devicei> &devs, const bd_addr_t addr) -> int;

      public:
        /// THIS have to be called prior to Bt system start!
        static auto registerScan() -> Error;
        auto scan() -> Error;
        void stopScan();
        void setVisibility(bool visibility);
        auto pair(const Devicei &device, std::uint8_t protectionLevel = 0) -> bool;
        auto unpair(const Devicei &device) -> bool;
        static auto getDevicesList() -> const std::vector<Devicei> &;
        static void respondPinCode(const std::string &pin);

        static Devicei currentlyProccesedDevice;
        explicit GAP(sys::Service *owner);
    };
} // namespace bluetooth