roo_transceivers
API Documentation for roo_transceivers
Loading...
Searching...
No Matches
id.cpp
Go to the documentation of this file.
2
3namespace roo_transceivers {
4
5DeviceLocator::DeviceLocator() : schema_(), device_id_() {}
6
7DeviceLocator::DeviceLocator(roo::string_view schema,
8 roo::string_view device_id)
9 : schema_(schema), device_id_(device_id) {}
10
11void DeviceLocator::write_cstr(char* buf) const {
12 strncpy(buf, schema_.c_str(), DeviceSchema::kCapacity);
13 size_t len = strlen(buf);
14 if (len > 0) {
15 buf[len++] = ':';
16 }
17 strncpy(buf + len, device_id_.c_str(), DeviceId::kCapacity);
18}
19
20std::string DeviceLocator::toString() const {
21 char buf[DeviceSchema::kCapacity + 1 + DeviceId::kCapacity];
22 write_cstr(buf);
23 return std::string(buf);
24}
25
26SensorLocator::SensorLocator() : device_locator_(), sensor_id_() {}
27
28SensorLocator::SensorLocator(roo::string_view schema,
29 roo::string_view device_id,
30 roo::string_view sensor_id)
31 : device_locator_(schema, device_id), sensor_id_(sensor_id) {}
32
34 roo::string_view sensor_id)
35 : device_locator_(device_loc), sensor_id_(sensor_id) {}
36
37void SensorLocator::write_cstr(char* buf) const {
38 device_locator_.write_cstr(buf);
39 size_t len = strlen(buf);
40 if (len > 0 && !sensor_id_.empty()) {
41 buf[len++] = '/';
42 strncpy(buf + len, sensor_id_.c_str(), SensorId::kCapacity);
43 }
44}
45
46std::string SensorLocator::toString() const {
47 char buf[DeviceSchema::kCapacity + 1 + DeviceId::kCapacity + 1 +
48 SensorId::kCapacity];
49 write_cstr(buf);
50 return std::string(buf);
51}
52
53ActuatorLocator::ActuatorLocator() : device_locator_(), actuator_id_() {}
54
56 roo::string_view actuator_id)
57 : device_locator_(device_loc), actuator_id_(actuator_id) {}
58
59ActuatorLocator::ActuatorLocator(roo::string_view schema,
60 roo::string_view device_id,
61 roo::string_view actuator_id)
62 : device_locator_(schema, device_id), actuator_id_(actuator_id) {}
63
64void ActuatorLocator::write_cstr(char* buf) const {
65 device_locator_.write_cstr(buf);
66 size_t len = strlen(buf);
67 if (len > 0 && !actuator_id_.empty()) {
68 buf[len++] = '/';
69 strncpy(buf + len, actuator_id_.c_str(), ActuatorId::kCapacity);
70 }
71}
72
73std::string ActuatorLocator::toString() const {
74 char buf[DeviceSchema::kCapacity + 1 + DeviceId::kCapacity + 1 +
75 ActuatorId::kCapacity];
76 write_cstr(buf);
77 return std::string(buf);
78}
79
80} // namespace roo_transceivers
81
82roo_logging::Stream& operator<<(roo_logging::Stream& s,
83 const roo_transceivers::DeviceSchema& schema) {
84 s << schema.c_str();
85 return s;
86}
87
88roo_logging::Stream& operator<<(roo_logging::Stream& s,
90 s << loc.schema() << ":" << loc.device_id().c_str();
91 return s;
92}
93
94roo_logging::Stream& operator<<(roo_logging::Stream& s,
96 s << loc.device_locator();
97 if (!loc.sensor_id().empty()) {
98 s << "/" << loc.sensor_id().c_str();
99 }
100 return s;
101}
102
103roo_logging::Stream& operator<<(roo_logging::Stream& s,
105 s << loc.device_locator();
106 if (!loc.actuator_id().empty()) {
107 s << "/" << loc.actuator_id().c_str();
108 }
109 return s;
110}
Identifies actuator within a transceiver device.
Definition id.h:104
const DeviceLocator & device_locator() const
Returns the device locator.
Definition id.h:115
void write_cstr(char *buf) const
Writes a null-terminated string representation into buf.
Definition id.cpp:64
std::string toString() const
Returns a string representation.
Definition id.cpp:73
const ActuatorId & actuator_id() const
Returns the actuator id.
Definition id.h:124
Identifies a transceiver device by schema and device id.
Definition id.h:21
const DeviceId & device_id() const
Returns the device id.
Definition id.h:30
const DeviceSchema & schema() const
Returns the device schema.
Definition id.h:28
std::string toString() const
Returns a string representation.
Definition id.cpp:20
void write_cstr(char *buf) const
Writes a null-terminated string representation into buf.
Definition id.cpp:11
Identifies sensor within a transceiver device.
Definition id.h:57
const SensorId & sensor_id() const
Returns the sensor id.
Definition id.h:76
const DeviceLocator & device_locator() const
Returns the device locator.
Definition id.h:67
std::string toString() const
Returns a string representation.
Definition id.cpp:46
void write_cstr(char *buf) const
Writes a null-terminated string representation into buf.
Definition id.cpp:37
roo_logging::Stream & operator<<(roo_logging::Stream &s, const roo_transceivers::DeviceSchema &schema)
Definition id.cpp:82
roo_collections::SmallString< 16 > DeviceSchema
Device schema identifier (short string).
Definition id.h:12