From d15cc3e12a87f97f56b1076efc43c418ba8f4456 Mon Sep 17 00:00:00 2001 From: Dave Marples Date: Fri, 20 Sep 2024 22:44:09 +0100 Subject: [PATCH] Add COBS draining state to ensure fast resync --- Inc/cobs.h | 3 ++- Src/cobs.c | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Inc/cobs.h b/Inc/cobs.h index 2b0827f7..a4199186 100644 --- a/Inc/cobs.h +++ b/Inc/cobs.h @@ -26,7 +26,8 @@ extern "C" { enum COBSPumpState { COBS_IDLE, - COBS_RXING + COBS_RXING, + COBS_DRAINING }; struct Frame diff --git a/Src/cobs.c b/Src/cobs.c index be1c2930..36f4ae17 100644 --- a/Src/cobs.c +++ b/Src/cobs.c @@ -132,6 +132,14 @@ void COBSPump( struct COBS *t, const uint8_t *incoming, int len, break; + case COBS_DRAINING: // --------------------------------------------------------------- + if ( COBS_SYNC_CHAR == *fp ) + { + t->s = COBS_IDLE; + } + + break; + case COBS_RXING: // ------------------------------------------------------------------- t->intervalCount--; @@ -160,7 +168,7 @@ void COBSPump( struct COBS *t, const uint8_t *incoming, int len, if ( ( t->f.len > COBS_MAX_PACKET_LEN ) || ( COBS_SYNC_CHAR == *fp ) ) { t->error++; - t->s = COBS_IDLE; + t->s = COBS_DRAINING; } else {