diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index 5a8c9a1d..66f90ef6 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -1286,6 +1286,20 @@ size_t SX128x::getPacketLength(bool update, uint8_t* offset) { return((size_t)rxBufStatus[0]); } +int16_t SX128x::getLoRaRxHeaderInfo(uint8_t* cr, bool* hasCRC) { + int16_t state = RADIOLIB_ERR_NONE; + + // check if in explicit header mode + if(this->headerType == RADIOLIB_SX128X_LORA_HEADER_IMPLICIT) { + return(RADIOLIB_ERR_WRONG_MODEM); + } + + if(cr) { *cr = this->mod->SPIgetRegValue(RADIOLIB_SX128X_REG_LORA_RX_CODING_RATE, 6, 4) >> 4; } + if(hasCRC) { *hasCRC = (this->mod->SPIgetRegValue(RADIOLIB_SX128X_REG_FEI_MSB, 4, 4) != 0); } + + return(state); +} + int16_t SX128x::fixedPacketLengthMode(uint8_t len) { return(setPacketMode(RADIOLIB_SX128X_GFSK_FLRC_PACKET_FIXED, len)); } diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 6c35f498..fe99d635 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -84,6 +84,7 @@ #define RADIOLIB_SX128X_REG_FREQ_ERROR_CORRECTION 0x093C #define RADIOLIB_SX128X_REG_LORA_SYNC_WORD_MSB 0x0944 #define RADIOLIB_SX128X_REG_LORA_SYNC_WORD_LSB 0x0945 +#define RADIOLIB_SX128X_REG_LORA_RX_CODING_RATE 0x0950 #define RADIOLIB_SX128X_REG_RANGING_FILTER_RSSI_OFFSET 0x0953 #define RADIOLIB_SX128X_REG_FEI_MSB 0x0954 #define RADIOLIB_SX128X_REG_FEI_MID 0x0955 @@ -795,6 +796,14 @@ class SX128x: public PhysicalLayer { */ size_t getPacketLength(bool update, uint8_t* offset); + /*! + \brief Get LoRa header information from last received packet. Only valid in explicit header mode. + \param cr Pointer to variable to store the coding rate. + \param hasCRC Pointer to variable to store the CRC status. + \returns \ref status_codes + */ + int16_t getLoRaRxHeaderInfo(uint8_t* cr, bool* hasCRC); + /*! \brief Set modem in fixed packet length mode. Available in GFSK mode only. \param len Packet length.