pull/1275/head
StevenCellist 2024-10-14 12:29:50 +02:00
commit 94d5d59d80
5 zmienionych plików z 39 dodań i 18 usunięć

Wyświetl plik

@ -509,9 +509,6 @@ void SX126x::clearChannelScanAction() {
} }
int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) { int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
// suppress unused variable warning
(void)addr;
// check packet length // check packet length
if(len > RADIOLIB_SX126X_MAX_PACKET_LENGTH) { if(len > RADIOLIB_SX126X_MAX_PACKET_LENGTH) {
return(RADIOLIB_ERR_PACKET_TOO_LONG); 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(); uint8_t modem = getPacketType();
if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) { if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, len, this->headerType, this->invertIQEnabled); state = setPacketParams(this->preambleLengthLoRa, this->crcTypeLoRa, len, this->headerType, this->invertIQEnabled);
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) { } else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType, len); 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) { } else if(modem != RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS) {
return(RADIOLIB_ERR_UNKNOWN); return(RADIOLIB_ERR_UNKNOWN);
} }
RADIOLIB_ASSERT(state); 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() { int16_t SX126x::finishTransmit() {
// clear interrupt flags // 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 // set mode to standby to disable transmitter/RF switch
return(standby()); 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" // 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 // check the IRQ to be sure this really originated from timeout event
int16_t state = this->mod->SPIcheckStream(); 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 // this is definitely Rx timeout
return(RADIOLIB_ERR_RX_TIMEOUT); return(RADIOLIB_ERR_RX_TIMEOUT);
} }
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// check integrity CRC // check integrity CRC
uint16_t irq = getIrqFlags();
int16_t crcState = RADIOLIB_ERR_NONE; 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) // 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))) { 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)); return(setSyncWord(syncWord, bytesLen));
} }
int16_t SX126x::setNodeAddress(uint8_t nodeAddr) { int16_t SX126x::setNodeAddress(uint8_t addr) {
// check active modem // check active modem
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) { if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
return(RADIOLIB_ERR_WRONG_MODEM); return(RADIOLIB_ERR_WRONG_MODEM);
@ -1232,7 +1245,8 @@ int16_t SX126x::setNodeAddress(uint8_t nodeAddr) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set node address // 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); return(state);
} }

Wyświetl plik

@ -901,10 +901,10 @@ class SX126x: public PhysicalLayer {
/*! /*!
\brief Sets node address. Calling this method will also enable address filtering for node address only. \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 \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 \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; uint8_t rxBandwidth = 0, pulseShape = 0, crcTypeFSK = 0, syncWordLength = 0, addrComp = 0, whitening = 0, packetType = 0;
uint16_t preambleLengthFSK = 0; uint16_t preambleLengthFSK = 0;
float rxBandwidthKhz = 0; float rxBandwidthKhz = 0;
uint8_t nodeAddr = 0;
float dataRateMeasured = 0; float dataRateMeasured = 0;

Wyświetl plik

@ -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); this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO0_PACK_PACKET_SENT, 7, 6);
} }
// set packet length // set packet length - increased by 1 when address filter is enabled
if (this->packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) {
this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, len);
}
// check address filtering
uint8_t filter = this->mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1); 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)) { if(this->packetLengthConfig == RADIOLIB_SX127X_PACKET_VARIABLE) {
this->mod->SPIwriteRegister(RADIOLIB_SX127X_REG_FIFO, addr); 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 // write packet to FIFO

Wyświetl plik

@ -1807,6 +1807,7 @@ int16_t LoRaWANNode::parseDownlink(uint8_t* data, size_t* len, LoRaWANEvent_t* e
event->dir = RADIOLIB_LORAWAN_DOWNLINK; event->dir = RADIOLIB_LORAWAN_DOWNLINK;
event->confirmed = isConfirmedDown; event->confirmed = isConfirmedDown;
event->confirming = isConfirmingUp; 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->datarate = this->channels[RADIOLIB_LORAWAN_DOWNLINK].dr;
event->freq = channels[event->dir].freq / 10000.0; event->freq = channels[event->dir].freq / 10000.0;
event->power = this->txPowerMax - this->txPowerSteps * 2; event->power = this->txPowerMax - this->txPowerSteps * 2;

Wyświetl plik

@ -504,6 +504,9 @@ struct LoRaWANEvent_t {
(e.g., server downlink reply to confirmed uplink sent by user application)*/ (e.g., server downlink reply to confirmed uplink sent by user application)*/
bool confirming; bool confirming;
/*! \brief Whether further downlink messages are pending on the server side. */
bool frmPending;
/*! \brief Datarate */ /*! \brief Datarate */
uint8_t datarate; uint8_t datarate;