[SX126x] Implemented getPacketLength
This commit is contained in:
parent
94301c9043
commit
5527573692
3 changed files with 39 additions and 32 deletions
|
@ -56,6 +56,7 @@ void setup() {
|
|||
// control must be enabled by calling
|
||||
// setTCXO() and specifying the reference
|
||||
// voltage.
|
||||
|
||||
/*
|
||||
Serial.print(F("[SX1262] Setting TCXO reference ... "));
|
||||
// enable TCXO
|
||||
|
@ -70,6 +71,7 @@ void setup() {
|
|||
while (true);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -90,7 +92,7 @@ void loop() {
|
|||
|
||||
if (state == ERR_NONE) {
|
||||
// the packet was successfully transmitted
|
||||
Serial.println(F(" success!"));
|
||||
Serial.println(F("success!"));
|
||||
|
||||
// print measured data rate
|
||||
Serial.print(F("[SX1262] Datarate:\t"));
|
||||
|
@ -99,11 +101,11 @@ void loop() {
|
|||
|
||||
} else if (state == ERR_PACKET_TOO_LONG) {
|
||||
// the supplied packet was longer than 256 bytes
|
||||
Serial.println(F(" too long!"));
|
||||
Serial.println(F("too long!"));
|
||||
|
||||
} else if (state == ERR_TX_TIMEOUT) {
|
||||
// timeout occured while transmitting packet
|
||||
Serial.println(F(" timeout!"));
|
||||
Serial.println(F("timeout!"));
|
||||
|
||||
} else {
|
||||
// some other error occurred
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "SX126x.h"
|
||||
|
||||
SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_CRYSTAL_FREQ, SX126X_DIV_EXPONENT) {
|
||||
SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_CRYSTAL_FREQ, SX126X_DIV_EXPONENT, SX126X_MAX_PACKET_LENGTH) {
|
||||
_mod = mod;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ int16_t SX126x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
}
|
||||
|
||||
// check packet length
|
||||
if(len >= 256) {
|
||||
if(len > SX126X_MAX_PACKET_LENGTH) {
|
||||
return(ERR_PACKET_TOO_LONG);
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
(void)addr;
|
||||
|
||||
// check packet length
|
||||
if(len >= 256) {
|
||||
if(len > SX126X_MAX_PACKET_LENGTH) {
|
||||
return(ERR_PACKET_TOO_LONG);
|
||||
}
|
||||
|
||||
|
@ -447,22 +447,10 @@ int16_t SX126x::readData(uint8_t* data, size_t len) {
|
|||
}
|
||||
|
||||
// get packet length
|
||||
uint8_t rxBufStatus[2];
|
||||
int16_t state = SPIreadCommand(SX126X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
size_t length = rxBufStatus[0];
|
||||
size_t length = getPacketLength();
|
||||
|
||||
// read packet data
|
||||
if(len == 0) {
|
||||
// argument 'len' equal to zero indicates String call, which means dynamically allocated data array
|
||||
// dispose of the original and create a new one
|
||||
delete[] data;
|
||||
data = new uint8_t[length + 1];
|
||||
}
|
||||
state = readBuffer(data, length);
|
||||
int16_t state = readBuffer(data, length);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
@ -872,6 +860,13 @@ float SX126x::getSNR() {
|
|||
return(snrPkt/4.0);
|
||||
}
|
||||
|
||||
size_t SX126x::getPacketLength(bool update) {
|
||||
(void)update;
|
||||
uint8_t rxBufStatus[2];
|
||||
SPIreadCommand(SX126X_CMD_GET_RX_BUFFER_STATUS, rxBufStatus, 2);
|
||||
return((size_t)rxBufStatus[0]);
|
||||
}
|
||||
|
||||
int16_t SX126x::setTCXO(float voltage, uint32_t timeout) {
|
||||
// set mode to standby
|
||||
standby();
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
// SX126X physical layer properties
|
||||
#define SX126X_CRYSTAL_FREQ 32.0
|
||||
#define SX126X_DIV_EXPONENT 25
|
||||
#define SX126X_MAX_PACKET_LENGTH 255
|
||||
|
||||
// SX126X SPI commands
|
||||
// operational modes commands
|
||||
|
@ -685,6 +686,15 @@ class SX126x: public PhysicalLayer {
|
|||
*/
|
||||
float getSNR();
|
||||
|
||||
/*!
|
||||
\brief Query modem for the packet length of received payload.
|
||||
|
||||
\param update Update received packet length. Will return cached value when set to false.
|
||||
|
||||
\returns Length of last received packet in bytes.
|
||||
*/
|
||||
size_t getPacketLength(bool update = true);
|
||||
|
||||
protected:
|
||||
// SX1276x SPI command implementations
|
||||
int16_t setTx(uint32_t timeout = 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue