daasiot_python
daas.hpp
Go to the documentation of this file.
1/*
2 * DaaS-IoT 2019, 2025 (@) Sebyone Srl
3 *
4 * File: daas.h
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 * If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
8 *
9 * Disclaimer of Warrant
10 * Covered Software is provided under this License on an "as is" basis, without warranty of any kind, either
11 * expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is
12 * free of defects, merchantable, fit for a particular purpose or non-infringing.
13 * The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered
14 * Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary
15 * servicing, repair, or correction.
16 * This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software
17 * is authorized under this License except under this disclaimer.
18 *
19 * Limitation of Liability
20 * Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise,
21 * shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for
22 * any direct, indirect, special, incidental, or consequential damages of any character including, without
23 * limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction,
24 * or any and all other commercial damages or losses, even if such party shall have been informed of the
25 * possibility of such damages. This limitation of liability shall not apply to liability for death or personal
26 * injury resulting from such party's negligence to the extent applicable law prohibits such limitation.
27 * Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this
28 * exclusion and limitation may not apply to You.
29 *
30 * Contributors:
31 * plogiacco@smartlab.it - initial design, implementation and documentation
32 * sebastiano.meduri@gmail.com - initial design, implementation and documentation
33 * l.grillo@sebyone.com - implementation and documentation
34 *
35 */
36
37#ifndef DAAS_H
38#define DAAS_H
39
40#include "daas_types.hpp"
41
42/* ----------------------------------------------------------------------------------------------------------- */
43
45{
46public:
49 DaasAPI(IDaasApiEvent *, const char *lhver_);
51
55
56 const char *listAvailableDrivers(); // Returns drivers list: 2.INET4;3.UART;4.MQTT
57 const char *getVersion(); // returns daas-version
58 const char *getBuildInfo(); // returns local daas-stack details
59
60 /*
61 End
62 - Releases resources and deactivates the node.
63 - Returns ERROR_NONE on success, or an error code on failure.
64 */
65 daas_error_t doEnd(); // releases resources and deactivates node
66
67 /*
68 Reset
69 - Resets the local node and clears all resources.
70 - Returns ERROR_NONE on success, or an error code on failure.
71 */
72 daas_error_t doReset(); // reset resources and restarts services
73
74 /*
75 Initialize
76 - sid_: SID of the local node
77 - din_: DIN of the local node
78 - Returns ERROR_NONE on success, or an error code on failure.
79 */
80 daas_error_t doInit(din_t sid_, din_t din_); // initializes services and resources (Real-Time or Multi-Threading, release dependent)
81
82 /*
83 Perform
84 - mode: PERFORM_CORE_NO_THREAD for real-time mode, PERFORM_CORE_THREAD for multi-threading mode
85 - Returns ERROR_NONE on success, or an error code on failure.
86 */
87 daas_error_t doPerform(performs_mode_t mode); // perform node's task ( in RT mode needs to be called cyclically)
88
89 /*
90 Enable Driver
91 - driver_id: the communication technology to enable (e.g., _LINK_INET4, _LINK_UART, _LINK_MQTT5)
92 - local_uri: the physical address of the local node
93 - Returns ERROR_NONE on success, or an error code on failure.
94 */
95 daas_error_t enableDriver(link_t driver_id, const char *local_uri); // Configure driver for network technology (links)
96
97 /*
98 Get Status
99 - Returns the status of the local node.
100 - This includes hardware version, linked channels, synchronization status, security policy, and more.
101 */
102 nodestate_t getStatus(); // returns local node's instance status
103
104 /*
105 Backup Configuration
106 - Saves the current configuration to the specified storage interface.
107 - Returns true if the backup was successful, false otherwise.
108 */
109 bool storeConfiguration(IDepot* storage_interface);
110
111 /*
112 Load Configuration
113 - Loads the configuration from the specified storage interface.
114 - Returns true if the configuration was loaded successfully, false otherwise.
115 */
116 bool loadConfiguration(IDepot* storage_interface);
117
118 /*
119 Do Statistics Reset
120 - Resets the system's statistics data.
121 - Returns true if the reset was successful, false otherwise.
122 */
124
125 /*
126 Get System Statistics
127 - label: the system code to get statistics for (e.g., _cor_dme_sended)
128 - Returns the system statistics for the given label.
129 */
131
132 /* Mapping -------------------------------------------------------------------------------------------- */
133
134 /*
135 Map: Maps a node to the local instance
136 - din: DIN of the node to map
137 - link_: the communication technology to use (e.g., _LINK_INET4, _LINK_UART, _LINK_MQTT5)
138 - suri: the physical address of the node (e.g., "192.168.1.1:2020")
139 - Returns ERROR_NONE on success, or an error code on failure.
140 */
141 daas_error_t map(din_t din); // adds new node to local instance
142 daas_error_t map(din_t din, link_t link_, const char *suri); // adds node-identifier and related physical address ( link: 1="INET4", 2="UART", 3="MQTT5")
143 daas_error_t map(din_t din, link_t link_, const char *suri, const char *skey); // adds node-identifier and related physical address ( link: 1="INET4", 2="UART", 3="MQTT5")
144
145 /*
146 Remove: Removes a node from the local instance
147 - din: DIN of the node to remove from the local instance
148 - Returns ERROR_NONE on success, or an error code on failure.
149 */
151
152 /* Availability -------------------------------------------------------------------------------------------- */
153
154 /*
155 List Nodes
156 - Returns a list of known nodes (din_t) in the local instance.
157 */
158 dinlist_t listNodes(); // Returns map entries (knows nodes) ( din1, din2, )
159
160 /*
161 Locate
162 - din_: DIN of the node to locate to be able to communicate with it.
163 - It starts a process to locate the node if it is not inside the known table.
164 - Returns ERROR_NONE if the node is known, or an error code if it is not.
165 */
167
168 /*
169 Send local node's status to remote node (din)
170 - din: DIN of the remote node to send status to
171 - Returns ERROR_NONE on success, or an error code on failure.
172 */
173 daas_error_t send_status(din_t din); // Send local status to remote node (din)
174
175 /*
176 Status
177 - din: DIN of the remote node to get status from
178 - Returns the nodestate_t of the remote node.
179 */
181
182 /*
183 Fetch
184 - din: DIN of the remote node to fetch
185 - opts: options for fetching (e.g., 0 for default, 1 for detailed)
186 - Returns the nodestate_t of the remote node after fetching.
187 - This function tries to connect to the remote node and update its status.
188 */
189 const nodestate_t& fetch(din_t din, uint16_t opts);
190
191 /*
192 Get Synced Timestamp
193 - This is the time with ATS correction to be able to communicate inside the net.
194 - Returns the synced timestamp of the local node.
195 */
197
198 /* Security -------------------------------------------------------------------------------------------- */
199
200 /*
201 Unlock
202 - din: DIN of the remote node to unlock
203 - skey: the security key to set
204 - Returns the nodestate_t of the remote node after unlocking.
205 */
206 const nodestate_t& unlock(din_t din, const char *skey);
207
208 /*
209 Set SKEY and security policy for local node
210 - skey: the security key to set
211 - policy_: the security policy to set
212 - Returns the nodestate_t of the local node after setting the security key and policy.
213 */
214 const nodestate_t& lock(const char *skey, unsigned policy_);
215
216 /* Synchronize -------------------------------------------------------------------------------------------- */
217
218 /*
219 Set the local system time on remote node <din> and synchronize ATS
220 - timezone: the timezone offset in seconds
221 - Returns the nodestate_t of the remote node after synchronization.
222 */
223 const nodestate_t& syncNode(din_t din, unsigned timezone);
224
225 /*
226 Set the local system time on remote node <din> and synchronize ATS
227 - bubble_time: time in milliseconds to wait for the synchronization to complete
228 - Returns the nodestate_t of the remote node after synchronization.
229 */
230 const nodestate_t& syncNet(din_t din, unsigned bubble_time);
231
232 /*
233 Set the maximum error allowed for ATS synchronization
234 - error: the maximum error in milliseconds
235 */
236 void setATSMaxError(int32_t error); // ATS
237
238 /* Exchange -------------------------------------------------------------------------------------------- */
239
240 /*
241 Use
242 - din: DIN of the remote node to use
243 - Returns true if the RT session was successfully started, false otherwise. (OPEN CONNECTION!!!!)
244 */
245 bool use(din_t din);
246
247 /*
248 End
249 - din: DIN of the remote node to end the RT session with
250 - Returns true if the RT session was successfully ended, false otherwise.
251 */
252 bool end(din_t din);
253
254 /*
255 Send
256 - din: DIN of the remote node to send data to
257 - outbound: pointer to the data to send
258 - size: size of the data to send
259 - Returns the size of data sent.
260 */
261 unsigned send(din_t din, unsigned char *outbound, unsigned size);
262
263 /*
264 Received
265 - din: DIN of the remote node to receive data from
266 - Returns the size of data received.
267 */
268 unsigned received(din_t din);
269
270
271 /*
272 Receive
273 - din: DIN of the remote node to receive data from
274 - inbound: reference to a variable that will hold the received data
275 - max_size: maximum size of data to receive
276 - Returns the size of data received.
277 */
278 unsigned receive(din_t din, unsigned char &inbound, unsigned max_size);
279
280 /* Transfer -------------------------------------------------------------------------------------------- */
281 /*
282 List Typesets
283 - Returns a reference to the list of user-defined typesets.
284 - The list is of type tsetlist_t, which is a Vector of typeset
285 */
287
288 /*
289 Pull
290 - din: DIN of the remote node to pull data from
291 - inboundDDO: pointer to a DDO pointer that will hold the pulled DDO
292 - Returns ERROR_NONE on success, or an error code on failure.
293 */
294 daas_error_t pull(din_t din, DDO **inboundDDO);
295
296 /*
297 Push
298 - din: DIN of the remote node to send data to
299 - outboundDDO: pointer to the DDO to send
300 - Returns ERROR_NONE on success, or an error code on failure.
301 */
302 daas_error_t push(din_t din, DDO *outboundDDO);
303
304 /*
305 Available pull
306 - din: DIN of the remote node to pull data from
307 - count: reference to a variable that will hold the number of available DDOs
308 - Returns ERROR_NONE on success, or an error code on failure.
309 */
310 daas_error_t availablesPull(din_t din, uint32_t &count);
311
312 /*
313 Adds user-defined typeset
314 - typeset_code: the code of the typeset to add
315 - typeset_size: the size of the typeset in bytes
316 - Returns ERROR_NONE on success, or an error code on failure.
317 */
318 daas_error_t addTypeset(const uint16_t typeset_code, const uint16_t typeset_size);
319
320
321 /* TEST */
322
323 /*
324 Frisbee
325 - din: DIN of the remote node to ping
326 - Returns ERROR_NONE on success, or an error code on failure.
327 */
329
330 /*
331 Frisbee ICMP
332 - din: DIN of the remote node to ping
333 - timeout: maximum time to wait for a reply (in milliseconds)
334 - retry: number of retries if no reply is received
335 - Returns ERROR_NONE on success, or an error code on failure.
336 */
337 daas_error_t frisbee_icmp(din_t din, uint32_t timeout, uint32_t retry);
338
339 /*
340 Frisbee performance test
341 - din: DIN of the remote node to ping
342 - sender_pkt_total: total number of packets to send
343 - block_size: size of each packet in bytes
344 - sender_trip_period: time period between each packet sent (in milliseconds)
345 - Returns ERROR_NONE on success, or an error code on failure.
346 */
347 daas_error_t frisbee_dperf(din_t din, uint32_t sender_pkt_total = 10, uint32_t block_size = 1024*1024, uint32_t sender_trip_period = 0);
348
349 /*
350 Frisbee performance result
351 - sender_first_timestamp: timestamp of the first packet sent by the sender
352 - local_end_timestamp: timestamp of the last packet received by the sender
353 - remote_first_timestamp: timestamp of the first packet received by the receiver
354 - remote_last_timestamp: timestamp of the last packet received by the receiver
355 - remote_pkt_counter: number of packets received by the receiver
356 - remote_data_counter: total data received by the receiver in bytes
357 */
359};
360
361#endif // DAASIOT_H
const nodestate_t & unlock(din_t din, const char *skey)
daas_error_t push(din_t din, DDO *outboundDDO)
daas_error_t frisbee_icmp(din_t din, uint32_t timeout, uint32_t retry)
nodestate_t getStatus()
unsigned send(din_t din, unsigned char *outbound, unsigned size)
daas_error_t addTypeset(const uint16_t typeset_code, const uint16_t typeset_size)
daas_error_t map(din_t din, link_t link_, const char *suri, const char *skey)
daas_error_t doEnd()
DaasAPI(IDaasApiEvent *, const char *lhver_)
daas_error_t pull(din_t din, DDO **inboundDDO)
unsigned received(din_t din)
const char * listAvailableDrivers()
const nodestate_t & fetch(din_t din, uint16_t opts)
const nodestate_t & lock(const char *skey, unsigned policy_)
unsigned receive(din_t din, unsigned char &inbound, unsigned max_size)
dinlist_t listNodes()
daas_error_t locate(din_t din)
uint64_t getSyncedTimestamp()
uint64_t getSystemStatistics(syscode_t label)
daas_error_t doPerform(performs_mode_t mode)
daas_error_t remove(din_t din)
const nodestate_t & syncNet(din_t din, unsigned bubble_time)
bool end(din_t din)
const char * getBuildInfo()
daas_error_t enableDriver(link_t driver_id, const char *local_uri)
daas_error_t doInit(din_t sid_, din_t din_)
daas_error_t doReset()
DaasAPI(IDaasApiEvent *)
daas_error_t map(din_t din, link_t link_, const char *suri)
bool loadConfiguration(IDepot *storage_interface)
bool doStatisticsReset()
daas_error_t map(din_t din)
daas_error_t send_status(din_t din)
const char * getVersion()
daas_error_t frisbee_dperf(din_t din, uint32_t sender_pkt_total=10, uint32_t block_size=1024 *1024, uint32_t sender_trip_period=0)
daas_error_t frisbee(din_t din)
const nodestate_t & status(din_t din)
bool storeConfiguration(IDepot *storage_interface)
bool use(din_t din)
tsetlist_t & listTypesets()
daas_error_t availablesPull(din_t din, uint32_t &count)
const nodestate_t & syncNode(din_t din, unsigned timezone)
dperf_info_result get_frisbee_dperf_result()
void setATSMaxError(int32_t error)
link_t
Vector< typeset_t > tsetlist_t
Node API !!!!!!!!!!!!!!
daas_error_t
syscode_t
Node API !!!!!!!!!!!!!!
uint32_t din_t
Vector< din_t > dinlist_t
performs_mode_t