RadioLib - getTimeOnAir for FSK mode in module SX127x

pull/540/head
Jaimi5 2022-06-26 23:33:05 +02:00
rodzic 19715ef204
commit 314fcb2d6e
1 zmienionych plików z 42 dodań i 21 usunięć

Wyświetl plik

@ -147,7 +147,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t modem = getActiveModem();
uint32_t start = 0;
if(modem == RADIOLIB_SX127X_LORA) {
// calculate timeout (150 % of expected time-one-air)
// calculate timeout (150 % of expected time-on-air)
uint32_t timeout = getTimeOnAir(len) * 1.5;
// start transmission
@ -166,7 +166,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
// calculate timeout (5ms + 500 % of expected time-on-air)
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0);
uint32_t timeout = 5000 + getTimeOnAir(len) * 5;
// start transmission
state = startTransmit(data, len, addr);
@ -218,8 +218,8 @@ int16_t SX127x::receive(uint8_t* data, size_t len) {
}
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
// calculate timeout (500 % of expected time-one-air)
uint32_t timeout = (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0);
// calculate timeout (500 % of expected time-on-air)
uint32_t timeout = getTimeOnAir(len) * 5;
// set mode to receive
state = startReceive(len, RADIOLIB_SX127X_RX);
@ -1039,8 +1039,11 @@ int16_t SX127x::variablePacketLengthMode(uint8_t maxLen) {
}
uint32_t SX127x::getTimeOnAir(size_t len) {
// check active modem
uint8_t modem = getActiveModem();
if (modem == RADIOLIB_SX127X_LORA) {
// Get symbol length in us
float symbolLength = (float) (uint32_t(1) << _sf) / (float) _bw * 1000;
float symbolLength = (float) (uint32_t(1) << _sf) / (float) _bw;
// Get Low Data Rate optimization flag
float de = 0;
if (symbolLength >= 16.0) {
@ -1056,7 +1059,25 @@ uint32_t SX127x::getTimeOnAir(size_t len) {
float n_pay = 8.0 + max(ceil((8.0 * (float) len - 4.0 * (float) _sf + 28.0 + 16.0 * crc - 20.0 * ih) / (4.0 * (float) _sf - 8.0 * de)) * (float) _cr, 0.0);
// Get time-on-air in us
return ceil(symbolLength * (n_pre + n_pay + 4.25));
return ceil(symbolLength * (n_pre + n_pay + 4.25)) * 1000;
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
// Get number of bits preamble
float n_pre = (float) ((_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_MSB_FSK) << 8) | _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PREAMBLE_LSB_FSK)) * 8;
//Get the number of bits of the sync word
float n_syncWord = (float) (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, 2, 0) + 1);
//Get CRC enabled flag
float crc = (float) (_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 4, 4) >> 2);
//Get payload length
uint16_t mode = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, 7, 7);
if (mode == RADIOLIB_SX127X_PACKET_FIXED)
len = _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH_FSK);
// Calculate time-on-air in us ((length in bytes) * (8 bits / 1 byte)) / ((Bit Rate in kbps) * (1000 bps / 1 kbps)) * (1000000 us in 1 sec)
return (uint32_t) (((crc + n_syncWord + n_pre + (float) (len * 8)) / (_br * 1000.0)) * 1000000.0);
} else {
return(RADIOLIB_ERR_UNKNOWN);
}
}
int16_t SX127x::setCrcFiltering(bool crcOn) {