[SX127x] Fixed known binary receive length
This commit is contained in:
parent
c2cfe597cc
commit
3047409b27
2 changed files with 14 additions and 14 deletions
|
@ -496,17 +496,20 @@ int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||||
|
|
||||||
int16_t SX127x::readData(uint8_t* data, size_t len) {
|
int16_t SX127x::readData(uint8_t* data, size_t len) {
|
||||||
int16_t modem = getActiveModem();
|
int16_t modem = getActiveModem();
|
||||||
size_t length = len;
|
|
||||||
|
|
||||||
// put module to standby
|
// put module to standby
|
||||||
standby();
|
standby();
|
||||||
|
|
||||||
if(modem == RADIOLIB_SX127X_LORA) {
|
// get packet length
|
||||||
// len set to maximum indicates unknown packet length, read the number of actually received bytes
|
size_t length = getPacketLength();
|
||||||
if(len == RADIOLIB_SX127X_MAX_PACKET_LENGTH) {
|
size_t dumpLen = 0;
|
||||||
length = getPacketLength();
|
if((len != 0) && (len < length)) {
|
||||||
|
// user requested less data than we got, only return what was requested
|
||||||
|
dumpLen = length - len;
|
||||||
|
length = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(modem == RADIOLIB_SX127X_LORA) {
|
||||||
// check packet header integrity
|
// check packet header integrity
|
||||||
if(_crcEnabled && (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 6, 6)) == 0) {
|
if(_crcEnabled && (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_HOP_CHANNEL, 6, 6)) == 0) {
|
||||||
// CRC is disabled according to packet header and enabled according to user
|
// CRC is disabled according to packet header and enabled according to user
|
||||||
|
@ -523,9 +526,6 @@ int16_t SX127x::readData(uint8_t* data, size_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||||
// read packet length (always required in FSK)
|
|
||||||
length = getPacketLength();
|
|
||||||
|
|
||||||
// check address filtering
|
// check address filtering
|
||||||
uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 2, 1);
|
uint8_t filter = _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((filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_SX127X_ADDRESS_FILTERING_NODE_BROADCAST)) {
|
||||||
|
@ -536,10 +536,9 @@ int16_t SX127x::readData(uint8_t* data, size_t len) {
|
||||||
// read packet data
|
// read packet data
|
||||||
_mod->SPIreadRegisterBurst(RADIOLIB_SX127X_REG_FIFO, length, data);
|
_mod->SPIreadRegisterBurst(RADIOLIB_SX127X_REG_FIFO, length, data);
|
||||||
|
|
||||||
// dump bytes that weren't requested
|
// dump the bytes that weren't requested
|
||||||
size_t packetLength = getPacketLength();
|
if(dumpLen != 0) {
|
||||||
if(packetLength > length) {
|
clearFIFO(dumpLen);
|
||||||
clearFIFO(packetLength - length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear internal flag so getPacketLength can return the new packet length
|
// clear internal flag so getPacketLength can return the new packet length
|
||||||
|
|
|
@ -730,7 +730,8 @@ class SX127x: public PhysicalLayer {
|
||||||
|
|
||||||
\param data Pointer to array to save the received binary data.
|
\param data Pointer to array to save the received binary data.
|
||||||
|
|
||||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
\param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
|
||||||
|
When more bytes than received are requested, only the number of bytes requested will be returned.
|
||||||
|
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue