Ares LoRa Firmware
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1
10
11#ifndef ARES_PACKET_H
12#define ARES_PACKET_H
13
14#include <zephyr/kernel.h>
15
19#define ARES_PACKET_HEADER_0 'A'
20
24#define ARES_PACKET_HEADER_1 'R'
25
29#define ARES_PACKET_FOOTER_0 'E'
30
34#define ARES_PACKET_FOOTER_1 'S'
35
39#define ARES_PACKET_HEADER_OVERHEAD 2
40
44#define ARES_PACKET_LEN_OVERHEAD 2
45
49#define ARES_PACKET_TYPE_OVERHEAD 1
50
54#define ARES_PACKET_ID_OVERHEAD 2
55
59#define ARES_PACKET_SEQ_CNT_OVERHEAD 1
60
64#define ARES_PACKET_PAN_ID_OVERHEAD 2
65
69#define ARES_PACKET_SRC_ID_OVERHEAD 2
70
74#define ARES_PACKET_DST_ID_OVERHEAD 2
75
79#define ARES_PACKET_PAYLOAD_TYPE_OVERHEAD 1
80
84#define ARES_PACKET_CRC_OVERHEAD 2
85
89#define ARES_PACKET_FOOTER_OVERHEAD 2
90
94#define ARES_PACKET_BROADCAST_OVERHEAD \
95 (ARES_PACKET_HEADER_OVERHEAD + ARES_PACKET_LEN_OVERHEAD + \
96 ARES_PACKET_TYPE_OVERHEAD + ARES_PACKET_ID_OVERHEAD + \
97 ARES_PACKET_SEQ_CNT_OVERHEAD + ARES_PACKET_PAN_ID_OVERHEAD + \
98 ARES_PACKET_SRC_ID_OVERHEAD + ARES_PACKET_PAYLOAD_TYPE_OVERHEAD + \
99 ARES_PACKET_CRC_OVERHEAD + ARES_PACKET_FOOTER_OVERHEAD)
100
104#define ARES_PACKET_DIRECT_OVERHEAD \
105 (ARES_PACKET_BROADCAST_OVERHEAD + ARES_PACKET_DST_ID_OVERHEAD)
106
120
130
134 union {
135 struct {
136 int64_t sec;
137 uint64_t nsec;
138 } START;
139
140 struct {
141 bool ready;
142 } HEARTBEAT;
143
144 struct {
145 uint8_t part;
146 uint8_t num_parts;
147 uint16_t log_id;
148 const char *msg;
149 size_t msg_len;
150 } LOG;
151
152 struct {
153 uint8_t part;
154 uint8_t num_parts;
155 uint16_t log_id;
156 } LOG_ACK;
158};
159
170
180
184 uint16_t pan_id;
185
189 uint16_t source_id;
190
196
201 uint16_t packet_id;
202
207
212};
213
226 int start;
227
233 int size;
234
241};
242
256int serialize_ares_packet(uint8_t *buf, size_t len,
257 const struct ares_packet *packet, uint8_t seq_num);
258
269int deserialize_ares_packet(struct ares_packet *packet, const uint8_t *buf,
270 size_t len);
271
281bool ares_packet_valid(const uint8_t *buf, size_t len);
282
294int ares_packet_present(const uint8_t *buf, size_t len,
295 struct ares_packet_info *info);
296
297#endif // ARES_PACKET_H
int serialize_ares_packet(uint8_t *buf, size_t len, const struct ares_packet *packet, uint8_t seq_num)
Function to serialize an ares packet into a buffer.
int ares_packet_present(const uint8_t *buf, size_t len, struct ares_packet_info *info)
Function to check if there is an ares packet in the buffer.
ares_packet_payload_type
Packet payload types.
Definition packet.h:111
@ ARES_PKT_PAYLOAD_HEARTBEAT
Heartbeat packet.
Definition packet.h:113
@ ARES_PKT_PAYLOAD_LOG
Log packet.
Definition packet.h:115
@ ARES_PKT_PAYLOAD_CLAIM
Claim master packet.
Definition packet.h:114
@ ARES_PKT_PAYLOAD_INVALID
Invalid packet type.
Definition packet.h:118
@ ARES_PKT_PAYLOAD_START
Start data collection packet.
Definition packet.h:112
@ ARES_PKT_PAYLOAD_LOG_ACK
Log acknowledge packet.
Definition packet.h:116
int deserialize_ares_packet(struct ares_packet *packet, const uint8_t *buf, size_t len)
Function to deserialize an ares packet from a buffer.
ares_packet_type
Ares packet types.
Definition packet.h:164
@ ARES_PKT_TYPE_INVALID
Invalid packet type.
Definition packet.h:168
@ ARES_PKT_TYPE_BROADCAST
Broadcast message to all listening nodes.
Definition packet.h:165
@ ARES_PKT_TYPE_DIRECT
Direct a packet to a specific node.
Definition packet.h:166
bool ares_packet_valid(const uint8_t *buf, size_t len)
Function to verify the packet in the buffer.
Serial buffer metadata that describes the location of a packet in a buffer, the size of the packet,...
Definition packet.h:220
int size
Definition packet.h:233
int start
Definition packet.h:226
int bytes_left
Definition packet.h:240
Payload of ares packets.
Definition packet.h:125
enum ares_packet_payload_type type
Definition packet.h:129
union ares_packet_payload::@026112377275002354333323156165115310321102177157 payload
Structured representation of an ares packet.
Definition packet.h:175
uint16_t destination_id
Definition packet.h:195
struct ares_packet_payload payload
Definition packet.h:211
uint8_t sequence_cnt
Definition packet.h:179
uint16_t source_id
Definition packet.h:189
uint16_t pan_id
Definition packet.h:184
uint16_t packet_id
Definition packet.h:201
enum ares_packet_type type
Definition packet.h:206