mirror of https://github.com/ARMmbed/mbed-os.git
Lora: Fix cancel_sending
This commit fixes some bugs from cancel_sending() method: - System crashed if method was called before initialization. Now LORAWAN_STATUS_NOT_INITIALIZED will be returned. - Method returned LORAWAN_STATUS_BUSY error when no send request was pending. LORAWAN_STATUS_OK should be returned in this case. - LORAWAN_STATUS_BUSY is now returned if backoff timer is just about to be dispatched (time_left returns 0).pull/7620/head
parent
8292affb53
commit
668c6ab6fa
|
@ -277,15 +277,17 @@ lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
|
|||
|
||||
lorawan_status_t LoRaWANStack::stop_sending(void)
|
||||
{
|
||||
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
|
||||
return LORAWAN_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
if (_loramac.clear_tx_pipe() == LORAWAN_STATUS_OK) {
|
||||
if (_device_current_state == DEVICE_STATE_SENDING) {
|
||||
_ctrl_flags &= ~TX_DONE_FLAG;
|
||||
_ctrl_flags &= ~TX_ONGOING_FLAG;
|
||||
_loramac.set_tx_ongoing(false);
|
||||
_device_current_state = DEVICE_STATE_IDLE;
|
||||
return LORAWAN_STATUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return LORAWAN_STATUS_BUSY;
|
||||
}
|
||||
|
|
|
@ -845,6 +845,7 @@ lorawan_status_t LoRaMac::handle_retransmission()
|
|||
void LoRaMac::on_backoff_timer_expiry(void)
|
||||
{
|
||||
Lock lock(*this);
|
||||
_lora_time.stop(_params.timers.backoff_timer);
|
||||
lorawan_status_t status = schedule_tx();
|
||||
MBED_ASSERT(status == LORAWAN_STATUS_OK);
|
||||
(void) status;
|
||||
|
@ -1018,7 +1019,13 @@ int LoRaMac::get_backoff_timer_event_id(void)
|
|||
lorawan_status_t LoRaMac::clear_tx_pipe(void)
|
||||
{
|
||||
// check if the event is not already queued
|
||||
if (_ev_queue->time_left(get_backoff_timer_event_id()) > 0) {
|
||||
const int id = get_backoff_timer_event_id();
|
||||
if (id == 0) {
|
||||
// No queued send request
|
||||
return LORAWAN_STATUS_OK;
|
||||
}
|
||||
|
||||
if (_ev_queue->time_left(id) > 0) {
|
||||
_lora_time.stop(_params.timers.backoff_timer);
|
||||
_lora_time.stop(_params.timers.ack_timeout_timer);
|
||||
memset(_params.tx_buffer, 0, sizeof _params.tx_buffer);
|
||||
|
@ -1026,10 +1033,11 @@ lorawan_status_t LoRaMac::clear_tx_pipe(void)
|
|||
reset_ongoing_tx(true);
|
||||
tr_debug("Sending Cancelled");
|
||||
return LORAWAN_STATUS_OK;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Event is already being dispatched so it cannot be cancelled
|
||||
return LORAWAN_STATUS_BUSY;
|
||||
}
|
||||
}
|
||||
|
||||
lorawan_status_t LoRaMac::schedule_tx()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue