[Si443x] Added fixed packet length mode

This commit is contained in:
jgromes 2022-01-23 17:05:58 +01:00
parent 0de8ef6bce
commit 19109bc7d8
2 changed files with 52 additions and 2 deletions

View file

@ -61,6 +61,8 @@ int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen)
state = setEncoding(0);
RADIOLIB_ASSERT(state);
state = variablePacketLengthMode();
return(state);
}
@ -233,8 +235,9 @@ int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
clearIRQFlags();
// set packet length
/// \todo variable packet length
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
if (_packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF) {
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
}
/// \todo use header as address field?
(void)addr;
@ -591,6 +594,14 @@ void Si443x::readBit(RADIOLIB_PIN_TYPE pin) {
updateDirectBuffer((uint8_t)digitalRead(pin));
}
int16_t Si443x::fixedPacketLengthMode(uint8_t len) {
return(Si443x::setPacketMode(RADIOLIB_SI443X_FIXED_PACKET_LENGTH_ON, len));
}
int16_t Si443x::variablePacketLengthMode(uint8_t maxLen) {
return(Si443x::setPacketMode(RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF, maxLen));
}
int16_t Si443x::setFrequencyRaw(float newFreq) {
// set mode to standby
int16_t state = standby();
@ -619,6 +630,25 @@ int16_t Si443x::setFrequencyRaw(float newFreq) {
return(state);
}
int16_t Si443x::setPacketMode(uint8_t mode, uint8_t len) {
// check packet length
if (len > RADIOLIB_SI443X_MAX_PACKET_LENGTH) {
return(RADIOLIB_ERR_PACKET_TOO_LONG);
}
// set to fixed packet length
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, mode, 3, 3);
RADIOLIB_ASSERT(state);
// set length to register
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
RADIOLIB_ASSERT(state);
// update cached value
_packetLengthConfig = mode;
return(state);
}
bool Si443x::findChip() {
uint8_t i = 0;
bool flagFound = false;

View file

@ -816,6 +816,24 @@ class Si443x: public PhysicalLayer {
*/
void readBit(RADIOLIB_PIN_TYPE pin);
/*!
\brief Set modem in fixed packet length mode.
\param len Packet length.
\returns \ref status_codes
*/
int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SI443X_MAX_PACKET_LENGTH);
/*!
\brief Set modem in variable packet length mode.
\param len Maximum packet length.
\returns \ref status_codes
*/
int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SI443X_MAX_PACKET_LENGTH);
#if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
protected:
#endif
@ -831,8 +849,10 @@ class Si443x: public PhysicalLayer {
size_t _packetLength = 0;
bool _packetLengthQueried = false;
uint8_t _packetLengthConfig = RADIOLIB_SI443X_FIXED_PACKET_LENGTH_ON;
int16_t setFrequencyRaw(float newFreq);
int16_t setPacketMode(uint8_t mode, uint8_t len);
#if !defined(RADIOLIB_GODMODE)
private: