daasiot_python
daas_types.hpp
Go to the documentation of this file.
1/*
2 * DaaS-IoT 2019, 2025 (@) Sebyone Srl
3 *
4 * File: daas-types.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_TYPES_H__
38#define _DAAS_TYPES_H__
39
40#include <stdint.h>
41
42typedef uint64_t stime_t; // Time-stamp absolute date (64bit) !!!!!!!!!!!!!!! SYSTEM RESOURCE
43typedef uint32_t din_t; // DIN (32bit, 0 NULL, )
44typedef uint16_t typeset_t; // Typeset (16bit)
45
46class DDO
47{
48public:
49 DDO();
50 DDO(typeset_t typeset_);
51 DDO(typeset_t typeset_, stime_t timestamp_);
52 DDO(const DDO &ddo_);
54
55 DDO *getDDO() { return this; }
56
60 void setTimestamp(stime_t tstamp);
61
65
66 uint32_t setPayload(const void *data_, uint32_t size_);
67 uint32_t getPayloadSize(void) { return _size; }
68 uint32_t getPayloadAsBinary(uint8_t *pbuffer_, unsigned offset_, uint32_t maxSize_);
69 uint32_t allocatePayload(uint32_t size_);
70 uint32_t appendPayloadData(const void *data_, uint32_t size_);
72
73 inline uint8_t *getPayloadPtr() { return _payload; }
74private:
75 typeset_t _typeset = 0; // Typeset (16bit)
76 stime_t _timestamp = 0; // Time-stamp absolute system's date and time (64bit)
77 uint32_t _size = 0;
78 uint32_t _data_offset = 0;
79 uint8_t *_payload = nullptr;
80 din_t _origin = 0; // DIN origin (32bit)
81};
82
83template <typename T>
84class Vector
85{
86private:
87 T* m_data;
88 unsigned int m_size;
89 unsigned int m_capacity;
90
91public:
92 explicit Vector(uint32_t initialCapacity);
95
96 uint32_t size() const;
97 uint32_t capacity() const;
98
99 bool pop_back();
100 bool empty() const;
101 bool push_back(const T& value);
102 bool reserve(uint32_t newCapacity);
103
104 T& at(uint32_t idx);
105 T& operator[](uint32_t index);
106 const T& operator[](uint32_t index) const;
107
108 void clear();
109};
110
112{
113public:
114 virtual ~IDaasApiEvent() = default;
115 virtual void dinAcceptedEvent(din_t) = 0;
116 virtual void ddoReceivedEvent(int payload_size, typeset_t, din_t) = 0;
117 virtual void frisbeeReceivedEvent(din_t) = 0;
118 virtual void nodeStateReceivedEvent(din_t) = 0;
119 virtual void atsSyncCompleted(din_t) = 0;
120 virtual void frisbeeDperfCompleted(din_t, uint32_t packets_sent, uint32_t block_size)= 0;
121};
122
124{
125public:
126 virtual ~DaaSEvent() = default;
127 virtual int daasEvent(int, int, int, int) = 0;
128};
129
130// Interface used to implement device specific storage handler to backup/restore
131// the library configuration to a non-volatile memory.
133{
134public:
135 virtual bool open(bool read_mode) = 0; // Open the partition handler
136 virtual bool close() = 0; // Close the partition handler
137 virtual bool clearSpace() = 0; // Deletes all the record saved
138 virtual bool getSpaceInfo() = 0; // Get how much space is left on the device
139 virtual bool trash(unsigned oKey) = 0; // Trash a specific entry
140 virtual unsigned save(unsigned oKey, unsigned char *pdata, unsigned dsize) = 0; // Save map to buffer (BINARY/XML/JSON)
141 virtual unsigned load(unsigned oKey, unsigned char *pdata, unsigned npartsize) = 0; // Load map data from buffer (BINARY/XML/JSON)
142};
143
144
153
154typedef struct
155{
156 stime_t lasttime; // time reference
157 uint32_t hwver; // platform (hard-coded)
158 uint32_t linked; // channels counter (0=not linked)
159 uint32_t in_sync; // synchronization status (0=not in sync)
160 uint32_t lock; // required security policy
161 uint8_t sklen; // security phrase lenght
162 uint8_t skey[14]; // security phrase (UTF-8)
163 uint32_t form; // data formatting model
164 uint32_t codec; // data encryption level
165
166 bool accept_all_requests; // ENABLE code to call unknowDIN()
167
168 int64_t oCap_i; // ATS
169 uint64_t on_time; // time since power on (ms)
170
171 // Availabe data ??
173
177
194
195/* DRIVER TYPES */
196typedef enum : unsigned // Supported communications technologies
197{
198 _LINK_NONE = 0, // ND
199 _LINK_DAAS, // DaaS routing & loopback
200 _LINK_INET4, // Inet/IP
201 _LINK_BT, // Bluetooth
202 _LINK_MQTT5, // MQTT
203 _LINK_UART, // Serial line
204} link_t;
205
211
234
235#endif // !_DAAS_TYPES_H__
DDO * getDDO()
void setOrigin(din_t)
DDO(typeset_t typeset_, stime_t timestamp_)
void setTimestamp(stime_t tstamp)
void clearPayload()
void setTypeset(typeset_t)
~DDO()
uint32_t getPayloadSize(void)
uint32_t setPayload(const void *data_, uint32_t size_)
DDO(typeset_t typeset_)
uint32_t allocatePayload(uint32_t size_)
din_t getOrigin()
DDO(const DDO &ddo_)
uint32_t appendPayloadData(const void *data_, uint32_t size_)
uint8_t * getPayloadCurrentPositionPointer()
stime_t getTimestamp()
uint8_t * getPayloadPtr()
uint32_t getPayloadAsBinary(uint8_t *pbuffer_, unsigned offset_, uint32_t maxSize_)
typeset_t getTypeset()
virtual ~DaaSEvent()=default
virtual int daasEvent(int, int, int, int)=0
virtual void nodeStateReceivedEvent(din_t)=0
virtual void frisbeeDperfCompleted(din_t, uint32_t packets_sent, uint32_t block_size)=0
virtual void ddoReceivedEvent(int payload_size, typeset_t, din_t)=0
virtual void dinAcceptedEvent(din_t)=0
virtual void atsSyncCompleted(din_t)=0
virtual void frisbeeReceivedEvent(din_t)=0
virtual ~IDaasApiEvent()=default
virtual bool open(bool read_mode)=0
virtual bool trash(unsigned oKey)=0
virtual unsigned save(unsigned oKey, unsigned char *pdata, unsigned dsize)=0
virtual bool close()=0
virtual bool getSpaceInfo()=0
virtual bool clearSpace()=0
virtual unsigned load(unsigned oKey, unsigned char *pdata, unsigned npartsize)=0
bool pop_back()
uint32_t size() const
void clear()
const T & operator[](uint32_t index) const
Vector(uint32_t initialCapacity)
bool reserve(uint32_t newCapacity)
uint32_t capacity() const
bool push_back(const T &value)
T & operator[](uint32_t index)
bool empty() const
T & at(uint32_t idx)
link_t
@ _LINK_MQTT5
@ _LINK_INET4
@ _LINK_NONE
@ _LINK_DAAS
@ _LINK_UART
@ _LINK_BT
uint64_t stime_t
uint16_t typeset_t
Vector< typeset_t > tsetlist_t
Node API !!!!!!!!!!!!!!
Vector< int > list_element
daas_error_t
@ ERROR_CORE_STOPPED
@ ERROR_INVALID_DME
@ ERROR_THREADS_ALREADY_STARTED
@ ERROR_CANNOT_INITIALIZE
@ ERROR_INVALID_USER_TYPESET
@ ERROR_ATS_NOT_SYNCED
@ ERROR_UNKNOWN
@ ERROR_NONE
@ ERROR_CANNOT_MAP_NODE
@ ERROR_NO_DDO_PRESENT
@ ERROR_DIN_UNKNOWN
@ ERROR_CHANNEL_FAILURE
@ ERROR_NOT_IMPLEMENTED
@ ERROR_CORE_ALREADY_INITIALIZED
@ ERROR_CANNOT_CREATE_NODE
@ ERROR_SEND_DDO
@ ERROR_DIN_ALREADY_EXIST
syscode_t
Node API !!!!!!!!!!!!!!
@ _ats_delta_avg
@ ___undefined
@ _cor_rx_buffer
@ _cor_dme_received
@ _ats_msg_decoded
@ _cor_tx_buffer
@ _ats_msg_encoded
@ _ats_sync_counter
@ _cor_dme_sended
uint32_t din_t
Vector< din_t > dinlist_t
performs_mode_t
@ PERFORM_CORE_NO_THREAD
@ PERFORM_CORE_THREAD
uint64_t sender_first_timestamp
uint64_t remote_last_timestamp
uint64_t remote_first_timestamp
uint64_t local_end_timestamp
uint64_t remote_data_counter
uint64_t remote_pkt_counter
uint32_t codec
uint64_t on_time
uint8_t skey[14]
uint32_t hwver
stime_t lasttime
uint8_t sklen
uint32_t in_sync
uint32_t lock
int64_t oCap_i
bool accept_all_requests
uint32_t linked
uint32_t form