Merge pull request #772 from h3ndrik/func

Pager: allow manual override of function bits
This commit is contained in:
Jan Gromeš 2023-06-19 22:18:28 +02:00 committed by GitHub
commit 9c8f94668a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 18 deletions

View file

@ -364,3 +364,4 @@ RADIOLIB_ERR_RANGING_TIMEOUT LITERAL1
RADIOLIB_ERR_INVALID_PAYLOAD LITERAL1 RADIOLIB_ERR_INVALID_PAYLOAD LITERAL1
RADIOLIB_ERR_ADDRESS_NOT_FOUND LITERAL1 RADIOLIB_ERR_ADDRESS_NOT_FOUND LITERAL1
RADIOLIB_ERR_INVALID_FUNCTION LITERAL1

View file

@ -476,6 +476,11 @@
*/ */
#define RADIOLIB_ERR_ADDRESS_NOT_FOUND (-1002) #define RADIOLIB_ERR_ADDRESS_NOT_FOUND (-1002)
/*!
\brief The function code is invalid. 2 Bits only.
*/
#define RADIOLIB_ERR_INVALID_FUNCTION (-1003)
/*! /*!
\} \}
*/ */

View file

@ -55,16 +55,16 @@ int16_t PagerClient::sendTone(uint32_t addr) {
} }
#if defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_BUILD_ARDUINO)
int16_t PagerClient::transmit(String& str, uint32_t addr, uint8_t encoding) { int16_t PagerClient::transmit(String& str, uint32_t addr, uint8_t encoding, uint8_t function) {
return(PagerClient::transmit(str.c_str(), addr, encoding)); return(PagerClient::transmit(str.c_str(), addr, encoding, function));
} }
#endif #endif
int16_t PagerClient::transmit(const char* str, uint32_t addr, uint8_t encoding) { int16_t PagerClient::transmit(const char* str, uint32_t addr, uint8_t encoding, uint8_t function) {
return(PagerClient::transmit((uint8_t*)str, strlen(str), addr, encoding)); return(PagerClient::transmit((uint8_t*)str, strlen(str), addr, encoding, function));
} }
int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding) { int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding, uint8_t function) {
if(addr > RADIOLIB_PAGER_ADDRESS_MAX) { if(addr > RADIOLIB_PAGER_ADDRESS_MAX) {
return(RADIOLIB_ERR_INVALID_ADDRESS_WIDTH); return(RADIOLIB_ERR_INVALID_ADDRESS_WIDTH);
} }
@ -75,29 +75,42 @@ int16_t PagerClient::transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t
// get symbol bit length based on encoding // get symbol bit length based on encoding
uint8_t symbolLength = 0; uint8_t symbolLength = 0;
uint32_t function = 0;
if(encoding == RADIOLIB_PAGER_BCD) { if(encoding == RADIOLIB_PAGER_BCD) {
symbolLength = 4; symbolLength = 4;
function = RADIOLIB_PAGER_FUNC_BITS_NUMERIC;
} else if(encoding == RADIOLIB_PAGER_ASCII) { } else if(encoding == RADIOLIB_PAGER_ASCII) {
symbolLength = 7; symbolLength = 7;
function = RADIOLIB_PAGER_FUNC_BITS_ALPHA;
} else { } else {
return(RADIOLIB_ERR_INVALID_ENCODING); return(RADIOLIB_ERR_INVALID_ENCODING);
} }
if(len == 0) { // Automatically set function bits based on given encoding
function = RADIOLIB_PAGER_FUNC_BITS_TONE; if (function == RADIOLIB_PAGER_FUNC_AUTO) {
if(encoding == RADIOLIB_PAGER_BCD) {
function = RADIOLIB_PAGER_FUNC_BITS_NUMERIC;
} else if(encoding == RADIOLIB_PAGER_ASCII) {
function = RADIOLIB_PAGER_FUNC_BITS_ALPHA;
} else {
return(RADIOLIB_ERR_INVALID_ENCODING);
}
if(len == 0) {
function = RADIOLIB_PAGER_FUNC_BITS_TONE;
}
}
if (function > RADIOLIB_PAGER_FUNC_BITS_ALPHA) {
return(RADIOLIB_ERR_INVALID_FUNCTION);
} }
// get target position in batch (3 LSB from address determine frame position in batch) // get target position in batch (3 LSB from address determine frame position in batch)
uint8_t framePos = 2*(addr & 0x07); uint8_t framePos = 2*(addr & 0x07);
// get address that will be written into address frame // get address that will be written into address frame
uint32_t frameAddr = ((addr >> 3) << RADIOLIB_PAGER_ADDRESS_POS) | function; uint32_t frameAddr = ((addr >> 3) << RADIOLIB_PAGER_ADDRESS_POS) | (function << RADIOLIB_PAGER_FUNC_BITS_POS);
// calculate the number of 20-bit data blocks // calculate the number of 20-bit data blocks
size_t numDataBlocks = (len * symbolLength) / RADIOLIB_PAGER_MESSAGE_BITS_LENGTH; size_t numDataBlocks = (len * symbolLength) / RADIOLIB_PAGER_MESSAGE_BITS_LENGTH;
@ -347,7 +360,7 @@ int16_t PagerClient::readData(uint8_t* data, size_t* len, uint32_t* addr) {
} }
// determine the encoding from the function bits // determine the encoding from the function bits
if((cw & RADIOLIB_PAGER_FUNCTION_BITS_MASK) == RADIOLIB_PAGER_FUNC_BITS_NUMERIC) { if((cw & RADIOLIB_PAGER_FUNCTION_BITS_MASK) >> RADIOLIB_PAGER_FUNC_BITS_POS == RADIOLIB_PAGER_FUNC_BITS_NUMERIC) {
symbolLength = 4; symbolLength = 4;
} else { } else {
symbolLength = 7; symbolLength = 7;

View file

@ -46,9 +46,11 @@
#define RADIOLIB_PAGER_BCH_BITS_MASK (0x000007FFUL) #define RADIOLIB_PAGER_BCH_BITS_MASK (0x000007FFUL)
// message type functional bits // message type functional bits
#define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00UL << RADIOLIB_PAGER_FUNC_BITS_POS) #define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00)
#define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01UL << RADIOLIB_PAGER_FUNC_BITS_POS) #define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01)
#define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11UL << RADIOLIB_PAGER_FUNC_BITS_POS) #define RADIOLIB_PAGER_FUNC_BITS_ACTIVATION (0b10)
#define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11)
#define RADIOLIB_PAGER_FUNC_AUTO 0xFF
// the maximum allowed address (2^22 - 1) // the maximum allowed address (2^22 - 1)
#define RADIOLIB_PAGER_ADDRESS_MAX (2097151) #define RADIOLIB_PAGER_ADDRESS_MAX (2097151)
@ -90,9 +92,10 @@ class PagerClient {
\param str Address of Arduino string that will be transmitted. \param str Address of Arduino string that will be transmitted.
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved. \param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
\param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD. \param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD.
\param function bits (NUMERIC, TONE, ACTIVATION, ALPHANUMERIC). Allowed values 0 to 3. Defaults to auto select by specified encoding
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD); int16_t transmit(String& str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
#endif #endif
/*! /*!
@ -100,9 +103,10 @@ class PagerClient {
\param str C-string that will be transmitted. \param str C-string that will be transmitted.
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved. \param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
\param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD. \param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD.
\param function bits (NUMERIC, TONE, ACTIVATION, ALPHANUMERIC). Allowed values 0 to 3. Defaults to auto select by specified encoding
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD); int16_t transmit(const char* str, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
/*! /*!
\brief Binary transmit method. Will transmit arbitrary binary data. \brief Binary transmit method. Will transmit arbitrary binary data.
@ -110,9 +114,10 @@ class PagerClient {
\param len Length of binary data to transmit (in bytes). \param len Length of binary data to transmit (in bytes).
\param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved. \param addr Address of the destination pager. Allowed values are 0 to 2097151 - values above 2000000 are reserved.
\param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD. \param encoding Encoding to be used (BCD or ASCII). Defaults to RADIOLIB_PAGER_BCD.
\param function bits (NUMERIC, TONE, ACTIVATION, ALPHANUMERIC). Allowed values 0 to 3. Defaults to auto select by specified encoding
\returns \ref status_codes \returns \ref status_codes
*/ */
int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD); int16_t transmit(uint8_t* data, size_t len, uint32_t addr, uint8_t encoding = RADIOLIB_PAGER_BCD, uint8_t function = RADIOLIB_PAGER_FUNC_AUTO);
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
/*! /*!