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.
pull/6059/head
Kimmo Vaisanen 2018-01-26 14:33:26 +02:00 committed by Hasnain Virk
parent 44bca596c5
commit 35045f19cc
3 changed files with 41 additions and 0 deletions

View File

@ -1193,6 +1193,9 @@ lorawan_status_t LoRaWANStack::lora_state_machine()
*/
drop_channel_list();
// Shutdown LoRaMac
_loramac.disconnect();
// Stop sending messages and set joined status to false.
#if defined(LORAWAN_COMPLIANCE_TEST)
_loramac.LoRaMacStopTxTimer();

View File

@ -1834,6 +1834,36 @@ lorawan_status_t LoRaMac::LoRaMacInitialization(loramac_primitives_t *primitives
return LORAWAN_STATUS_OK;
}
void LoRaMac::disconnect()
{
// Cancel all timers
_lora_time.TimerStop(_params.timers.mac_state_check_timer);
_lora_time.TimerStop(_params.timers.tx_delayed_timer);
_lora_time.TimerStop(_params.timers.rx_window1_timer);
_lora_time.TimerStop(_params.timers.rx_window2_timer);
_lora_time.TimerStop(_params.timers.ack_timeout_timer);
// Put radio to sleep
lora_phy->put_radio_to_sleep();
// Reset internal state
_params.is_nwk_joined = false;
_params.is_ack_retry_timeout_expired = false;
_params.is_rx_window_enabled = true;
_params.is_node_ack_requested = false;
_params.is_srv_ack_requested = false;
_params.flags.value = 0;
_params.mac_state = 0;
// Clear MAC commands
mac_commands.ClearCommandBuffer();
mac_commands.ClearRepeatBuffer();
mac_commands.ClearMacCommandsInNextTx();
// Set internal state to idle.
_params.mac_state = LORAMAC_IDLE;
}
lorawan_status_t LoRaMac::LoRaMacQueryTxPossible( uint8_t size, loramac_tx_info_t* txInfo )
{
AdrNextParams_t adrNext;

View File

@ -91,6 +91,14 @@ public:
LoRaPHY *phy,
events::EventQueue *queue);
/*!
* \brief Disconnect LoRaMac layer
*
* \details Cancels all outstanding requests and sets LoRaMac's
* internal state to idle.
*/
void disconnect(void);
/*!
* \brief Queries the LoRaMAC whether it is possible to send the next frame with
* a given payload size. The LoRaMAC takes the scheduled MAC commands into