Skip to content

Commit b74bda7

Browse files
committed
added logging support for better debug
1 parent 5305779 commit b74bda7

File tree

6 files changed

+40
-5
lines changed

6 files changed

+40
-5
lines changed

TF_Config.example.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ typedef uint8_t TF_COUNT;
6969
// ticks = number of calls to TF_Tick()
7070
#define TF_PARSER_TIMEOUT_TICKS 10
7171

72+
// Error reporting function. To disable debug, change to empty define
73+
#define TF_Error(format, ...) printf("[TF] " format "\n", ##__VA_ARGS__)
74+
7275
//------------------------- End of user config ------------------------------
7376

7477
#endif //TF_CONFIG_H

TinyFrame.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ bool _TF_FN TF_AddIdListener(TinyFrame *tf, TF_Msg *msg, TF_Listener cb, TF_TICK
243243
return true;
244244
}
245245
}
246+
247+
TF_Error("Failed to add ID listener");
246248
return false;
247249
}
248250

@@ -263,6 +265,8 @@ bool _TF_FN TF_AddTypeListener(TinyFrame *tf, TF_TYPE frame_type, TF_Listener cb
263265
return true;
264266
}
265267
}
268+
269+
TF_Error("Failed to add type listener");
266270
return false;
267271
}
268272

@@ -282,6 +286,8 @@ bool _TF_FN TF_AddGenericListener(TinyFrame *tf, TF_Listener cb)
282286
return true;
283287
}
284288
}
289+
290+
TF_Error("Failed to add generic listener");
285291
return false;
286292
}
287293

@@ -298,6 +304,8 @@ bool _TF_FN TF_RemoveIdListener(TinyFrame *tf, TF_ID frame_id)
298304
return true;
299305
}
300306
}
307+
308+
TF_Error("ID listener %d to remove not found", (int)frame_id);
301309
return false;
302310
}
303311

@@ -314,6 +322,8 @@ bool _TF_FN TF_RemoveTypeListener(TinyFrame *tf, TF_TYPE type)
314322
return true;
315323
}
316324
}
325+
326+
TF_Error("Type listener %d to remove not found", (int)type);
317327
return false;
318328
}
319329

@@ -330,6 +340,8 @@ bool _TF_FN TF_RemoveGenericListener(TinyFrame *tf, TF_Listener cb)
330340
return true;
331341
}
332342
}
343+
344+
TF_Error("Generic listener to remove not found");
333345
return false;
334346
}
335347

@@ -428,6 +440,8 @@ static void _TF_FN TF_HandleReceivedMessage(TinyFrame *tf)
428440
}
429441
}
430442
}
443+
444+
TF_Error("Unhandled message, type %d", (int)msg.type);
431445
}
432446

433447
//endregion Listeners
@@ -468,7 +482,10 @@ void _TF_FN TF_AcceptChar(TinyFrame *tf, unsigned char c)
468482
{
469483
// Parser timeout - clear
470484
if (tf->parser_timeout_ticks >= TF_PARSER_TIMEOUT_TICKS) {
471-
TF_ResetParser(tf);
485+
if (tf->state != TFState_SOF) {
486+
TF_ResetParser(tf);
487+
TF_Error("Parser timeout");
488+
}
472489
}
473490
tf->parser_timeout_ticks = 0;
474491

@@ -481,7 +498,7 @@ void _TF_FN TF_AcceptChar(TinyFrame *tf, unsigned char c)
481498

482499
#if !TF_USE_SOF_BYTE
483500
if (tf->state == TFState_SOF) {
484-
pars_begin_frame();
501+
pars_begin_frame(tf);
485502
}
486503
#endif
487504

@@ -532,6 +549,7 @@ void _TF_FN TF_AcceptChar(TinyFrame *tf, unsigned char c)
532549
CKSUM_FINALIZE(tf->cksum);
533550

534551
if (tf->cksum != tf->ref_cksum) {
552+
TF_Error("Rx head cksum mismatch");
535553
TF_ResetParser(tf);
536554
break;
537555
}
@@ -550,6 +568,7 @@ void _TF_FN TF_AcceptChar(TinyFrame *tf, unsigned char c)
550568
CKSUM_RESET(tf->cksum); // Start collecting the payload
551569

552570
if (tf->len > TF_MAX_PAYLOAD_RX) {
571+
TF_Error("Rx payload too long: %d", (int)tf->len);
553572
// ERROR - frame too long. Consume, but do not store.
554573
tf->discard_data = true;
555574
}
@@ -582,8 +601,12 @@ void _TF_FN TF_AcceptChar(TinyFrame *tf, unsigned char c)
582601
COLLECT_NUMBER(tf->ref_cksum, TF_CKSUM) {
583602
// Check the header checksum against the computed value
584603
CKSUM_FINALIZE(tf->cksum);
585-
if (!tf->discard_data && tf->cksum == tf->ref_cksum) {
586-
TF_HandleReceivedMessage(tf);
604+
if (!tf->discard_data) {
605+
if (tf->cksum == tf->ref_cksum) {
606+
TF_HandleReceivedMessage(tf);
607+
} else {
608+
TF_Error("Body cksum mismatch");
609+
}
587610
}
588611

589612
TF_ResetParser(tf);
@@ -847,6 +870,8 @@ bool _TF_FN TF_RenewIdListener(TinyFrame *tf, TF_ID id)
847870
return true;
848871
}
849872
}
873+
874+
TF_Error("Renew listener: not found (id %d)", (int)id);
850875
return false;
851876
}
852877

@@ -867,6 +892,7 @@ void _TF_FN TF_Tick(TinyFrame *tf)
867892
if (!lst->fn || lst->timeout == 0) continue;
868893
// count down...
869894
if (--lst->timeout == 0) {
895+
TF_Error("ID listener %d has expired", (int)lst->id);
870896
// Listener has expired
871897
cleanup_id_listener(tf, i, lst);
872898
}

TinyFrame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Upstream URL: https://github.com/MightyPork/TinyFrame
1111
*/
1212

13-
#define TF_VERSION "2.0.5"
13+
#define TF_VERSION "2.1.0"
1414

1515
//---------------------------------------------------------------------------
1616
#include <stdint.h> // for uint8_t etc

demo/multipart_tx/TF_Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ typedef uint8_t TF_COUNT;
2222
#define TF_MAX_GEN_LST 5
2323
#define TF_PARSER_TIMEOUT_TICKS 10
2424

25+
#define TF_Error(format, ...) printf("[TF] " format "\n", ##__VA_ARGS__)
26+
2527
#endif //TF_CONFIG_H

demo/simple/TF_Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ typedef uint8_t TF_COUNT;
2222
#define TF_MAX_GEN_LST 5
2323
#define TF_PARSER_TIMEOUT_TICKS 10
2424

25+
#define TF_Error(format, ...) printf("[TF] " format "\n", ##__VA_ARGS__)
26+
2527
#endif //TF_CONFIG_H

demo/socket_demo/TF_Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ typedef uint8_t TF_COUNT;
2222
#define TF_MAX_GEN_LST 5
2323
#define TF_PARSER_TIMEOUT_TICKS 10
2424

25+
#define TF_Error(format, ...) printf("[TF] " format "\n", ##__VA_ARGS__)
26+
2527
#endif //TF_CONFIG_H

0 commit comments

Comments
 (0)