kopia lustrzana https://github.com/jgromes/RadioLib
[SX127x] Use length from startReceive in implicit header mode (#1345)
rodzic
111de250ec
commit
0cc72c8310
|
@ -497,11 +497,13 @@ int16_t SX1272::autoLDRO() {
|
|||
}
|
||||
|
||||
int16_t SX1272::implicitHeader(size_t len) {
|
||||
return(setHeaderType(RADIOLIB_SX1272_HEADER_IMPL_MODE, len));
|
||||
this->implicitHdr = true;
|
||||
return(setHeaderType(RADIOLIB_SX1272_HEADER_IMPL_MODE, 2, len));
|
||||
}
|
||||
|
||||
int16_t SX1272::explicitHeader() {
|
||||
return(setHeaderType(RADIOLIB_SX1272_HEADER_EXPL_MODE));
|
||||
this->implicitHdr = false;
|
||||
return(setHeaderType(RADIOLIB_SX1272_HEADER_EXPL_MODE, 2));
|
||||
}
|
||||
|
||||
int16_t SX1272::setBandwidthRaw(uint8_t newBandwidth) {
|
||||
|
@ -521,11 +523,13 @@ int16_t SX1272::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
|
|||
// write registers
|
||||
Module* mod = this->getMod();
|
||||
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
|
||||
this->implicitHdr = true;
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
|
||||
} else {
|
||||
this->implicitHdr = false;
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
|
||||
|
@ -544,27 +548,6 @@ int16_t SX1272::setCodingRateRaw(uint8_t newCodingRate) {
|
|||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::setHeaderType(uint8_t headerType, size_t len) {
|
||||
// check active modem
|
||||
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// set requested packet mode
|
||||
Module* mod = this->getMod();
|
||||
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set length to register
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update cached value
|
||||
SX127x::packetLength = len;
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::configFSK() {
|
||||
// configure common registers
|
||||
int16_t state = SX127x::configFSK();
|
||||
|
|
|
@ -316,7 +316,6 @@ class SX1272: public SX127x {
|
|||
int16_t setBandwidthRaw(uint8_t newBandwidth);
|
||||
int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
|
||||
int16_t setCodingRateRaw(uint8_t newCodingRate);
|
||||
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
|
||||
|
||||
int16_t configFSK();
|
||||
void errataFix(bool rx) override;
|
||||
|
|
|
@ -535,11 +535,13 @@ int16_t SX1278::autoLDRO() {
|
|||
}
|
||||
|
||||
int16_t SX1278::implicitHeader(size_t len) {
|
||||
return(setHeaderType(RADIOLIB_SX1278_HEADER_IMPL_MODE, len));
|
||||
this->implicitHdr = true;
|
||||
return(setHeaderType(RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, len));
|
||||
}
|
||||
|
||||
int16_t SX1278::explicitHeader() {
|
||||
return(setHeaderType(RADIOLIB_SX1278_HEADER_EXPL_MODE));
|
||||
this->implicitHdr = false;
|
||||
return(setHeaderType(RADIOLIB_SX1278_HEADER_EXPL_MODE, 0));
|
||||
}
|
||||
|
||||
int16_t SX1278::setBandwidthRaw(uint8_t newBandwidth) {
|
||||
|
@ -559,11 +561,13 @@ int16_t SX1278::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
|
|||
// write registers
|
||||
Module* mod = this->getMod();
|
||||
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
|
||||
this->implicitHdr = true;
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
|
||||
} else {
|
||||
this->implicitHdr = false;
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
|
||||
|
@ -582,27 +586,6 @@ int16_t SX1278::setCodingRateRaw(uint8_t newCodingRate) {
|
|||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::setHeaderType(uint8_t headerType, size_t len) {
|
||||
// check active modem
|
||||
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// set requested packet mode
|
||||
Module* mod = this->getMod();
|
||||
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set length to register
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update cached value
|
||||
SX127x::packetLength = len;
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::configFSK() {
|
||||
// configure common registers
|
||||
int16_t state = SX127x::configFSK();
|
||||
|
|
|
@ -328,7 +328,6 @@ class SX1278: public SX127x {
|
|||
int16_t setBandwidthRaw(uint8_t newBandwidth);
|
||||
int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
|
||||
int16_t setCodingRateRaw(uint8_t newCodingRate);
|
||||
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
|
||||
|
||||
int16_t configFSK();
|
||||
void errataFix(bool rx) override;
|
||||
|
|
|
@ -417,8 +417,9 @@ int16_t SX127x::startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags, Radi
|
|||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_1, RADIOLIB_SX127X_DIO1_LORA_FHSS_CHANGE_CHANNEL, 5, 4);
|
||||
}
|
||||
|
||||
// set expected packet length for SF6
|
||||
if(this->spreadingFactor == 6) {
|
||||
// in implicit header mode, use the provided length if it is nonzero
|
||||
// otherwise we trust the user has previously set the payload length manually
|
||||
if((this->implicitHdr) && (len != 0)) {
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
this->packetLength = len;
|
||||
}
|
||||
|
@ -1211,12 +1212,12 @@ size_t SX127x::getPacketLength(bool update) {
|
|||
int16_t modem = getActiveModem();
|
||||
|
||||
if(modem == RADIOLIB_SX127X_LORA) {
|
||||
if(this->spreadingFactor != 6) {
|
||||
// get packet length for SF7 - SF12
|
||||
if(!this->implicitHdr) {
|
||||
// get packet length for explicit header mode
|
||||
return(this->mod->SPIreadRegister(RADIOLIB_SX127X_REG_RX_NB_BYTES));
|
||||
|
||||
} else {
|
||||
// return the cached value for SF6
|
||||
// return the cached value for implicit header mode
|
||||
return(this->packetLength);
|
||||
}
|
||||
|
||||
|
@ -1860,6 +1861,27 @@ float SX127x::getRSSI(bool packet, bool skipReceive, int16_t offset) {
|
|||
}
|
||||
}
|
||||
|
||||
int16_t SX127x::setHeaderType(uint8_t headerType, uint8_t bitIndex, size_t len) {
|
||||
// check active modem
|
||||
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// set requested packet mode
|
||||
Module* mod = this->getMod();
|
||||
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, bitIndex, bitIndex);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set length to register
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update cached value
|
||||
SX127x::packetLength = len;
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX127x::setLowBatteryThreshold(int8_t level, uint32_t pin) {
|
||||
// check disable
|
||||
if(level < 0) {
|
||||
|
|
|
@ -1249,12 +1249,14 @@ class SX127x: public PhysicalLayer {
|
|||
uint8_t codingRate = 0;
|
||||
bool crcEnabled = false;
|
||||
bool ookEnabled = false;
|
||||
bool implicitHdr = false;
|
||||
|
||||
int16_t configFSK();
|
||||
int16_t getActiveModem();
|
||||
int16_t setFrequencyRaw(float newFreq);
|
||||
int16_t setBitRateCommon(float br, uint8_t fracRegAddr);
|
||||
float getRSSI(bool packet, bool skipReceive, int16_t offset);
|
||||
int16_t setHeaderType(uint8_t headerType, uint8_t bitIndex, size_t len = 0xFF);
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
|
|
Ładowanie…
Reference in New Issue