esp-nimble-cpp 2.3.2
Loading...
Searching...
No Matches
NimBLEBeacon.h
1/*
2 * Copyright 2020-2025 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_BEACON_H_
19#define NIMBLE_CPP_BEACON_H_
20
21#include "syscfg/syscfg.h"
22#if CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER)
23
24class NimBLEUUID;
25
26# include <cstdint>
27# include <vector>
28
34class NimBLEBeacon {
35 public:
36 struct BeaconData {
37 uint16_t manufacturerId{0x4c00};
38 uint8_t subType{0x02};
39 uint8_t subTypeLength{0x15};
40 uint8_t proximityUUID[16]{};
41 uint16_t major{};
42 uint16_t minor{};
43 int8_t signalPower{};
44 operator std::vector<uint8_t> () const {
45 return std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(this),
46 reinterpret_cast<const uint8_t*>(this) + sizeof(BeaconData));
47 }
48 } __attribute__((packed));
49
50 const BeaconData& getData();
51 uint16_t getMajor();
52 uint16_t getMinor();
53 uint16_t getManufacturerId();
54 NimBLEUUID getProximityUUID();
55 int8_t getSignalPower();
56 void setData(const uint8_t* data, uint8_t length);
57 void setData(const BeaconData& data);
58 void setMajor(uint16_t major);
59 void setMinor(uint16_t minor);
60 void setManufacturerId(uint16_t manufacturerId);
61 void setProximityUUID(const NimBLEUUID& uuid);
62 void setSignalPower(int8_t signalPower);
63
64 private:
65 BeaconData m_beaconData;
66}; // NimBLEBeacon
67
68#endif // CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
69#endif // NIMBLE_CPP_BEACON_H_
A model of a BLE UUID.
Definition NimBLEUUID.h:41