Ares LoRa Firmware
Loading...
Searching...
No Matches
frame.h
Go to the documentation of this file.
1
14
15#ifndef ARES_SERIAL_FRAME_H
16#define ARES_SERIAL_FRAME_H
17
18#include <zephyr/kernel.h>
19
23#define ARES_FRAME_HEADER '^'
24
28#define ARES_FRAME_FOOTER '@'
29
33#define ARES_FRAME_HEADER_OVERHEAD UINT32_C(1)
34
38#define ARES_FRAME_TYPE_OVERHEAD UINT32_C(1)
39
43#define ARES_FRAME_LEN_OVERHEAD UINT32_C(2)
44
48#define ARES_FRAME_FOOTER_OVERHEAD UINT32_C(1)
49
53#define ARES_FRAME_OVERHEAD \
54 (uint64_t)(ARES_FRAME_HEADER_OVERHEAD + ARES_FRAME_TYPE_OVERHEAD + \
55 ARES_FRAME_LEN_OVERHEAD + ARES_FRAME_FOOTER_OVERHEAD)
56
66
89
94struct ares_frame {
99
103 union {
104 struct {
105 uint16_t setting;
106 uint32_t value;
107 bool set;
109
110 struct {
111 int64_t sec;
112 uint64_t ns;
113 uint16_t id;
114 uint16_t packet_id;
115 bool broadcast;
116 uint8_t seq_cnt;
118
119 struct {
120 uint32_t freq_hz;
121 uint16_t preamble_len;
122 uint8_t bandwidth;
123 uint8_t data_rate;
124 uint8_t coding_rate;
125 int8_t tx_pow_dbm;
126 uint8_t cad_mode;
127 uint8_t cad_symbol_num;
128 uint8_t cad_detection_peak;
129 uint8_t cad_detection_min;
131
132 struct {
133 struct {
134 uint8_t ready : 1;
135 uint8_t broadcast : 1;
136 uint8_t padding : 6;
137 } flags;
138 uint8_t tx_count;
139 uint16_t id;
141
142 struct {
143 uint8_t led;
144 uint8_t state;
145 } LED;
146
147 uint16_t CLAIM;
148
149 struct {
150 bool broadcast;
151 uint8_t tx_cnt;
152 uint8_t part;
153 uint8_t num_parts;
154 uint16_t id;
155 uint16_t log_id;
156 size_t msg_len;
157 const char *msg; // This must remain valid for
158 // the lifetime of the frame.
159 } LOG;
160
161 struct {
162 uint8_t part;
163 uint8_t num_parts;
164 uint16_t id;
165 uint16_t log_id;
167
168 struct {
169 uint32_t app;
170 uint32_t ncs;
171 uint32_t kernel;
173
174 int ACK;
175
177
178 int DBG;
179
180 struct {
181 uint16_t packet_id;
182 uint16_t src_id;
183 uint8_t seq_cnt;
185
186 uint32_t PKT_TX;
188};
189
203
210
217};
218
230int ares_serialize_frame(uint8_t *buf, size_t len,
231 const struct ares_frame *frame);
232
244int ares_deserialize_frame(struct ares_frame *frame, const uint8_t *buf,
245 size_t len);
246
258int ares_serial_frame_present(const uint8_t *buf, size_t len,
259 struct ares_frame_info *info);
260
270bool ares_check_if_frame(const uint8_t *buf, size_t len);
271
272#endif // ARES_SERIAL_FRAME_H
ares_frame_error
Frame related errors.
Definition frame.h:61
@ ARES_FRAME_ERROR_BAD_FRAME
Frame could not be deserialized.
Definition frame.h:62
@ ARES_FRAME_ERROR_NOT_IMPLEMENTED
Frame handler not implemented.
Definition frame.h:64
@ ARES_FRAME_ERROR_BAD_TYPE
Frame type not valid for reception.
Definition frame.h:63
int ares_serialize_frame(uint8_t *buf, size_t len, const struct ares_frame *frame)
Function to serialize an ares frame into a buffer.
ares_frame_type
Frame types.
Definition frame.h:71
@ ARES_FRAME_LORA_CONFIG
LoRa configuration frame.
Definition frame.h:74
@ ARES_FRAME_DBG
Debug frames, TX only.
Definition frame.h:83
@ ARES_FRAME_START
Start time frame.
Definition frame.h:73
@ ARES_FRAME_SETTING
SETTING frame.
Definition frame.h:72
@ ARES_FRAME_LOG_ACK
Log message ACK from LoRa.
Definition frame.h:79
@ ARES_FRAME_PKT_RX
Packet received, TX only.
Definition frame.h:84
@ ARES_FRAME_FRAMING_ERROR
Framing error frame. TX only.
Definition frame.h:82
@ ARES_FRAME_CLAIM
LoRa host claim frame.
Definition frame.h:77
@ ARES_FRAME_VERSION
Version information.
Definition frame.h:80
@ ARES_FRAME_LOG
Log message.
Definition frame.h:78
@ ARES_FRAME_ACK
ACK frame.
Definition frame.h:81
@ ARES_FRAME_PKT_TX
Packet transmitted, TX only.
Definition frame.h:85
@ ARES_FRAME_TYPE_INVALID
Invalid frame.
Definition frame.h:87
@ ARES_FRAME_HEARTBEAT
LoRa Heart Beat frame.
Definition frame.h:76
@ ARES_FRAME_LED
Control LED state.
Definition frame.h:75
int ares_deserialize_frame(struct ares_frame *frame, const uint8_t *buf, size_t len)
Function to deserialize an ares frame from a buffer.
bool ares_check_if_frame(const uint8_t *buf, size_t len)
Check if the frame in the buffer is valid.
int ares_serial_frame_present(const uint8_t *buf, size_t len, struct ares_frame_info *info)
Function to check if there is an ares frame in the buffer.
led
Definition led.h:32
Serial buffer metadata that describes the location of a frame in a buffer, the size of the frame,...
Definition frame.h:196
int frame_size
Definition frame.h:209
int start_index
Definition frame.h:202
int bytes_left
Definition frame.h:216
Structured representation of an ares frame.
Definition frame.h:94
struct ares_frame::@374352004270334174265237346140161256060261362272::@203254315067334021223073267021150040075101067065 HEARTBEAT
ARES_FRAME_HEARTBEAT.
enum ares_frame_error FRAMING_ERROR
ARES_FRAME_FRAMING_ERROR.
Definition frame.h:176
union ares_frame::@374352004270334174265237346140161256060261362272 payload
struct ares_frame::@374352004270334174265237346140161256060261362272::@123345237273217274012176272225135172074343367026 LORA_CONFIG
ARES_FRAME_LORA_CONFIG.
uint16_t CLAIM
ARES_FRAME_CLAIM.
Definition frame.h:147
struct ares_frame::@374352004270334174265237346140161256060261362272::@377363006262176051154052201263065200317013100346 SETTING
ARES_FRAME_SETTING.
struct ares_frame::@374352004270334174265237346140161256060261362272::@007202216350257264046200241060160134244122065363 LED
ARES_FRAME_LED.
int DBG
ARES_FRAME_DBG.
Definition frame.h:178
struct ares_frame::@374352004270334174265237346140161256060261362272::@342113245354176232372045362126071211103100144265 LOG
ARES_FRAME_LOG.
struct ares_frame::@374352004270334174265237346140161256060261362272::@104121142016223002303203034052024051250074302166 PKT_RX
ARES_FRAME_PKT_RX.
struct ares_frame::@374352004270334174265237346140161256060261362272::@075365105005327057272274234253154326200364245040 VERSION
ARES_FRAME_VERSION.
int ACK
ARES_FRAME_ACK.
Definition frame.h:174
uint32_t PKT_TX
ARES_FRAME_PKT_TX.
Definition frame.h:186
struct ares_frame::@374352004270334174265237346140161256060261362272::@123205165062376031253055366322112146373000060341 LOG_ACK
ARES_FRAME_LOG_ACK.
enum ares_frame_type type
Definition frame.h:98
struct ares_frame::@374352004270334174265237346140161256060261362272::@371051361254270065332050147031327021305323146131 START
ARES_FRAME_START.