From a848cf281b6f4fe5475bf94cfc6b942792d741f9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 14 Nov 2022 21:19:16 +0100 Subject: [PATCH] [Pager] Added option to retrieve matched address on reception --- src/protocols/Pager/Pager.cpp | 13 ++++++++----- src/protocols/Pager/Pager.h | 8 ++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/protocols/Pager/Pager.cpp b/src/protocols/Pager/Pager.cpp index 73d0ef5d..90ddaa59 100644 --- a/src/protocols/Pager/Pager.cpp +++ b/src/protocols/Pager/Pager.cpp @@ -244,7 +244,7 @@ size_t PagerClient::available() { return(_phy->available() + sizeof(uint32_t))/(sizeof(uint32_t) * (RADIOLIB_PAGER_BATCH_LEN + 1)); } -int16_t PagerClient::readData(String& str, size_t len) { +int16_t PagerClient::readData(String& str, size_t len, uint32_t* addr) { int16_t state = RADIOLIB_ERR_NONE; // determine the message length, based on user input or the amount of received data @@ -265,7 +265,7 @@ int16_t PagerClient::readData(String& str, size_t len) { #endif // read the received data - state = readData(data, &length); + state = readData(data, &length, addr); if(state == RADIOLIB_ERR_NONE) { // check tone-only tramsissions @@ -289,7 +289,7 @@ int16_t PagerClient::readData(String& str, size_t len) { return(state); } -int16_t PagerClient::readData(uint8_t* data, size_t* len) { +int16_t PagerClient::readData(uint8_t* data, size_t* len, uint32_t* addr) { // find the correct address bool match = false; uint8_t framePos = 0; @@ -316,10 +316,13 @@ int16_t PagerClient::readData(uint8_t* data, size_t* len) { } // should be an address code word, extract the address - uint32_t addr = ((cw & RADIOLIB_PAGER_ADDRESS_BITS_MASK) >> (RADIOLIB_PAGER_ADDRESS_POS - 3)) | (framePos/2); - if((addr & _filterMask) == (_filterAddr & _filterMask)) { + uint32_t addr_found = ((cw & RADIOLIB_PAGER_ADDRESS_BITS_MASK) >> (RADIOLIB_PAGER_ADDRESS_POS - 3)) | (framePos/2); + if((addr_found & _filterMask) == (_filterAddr & _filterMask)) { // we have a match! match = true; + if(addr) { + *addr = addr_found; + } // determine the encoding from the function bits if((cw & RADIOLIB_PAGER_FUNCTION_BITS_MASK) == RADIOLIB_PAGER_FUNC_BITS_NUMERIC) { diff --git a/src/protocols/Pager/Pager.h b/src/protocols/Pager/Pager.h index 21a71eb8..6a831b9e 100644 --- a/src/protocols/Pager/Pager.h +++ b/src/protocols/Pager/Pager.h @@ -166,9 +166,11 @@ class PagerClient { \param len Expected number of characters in the message. When set to 0, the message length will be retreived automatically. When more bytes than received are requested, only the number of bytes requested will be returned. + \param addr Pointer to variable holding the address of the received pager message. Set to NULL to not retrieve address. + \returns \ref status_codes */ - int16_t readData(String& str, size_t len = 0); + int16_t readData(String& str, size_t len = 0, uint32_t* addr = NULL); /*! \brief Reads data that was received after calling startReceive method. @@ -179,9 +181,11 @@ class PagerClient { When more bytes than received are requested, only the number of bytes requested will be returned. Upon completion, the number of bytes received will be written to this variable. + \param addr Pointer to variable holding the address of the received pager message. Set to NULL to not retrieve address. + \returns \ref status_codes */ - int16_t readData(uint8_t* data, size_t* len); + int16_t readData(uint8_t* data, size_t* len, uint32_t* addr = NULL); #if !defined(RADIOLIB_GODMODE) private: