[SX128x] Implement blocking receive timeout

pull/1592/head
jgromes 2025-09-06 18:09:49 +01:00
rodzic 792dd13b7b
commit 9ff26d9679
2 zmienionych plików z 11 dodań i 6 usunięć

Wyświetl plik

@ -350,7 +350,7 @@ int16_t SX128x::transmit(const uint8_t* data, size_t len, uint8_t addr) {
return(finishTransmit());
}
int16_t SX128x::receive(uint8_t* data, size_t len) {
int16_t SX128x::receive(uint8_t* data, size_t len, RadioLibTime_t timeout) {
// check active modem
uint8_t modem = getPacketType();
if(modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING) {
@ -362,11 +362,14 @@ int16_t SX128x::receive(uint8_t* data, size_t len) {
RADIOLIB_ASSERT(state);
// calculate timeout (1000% of expected time-on-air)
RadioLibTime_t timeout = getTimeOnAir(len) * 10;
RadioLibTime_t timeoutInternal = timeout;
if(!timeoutInternal) {
timeoutInternal = getTimeOnAir(len) * 10;
}
RADIOLIB_DEBUG_BASIC_PRINTLN("Timeout in %lu ms", (uint32_t)((timeout + 999) / 1000));
// start reception
uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625f);
uint32_t timeoutValue = (uint32_t)((float)timeoutInternal / 15.625f);
state = startReceive(timeoutValue);
RADIOLIB_ASSERT(state);

Wyświetl plik

@ -435,11 +435,13 @@ class SX128x: public PhysicalLayer {
/*!
\brief Blocking binary receive method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\param data Pointer to array to save the received binary data.
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
\param timeout Reception timeout in milliseconds. If set to 0,
timeout period will be calculated automatically based on the radio configuration.
\returns \ref status_codes
*/
int16_t receive(uint8_t* data, size_t len) override;
int16_t receive(uint8_t* data, size_t len, RadioLibTime_t timeout = 0) override;
/*!
\brief Starts direct mode transmission.