Merge pull request #772 from h3ndrik/func
Pager: allow manual override of function bits
This commit is contained in:
commit
9c8f94668a
4 changed files with 42 additions and 18 deletions
|
@ -364,3 +364,4 @@ RADIOLIB_ERR_RANGING_TIMEOUT LITERAL1
|
|||
|
||||
RADIOLIB_ERR_INVALID_PAYLOAD LITERAL1
|
||||
RADIOLIB_ERR_ADDRESS_NOT_FOUND LITERAL1
|
||||
RADIOLIB_ERR_INVALID_FUNCTION LITERAL1
|
||||
|
|
|
@ -476,6 +476,11 @@
|
|||
*/
|
||||
#define RADIOLIB_ERR_ADDRESS_NOT_FOUND (-1002)
|
||||
|
||||
/*!
|
||||
\brief The function code is invalid. 2 Bits only.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_FUNCTION (-1003)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
|
|
@ -55,16 +55,16 @@ int16_t PagerClient::sendTone(uint32_t addr) {
|
|||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t PagerClient::transmit(String& str, uint32_t addr, uint8_t encoding) {
|
||||
return(PagerClient::transmit(str.c_str(), addr, encoding));
|
||||
int16_t PagerClient::transmit(String& str, uint32_t addr, uint8_t encoding, uint8_t function) {
|
||||
return(PagerClient::transmit(str.c_str(), addr, encoding, function));
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t PagerClient::transmit(const char* str, uint32_t addr, uint8_t encoding) {
|
||||
return(PagerClient::transmit((uint8_t*)str, strlen(str), addr, 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, 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) {
|
||||
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
|
||||
uint8_t symbolLength = 0;
|
||||
uint32_t function = 0;
|
||||
if(encoding == RADIOLIB_PAGER_BCD) {
|
||||
symbolLength = 4;
|
||||
function = RADIOLIB_PAGER_FUNC_BITS_NUMERIC;
|
||||
|
||||
} else if(encoding == RADIOLIB_PAGER_ASCII) {
|
||||
symbolLength = 7;
|
||||
function = RADIOLIB_PAGER_FUNC_BITS_ALPHA;
|
||||
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_ENCODING);
|
||||
|
||||
}
|
||||
|
||||
if(len == 0) {
|
||||
function = RADIOLIB_PAGER_FUNC_BITS_TONE;
|
||||
// Automatically set function bits based on given encoding
|
||||
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)
|
||||
uint8_t framePos = 2*(addr & 0x07);
|
||||
|
||||
// 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
|
||||
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
|
||||
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;
|
||||
} else {
|
||||
symbolLength = 7;
|
||||
|
|
|
@ -46,9 +46,11 @@
|
|||
#define RADIOLIB_PAGER_BCH_BITS_MASK (0x000007FFUL)
|
||||
|
||||
// message type functional bits
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00UL << RADIOLIB_PAGER_FUNC_BITS_POS)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01UL << RADIOLIB_PAGER_FUNC_BITS_POS)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_ALPHA (0b11UL << RADIOLIB_PAGER_FUNC_BITS_POS)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_NUMERIC (0b00)
|
||||
#define RADIOLIB_PAGER_FUNC_BITS_TONE (0b01)
|
||||
#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)
|
||||
#define RADIOLIB_PAGER_ADDRESS_MAX (2097151)
|
||||
|
@ -90,9 +92,10 @@ class PagerClient {
|
|||
\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 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
|
||||
*/
|
||||
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
|
||||
|
||||
/*!
|
||||
|
@ -100,9 +103,10 @@ class PagerClient {
|
|||
\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 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
|
||||
*/
|
||||
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.
|
||||
|
@ -110,9 +114,10 @@ class PagerClient {
|
|||
\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 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
|
||||
*/
|
||||
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)
|
||||
/*!
|
||||
|
|
Loading…
Add table
Reference in a new issue