kopia lustrzana https://github.com/jgromes/RadioLib
[SX128x] Implement blocking receive timeout
rodzic
792dd13b7b
commit
9ff26d9679
|
@ -350,7 +350,7 @@ int16_t SX128x::transmit(const uint8_t* data, size_t len, uint8_t addr) {
|
||||||
return(finishTransmit());
|
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
|
// check active modem
|
||||||
uint8_t modem = getPacketType();
|
uint8_t modem = getPacketType();
|
||||||
if(modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING) {
|
if(modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING) {
|
||||||
|
@ -362,11 +362,14 @@ int16_t SX128x::receive(uint8_t* data, size_t len) {
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
// calculate timeout (1000% of expected time-on-air)
|
// 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));
|
RADIOLIB_DEBUG_BASIC_PRINTLN("Timeout in %lu ms", (uint32_t)((timeout + 999) / 1000));
|
||||||
|
|
||||||
// start reception
|
// start reception
|
||||||
uint32_t timeoutValue = (uint32_t)((float)timeout / 15.625f);
|
uint32_t timeoutValue = (uint32_t)((float)timeoutInternal / 15.625f);
|
||||||
state = startReceive(timeoutValue);
|
state = startReceive(timeoutValue);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
|
|
|
@ -435,11 +435,13 @@ class SX128x: public PhysicalLayer {
|
||||||
/*!
|
/*!
|
||||||
\brief Blocking binary receive method.
|
\brief Blocking binary receive method.
|
||||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||||
\param data Binary data to be sent.
|
\param data Pointer to array to save the received binary data.
|
||||||
\param len Number of bytes to send.
|
\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
|
\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.
|
\brief Starts direct mode transmission.
|
||||||
|
|
Ładowanie…
Reference in New Issue