Skip to content

Commit b4abfe6

Browse files
authored
Merge pull request #14422 from pan-/lora-cancellation
Fix Lora timer cancellation
2 parents 09eac13 + 70920d4 commit b4abfe6

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

UNITTESTS/stubs/LoRaWANTimer_stub.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ void LoRaWANTimeHandler::stop(timer_event_t &obj)
6262
{
6363
obj.timer_id = 0;
6464
}
65+
66+
void LoRaWANTimeHandler::clear(timer_event_t &obj)
67+
{
68+
obj.timer_id = 0;
69+
}

connectivity/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,13 @@ void LoRaMac::set_device_class(const device_class_t &device_class,
14191419
_device_class = device_class;
14201420
_rx2_would_be_closure_for_class_c = rx2_would_be_closure_handler;
14211421

1422-
_lora_time.init(_rx2_closure_timer_for_class_c, _rx2_would_be_closure_for_class_c);
1422+
_lora_time.init(_rx2_closure_timer_for_class_c, [this] {
1423+
{
1424+
Lock lock(*this);
1425+
_lora_time.clear(_rx2_closure_timer_for_class_c);
1426+
}
1427+
_rx2_would_be_closure_for_class_c();
1428+
});
14231429

14241430
if (CLASS_A == _device_class) {
14251431
tr_debug("Changing device class to -> CLASS_A");
@@ -1805,14 +1811,34 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue,
18051811
_lora_phy->setup_public_network_mode(_params.is_nwk_public);
18061812
_lora_phy->put_radio_to_sleep();
18071813

1808-
_lora_time.init(_params.timers.backoff_timer,
1809-
mbed::callback(this, &LoRaMac::on_backoff_timer_expiry));
1810-
_lora_time.init(_params.timers.rx_window1_timer,
1811-
mbed::callback(this, &LoRaMac::open_rx1_window));
1812-
_lora_time.init(_params.timers.rx_window2_timer,
1813-
mbed::callback(this, &LoRaMac::open_rx2_window));
1814-
_lora_time.init(_params.timers.ack_timeout_timer,
1815-
mbed::callback(this, &LoRaMac::on_ack_timeout_timer_event));
1814+
_lora_time.init(_params.timers.backoff_timer, [this] {
1815+
{
1816+
Lock lock(*this);
1817+
_lora_time.clear(_params.timers.backoff_timer);
1818+
}
1819+
on_backoff_timer_expiry();
1820+
});
1821+
_lora_time.init(_params.timers.rx_window1_timer, [this] {
1822+
{
1823+
Lock lock(*this);
1824+
_lora_time.clear(_params.timers.rx_window1_timer);
1825+
}
1826+
open_rx1_window();
1827+
});
1828+
_lora_time.init(_params.timers.rx_window2_timer, [this] {
1829+
{
1830+
Lock lock(*this);
1831+
_lora_time.clear(_params.timers.rx_window2_timer);
1832+
}
1833+
open_rx2_window();
1834+
});
1835+
_lora_time.init(_params.timers.ack_timeout_timer, [this] {
1836+
{
1837+
Lock lock(*this);
1838+
_lora_time.clear(_params.timers.ack_timeout_timer);
1839+
}
1840+
on_ack_timeout_timer_event();
1841+
});
18161842

18171843
_params.timers.mac_init_time = _lora_time.get_current_time();
18181844

connectivity/lorawan/system/LoRaWANTimer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,8 @@ void LoRaWANTimeHandler::stop(timer_event_t &obj)
6464
_queue->cancel(obj.timer_id);
6565
obj.timer_id = 0;
6666
}
67+
68+
void LoRaWANTimeHandler::clear(timer_event_t &obj)
69+
{
70+
obj.timer_id = 0;
71+
}

connectivity/lorawan/system/LoRaWANTimer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ class LoRaWANTimeHandler {
7676
*/
7777
void stop(timer_event_t &obj);
7878

79+
/** Clear timer state so it is not inadvertently canceled. This function
80+
* must be called by the callback registered in init.
81+
*
82+
* @param [in] obj The structure containing the timer object parameters.
83+
*/
84+
void clear(timer_event_t &obj);
85+
7986
private:
8087
events::EventQueue *_queue;
8188
};

0 commit comments

Comments
 (0)