[SX126x] Start reading from Rx buffer offset

Remove setting RxBaseAddr to 0
This commit is contained in:
GUVWAF 2024-08-10 12:54:39 +02:00
parent 141bdd0998
commit 0620d8edda
2 changed files with 22 additions and 9 deletions

View file

@ -709,20 +709,17 @@ int16_t SX126x::readData(uint8_t* data, size_t len) {
if((irq & RADIOLIB_SX126X_IRQ_CRC_ERR) || (irq & RADIOLIB_SX126X_IRQ_HEADER_ERR)) {
crcState = RADIOLIB_ERR_CRC_MISMATCH;
}
// get packet length
size_t length = getPacketLength();
// get packet length and Rx buffer offset
uint8_t offset = 0;
size_t length = getPacketLength(true, &offset);
if((len != 0) && (len < length)) {
// user requested less data than we got, only return what was requested
length = len;
}
// read packet data
state = readBuffer(data, length);
RADIOLIB_ASSERT(state);
// reset the base addresses
state = setBufferBaseAddress();
// read packet data starting at offset
state = readBuffer(data, length, offset);
RADIOLIB_ASSERT(state);
// clear interrupt flags
@ -1395,6 +1392,11 @@ float SX126x::getFrequencyError() {
size_t SX126x::getPacketLength(bool update) {
(void)update;
return(this->getPacketLength(update, NULL));
}
size_t SX126x::getPacketLength(bool update, uint8_t* offset) {
(void)update;
// in implicit mode, return the cached value
if((getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA) && (this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT)) {
@ -1403,6 +1405,9 @@ size_t SX126x::getPacketLength(bool update) {
uint8_t rxBufStatus[2] = {0, 0};
this->mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2);
if(offset) { *offset = rxBufStatus[1]; }
return((size_t)rxBufStatus[0]);
}

View file

@ -952,6 +952,14 @@ class SX126x: public PhysicalLayer {
*/
size_t getPacketLength(bool update = true) override;
/*!
\brief Query modem for the packet length of received payload and Rx buffer offset.
\param update Update received packet length. Will return cached value when set to false.
\param offset Pointer to variable to store the Rx buffer offset.
\returns Length of last received packet in bytes.
*/
size_t getPacketLength(bool update, uint8_t* offset);
/*!
\brief Set modem in fixed packet length mode. Available in FSK mode only.
\param len Packet length.