Skip to content

Commit a12f9e0

Browse files
committed
Added option block processing.
1 parent 09d2d5f commit a12f9e0

File tree

1 file changed

+85
-20
lines changed

1 file changed

+85
-20
lines changed

Diff for: src/eotd.c

+85-20
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void add_comma(char *text, int text_size) {
5757
strlcat(text, ",", text_size);
5858
}
5959

60-
void get_r2f_chain(uint64_t pkt, char *text, int text_size) {
60+
int get_chain(uint64_t pkt, char *text, int text_size) {
6161
uint32_t val;
6262

6363
val = pkt & 0x03ULL;
@@ -78,6 +78,8 @@ void get_r2f_chain(uint64_t pkt, char *text, int text_size) {
7878
strlcat(text, "ONLY", text_size);
7979
break;
8080
}
81+
82+
return val;
8183
}
8284

8385
void get_r2f_dev_batt_stat(uint64_t pkt, char *text, int text_size) {
@@ -250,7 +252,7 @@ void get_r2f_mkr_light_bit(uint64_t pkt, char *text, int text_size) {
250252

251253
void decode_basic_r2f(uint64_t pkt, char *text, int text_size) {
252254

253-
get_r2f_chain(pkt, text, text_size);
255+
strlcat(text, "block=BASIC", text_size);
254256
add_comma(text, text_size);
255257
get_r2f_dev_batt_stat(pkt, text, text_size);
256258
add_comma(text, text_size);
@@ -275,20 +277,6 @@ void decode_basic_r2f(uint64_t pkt, char *text, int text_size) {
275277
get_r2f_mkr_light_bit(pkt, text, text_size);
276278
}
277279

278-
void get_f2r_chain(uint64_t pkt, char *text, int text_size) {
279-
uint32_t val;
280-
281-
val = pkt & 0x03;
282-
283-
strlcat(text, "chain=", text_size);
284-
285-
if (val == 3) {
286-
strlcat(text, "VALID", text_size);
287-
} else {
288-
strlcat(text, "INVALID", text_size);
289-
}
290-
}
291-
292280
void get_f2r_msg_id_type(uint64_t pkt, char *text, int text_size) {
293281
uint32_t val;
294282

@@ -333,9 +321,18 @@ void get_f2r_command(uint64_t pkt, char *text, int text_size) {
333321
}
334322
}
335323

324+
int get_option_format(uint64_t pkt, char *text, int text_size) {
325+
uint32_t val;
326+
327+
pkt >>= 2;
328+
val = pkt & 0x01;
329+
330+
return val;
331+
}
332+
336333
void decode_basic_f2r(uint64_t pkt, char *text, int text_size) {
337334

338-
get_f2r_chain(pkt, text, text_size);
335+
strlcat(text, "block=BASIC", text_size);
339336
add_comma(text, text_size);
340337
get_f2r_msg_id_type(pkt, text, text_size);
341338
add_comma(text, text_size);
@@ -344,6 +341,62 @@ void decode_basic_f2r(uint64_t pkt, char *text, int text_size) {
344341
get_f2r_command(pkt, text, text_size);
345342
}
346343

344+
void decode_r2f_option_block(uint64_t pkt, char *text, int text_size) {
345+
346+
int indicator = get_option_format(pkt, text, text_size);
347+
if (indicator == 0) {
348+
// BINARY
349+
350+
strlcat(text, "block=OPT_BINARY", text_size);
351+
add_comma(text, text_size);
352+
353+
int type, val;
354+
char temp[32];
355+
356+
pkt >>= 3; // Skip chain and format bits
357+
358+
for (int i = 0; i < 3; i++ ) {
359+
type = pkt & 0x7f;
360+
pkt >>= 7;
361+
val = pkt & 0x7f;
362+
pkt >>= 7;
363+
364+
// 'No Data' indicator
365+
if (type == 0) {
366+
continue;
367+
}
368+
369+
sprintf(temp, "TYPE_%c=%d", 'A' + i, type);
370+
strlcat(text, temp, text_size);
371+
add_comma(text, text_size);
372+
sprintf(temp, "VALUE_%c=%d", 'A' + i, val);
373+
strlcat(text, temp, text_size);
374+
if (i != 2) add_comma(text, text_size);
375+
}
376+
} else {
377+
// ASCII
378+
strlcat(text, "block=OPT_ASCII", text_size);
379+
add_comma(text, text_size);
380+
381+
char msg[8] = { 0 };
382+
383+
pkt >>= 3; // Skip chain and format bits
384+
385+
for (int i = 0; i < 6; i++) {
386+
msg[i] = pkt & 0x7f;
387+
pkt >>= 7;
388+
}
389+
390+
strlcat(text, "message=", text_size);
391+
strlcat(text, msg, text_size);
392+
}
393+
}
394+
395+
396+
void decode_f2r_option_block(uint64_t pkt, char *text, int text_size) {
397+
strlcat(text, "TODO: F2R OPTION BLOCK", text_size);
398+
}
399+
347400
void eotd_to_text (unsigned char *eotd, int eotd_len, char *text, int text_size)
348401
{
349402
assert (eotd_len == EOTD_LENGTH + 1);
@@ -378,10 +431,22 @@ void eotd_to_text (unsigned char *eotd, int eotd_len, char *text, int text_size)
378431
strlcat(text, date_buffer, text_size);
379432
#endif
380433

381-
if (eotd_type == EOTD_TYPE_R2F) {
382-
decode_basic_r2f(pkt, text, text_size);
434+
int chain = get_chain(pkt, text, text_size);
435+
add_comma(text, text_size);
436+
437+
// check for 'first' block - it's always the basic block
438+
if (chain & 0x02) {
439+
if (eotd_type == EOTD_TYPE_R2F) {
440+
decode_basic_r2f(pkt, text, text_size);
441+
} else {
442+
decode_basic_f2r(pkt, text, text_size);
443+
}
383444
} else {
384-
decode_basic_f2r(pkt, text, text_size);
445+
if (eotd_type == EOTD_TYPE_R2F) {
446+
decode_r2f_option_block(pkt, text, text_size);
447+
} else {
448+
decode_f2r_option_block(pkt, text, text_size);
449+
}
385450
}
386451

387452
#ifdef EOTD_APPEND_HEX

0 commit comments

Comments
 (0)