From d9ea40032fb8c1c11e672be1220d0c4d711c057a Mon Sep 17 00:00:00 2001 From: Volker Christian Date: Fri, 11 Oct 2024 20:08:04 +0200 Subject: [PATCH 1/3] [LoRaWAN] Just for convenience: Add a frmPending field in --- src/protocols/LoRaWAN/LoRaWAN.cpp | 1 + src/protocols/LoRaWAN/LoRaWAN.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index 5e994c672..26471f494 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -1807,6 +1807,7 @@ int16_t LoRaWANNode::parseDownlink(uint8_t* data, size_t* len, LoRaWANEvent_t* e event->dir = RADIOLIB_LORAWAN_DOWNLINK; event->confirmed = isConfirmedDown; event->confirming = isConfirmingUp; + event->frmPending = (downlinkMsg[RADIOLIB_LORAWAN_FHDR_FCTRL_POS] & RADIOLIB_LORAWAN_FCTRL_FRAME_PENDING) != 0; event->datarate = this->channels[RADIOLIB_LORAWAN_DOWNLINK].dr; event->freq = channels[event->dir].freq / 10000.0; event->power = this->txPowerMax - this->txPowerSteps * 2; diff --git a/src/protocols/LoRaWAN/LoRaWAN.h b/src/protocols/LoRaWAN/LoRaWAN.h index 6ff198dfe..d3c5f7150 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.h +++ b/src/protocols/LoRaWAN/LoRaWAN.h @@ -504,6 +504,9 @@ struct LoRaWANEvent_t { (e.g., server downlink reply to confirmed uplink sent by user application)*/ bool confirming; + /*! \brief Whether further downlink messages are pending on the server side. */ + bool frmPending; + /*! \brief Datarate */ uint8_t datarate; From e9b6e27739007acdc890d48fef210277216feb36 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 12 Oct 2024 14:15:05 +0100 Subject: [PATCH 2/3] [SX126x] Fix FSK addresses on transmission (#1268) --- src/modules/SX126x/SX126x.cpp | 30 ++++++++++++++++++++++-------- src/modules/SX126x/SX126x.h | 5 +++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 7109d6d98..63e37939b 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -509,9 +509,6 @@ void SX126x::clearChannelScanAction() { } int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) { - // suppress unused variable warning - (void)addr; - // check packet length if(len > RADIOLIB_SX126X_MAX_PACKET_LENGTH) { return(RADIOLIB_ERR_PACKET_TOO_LONG); @@ -527,10 +524,19 @@ int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) { uint8_t modem = getPacketType(); if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, len, this->headerType, this->invertIQEnabled); + } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType, len); + + // address is taken from the register + if(this->addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) { + RADIOLIB_ASSERT(state); + state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &addr, 1); + } + } else if(modem != RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS) { return(RADIOLIB_ERR_UNKNOWN); + } RADIOLIB_ASSERT(state); @@ -617,7 +623,14 @@ int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) { int16_t SX126x::finishTransmit() { // clear interrupt flags - clearIrqStatus(); + int16_t state = clearIrqStatus(); + RADIOLIB_ASSERT(state); + + // restore the original node address + if(getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { + state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &this->nodeAddr, 1); + RADIOLIB_ASSERT(state); + } // set mode to standby to disable transmitter/RF switch return(standby()); @@ -739,14 +752,14 @@ int16_t SX126x::readData(uint8_t* data, size_t len) { // if that's the case, the first call will return "SPI command timeout error" // check the IRQ to be sure this really originated from timeout event int16_t state = this->mod->SPIcheckStream(); - if((state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) && (getIrqFlags() & RADIOLIB_SX126X_IRQ_TIMEOUT)) { + uint16_t irq = getIrqFlags(); + if((state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) && (irq & RADIOLIB_SX126X_IRQ_TIMEOUT)) { // this is definitely Rx timeout return(RADIOLIB_ERR_RX_TIMEOUT); } RADIOLIB_ASSERT(state); // check integrity CRC - uint16_t irq = getIrqFlags(); int16_t crcState = RADIOLIB_ERR_NONE; // Report CRC mismatch when there's a payload CRC error, or a header error and no valid header (to avoid false alarm from previous packet) if((irq & RADIOLIB_SX126X_IRQ_CRC_ERR) || ((irq & RADIOLIB_SX126X_IRQ_HEADER_ERR) && !(irq & RADIOLIB_SX126X_IRQ_HEADER_VALID))) { @@ -1220,7 +1233,7 @@ int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) { return(setSyncWord(syncWord, bytesLen)); } -int16_t SX126x::setNodeAddress(uint8_t nodeAddr) { +int16_t SX126x::setNodeAddress(uint8_t addr) { // check active modem if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) { return(RADIOLIB_ERR_WRONG_MODEM); @@ -1232,7 +1245,8 @@ int16_t SX126x::setNodeAddress(uint8_t nodeAddr) { RADIOLIB_ASSERT(state); // set node address - state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &nodeAddr, 1); + this->nodeAddr = addr; + state = writeRegister(RADIOLIB_SX126X_REG_NODE_ADDRESS, &addr, 1); return(state); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index a64356aaa..766e02087 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -901,10 +901,10 @@ class SX126x: public PhysicalLayer { /*! \brief Sets node address. Calling this method will also enable address filtering for node address only. - \param nodeAddr Node address to be set. + \param addr Node address to be set. \returns \ref status_codes */ - int16_t setNodeAddress(uint8_t nodeAddr); + int16_t setNodeAddress(uint8_t addr); /*! \brief Sets broadcast address. Calling this method will also enable address @@ -1263,6 +1263,7 @@ class SX126x: public PhysicalLayer { uint8_t rxBandwidth = 0, pulseShape = 0, crcTypeFSK = 0, syncWordLength = 0, addrComp = 0, whitening = 0, packetType = 0; uint16_t preambleLengthFSK = 0; float rxBandwidthKhz = 0; + uint8_t nodeAddr = 0; float dataRateMeasured = 0; From 16504803d1d5ccd4ac08627bf6d9c5e808f1ff61 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 12 Oct 2024 14:15:23 +0100 Subject: [PATCH 3/3] [SX127x] Fix FSK address handling --- src/modules/SX127x/SX127x.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 036fce836..55138aa1e 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -605,16 +605,18 @@ int16_t SX127x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) { this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT, 7, 6); } - // set packet length - if (this->packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) { - this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, len); - } - - // check address filtering + // set packet length - increased by 1 when address filter is enabled uint8_t filter = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1); - if((filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST)) { - this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, addr); + if(this->packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) { + if((filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST)) { + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, len + 1); + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, addr); + } else { + this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, len); + } + } + } // write packet to FIFO