roo_transceivers
API Documentation for roo_transceivers
Loading...
Searching...
No Matches
arduino_prefs_store.cpp
Go to the documentation of this file.
2
3#include <cstdio>
4
5#include "roo_backport.h"
6#include "roo_backport/string_view.h"
7
8namespace roo_transceivers {
9
10namespace {
11
12void id2key(int id, char* key) { sprintf(key, "r_%d", id); }
13
14} // namespace
15
16using Rep = char[64];
17
19 roo_prefs::Transaction t(collection_, true);
20 char skey[16];
21 id2key(key, skey);
22 Rep rep;
23 roo_prefs::ReadResult result = t.store().readObject(skey, rep);
24 if (result != roo_prefs::READ_OK) {
25 return SensorLocator();
26 }
27 return SensorLocator(roo::string_view(&rep[0], 16),
28 roo::string_view(&rep[16], 24),
29 roo::string_view(&rep[40], 24));
30}
31
33 SensorKey key, const SensorLocator& locator) {
34 roo_prefs::Transaction t(collection_);
35 char skey[16];
36 id2key(key, skey);
37 Rep rep;
38 memset(&rep[0], 0, 64);
39 strncpy(&rep[0], locator.schema().c_str(), 16);
40 strncpy(&rep[16], locator.device_id().c_str(), 24);
41 strncpy(&rep[40], locator.sensor_id().c_str(), 24);
42 t.store().writeObject(skey, rep);
43}
44
46 roo_prefs::Transaction t(collection_);
47 char skey[16];
48 id2key(key, skey);
49 t.store().clear(skey);
50}
51
53 ActuatorKey key) {
54 roo_prefs::Transaction t(collection_, true);
55 char skey[16];
56 id2key(key, skey);
57 Rep rep;
58 roo_prefs::ReadResult result = t.store().readObject(skey, rep);
59 if (result != roo_prefs::READ_OK) {
60 return ActuatorLocator();
61 }
62 return ActuatorLocator(roo::string_view(&rep[0], 16),
63 roo::string_view(&rep[16], 24),
64 roo::string_view(&rep[40], 24));
65}
66
68 ActuatorKey key, const ActuatorLocator& locator) {
69 roo_prefs::Transaction t(collection_);
70 char skey[16];
71 id2key(key, skey);
72 Rep rep;
73 memset(&rep[0], 0, 64);
74 strncpy(&rep[0], locator.schema().c_str(), 16);
75 strncpy(&rep[16], locator.device_id().c_str(), 24);
76 strncpy(&rep[40], locator.actuator_id().c_str(), 24);
77 t.store().writeObject(skey, rep);
78}
79
81 roo_prefs::Transaction t(collection_);
82 char skey[16];
83 id2key(key, skey);
84 t.store().clear(skey);
85}
86
88 roo_prefs::Transaction t(collection_, true);
89 char skey[16];
90 id2key(key, skey);
91 Rep rep;
92 roo_prefs::ReadResult result = t.store().readObject(skey, rep);
93 if (result != roo_prefs::READ_OK) {
94 return DeviceLocator();
95 }
96 return DeviceLocator(roo::string_view(&rep[0], 16),
97 roo::string_view(&rep[16], 24));
98}
99
101 DeviceKey key, const DeviceLocator& locator) {
102 roo_prefs::Transaction t(collection_);
103 char skey[16];
104 id2key(key, skey);
105 Rep rep;
106 memset(&rep[0], 0, 40);
107 strncpy(&rep[0], locator.schema().c_str(), 16);
108 strncpy(&rep[16], locator.device_id().c_str(), 24);
109 t.store().writeObject(skey, rep);
110}
111
113 roo_prefs::Transaction t(collection_);
114 char skey[16];
115 id2key(key, skey);
116 t.store().clear(skey);
117}
118
119} // 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
void setActuatorBinding(ActuatorKey key, const ActuatorLocator &locator) override
DeviceLocator getDeviceBinding(DeviceKey key) override
void setSensorBinding(SensorKey key, const SensorLocator &locator) override
ActuatorLocator getActuatorBinding(ActuatorKey key) override
SensorLocator getSensorBinding(SensorKey key) override
void setDeviceBinding(DeviceKey key, const DeviceLocator &locator) override
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
Identifies sensor within a transceiver device.
Definition id.h:57
const SensorId & sensor_id() const
Returns the sensor id.
Definition id.h:76
const DeviceSchema & schema() const
Returns the device schema.
Definition id.h:70
const DeviceId & device_id() const
Returns the device id.
Definition id.h:73