Skyward boardcore
Loading...
Searching...
No Matches
APIFramesLog.h
Go to the documentation of this file.
1/* Copyright (c) 2021 Skyward Experimental Rocketry
2 * Author: Luca Erbetta
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include <algorithm>
26#include <cstdint>
27#include <ostream>
28#include <string>
29#include <utility>
30
31#include "APIFrames.h"
32
33using std::min;
34
35namespace Boardcore
36{
37
43namespace Xbee
44{
45
47{
48 int64_t timestamp;
49 uint8_t frameType;
51 uint8_t frameData[FRAME_DATA_SIZE];
52
53 static bool fromAPIFrame(APIFrame& api, APIFrameLog* dest)
54 {
55 dest->timestamp = api.timestamp;
56 dest->frameType = api.frameType;
58
59 memcpy(dest->frameData, api.frameData, dest->frameDataLength);
60
61 return true;
62 }
63
64 static constexpr auto reflect()
65 {
66 return STRUCT_DEF(APIFrameLog,
67 FIELD_DEF(timestamp) FIELD_DEF(frameType)
68 FIELD_DEF(frameDataLength) FIELD_DEF(frameData));
69 }
70};
71
73{
74 int32_t timestamp;
75 uint8_t frameId = 0;
76 char atCommand[2];
77
78 uint8_t commandData[MAX_AT_COMMAND_PARAMS_LENGTH];
79 uint16_t commandDataLength = 0;
80
81 static bool toFrameType(APIFrame& api, ATCommandFrameLog* dest)
82 {
83 if (api.frameType != FTYPE_AT_COMMAND)
84 return false;
85
86 if (api.getFrameDataLength() < MIN_AT_COMMAND_FRAME_SIZE ||
87 api.getFrameDataLength() >
88 MIN_AT_COMMAND_FRAME_SIZE + MAX_AT_COMMAND_PARAMS_LENGTH)
89 {
90 return false;
91 }
93
94 dest->timestamp = at->timestamp;
95 dest->frameId = at->getFrameID();
96
97 memcpy(dest->atCommand, at->getATCommand(), 2);
98
100 memcpy(dest->commandData, at->getCommandDataPointer(),
101 dest->commandDataLength);
102
103 return true;
104 }
105
106 static constexpr auto reflect()
107 {
108 return STRUCT_DEF(ATCommandFrameLog,
109 FIELD_DEF(timestamp) FIELD_DEF(frameId)
110 FIELD_DEF(atCommand) FIELD_DEF(commandData)
111 FIELD_DEF(commandDataLength));
112 }
113};
114
116{
117 int64_t timestamp = 0;
118 uint8_t frameId = 0;
119
120 uint64_t destinationAddress = 0;
121
122 uint8_t broadcastRadius = 0;
123 uint8_t transmitOptions = 0;
124
125 uint8_t rfData[MAX_PACKET_PAYLOAD_LENGTH];
126 uint16_t rfDataLength = 0;
127
128 static bool toFrameType(APIFrame& api, TXRequestFrameLog* dest)
129 {
130 if (api.frameType != FTYPE_TX_REQUEST)
131 return false;
132
133 if (api.getFrameDataLength() < MIN_TX_REQUEST_FRAME_SIZE ||
134 api.getFrameDataLength() >
135 MIN_TX_REQUEST_FRAME_SIZE + MAX_PACKET_PAYLOAD_LENGTH)
136 {
137 return false;
138 }
139
141
142 dest->timestamp = api.timestamp;
143 dest->frameId = tx->getFrameID();
144
146
149
150 dest->rfDataLength = tx->getRFDataLength();
151 memcpy(dest->rfData, tx->getRFDataPointer(), dest->rfDataLength);
152
153 return true;
154 }
155
156 static constexpr auto reflect()
157 {
158 return STRUCT_DEF(TXRequestFrameLog,
159 FIELD_DEF(timestamp) FIELD_DEF(frameId) FIELD_DEF(
161 FIELD_DEF(transmitOptions) FIELD_DEF(rfData)
162 FIELD_DEF(rfDataLength));
163 }
164};
165
167{
168 int64_t timestamp = 0;
169 uint8_t frameId = 0;
170 char atCommand[2];
171 uint8_t commandStatus = 0;
172
173 uint8_t commandData[MAX_AT_COMMAND_RESPONSE_LENGTH];
174 uint16_t commandDataLength = 0;
175
177 {
179 return false;
180
181 if (api.getFrameDataLength() < MIN_AT_COMMAND_FRAME_SIZE ||
182 api.getFrameDataLength() >
183 MIN_AT_COMMAND_FRAME_SIZE + MAX_AT_COMMAND_RESPONSE_LENGTH)
184 {
185 return false;
186 }
187
189
190 dest->timestamp = api.timestamp;
191 dest->frameId = at->getFrameID();
192 memcpy(dest->atCommand, at->getATCommand(), 2);
193
194 dest->commandStatus = at->getCommandStatus();
195
197 memcpy(dest->commandData, at->getCommandDataPointer(),
198 dest->commandDataLength);
199
200 return true;
201 }
202
203 static constexpr auto reflect()
204 {
205 return STRUCT_DEF(ATCommandResponseFrameLog,
206 FIELD_DEF(timestamp) FIELD_DEF(frameId)
207 FIELD_DEF(atCommand) FIELD_DEF(commandStatus)
208 FIELD_DEF(commandData)
209 FIELD_DEF(commandDataLength));
210 }
211};
212
214{
215 int64_t timestamp = 0;
216 uint8_t modemStatus = 0;
217
218 static bool toFrameType(APIFrame& api, ModemStatusFrameLog* dest)
219 {
220 if (api.frameType != FTYPE_MODEM_STATUS)
221 return false;
222
223 if (api.getFrameDataLength() != MODEM_STATUS_FRAME_SIZE)
224 return false;
225
227
228 dest->timestamp = api.timestamp;
229 dest->modemStatus = modem->getStatus();
230
231 return true;
232 }
233
234 static constexpr auto reflect()
235 {
236 return STRUCT_DEF(ModemStatusFrameLog,
237 FIELD_DEF(timestamp) FIELD_DEF(modemStatus));
238 }
239};
240
242{
243 int64_t timestamp = 0;
244 uint8_t frameId = 0;
245 uint8_t txRetryCount = 0;
246 uint8_t deliveryStatus = 0;
247 uint8_t discoveryStatus = 0;
248
249 static bool toFrameType(APIFrame& api, TXStatusFrameLog* dest)
250 {
251 if (api.frameType != FTYPE_TX_STATUS)
252 return false;
253
254 if (api.getFrameDataLength() != TX_STATUS_FRAME_SIZE)
255 return false;
256
258
259 dest->timestamp = api.timestamp;
260 dest->frameId = tx->getFrameID();
261
263 dest->deliveryStatus = tx->getDeliveryStatus();
265
266 return true;
267 }
268
269 static constexpr auto reflect()
270 {
271 return STRUCT_DEF(TXStatusFrameLog,
272 FIELD_DEF(timestamp) FIELD_DEF(frameId)
273 FIELD_DEF(txRetryCount) FIELD_DEF(deliveryStatus)
274 FIELD_DEF(discoveryStatus));
275 }
276};
277
279{
280 int64_t timestamp = 0;
281
282 uint64_t sourceAddress = 0;
283
284 uint8_t receiveOptions = 0;
285
286 uint8_t rxData[MAX_PACKET_PAYLOAD_LENGTH];
287 uint16_t rxDataLength = 0;
288
289 static bool toFrameType(APIFrame& api, RXPacketFrameLog* dest)
290 {
292 return false;
293
294 if (api.getFrameDataLength() < MIN_RX_PACKET_FRAME_SIZE ||
295 api.getFrameDataLength() >
296 MIN_RX_PACKET_FRAME_SIZE + MAX_PACKET_PAYLOAD_LENGTH)
297 {
298 return false;
299 }
300
302
303 dest->timestamp = api.timestamp;
304 dest->sourceAddress = rx->getSourceAddress();
305
306 dest->receiveOptions = rx->getReceiveOptions();
307
308 dest->rxDataLength = rx->getRXDataLength();
309 memcpy(dest->rxData, rx->getRXDataPointer(), dest->rxDataLength);
310
311 return true;
312 }
313
314 static constexpr auto reflect()
315 {
316 return STRUCT_DEF(RXPacketFrameLog,
317 FIELD_DEF(timestamp) FIELD_DEF(sourceAddress)
318 FIELD_DEF(receiveOptions) FIELD_DEF(rxData)
319 FIELD_DEF(rxDataLength));
320 }
321};
322
323} // namespace Xbee
324
325} // namespace Boardcore
@ FTYPE_AT_COMMAND_RESPONSE
Definition APIFrames.h:72
Driver for the VN100S IMU.
uint8_t frameData[FRAME_DATA_SIZE]
Definition APIFrames.h:143
FrameType * toFrameType()
Definition APIFrames.h:184
uint16_t getFrameDataLength() const
Definition APIFrames.h:151
static bool fromAPIFrame(APIFrame &api, APIFrameLog *dest)
uint8_t frameData[FRAME_DATA_SIZE]
static constexpr auto reflect()
uint16_t getCommandDataLength() const
Definition APIFrames.h:240
const char * getATCommand() const
Definition APIFrames.h:227
static bool toFrameType(APIFrame &api, ATCommandFrameLog *dest)
static constexpr auto reflect()
uint8_t commandData[MAX_AT_COMMAND_PARAMS_LENGTH]
uint8_t commandData[MAX_AT_COMMAND_RESPONSE_LENGTH]
static bool toFrameType(APIFrame &api, ATCommandResponseFrameLog *dest)
static constexpr auto reflect()
static bool toFrameType(APIFrame &api, ModemStatusFrameLog *dest)
uint64_t getSourceAddress() const
Definition APIFrames.h:417
uint8_t getReceiveOptions() const
Definition APIFrames.h:432
uint16_t getRXDataLength() const
Definition APIFrames.h:438
static constexpr auto reflect()
static bool toFrameType(APIFrame &api, RXPacketFrameLog *dest)
uint8_t rxData[MAX_PACKET_PAYLOAD_LENGTH]
uint16_t getRFDataLength() const
Definition APIFrames.h:340
uint8_t getBroadcastRadius() const
Definition APIFrames.h:330
uint8_t getTrasmitOptions() const
Definition APIFrames.h:334
uint64_t getDestAddress() const
Definition APIFrames.h:317
static bool toFrameType(APIFrame &api, TXRequestFrameLog *dest)
static constexpr auto reflect()
uint8_t rfData[MAX_PACKET_PAYLOAD_LENGTH]
uint8_t getDeliveryStatus() const
Definition APIFrames.h:393
uint8_t getTransmitRetryCount() const
Definition APIFrames.h:389
uint8_t getDiscoveryStatus() const
Definition APIFrames.h:397
static constexpr auto reflect()
static bool toFrameType(APIFrame &api, TXStatusFrameLog *dest)