[LR11x0] Added methods for LoRaWAN compatibility

This commit is contained in:
jgromes 2024-05-08 14:55:48 +02:00
parent 2f06885f9f
commit c494b983f5
2 changed files with 66 additions and 4 deletions

View file

@ -432,10 +432,11 @@ int16_t LR11x0::finishTransmit() {
}
int16_t LR11x0::startReceive() {
return(this->startReceive(RADIOLIB_LR11X0_RX_TIMEOUT_INF, RADIOLIB_LR11X0_IRQ_RX_DONE, 0));
return(this->startReceive(RADIOLIB_LR11X0_RX_TIMEOUT_INF, RADIOLIB_LR11X0_IRQ_RX_DONE, 0, 0));
}
int16_t LR11x0::startReceive(uint32_t timeout, uint32_t irqFlags, size_t len) {
int16_t LR11x0::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) {
(void)irqMask;
(void)len;
// check active modem
@ -849,8 +850,16 @@ int16_t LR11x0::setSyncWord(uint8_t* syncWord, size_t len) {
uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
int16_t state = getPacketType(&type);
RADIOLIB_ASSERT(state);
if(type != RADIOLIB_LR11X0_PACKET_TYPE_GFSK) {
if(type == RADIOLIB_LR11X0_PACKET_TYPE_LORA) {
// with length set to 1 and LoRa modem active, assume it is the LoRa sync word
if(len > 1) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
return(setSyncWord(syncWord[0]));
} else if(type != RADIOLIB_LR11X0_PACKET_TYPE_GFSK) {
return(RADIOLIB_ERR_WRONG_MODEM);
}
// update sync word length
@ -1310,6 +1319,31 @@ RadioLibTime_t LR11x0::getTimeOnAir(size_t len) {
return(0);
}
RadioLibTime_t LR11x0::calculateRxTimeout(RadioLibTime_t timeoutUs) {
// the timeout value is given in units of 30.52 microseconds
// the calling function should provide some extra width, as this number of units is truncated to integer
RadioLibTime_t timeout = timeoutUs / 30.52;
return(timeout);
}
int16_t LR11x0::irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) {
irqFlags = RADIOLIB_LR11X0_IRQ_RX_DONE | RADIOLIB_LR11X0_IRQ_TIMEOUT; // flags that can appear in the IRQ register
irqMask = irqFlags; // on LR11x0, these are the same
return(RADIOLIB_ERR_NONE);
}
bool LR11x0::isRxTimeout() {
uint32_t irq = getIrqStatus();
bool rxTimedOut = irq & RADIOLIB_LR11X0_IRQ_TIMEOUT;
return(rxTimedOut);
}
uint8_t LR11x0::randomByte() {
uint32_t num = 0;
(void)getRandomNumber(&num);
return((uint8_t)num);
}
int16_t LR11x0::implicitHeader(size_t len) {
return(this->setHeaderType(RADIOLIB_LR11X0_LORA_HEADER_IMPLICIT, len));
}

View file

@ -843,10 +843,11 @@ class LR11x0: public PhysicalLayer {
If timeout other than infinite is set, signal will be generated on IRQ1.
\param irqFlags Sets the IRQ flags that will trigger IRQ1, defaults to RADIOLIB_LR11X0_IRQ_RX_DONE.
\param irqMask Only for PhysicalLayer compatibility, not used.
\param len Only for PhysicalLayer compatibility, not used.
\returns \ref status_codes
*/
int16_t startReceive(uint32_t timeout, uint32_t irqFlags = RADIOLIB_LR11X0_IRQ_RX_DONE, size_t len = 0);
int16_t startReceive(uint32_t timeout, uint32_t irqFlags = RADIOLIB_LR11X0_IRQ_RX_DONE, uint32_t irqMask = 0, size_t len = 0);
/*!
\brief Reads the current IRQ status.
@ -1141,6 +1142,33 @@ class LR11x0: public PhysicalLayer {
*/
RadioLibTime_t getTimeOnAir(size_t len) override;
/*!
\brief Calculate the timeout value for this specific module / series (in number of symbols or units of time)
\param timeoutUs Timeout in microseconds to listen for
\returns Timeout value in a unit that is specific for the used module
*/
RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override;
/*!
\brief Create the flags that make up RxDone and RxTimeout used for receiving downlinks
\param irqFlags The flags for which IRQs must be triggered
\param irqMask Mask indicating which IRQ triggers a DIO
\returns \ref status_codes
*/
int16_t irqRxDoneRxTimeout(uint32_t &irqFlags, uint32_t &irqMask) override;
/*!
\brief Check whether the IRQ bit for RxTimeout is set
\returns Whether RxTimeout IRQ is set
*/
bool isRxTimeout() override;
/*!
\brief Get one truly random byte from RSSI noise.
\returns TRNG byte.
*/
uint8_t randomByte();
/*!
\brief Set implicit header mode for future reception/transmission.
\param len Payload length in bytes.