From 2125dfe2766d8ed7be27a862e19b5e5007700b70 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 26 Sep 2021 17:45:35 +0200 Subject: [PATCH] [PHY] Added option to disable sync word matching (#337) --- src/protocols/PhysicalLayer/PhysicalLayer.cpp | 15 ++++++++++++--- src/protocols/PhysicalLayer/PhysicalLayer.h | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.cpp b/src/protocols/PhysicalLayer/PhysicalLayer.cpp index d32670a7..95a39901 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.cpp +++ b/src/protocols/PhysicalLayer/PhysicalLayer.cpp @@ -193,18 +193,27 @@ int16_t PhysicalLayer::available() { } uint8_t PhysicalLayer::read() { - _gotSync = false; - _syncBuffer = 0; + if(_directSyncWordLen > 0) { + _gotSync = false; + _syncBuffer = 0; + } _bufferWritePos--; return(_buffer[_bufferReadPos++]); } int16_t PhysicalLayer::setDirectSyncWord(uint32_t syncWord, uint8_t len) { - if((len > 32) || (len == 0)) { + if(len > 32) { return(ERR_INVALID_SYNC_WORD); } _directSyncWordMask = 0xFFFFFFFF >> (32 - len); + _directSyncWordLen = len; _directSyncWord = syncWord; + + // override sync word matching when length is set to 0 + if(_directSyncWordLen == 0) { + _gotSync = true; + } + return(ERR_NONE); } diff --git a/src/protocols/PhysicalLayer/PhysicalLayer.h b/src/protocols/PhysicalLayer/PhysicalLayer.h index 7e910f11..8b91d530 100644 --- a/src/protocols/PhysicalLayer/PhysicalLayer.h +++ b/src/protocols/PhysicalLayer/PhysicalLayer.h @@ -264,7 +264,7 @@ class PhysicalLayer { \param syncWord Sync word bits. - \param len Sync word length in bits. + \param len Sync word length in bits. Set to zero to disable sync word matching. \returns \ref status_codes */ @@ -313,6 +313,7 @@ class PhysicalLayer { uint8_t _buffer[RADIOLIB_STATIC_ARRAY_SIZE]; uint32_t _syncBuffer; uint32_t _directSyncWord; + uint8_t _directSyncWordLen; uint32_t _directSyncWordMask; bool _gotSync; };