Skip to content

Commit 35045f1

Browse files
Kimmo VaisanenHasnain Virk
authored andcommitted
Implement LoRaMac::disconnect
In order to reset LoRaMac's state in disconnect, we need to implement an API which can be used to cancel all outstanding requests and reset LoRaMac's internal state to idle. This commit introduces LoRaMac::disconnect() which can be used for this purpose.
1 parent 44bca59 commit 35045f1

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,9 @@ lorawan_status_t LoRaWANStack::lora_state_machine()
11931193
*/
11941194
drop_channel_list();
11951195

1196+
// Shutdown LoRaMac
1197+
_loramac.disconnect();
1198+
11961199
// Stop sending messages and set joined status to false.
11971200
#if defined(LORAWAN_COMPLIANCE_TEST)
11981201
_loramac.LoRaMacStopTxTimer();

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,6 +1834,36 @@ lorawan_status_t LoRaMac::LoRaMacInitialization(loramac_primitives_t *primitives
18341834
return LORAWAN_STATUS_OK;
18351835
}
18361836

1837+
void LoRaMac::disconnect()
1838+
{
1839+
// Cancel all timers
1840+
_lora_time.TimerStop(_params.timers.mac_state_check_timer);
1841+
_lora_time.TimerStop(_params.timers.tx_delayed_timer);
1842+
_lora_time.TimerStop(_params.timers.rx_window1_timer);
1843+
_lora_time.TimerStop(_params.timers.rx_window2_timer);
1844+
_lora_time.TimerStop(_params.timers.ack_timeout_timer);
1845+
1846+
// Put radio to sleep
1847+
lora_phy->put_radio_to_sleep();
1848+
1849+
// Reset internal state
1850+
_params.is_nwk_joined = false;
1851+
_params.is_ack_retry_timeout_expired = false;
1852+
_params.is_rx_window_enabled = true;
1853+
_params.is_node_ack_requested = false;
1854+
_params.is_srv_ack_requested = false;
1855+
_params.flags.value = 0;
1856+
_params.mac_state = 0;
1857+
1858+
// Clear MAC commands
1859+
mac_commands.ClearCommandBuffer();
1860+
mac_commands.ClearRepeatBuffer();
1861+
mac_commands.ClearMacCommandsInNextTx();
1862+
1863+
// Set internal state to idle.
1864+
_params.mac_state = LORAMAC_IDLE;
1865+
}
1866+
18371867
lorawan_status_t LoRaMac::LoRaMacQueryTxPossible( uint8_t size, loramac_tx_info_t* txInfo )
18381868
{
18391869
AdrNextParams_t adrNext;

features/lorawan/lorastack/mac/LoRaMac.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ class LoRaMac
9191
LoRaPHY *phy,
9292
events::EventQueue *queue);
9393

94+
/*!
95+
* \brief Disconnect LoRaMac layer
96+
*
97+
* \details Cancels all outstanding requests and sets LoRaMac's
98+
* internal state to idle.
99+
*/
100+
void disconnect(void);
101+
94102
/*!
95103
* \brief Queries the LoRaMAC whether it is possible to send the next frame with
96104
* a given payload size. The LoRaMAC takes the scheduled MAC commands into

0 commit comments

Comments
 (0)