Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BLEAdvertisement.cxx
Go to the documentation of this file.
1
29
30#include <endian.h>
31
33
34namespace openlcb
35{
36
37//
38// BLEAdvertisement::BLEAdvertisement()
39//
41 NodeID node_id, const char *node_name, uint32_t pip)
42 : Advertisement(ble::Advertisement::MAX_DATA_PAYLOAD_SIZE,
43 ble::Advertisement::MAX_SCAN_DATA_PAYLOAD_SIZE)
44{
45 // Add flags to data.
46 uint8_t flags = static_cast<uint8_t>(Flags::LE_ONLY_GENERAL_DISC_MODE);
48 // Add name to data.
49 if (node_name && strlen(node_name) != 0)
50 {
51 std::string name(node_name);
53 }
54
55 // Add OpenLCB service data 128 to scan data.
56 pip = htole32(pip);
57 node_id = htole64(node_id);
58 std::basic_string<uint8_t> payload =
59 std::basic_string<uint8_t>((uint8_t*)&node_id, 6) +
60 std::basic_string<uint8_t>((uint8_t*)&pip, sizeof(pip));
61 std::basic_string<uint8_t> srvc_data = concat_service_data_128(
64}
65
66} // namespace openlcb
@ LE_ONLY_GENERAL_DISC_MODE
BEE only general discovery mode.
int append(Field field, Defs::AdvType type, const void *buf, size_t size, bool clip=false)
Add to the end of the advertisement.
int append_name(Field field, std::string &name)
Add name to the end of the advertisement.
std::basic_string< uint8_t > concat_service_data_128(const uint8_t uuid[16], const void *buf, size_t size)
Concatenate a 128-bit (16-byte) UUID with provided data.
@ SERVICE_DATA_128
128-bit service UUID folloed by data
@ FLAGS
GAP discovery modes.
BLEAdvertisement(NodeID node_id, const char *node_name, uint32_t pip)
Constructor.
static const uint8_t GATT_SERVICE_UUID_OPENLCB[16]
OpenLCB GATT service UUID.
uint64_t NodeID
48-bit NMRAnet Node ID type