roo_transceivers
API Documentation for roo_transceivers
Loading...
Searching...
No Matches
proto.cpp
Go to the documentation of this file.
2
3#include "roo_logging.h"
4
5namespace roo_transceivers {
6namespace proto {
7
13
21
29
36
46
53
55 int descriptor_key) {
58 auto& payload = msg.contents.device_added;
59 strncpy(payload.locator_schema, locator.schema().c_str(),
60 DeviceSchema::kCapacity);
61 strncpy(payload.locator_id, locator.device_id().c_str(), DeviceId::kCapacity);
62 msg.contents.device_added.descriptor_key = descriptor_key;
63 return msg;
64}
65
67 size_t count) {
70 auto& payload = msg.contents.device_preserved;
71 payload.prev_index = first_preserved_ordinal;
72 payload.has_count = (count > 1);
73 if (payload.has_count) {
74 payload.count = count;
75 }
76 return msg;
77}
78
80 int descriptor_key) {
83 auto& payload = msg.contents.device_modified;
84 payload.prev_index = prev_ordinal;
85 payload.descriptor_key = descriptor_key;
86 return msg;
87}
88
96
102
108
112 auto& payload = msg.contents.reading;
113 strncpy(payload.device_locator_schema, device.schema().c_str(),
114 DeviceSchema::kCapacity);
115 strncpy(payload.device_locator_id, device.device_id().c_str(),
116 DeviceId::kCapacity);
117 return msg;
118}
119
121 const SensorId& sensor_id, float value, uint64_t age_ms) {
122 // CHECK_EQ(reading.which_contents,
123 // roo_transceivers_ServerMessage_reading_tag);
124 auto& payload = reading.contents.reading;
125 // CHECK_LT(payload.sensor_values_count, 16);
126 auto& val = payload.sensor_values[payload.sensor_values_count];
127 strncpy(val.device_locator_sensor_id, sensor_id.c_str(), SensorId::kCapacity);
128 val.value = value;
129 val.age_ms = age_ms;
130 ++payload.sensor_values_count;
131}
132
138
144
146 float value) {
149 auto& payload = msg.contents.write;
150 strncpy(payload.device_locator_schema, actuator.schema().c_str(),
151 DeviceSchema::kCapacity);
152 strncpy(payload.device_locator_id, actuator.device_id().c_str(),
153 DeviceId::kCapacity);
154 strncpy(payload.device_locator_actuator_id, actuator.actuator_id().c_str(),
155 ActuatorId::kCapacity);
156 payload.value = value;
157 return msg;
158}
159
160} // namespace proto
161
162} // namespace roo_transceivers
Identifies actuator within a transceiver device.
Definition id.h:104
const DeviceSchema & schema() const
Returns the device schema.
Definition id.h:118
const DeviceId & device_id() const
Returns the device id.
Definition id.h:121
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
roo_transceivers_ServerMessage SrvDeviceRemoved(int prev_ordinal)
Removes a device.
Definition proto.cpp:89
roo_transceivers_ServerMessage SrvDeltaUpdateBegin()
Begins a delta update sequence.
Definition proto.cpp:22
roo_transceivers_ServerMessage SrvDescriptorAdded(int key, const roo_transceivers_Descriptor &descriptor)
Adds a descriptor in the server stream.
Definition proto.cpp:37
roo_transceivers_ClientMessage ClientRequestState()
Builds a client state request.
Definition proto.cpp:139
roo_transceivers_ClientMessage ClientWrite(const ActuatorLocator &actuator, float value)
Builds a client write request.
Definition proto.cpp:145
roo_transceivers_ServerMessage SrvDevicesModified(int prev_ordinal, int descriptor_key)
Marks a device as modified.
Definition proto.cpp:79
roo_transceivers_ServerMessage SrvUpdateEnd()
Ends an update sequence.
Definition proto.cpp:30
roo_transceivers_ServerMessage SrvReading(const DeviceLocator &device)
Begins readings for a device.
Definition proto.cpp:109
void AddReading(roo_transceivers_ServerMessage &reading, const SensorId &sensor_id, float value, uint64_t age_ms)
Appends a single sensor reading to a readings message.
Definition proto.cpp:120
roo_transceivers_ServerMessage SrvDeviceAdded(const DeviceLocator &locator, int descriptor_key)
Adds a device with a descriptor key.
Definition proto.cpp:54
roo_transceivers_ServerMessage SrvFullUpdateBegin()
Begins a full update sequence.
Definition proto.cpp:14
roo_transceivers_ServerMessage SrvInit()
Builds an init server message.
Definition proto.cpp:8
roo_transceivers_ServerMessage SrvDevicesPreserved(int first_preserved_ordinal, size_t count)
Marks a range of devices as preserved.
Definition proto.cpp:66
roo_transceivers_ServerMessage SrvReadingsEnd()
Ends a readings block.
Definition proto.cpp:103
roo_transceivers_ServerMessage SrvReadingsBegin()
Begins a readings block.
Definition proto.cpp:97
roo_transceivers_ServerMessage SrvDescriptorRemoved(int key)
Removes a descriptor from the server stream.
Definition proto.cpp:47
roo_transceivers_ClientMessage ClientRequestUpdate()
Builds a client update request.
Definition proto.cpp:133
roo_collections::SmallString< 24 > SensorId
Sensor identifier (short string).
Definition id.h:16
#define roo_transceivers_ServerMessage_transceiver_update_end_tag
#define roo_transceivers_ClientMessage_init_zero
#define roo_transceivers_ServerMessage_device_modified_tag
#define roo_transceivers_ClientMessage_request_update_tag
#define roo_transceivers_ServerMessage_reading_tag
#define roo_transceivers_ClientMessage_request_state_tag
#define roo_transceivers_ServerMessage_device_added_tag
#define roo_transceivers_ServerMessage_transceiver_update_begin_tag
#define roo_transceivers_ServerMessage_device_preserved_tag
#define roo_transceivers_ServerMessage_readings_begin_tag
#define roo_transceivers_ServerMessage_init_tag
#define roo_transceivers_ServerMessage_readings_end_tag
#define roo_transceivers_ServerMessage_descriptor_removed_tag
#define roo_transceivers_ServerMessage_init_zero
#define roo_transceivers_ServerMessage_descriptor_added_tag
#define roo_transceivers_ServerMessage_device_removed_tag
#define roo_transceivers_ClientMessage_write_tag
roo_transceivers_ClientMessage_Write write
union _roo_transceivers_ClientMessage::@0 contents
roo_transceivers_ServerMessage_Reading_SensorValue sensor_values[16]
roo_transceivers_ServerMessage_DeviceAdded device_added
roo_transceivers_ServerMessage_Reading reading
roo_transceivers_ServerMessage_UpdateBegin transceiver_update_begin
roo_transceivers_ServerMessage_DeviceRemoved device_removed
roo_transceivers_ServerMessage_DescriptorRemoved descriptor_removed
roo_transceivers_ServerMessage_DescriptorAdded descriptor_added
roo_transceivers_ServerMessage_DeviceModified device_modified
union _roo_transceivers_ServerMessage::@1 contents
roo_transceivers_ServerMessage_DevicePreserved device_preserved