From 53c42b050ad9a4af81e440253910c0ab8cfc6004 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Thu, 10 Jan 2019 19:43:25 +0100 Subject: [PATCH] W433DataReciver robustness changes --- W433DataReciver.cpp | 14 ++++++++++---- W433DataReciver.h | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/W433DataReciver.cpp b/W433DataReciver.cpp index c766c32..613a4ae 100644 --- a/W433DataReciver.cpp +++ b/W433DataReciver.cpp @@ -64,8 +64,12 @@ bool W433DataReciver::reciveSync(const uint16_t elapsedTime) } else { - if(syncCount > 5) error(ERR_SYNC_FAIL); - syncCount = 0; + if(syncCount > 4 && syncFailCount < 3) ++syncFailCount; + else + { + syncCount = 0; + syncFailCount = 0; + } } if(syncCount > 10) return true; else return false; @@ -105,6 +109,8 @@ void W433DataReciver::setState(const uint8_t stateIn) state = stateIn; timesBufferIndex = 0; packetIndex = 0; + syncCount = 0; + syncFailCount = 0; } void W433DataReciver::interrupt() @@ -130,9 +136,9 @@ void W433DataReciver::interrupt() } else if(state == LOOKING_FOR_SYNC_END) { - if(elapsedTime > SYNC_TIME + 50) + if(elapsedTime > SYNC_TIME + SYNC_TIME_TOLERANCE) { - if(elapsedTime < LARGE_TIME + 50) + if(elapsedTime < LARGE_TIME - LARGE_TIME_TOLERANCE) { setState(LOOKING_FOR_SYNC); error(ERR_NO_SYNC_END); diff --git a/W433DataReciver.h b/W433DataReciver.h index 4db8e5e..bc2c30b 100644 --- a/W433DataReciver.h +++ b/W433DataReciver.h @@ -60,6 +60,7 @@ private: void* const _userData; volatile uint8_t syncCount = 0; + volatile uint8_t syncFailCount = 0; volatile uint8_t state = 0; //private functions