From 607ae1035c3a6694a4fd6c2c5b93c2faa585c099 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 22 Dec 2022 16:19:10 +0100 Subject: [PATCH] [Pager] Fixed inversion logic (#641) --- src/protocols/Pager/Pager.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/protocols/Pager/Pager.cpp b/src/protocols/Pager/Pager.cpp index 72a6ab59..cc7591d8 100644 --- a/src/protocols/Pager/Pager.cpp +++ b/src/protocols/Pager/Pager.cpp @@ -235,11 +235,16 @@ int16_t PagerClient::startReceive(RADIOLIB_PIN_TYPE pin, uint32_t addr, uint32_t // now set up the direct mode reception Module* mod = _phy->getMod(); mod->pinMode(pin, INPUT); - if(inv) { + + // set direct sync word to the frame sync word + // the logic here is inverted, because modules like SX1278 + // assume high frequency to be logic 1, which is opposite to POCSAG + if(!inv) { _phy->setDirectSyncWord(~RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD, 32); } else { _phy->setDirectSyncWord(RADIOLIB_PAGER_FRAME_SYNC_CODE_WORD, 32); } + _phy->setDirectAction(PagerClientReadBit); _phy->receiveDirect(); @@ -449,7 +454,7 @@ void PagerClient::write(uint32_t codeWord) { } // finally, check if inversion is enabled - if(!inv) { + if(inv) { change = -change; } @@ -474,10 +479,15 @@ uint32_t PagerClient::read() { codeWord |= (uint32_t)_phy->read(); // check if we need to invert bits - if(inv) { + // the logic here is inverted, because modules like SX1278 + // assume high frequency to be logic 1, which is opposite to POCSAG + if(!inv) { codeWord = ~codeWord; } + RADIOLIB_VERBOSE_PRINT("R\t"); + RADIOLIB_VERBOSE_PRINTLN(codeWord, HEX); + // TODO BCH error correction here return(codeWord); }