Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jgromes/RadioLib
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenCellist committed Oct 14, 2024
2 parents 3633391 + 1650480 commit 94d5d59
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
30 changes: 22 additions & 8 deletions src/modules/SX126x/SX126x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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))) {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions src/modules/SX126x/SX126x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
18 changes: 10 additions & 8 deletions src/modules/SX127x/SX127x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/protocols/LoRaWAN/LoRaWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/protocols/LoRaWAN/LoRaWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 94d5d59

Please sign in to comment.