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 long long 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;
57 dest->frameDataLength = api.getFrameDataLength();
58
59 memcpy(dest->frameData, api.frameData, dest->frameDataLength);
60
61 return true;
62 }
63
64 static string header() { return "timestamp,length,frame_type\n"; }
65
66 void print(std::ostream& os) const
67 {
68 os << timestamp << "," << frameDataLength << "," << frameType << "\n";
69 }
70};
71
73{
74 long long 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
99 dest->commandDataLength = at->getCommandDataLength();
100 memcpy(dest->commandData, at->getCommandDataPointer(),
101 dest->commandDataLength);
102
103 return true;
104 }
105
106 static string header() { return "timestamp,id,cmd,param_size,params\n"; }
107
108 void print(std::ostream& os) const
109 {
110 char cmd[3];
111
112 strncpy(cmd, atCommand, 2);
113 cmd[2] = '\0';
114
115 os << timestamp << "," << (int)frameId << "," << cmd << ","
116 << commandDataLength << ",";
117
118 if (commandDataLength > 0)
119 for (uint16_t i = 0; i < commandDataLength; i++)
120 os << (int)commandData[i] << " ";
121 else
122 os << "-";
123
124 os << "\n";
125 }
126};
127
129{
130 long long timestamp = 0;
131 uint8_t frameId = 0;
132
133 uint64_t destinationAddress = 0;
134
135 uint8_t broadcastRadius = 0;
136 uint8_t transmitOptions = 0;
137
138 uint8_t rfData[MAX_PACKET_PAYLOAD_LENGTH];
139 uint16_t rfDataLength = 0;
140
141 static bool toFrameType(APIFrame& api, TXRequestFrameLog* dest)
142 {
143 if (api.frameType != FTYPE_TX_REQUEST)
144 return false;
145
146 if (api.getFrameDataLength() < MIN_TX_REQUEST_FRAME_SIZE ||
147 api.getFrameDataLength() >
148 MIN_TX_REQUEST_FRAME_SIZE + MAX_PACKET_PAYLOAD_LENGTH)
149 {
150 return false;
151 }
152
154
155 dest->timestamp = api.timestamp;
156 dest->frameId = tx->getFrameID();
157
158 dest->destinationAddress = tx->getDestAddress();
159
160 dest->broadcastRadius = tx->getBroadcastRadius();
161 dest->transmitOptions = tx->getTrasmitOptions();
162
163 dest->rfDataLength = tx->getRFDataLength();
164 memcpy(dest->rfData, tx->getRFDataPointer(), dest->rfDataLength);
165
166 return true;
167 }
168
169 static string header()
170 {
171 return "timestamp,id,dest_addr,broadcast_radius,tx_options,rf_data_"
172 "len,first_uint32\n";
173 }
174
175 void print(std::ostream& os) const
176 {
177 uint32_t d;
178 memcpy(&d, rfData, sizeof(d));
179 os << timestamp << "," << (int)frameId << "," << destinationAddress
180 << "," << (int)broadcastRadius << "," << (int)transmitOptions << ","
181 << rfDataLength << "," << d << "\n";
182 }
183};
184
186{
187 long long timestamp = 0;
188 uint8_t frameId = 0;
189 char atCommand[2];
190 uint8_t commandStatus = 0;
191
192 uint8_t commandData[MAX_AT_COMMAND_RESPONSE_LENGTH];
193 uint16_t commandDataLength = 0;
194
196 {
197 if (api.frameType != FTYPE_AT_COMMAND_RESPONSE)
198 return false;
199
200 if (api.getFrameDataLength() < MIN_AT_COMMAND_FRAME_SIZE ||
201 api.getFrameDataLength() >
202 MIN_AT_COMMAND_FRAME_SIZE + MAX_AT_COMMAND_RESPONSE_LENGTH)
203 {
204 return false;
205 }
206
208
209 dest->timestamp = api.timestamp;
210 dest->frameId = at->getFrameID();
211 memcpy(dest->atCommand, at->getATCommand(), 2);
212
213 dest->commandStatus = at->getCommandStatus();
214
215 dest->commandDataLength = at->getCommandDataLength();
216 memcpy(dest->commandData, at->getCommandDataPointer(),
217 dest->commandDataLength);
218
219 return true;
220 }
221
222 static string header()
223 {
224 return "timestamp,id,cmd,status,param_size,params\n";
225 }
226
227 void print(std::ostream& os) const
228 {
229 char cmd[3];
230
231 strncpy(cmd, atCommand, 2);
232 cmd[2] = '\0';
233
234 os << timestamp << "," << (int)frameId << "," << cmd << ","
235 << (int)commandStatus << "," << commandDataLength << ",";
236
237 if (commandDataLength > 0)
238 for (uint16_t i = 0; i < commandDataLength; i++)
239 os << (int)commandData[i] << " ";
240 else
241 os << "-";
242
243 os << "\n";
244 }
245};
246
248{
249 long long timestamp = 0;
250 uint8_t modemStatus = 0;
251
252 static bool toFrameType(APIFrame& api, ModemStatusFrameLog* dest)
253 {
254 if (api.frameType != FTYPE_MODEM_STATUS)
255 return false;
256
257 if (api.getFrameDataLength() != MODEM_STATUS_FRAME_SIZE)
258 return false;
259
261
262 dest->timestamp = api.timestamp;
263 dest->modemStatus = modem->getStatus();
264
265 return true;
266 }
267
268 static string header() { return "timestamp,status\n"; }
269
270 void print(std::ostream& os) const
271 {
272 os << timestamp << "," << (int)modemStatus << "\n";
273 }
274};
275
277{
278 long long timestamp = 0;
279 uint8_t frameId = 0;
280 uint8_t txRetryCount = 0;
281 uint8_t deliveryStatus = 0;
282 uint8_t discoveryStatus = 0;
283
284 static bool toFrameType(APIFrame& api, TXStatusFrameLog* dest)
285 {
286 if (api.frameType != FTYPE_TX_STATUS)
287 return false;
288
289 if (api.getFrameDataLength() != TX_STATUS_FRAME_SIZE)
290 return false;
291
293
294 dest->timestamp = api.timestamp;
295 dest->frameId = tx->getFrameID();
296
297 dest->txRetryCount = tx->getTransmitRetryCount();
298 dest->deliveryStatus = tx->getDeliveryStatus();
299 dest->discoveryStatus = tx->getDiscoveryStatus();
300
301 return true;
302 }
303
304 static string header()
305 {
306 return "timestamp,id,tx_retries,delivery_status,discovery_status\n";
307 }
308
309 void print(std::ostream& os) const
310 {
311 os << timestamp << "," << (int)frameId << "," << (int)txRetryCount
312 << "," << (int)deliveryStatus << "," << (int)discoveryStatus << "\n";
313 }
314};
315
317{
318 long long timestamp = 0;
319
320 uint64_t sourceAddress = 0;
321
322 uint8_t receiveOptions = 0;
323
324 uint8_t rxData[MAX_PACKET_PAYLOAD_LENGTH];
325 uint16_t rxDataLength = 0;
326
327 static bool toFrameType(APIFrame& api, RXPacketFrameLog* dest)
328 {
329 if (api.frameType != FTYPE_RX_PACKET_FRAME)
330 return false;
331
332 if (api.getFrameDataLength() < MIN_RX_PACKET_FRAME_SIZE ||
333 api.getFrameDataLength() >
334 MIN_RX_PACKET_FRAME_SIZE + MAX_PACKET_PAYLOAD_LENGTH)
335 {
336 return false;
337 }
338
340
341 dest->timestamp = api.timestamp;
342 dest->sourceAddress = rx->getSourceAddress();
343
344 dest->receiveOptions = rx->getReceiveOptions();
345
346 dest->rxDataLength = rx->getRXDataLength();
347 memcpy(dest->rxData, rx->getRXDataPointer(), dest->rxDataLength);
348
349 return true;
350 }
351
352 static string header()
353 {
354 return "timestamp,src_addr,rx_options,rx_data_size,payload32_0,"
355 "payload32_1\n";
356 }
357
358 void print(std::ostream& os) const
359 {
360 uint32_t data[2];
361 memcpy(&data, rxData, min(sizeof(uint32_t) * 2, (size_t)rxDataLength));
362 os << timestamp << "," << sourceAddress << "," << (int)receiveOptions
363 << "," << rxDataLength << "," << data[0] << "," << data[1] << "\n";
364 }
365};
366
367} // namespace Xbee
368
369} // namespace Boardcore
@ FTYPE_AT_COMMAND_RESPONSE
Definition APIFrames.h:72
This file includes all the types the logdecoder script will decode.
FrameType * toFrameType()
Definition APIFrames.h:184
static bool fromAPIFrame(APIFrame &api, APIFrameLog *dest)
uint8_t frameData[FRAME_DATA_SIZE]
void print(std::ostream &os) const
static bool toFrameType(APIFrame &api, ATCommandFrameLog *dest)
void print(std::ostream &os) const
uint8_t commandData[MAX_AT_COMMAND_PARAMS_LENGTH]
uint8_t commandData[MAX_AT_COMMAND_RESPONSE_LENGTH]
static bool toFrameType(APIFrame &api, ATCommandResponseFrameLog *dest)
void print(std::ostream &os) const
void print(std::ostream &os) const
static bool toFrameType(APIFrame &api, ModemStatusFrameLog *dest)
static bool toFrameType(APIFrame &api, RXPacketFrameLog *dest)
void print(std::ostream &os) const
uint8_t rxData[MAX_PACKET_PAYLOAD_LENGTH]
void print(std::ostream &os) const
static bool toFrameType(APIFrame &api, TXRequestFrameLog *dest)
uint8_t rfData[MAX_PACKET_PAYLOAD_LENGTH]
void print(std::ostream &os) const
static bool toFrameType(APIFrame &api, TXStatusFrameLog *dest)