Remove old methods and equivalance tests

pull/1596/head
GUVWAF 2025-09-13 14:32:06 +02:00
rodzic 0a711b2b22
commit c25c653119
8 zmienionych plików z 3 dodań i 430 usunięć

Wyświetl plik

@ -10,7 +10,6 @@ file(GLOB_RECURSE TEST_SOURCES
"tests/main.cpp"
"tests/TestModule.cpp"
"tests/TestCalculateTimeOnAir.cpp"
"tests/TestGetTimeOnAir.cpp"
)
# create the executable

Wyświetl plik

@ -1,188 +0,0 @@
// TestTimeOnAirEquivalence.cpp
#include <boost/test/unit_test.hpp>
#include "TestHal.hpp"
#include "modules/SX126x/SX126x.h"
#include "modules/SX128x/SX128x.h"
#include "modules/LR11x0/LR11x0.h"
#include "Module.h"
// -----------------------------------------------------------------------------
// Testable wrappers
// -----------------------------------------------------------------------------
class SX126xTestable : public SX126x {
public:
explicit SX126xTestable(Module* mod) : SX126x(mod) {}
uint8_t currentPacketType = RADIOLIB_SX126X_PACKET_TYPE_LORA;
uint8_t getPacketType() { return currentPacketType; }
};
class SX128xTestable : public SX128x {
public:
explicit SX128xTestable(Module* mod) : SX128x(mod) {}
uint8_t currentPacketType = RADIOLIB_SX128X_PACKET_TYPE_LORA;
uint8_t getPacketType() { return currentPacketType; }
};
class LR11x0Testable : public LR11x0 {
public:
explicit LR11x0Testable(Module* mod) : LR11x0(mod) {}
uint8_t currentPacketType = RADIOLIB_LR11X0_PACKET_TYPE_LORA;
int16_t getPacketType(uint8_t *type) { *type = currentPacketType; return RADIOLIB_ERR_NONE; }
};
// -----------------------------------------------------------------------------
// Fixture (shared for all radios)
// -----------------------------------------------------------------------------
struct TimeOnAirFixture {
TestHal* hal = nullptr;
EmulatedRadio* radioHardware = nullptr;
Module* dummyModule = nullptr;
TimeOnAirFixture() {
hal = new TestHal();
radioHardware = new EmulatedRadio();
hal->connectRadio(radioHardware);
dummyModule = new Module(
hal,
EMULATED_RADIO_NSS_PIN,
EMULATED_RADIO_IRQ_PIN,
EMULATED_RADIO_RST_PIN,
EMULATED_RADIO_GPIO_PIN
);
dummyModule->init();
}
~TimeOnAirFixture() {
dummyModule->term();
delete dummyModule;
delete[] hal;
delete[] radioHardware;
}
};
// -----------------------------------------------------------------------------
// Helpers
// -----------------------------------------------------------------------------
template <typename RadioT>
static void compareTimeOnAir(RadioT* radio, size_t len) {
auto oldVal = radio->getTimeOnAir_old(len);
auto newVal = radio->getTimeOnAir(len);
BOOST_TEST_MESSAGE("Len=" << len
<< " old=" << oldVal
<< " new=" << newVal);
BOOST_CHECK_EQUAL(oldVal, newVal);
}
template <typename RadioT>
static void runEquivalenceTests(RadioT* radio,
const std::string& name,
std::initializer_list<size_t> lens) {
BOOST_TEST_MESSAGE("--- Test getTimeOnAir " << name);
for (auto len : lens) {
compareTimeOnAir(radio, len);
}
}
// -----------------------------------------------------------------------------
// Test Suite
// -----------------------------------------------------------------------------
BOOST_FIXTURE_TEST_SUITE(suite_TimeOnAirEquivalence, TimeOnAirFixture)
// --- SX126x ---
BOOST_FIXTURE_TEST_CASE(SX126x_LoRa_equivalence, TimeOnAirFixture) {
SX126xTestable radio(dummyModule);
radio.currentPacketType = RADIOLIB_SX126X_PACKET_TYPE_LORA;
radio.setSpreadingFactor(7);
radio.setBandwidth(125);
radio.setCodingRate(5);
radio.implicitHeader(false);
radio.setPreambleLength(8);
radio.setCRC(2);
radio.forceLDRO(false);
runEquivalenceTests(&radio, "SX126x LoRa", {1, 10, 50, 255});
}
BOOST_FIXTURE_TEST_CASE(SX126x_GFSK_equivalence, TimeOnAirFixture) {
SX126xTestable radio(dummyModule);
radio.currentPacketType = RADIOLIB_SX126X_PACKET_TYPE_GFSK;
radio.setPreambleLength(16);
uint8_t syncWord[] = {0x2b, 0xd4};
radio.setSyncBits(syncWord, 16);
radio.setCRC(2);
radio.setBitRate(100.0f); // in kbps
runEquivalenceTests(&radio, "SX126x GFSK", {1, 16, 64, 200});
}
BOOST_FIXTURE_TEST_CASE(SX126x_LRFHSS_equivalence, TimeOnAirFixture) {
SX126xTestable radio(dummyModule);
radio.currentPacketType = RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS;
radio.setLrFhssConfig(RADIOLIB_LR11X0_LR_FHSS_BW_386_72, RADIOLIB_SX126X_LR_FHSS_CR_2_3, 2);
runEquivalenceTests(&radio, "SX126x LR-FHSS", {1, 20, 100});
}
// --- SX128x ---
BOOST_FIXTURE_TEST_CASE(SX128x_LoRa_equivalence, TimeOnAirFixture) {
SX128xTestable radio(dummyModule);
radio.currentPacketType = RADIOLIB_SX128X_PACKET_TYPE_LORA;
radio.setSpreadingFactor(8);
radio.setBandwidth(406.25);
radio.setCodingRate(7);
radio.implicitHeader(false);
radio.setPreambleLength(8);
radio.setCRC(2);
runEquivalenceTests(&radio, "SX128x LoRa", {1, 50, 200});
}
BOOST_FIXTURE_TEST_CASE(SX128x_GFSK_equivalence, TimeOnAirFixture) {
SX128xTestable radio(dummyModule);
radio.currentPacketType = RADIOLIB_SX128X_PACKET_TYPE_GFSK;
radio.setPreambleLength(16);
uint8_t syncWord[] = {0x2b, 0xd4};
radio.setSyncWord(syncWord, 2);
radio.setCRC(2);
radio.setBitRate(250.0f);
runEquivalenceTests(&radio, "SX128x GFSK", {1, 32, 64, 128});
}
// --- LR11x0 ---
BOOST_FIXTURE_TEST_CASE(LR11x0_LoRa_equivalence, TimeOnAirFixture) {
LR11x0Testable radio(dummyModule);
radio.currentPacketType = RADIOLIB_LR11X0_PACKET_TYPE_LORA;
radio.setSpreadingFactor(10);
radio.setBandwidth(250);
radio.setCodingRate(5);
radio.implicitHeader(false);
radio.setPreambleLength(8);
radio.setCRC(2);
radio.forceLDRO(true);
runEquivalenceTests(&radio, "LR11x0 LoRa", {1, 20, 100});
}
BOOST_FIXTURE_TEST_CASE(LR11x0_LRFHSS_equivalence, TimeOnAirFixture) {
LR11x0Testable radio(dummyModule);
radio.currentPacketType = RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS;
radio.setLrFhssConfig(RADIOLIB_LR11X0_LR_FHSS_BW_136_72, RADIOLIB_LR11X0_LR_FHSS_CR_1_3, 1);
runEquivalenceTests(&radio, "LR11x0 LR-FHSS", {1, 10, 50});
}
BOOST_FIXTURE_TEST_CASE(LR11x0_GFSK_equivalence, TimeOnAirFixture) {
LR11x0Testable radio(dummyModule);
radio.currentPacketType = RADIOLIB_LR11X0_PACKET_TYPE_GFSK;
radio.setPreambleLength(16);
uint8_t syncWord[] = {0x2b, 0xd4, 0x2b, 0xd4};
radio.setSyncWord(syncWord, 4);
radio.setCRC(2);
radio.setBitRate(200.0f);
runEquivalenceTests(&radio, "LR11x0 GFSK", {1, 32, 64, 200});
}
BOOST_AUTO_TEST_SUITE_END()

Wyświetl plik

@ -1320,103 +1320,6 @@ RadioLibTime_t LR11x0::getTimeOnAir(size_t len) {
return(this->calculateTimeOnAir(modem, dr, pc, len));
}
RadioLibTime_t LR11x0::getTimeOnAir_old(size_t len) {
// check active modem
uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
(void)getPacketType(&type);
if(type == RADIOLIB_LR11X0_PACKET_TYPE_LORA) {
// calculate number of symbols
float N_symbol = 0;
if(this->codingRate <= RADIOLIB_LR11X0_LORA_CR_4_8_SHORT) {
// legacy coding rate - nice and simple
// get SF coefficients
float coeff1 = 0;
int16_t coeff2 = 0;
int16_t coeff3 = 0;
if(this->spreadingFactor < 7) {
// SF5, SF6
coeff1 = 6.25;
coeff2 = 4*this->spreadingFactor;
coeff3 = 4*this->spreadingFactor;
} else if(this->spreadingFactor < 11) {
// SF7. SF8, SF9, SF10
coeff1 = 4.25;
coeff2 = 4*this->spreadingFactor + 8;
coeff3 = 4*this->spreadingFactor;
} else {
// SF11, SF12
coeff1 = 4.25;
coeff2 = 4*this->spreadingFactor + 8;
coeff3 = 4*(this->spreadingFactor - 2);
}
// get CRC length
int16_t N_bitCRC = 16;
if(this->crcTypeLoRa == RADIOLIB_LR11X0_LORA_CRC_DISABLED) {
N_bitCRC = 0;
}
// get header length
int16_t N_symbolHeader = 20;
if(this->headerType == RADIOLIB_LR11X0_LORA_HEADER_IMPLICIT) {
N_symbolHeader = 0;
}
// calculate number of LoRa preamble symbols
uint32_t N_symbolPreamble = (this->preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((this->preambleLengthLoRa & 0xF0) >> 4));
// calculate the number of symbols
N_symbol = (float)N_symbolPreamble + coeff1 + 8.0f + ceilf((float)RADIOLIB_MAX((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(this->codingRate + 4);
} else {
// long interleaving - abandon hope all ye who enter here
/// \todo implement this mess - SX1280 datasheet v3.0 section 7.4.4.2
}
// get time-on-air in us
return(((uint32_t(1) << this->spreadingFactor) / this->bandwidthKhz) * N_symbol * 1000.0f);
} else if(type == RADIOLIB_LR11X0_PACKET_TYPE_GFSK) {
return(((uint32_t)len * 8 * 1000000UL) / this->bitRate);
} else if(type == RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS) {
// calculate the number of bits based on coding rate
uint16_t N_bits;
switch(this->lrFhssCr) {
case RADIOLIB_LR11X0_LR_FHSS_CR_5_6:
N_bits = ((len * 6) + 4) / 5; // this is from the official LR11xx driver, but why the extra +4?
break;
case RADIOLIB_LR11X0_LR_FHSS_CR_2_3:
N_bits = (len * 3) / 2;
break;
case RADIOLIB_LR11X0_LR_FHSS_CR_1_2:
N_bits = len * 2;
break;
case RADIOLIB_LR11X0_LR_FHSS_CR_1_3:
N_bits = len * 3;
break;
default:
return(RADIOLIB_ERR_INVALID_CODING_RATE);
}
// calculate number of bits when accounting for unaligned last block
uint16_t N_payBits = (N_bits / RADIOLIB_LR11X0_LR_FHSS_FRAG_BITS) * RADIOLIB_LR11X0_LR_FHSS_BLOCK_BITS;
uint16_t N_lastBlockBits = N_bits % RADIOLIB_LR11X0_LR_FHSS_FRAG_BITS;
if(N_lastBlockBits) {
N_payBits += N_lastBlockBits + 2;
}
// add header bits
uint16_t N_totalBits = (RADIOLIB_LR11X0_LR_FHSS_HEADER_BITS * this->lrFhssHdrCount) + N_payBits;
return(((uint32_t)N_totalBits * 8 * 1000000UL) / RADIOLIB_LR11X0_LR_FHSS_BIT_RATE);
}
return(0);
}
RadioLibTime_t LR11x0::calculateRxTimeout(RadioLibTime_t timeoutUs) {
// the timeout value is given in units of 30.52 microseconds
// the calling function should provide some extra width, as this number of units is truncated to integer

Wyświetl plik

@ -1389,8 +1389,6 @@ class LR11x0: public PhysicalLayer {
*/
RadioLibTime_t getTimeOnAir(size_t len) override;
RadioLibTime_t getTimeOnAir_old(size_t len);
/*!
\brief Calculate the timeout value for this specific module / series (in number of symbols or units of time)
\param timeoutUs Timeout in microseconds to listen for
@ -1700,7 +1698,7 @@ class LR11x0: public PhysicalLayer {
int16_t resetStats(void);
int16_t getStats(uint16_t* nbPktReceived, uint16_t* nbPktCrcError, uint16_t* data1, uint16_t* data2);
virtual int16_t getPacketType(uint8_t* type);
int16_t getPacketType(uint8_t* type);
int16_t getRxBufferStatus(uint8_t* len, uint8_t* startOffset);
int16_t getPacketStatusLoRa(float* rssiPkt, float* snrPkt, float* signalRssiPkt);
int16_t getPacketStatusGFSK(float* rssiSync, float* rssiAvg, uint8_t* rxLen, uint8_t* stat);

Wyświetl plik

@ -1348,77 +1348,6 @@ int16_t SX126x::variablePacketLengthMode(uint8_t maxLen) {
return(setPacketMode(RADIOLIB_SX126X_GFSK_PACKET_VARIABLE, maxLen));
}
RadioLibTime_t SX126x::getTimeOnAir_old(size_t len) {
// everything is in microseconds to allow integer arithmetic
// some constants have .25, these are multiplied by 4, and have _x4 postfix to indicate that fact
uint8_t modem = getPacketType();
if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << this->spreadingFactor) / (this->bandwidthKhz * 10) ;
uint8_t sfCoeff1_x4 = 17; // (4.25 * 4)
uint8_t sfCoeff2 = 8;
if(this->spreadingFactor == 5 || this->spreadingFactor == 6) {
sfCoeff1_x4 = 25; // 6.25 * 4
sfCoeff2 = 0;
}
uint8_t sfDivisor = 4*this->spreadingFactor;
if(symbolLength_us >= 16000) {
sfDivisor = 4*(this->spreadingFactor - 2);
}
const int8_t bitsPerCrc = 16;
const int8_t N_symbol_header = this->headerType == RADIOLIB_SX126X_LORA_HEADER_EXPLICIT ? 20 : 0;
// numerator of equation in section 6.1.4 of SX1268 datasheet v1.1 (might not actually be bitcount, but it has len * 8)
int16_t bitCount = (int16_t) 8 * len + this->crcTypeLoRa * bitsPerCrc - 4 * this->spreadingFactor + sfCoeff2 + N_symbol_header;
if(bitCount < 0) {
bitCount = 0;
}
// add (sfDivisor) - 1 to the numerator to give integer CEIL(...)
uint16_t nPreCodedSymbols = (bitCount + (sfDivisor - 1)) / (sfDivisor);
// preamble can be 65k, therefore nSymbol_x4 needs to be 32 bit
uint32_t nSymbol_x4 = (this->preambleLengthLoRa + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * (this->codingRate + 4) * 4;
return((symbolLength_us * nSymbol_x4) / 4);
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
return(((uint32_t)len * 8 * this->bitRate) / (RADIOLIB_SX126X_CRYSTAL_FREQ * 32));
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS) {
// calculate the number of bits based on coding rate
uint16_t N_bits;
switch(this->lrFhssCr) {
case RADIOLIB_SX126X_LR_FHSS_CR_5_6:
N_bits = ((len * 6) + 4) / 5; // this is from the official LR11xx driver, but why the extra +4?
break;
case RADIOLIB_SX126X_LR_FHSS_CR_2_3:
N_bits = (len * 3) / 2;
break;
case RADIOLIB_SX126X_LR_FHSS_CR_1_2:
N_bits = len * 2;
break;
case RADIOLIB_SX126X_LR_FHSS_CR_1_3:
N_bits = len * 3;
break;
default:
return(RADIOLIB_ERR_INVALID_CODING_RATE);
}
// calculate number of bits when accounting for unaligned last block
uint16_t N_payBits = (N_bits / RADIOLIB_SX126X_LR_FHSS_FRAG_BITS) * RADIOLIB_SX126X_LR_FHSS_BLOCK_BITS;
uint16_t N_lastBlockBits = N_bits % RADIOLIB_SX126X_LR_FHSS_FRAG_BITS;
if(N_lastBlockBits) {
N_payBits += N_lastBlockBits + 2;
}
// add header bits
uint16_t N_totalBits = (RADIOLIB_SX126X_LR_FHSS_HEADER_BITS * this->lrFhssHdrCount) + N_payBits;
return(((uint32_t)N_totalBits * 8 * 1000000UL) / 488.28215f);
}
return(RADIOLIB_ERR_UNKNOWN);
}
RadioLibTime_t SX126x::calculateTimeOnAir(ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len) {
// everything is in microseconds to allow integer arithmetic
// some constants have .25, these are multiplied by 4, and have _x4 postfix to indicate that fact

Wyświetl plik

@ -1025,8 +1025,6 @@ class SX126x: public PhysicalLayer {
*/
RadioLibTime_t getTimeOnAir(size_t len) override;
RadioLibTime_t getTimeOnAir_old(size_t len);
/*!
\brief Calculate the timeout value for this specific module / series (in number of symbols or units of time)
\param timeoutUs Timeout in microseconds to listen for
@ -1243,7 +1241,7 @@ class SX126x: public PhysicalLayer {
virtual int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX126X_IRQ_ALL);
int16_t setRfFrequency(uint32_t frf);
int16_t calibrateImage(const uint8_t* data);
virtual uint8_t getPacketType();
uint8_t getPacketType();
int16_t setTxParams(uint8_t power, uint8_t rampTime);
int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro);
int16_t setModulationParamsFSK(uint32_t br, uint8_t sh, uint8_t rxBw, uint32_t freqDev);

Wyświetl plik

@ -1430,70 +1430,6 @@ RadioLibTime_t SX128x::getTimeOnAir(size_t len) {
}
RadioLibTime_t SX128x::getTimeOnAir_old(size_t len) {
// check active modem
uint8_t modem = getPacketType();
if(modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) {
// calculate number of symbols
float N_symbol = 0;
uint8_t sf = this->spreadingFactor >> 4;
if(this->codingRateLoRa <= RADIOLIB_SX128X_LORA_CR_4_8) {
// legacy coding rate - nice and simple
// get SF coefficients
float coeff1 = 0;
int16_t coeff2 = 0;
int16_t coeff3 = 0;
if(sf < 7) {
// SF5, SF6
coeff1 = 6.25;
coeff2 = 4*sf;
coeff3 = 4*sf;
} else if(sf < 11) {
// SF7. SF8, SF9, SF10
coeff1 = 4.25;
coeff2 = 4*sf + 8;
coeff3 = 4*sf;
} else {
// SF11, SF12
coeff1 = 4.25;
coeff2 = 4*sf + 8;
coeff3 = 4*(sf - 2);
}
// get CRC length
int16_t N_bitCRC = 16;
if(this->crcLoRa == RADIOLIB_SX128X_LORA_CRC_OFF) {
N_bitCRC = 0;
}
// get header length
int16_t N_symbolHeader = 20;
if(this->headerType == RADIOLIB_SX128X_LORA_HEADER_IMPLICIT) {
N_symbolHeader = 0;
}
// calculate number of LoRa preamble symbols
uint32_t N_symbolPreamble = (this->preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((this->preambleLengthLoRa & 0xF0) >> 4));
// calculate the number of symbols
N_symbol = (float)N_symbolPreamble + coeff1 + 8.0f + ceilf((float)RADIOLIB_MAX((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(this->codingRateLoRa + 4);
} else {
// long interleaving - abandon hope all ye who enter here
/// \todo implement this mess - SX1280 datasheet v3.0 section 7.4.4.2
}
// get time-on-air in us
return(((uint32_t(1) << sf) / this->bandwidthKhz) * N_symbol * 1000.0f);
} else {
return(((uint32_t)len * 8 * 1000) / this->bitRateKbps);
}
}
int16_t SX128x::implicitHeader(size_t len) {
return(setHeaderType(RADIOLIB_SX128X_LORA_HEADER_IMPLICIT, len));
}

Wyświetl plik

@ -845,8 +845,6 @@ class SX128x: public PhysicalLayer {
*/
RadioLibTime_t getTimeOnAir(size_t len) override;
RadioLibTime_t getTimeOnAir_old(size_t len);
/*!
\brief Set implicit header mode for future reception/transmission.
\returns \ref status_codes
@ -925,7 +923,7 @@ class SX128x: public PhysicalLayer {
int16_t setTx(uint16_t periodBaseCount = RADIOLIB_SX128X_TX_TIMEOUT_NONE, uint8_t periodBase = RADIOLIB_SX128X_PERIOD_BASE_15_625_US);
int16_t setRx(uint16_t periodBaseCount, uint8_t periodBase = RADIOLIB_SX128X_PERIOD_BASE_15_625_US);
int16_t setCad(uint8_t symbolNum);
virtual uint8_t getPacketType();
uint8_t getPacketType();
int16_t setRfFrequency(uint32_t frf);
int16_t setTxParams(uint8_t pwr, uint8_t rampTime = RADIOLIB_SX128X_PA_RAMP_10_US);
int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00);