forked from dastcvi/StrateoleXML
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTelecommand.cpp
489 lines (421 loc) · 15.7 KB
/
Telecommand.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
/*
* Telecommand.cpp
* Author: Alex St. Clair
* Created: August 2019
*
* This file contains all of the functions for parsing telecommands from the
* binary section of a Zephyr TC message. All telecommands are of the form:
*
* tc_id,param_1,param_2,...param_n;
*/
#include "Telecommand.h"
#include "XMLReader_v5.h"
// --------------------------------------------------------
// Telecommand parsing interface
// --------------------------------------------------------
TCParseStatus_t XMLReader::GetTelecommand()
{
zephyr_tc = NULL_TELECOMMAND;
// make sure there are still TCs in the buffer
if (curr_tc++ == num_tcs) {
return NO_TCs;
}
// read the telecommand number
if (!Get_uint8((uint8_t *) &zephyr_tc, 1)) {
ClearTC();
return TC_ERROR;
}
if (!ParseTelecommand(zephyr_tc)) {
ClearTC();
return TC_ERROR;
} else {
return READ_TC;
}
}
// get the telecommand parameters, if any
bool XMLReader::ParseTelecommand(uint8_t telecommand)
{
// Only telecommands with parameters are processed here;
// they are decoded into the appropriate params global variable.
switch (telecommand) {
// MCB Parameters -------------------------------------
case DEPLOYx:
if (!Get_float(&(mcbParam.deployLen),1)) return false;
break;
case DEPLOYv:
if (!Get_float(&(mcbParam.deployVel),1)) return false;
break;
case DEPLOYa:
if (!Get_float(&(mcbParam.deployAcc),1)) return false;
break;
case RETRACTx:
if (!Get_float(&(mcbParam.retractLen),1)) return false;
break;
case RETRACTv:
if (!Get_float(&(mcbParam.retractVel),1)) return false;
break;
case RETRACTa:
if (!Get_float(&(mcbParam.retractAcc),1)) return false;
break;
case DOCKx:
if (!Get_float(&(mcbParam.dockLen),1)) return false;
break;
case DOCKv:
if (!Get_float(&(mcbParam.dockVel),1)) return false;
break;
case DOCKa:
if (!Get_float(&(mcbParam.dockAcc),1)) return false;
break;
case TEMPLIMITS:
if (!Get_float(mcbParam.tempLimits,6)) return false;
break;
case TORQUELIMITS:
if (!Get_float(mcbParam.torqueLimits,2)) return false;
break;
case CURRLIMITS:
if (!Get_float(mcbParam.currLimits,2)) return false;
break;
// RATS Parameters ------------------------------------
case RATSDATAPROCTYPE:
if (!Get_uint8(&(ratsParam.data_proc_method),1)) return false;
break;
case RATSECUTEMP:
if (!Get_float(&(ratsParam.ecu_tempC),1)) return false;
break;
// LPC Parameters -------------------------------------
case SETSAMPLE:
if (!Get_uint16(&(lpcParam.samples),1)) return false;
break;
case SETWARMUPTIME:
if (!Get_uint16(&(lpcParam.warmUpTime),1)) return false;
break;
case SETCYCLETIME:
if (!Get_uint8(&(lpcParam.setCycleTime),1)) return false;
break;
case SETHGBINS:
if (!Get_uint8(lpcParam.newHGBins,24)) return false;
break;
case SETLGBINS:
if (!Get_uint8(lpcParam.newLGBins,24)) return false;
break;
case SETLASERTEMP:
if (!Get_uint8(&(lpcParam.setLaserTemp),1)) return false;
break;
case SETFLUSH:
if (!Get_uint8(&(lpcParam.lpc_flush),1)) return false;
break;
case SETSAMPLEAVG:
if (!Get_uint16(&(lpcParam.samplesToAverage),1)) return false;
break;
case SETPHA:
if (!Get_uint16(&(lpcParam.phaHiGainThreshold),1)) return false;
if (!Get_uint16(&(lpcParam.phaHiGainOffset),1)) return false;
if (!Get_uint16(&(lpcParam.phaLoGainOffset),1)) return false;
break;
case SETFLOW:
if (!Get_float(&(lpcParam.flowSetpoint),1)) return false;
break;
case SETPUMPTEMP:
if (!Get_float(&(lpcParam.pumpMinTemp),1)) return false;
break;
// DIB Parameters -------------------------------------
case FTRONTIME:
if (!Get_uint16(&(dibParam.ftrOnTime),1)) return false;
break;
case FTRCYCLETIME:
if (!Get_uint16(&(dibParam.ftrCycleTime),1)) return false;
break;
case SETDIBHKPERIOD:
if (!Get_uint16(&(dibParam.hkPeriod),1)) return false;
break;
case FTRSTATUSLIMIT:
if (!Get_uint16(&(dibParam.statusLimit),1)) return false;
break;
case RAMANLEN:
if (!Get_uint16(&(dibParam.ramanScanLength),1)) return false;
break;
case SETMEASURETYPE:
if (!Get_uint8(&(dibParam.ftrMeasureType),1)) return false;
if (!Get_uint8(&(dibParam.ftrBurstLim),1)) return false;
break;
// PIB Parameters -------------------------------------
case SETSZAMIN:
if (!Get_float(&(pibParam.szaMinimum),1)) return false;
break;
case SETPROFILESIZE:
if (!Get_float(&(pibParam.profileSize),1)) return false;
break;
case SETDOCKAMOUNT:
if (!Get_float(&(pibParam.dockAmount),1)) return false;
break;
case SETDWELLTIME:
if (!Get_uint16(&(pibParam.dwellTime),1)) return false;
break;
case SETPROFILEPERIOD:
if (!Get_uint16(&(pibParam.profilePeriod),1)) return false;
break;
case SETNUMPROFILES:
if (!Get_uint8(&(pibParam.numProfiles),1)) return false;
break;
case SETTIMETRIGGER:
if (!Get_uint32(&(pibParam.timeTrigger),1)) return false;
break;
case SETDOCKOVERSHOOT:
if (!Get_float(&(pibParam.dockOvershoot),1)) return false;
break;
case RETRYDOCK:
if (!Get_float(&(mcbParam.deployLen),1)) return false;
if (!Get_float(&(mcbParam.retractLen),1)) return false;
break;
case MANUALPROFILE:
if (!Get_float(&(pibParam.profileSize),1)) return false;
if (!Get_float(&(pibParam.dockAmount),1)) return false;
if (!Get_float(&(pibParam.dockOvershoot),1)) return false;
if (!Get_uint16(&(pibParam.dwellTime),1)) return false;
break;
case SETPREPROFILETIME:
if (!Get_uint16(&(pibParam.preprofileTime),1)) return false;
break;
case SETPUWARMUPTIME:
if (!Get_uint16(&(pibParam.warmupTime),1)) return false;
break;
case AUTOREDOCKPARAMS:
if (!Get_float(&(pibParam.autoRedockOut),1)) return false;
if (!Get_float(&(pibParam.autoRedockIn),1)) return false;
if (!Get_uint8(&(pibParam.numRedock),1)) return false;
break;
case SETMOTIONTIMEOUT:
if (!Get_uint8(&(pibParam.motionTimeout),1)) return false;
break;
case DOCKEDPROFILE:
if (!Get_uint16(&(pibParam.dockedProfileTime),1)) return false;
break;
// PU parameters --------------------------------------
case PUWARMUPCONFIGS:
if (!Get_float(&(puParam.flashT),1)) return false;
if (!Get_float(&(puParam.heater1T),1)) return false;
if (!Get_float(&(puParam.heater2T),1)) return false;
if (!Get_uint8(&(puParam.flashPower),1)) return false;
if (!Get_uint8(&(puParam.tsenPower),1)) return false;
break;
case PUPROFILECONFIGS:
if (!Get_uint32(&(puParam.profileRate),1)) return false;
if (!Get_uint32(&(puParam.dwellRate),1)) return false;
if (!Get_uint8(&(puParam.profileFLASH),1)) return false;
if (!Get_uint8(&(puParam.profileROPC),1)) return false;
if (!Get_uint8(&(puParam.profileTSEN),1)) return false;
break;
case PUDOCKEDCONFIGS:
if (!Get_uint32(&(puParam.dockedRate),1)) return false;
if (!Get_uint8(&(puParam.dockedFLASH),1)) return false;
if (!Get_uint8(&(puParam.dockedROPC),1)) return false;
if (!Get_uint8(&(puParam.dockedTSEN),1)) return false;
break;
// Messages without parameters ------------------------
default:
break;
}
return true;
}
// --------------------------------------------------------
// Telecommand parsing utilties
// --------------------------------------------------------
bool XMLReader::Get_uint8(uint8_t * ret_array, uint8_t num_elements)
{
char int_buffer[4] = {0};
unsigned int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 3; // uint8_t can have 3 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%u", &temp)) return false;
if (temp > 255) return false;
ret_array[i] = (uint8_t) temp;
}
return true;
}
bool XMLReader::Get_uint16(uint16_t * ret_array, uint8_t num_elements)
{
char int_buffer[6] = {0};
unsigned int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 5; // uint16_t can have 5 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%u", &temp)) return false;
if (temp > 65535) return false;
ret_array[i] = (uint16_t) temp;
}
return true;
}
bool XMLReader::Get_uint32(uint32_t * ret_array, uint8_t num_elements)
{
char int_buffer[11] = {0};
unsigned int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 10; // uint32_t can have 10 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%u", &temp)) return false;
ret_array[i] = temp;
}
return true;
}
bool XMLReader::Get_int8(int8_t * ret_array, uint8_t num_elements)
{
char int_buffer[5] = {0};
int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 4; // int8_t can have 4 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%d", &temp)) return false;
if (temp > 127 || temp < -128) return false;
ret_array[i] = (int8_t) temp;
}
return true;
}
bool XMLReader::Get_int16(int16_t * ret_array, uint8_t num_elements)
{
char int_buffer[7] = {0};
int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 6; // int16_t can have 6 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%d", &temp)) return false;
if (temp > 32767 || temp < -32768) return false;
ret_array[i] = (int16_t) temp;
}
return true;
}
bool XMLReader::Get_int32(int32_t * ret_array, uint8_t num_elements)
{
char int_buffer[12] = {0};
int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 11; // uint32 can have 11 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%d", &temp)) return false;
ret_array[i] = temp;
}
return true;
}
bool XMLReader::Get_float(float * ret_array, uint8_t num_elements)
{
char int_buffer[16] = {0};
float temp_float = 0.0f;
unsigned int temp = 0;
uint16_t max_index;
for (uint8_t i = 0; i < num_elements; i++) {
max_index = tc_index + 15; // 15 chars max
temp = 0;
while (tc_index <= max_index && tc_index < tc_length) {
if (',' == tc_buffer[tc_index] || ';' == tc_buffer[tc_index] || '\0' == tc_buffer[tc_index]) {
break;
}
int_buffer[temp++] = tc_buffer[tc_index++];
}
int_buffer[temp] = '\0';
// ensure next char is ',' or ';' (if the last element) and move the index past it
if (',' == tc_buffer[tc_index] || (';' == tc_buffer[tc_index] && i == (num_elements - 1))) {
tc_index++;
} else {
return false;
}
// convert the message id
if (1 != sscanf(int_buffer, "%f", &temp_float)) return false;
ret_array[i] = temp_float;
}
return true;
}
// clears the rest of an errant TC
void XMLReader::ClearTC()
{
while (tc_index < tc_length && ';' != tc_buffer[tc_index++]);
}