Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BLEDefs.hxx
Go to the documentation of this file.
1
28#ifndef _OPENLCB_BLEDEFS_HXX_
29#define _OPENLCB_BLEDEFS_HXX_
30
31#include <memory>
32
34
35namespace openlcb
36{
37
38#include <string>
39
43public:
46 virtual void disconnect_and_delete() = 0;
47
48 struct Deleter {
49 void operator()(BLEProtocolEngine* e) {
51 }
52 };
53};
54
55using BLEProtocolEnginePtr = std::unique_ptr<BLEProtocolEngine, BLEProtocolEngine::Deleter>;
56
57
60{
61public:
65 static std::basic_string<uint8_t> random_address_from_node_id(NodeID id)
66 {
67 // Random addresses have 2 most significant bits set.
68 id |= 0x0000C00000000000ULL;
69
70 return std::basic_string<uint8_t>(
71 {
72 static_cast<uint8_t>((id >> 40) & 0xFF),
73 static_cast<uint8_t>((id >> 32) & 0xFF),
74 static_cast<uint8_t>((id >> 24) & 0xFF),
75 static_cast<uint8_t>((id >> 16) & 0xFF),
76 static_cast<uint8_t>((id >> 8) & 0xFF),
77 static_cast<uint8_t>((id >> 0) & 0xFF)
78 });
79 }
80};
81
82} // namespace openlcb
83
84#endif // _OPENLCB_BLEDEFS_HXX_
Base class of everything with a virtual destructor.
Miscellaneous BLE definitions.
Definition BLEDefs.hxx:60
static std::basic_string< uint8_t > random_address_from_node_id(NodeID id)
Create a valid BLE random address from an OpenLCB Node ID.
Definition BLEDefs.hxx:65
Shared base class for protocol implementation on a per-BLE-connection basis.
Definition BLEDefs.hxx:42
virtual void disconnect_and_delete()=0
Notifies the protocol engine that the connection has been terminated.
uint64_t NodeID
48-bit NMRAnet Node ID type