Lora: All API methods should check if stack has been initialized

pull/6938/head
Kimmo Vaisanen 2018-05-17 10:53:30 +03:00 committed by Hasnain Virk
parent 52cb119571
commit d3327c3f5a
1 changed files with 23 additions and 12 deletions

View File

@ -127,6 +127,10 @@ lorawan_status_t LoRaWANStack::initialize_mac_layer(EventQueue *queue)
lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t *callbacks)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (!callbacks || !callbacks->events) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -148,7 +152,6 @@ lorawan_status_t LoRaWANStack::set_lora_callbacks(const lorawan_app_callbacks_t
lorawan_status_t LoRaWANStack::connect()
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -164,7 +167,6 @@ lorawan_status_t LoRaWANStack::connect()
lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -186,7 +188,6 @@ lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel_plan)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -196,7 +197,6 @@ lorawan_status_t LoRaWANStack::add_channels(const lorawan_channelplan_t &channel
lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -206,7 +206,6 @@ lorawan_status_t LoRaWANStack::remove_a_channel(uint8_t channel_id)
lorawan_status_t LoRaWANStack::drop_channel_list()
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -216,7 +215,6 @@ lorawan_status_t LoRaWANStack::drop_channel_list()
lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t& channel_plan)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
tr_error("Stack not initialized!");
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -225,6 +223,10 @@ lorawan_status_t LoRaWANStack::get_enabled_channels(lorawan_channelplan_t& chann
lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (count >= MAX_CONFIRMED_MSG_RETRIES) {
return LORAWAN_STATUS_PARAMETER_INVALID;
}
@ -236,9 +238,7 @@ lorawan_status_t LoRaWANStack::set_confirmed_msg_retry(uint8_t count)
lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state)
{
tr_error("Stack not initialized!");
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
@ -248,11 +248,10 @@ lorawan_status_t LoRaWANStack::set_channel_data_rate(uint8_t data_rate)
lorawan_status_t LoRaWANStack::enable_adaptive_datarate(bool adr_enabled)
{
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED)
{
tr_error("Stack not initialized!");
if (_device_current_state == DEVICE_STATE_NOT_INITIALIZED) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
_loramac.enable_adaptive_datarate(adr_enabled);
return LORAWAN_STATUS_OK;
}
@ -410,6 +409,10 @@ int16_t LoRaWANStack::handle_rx(uint8_t* data, uint16_t length, uint8_t& port, i
lorawan_status_t LoRaWANStack::set_link_check_request()
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
_link_check_requested = true;
if (!_callbacks.link_check_resp) {
tr_error("Must assign a callback function for link check request. ");
@ -427,11 +430,19 @@ void LoRaWANStack::remove_link_check_request()
lorawan_status_t LoRaWANStack::shutdown()
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
return state_controller(DEVICE_STATE_SHUTDOWN);
}
lorawan_status_t LoRaWANStack::set_device_class(const device_class_t& device_class)
{
if (DEVICE_STATE_NOT_INITIALIZED == _device_current_state) {
return LORAWAN_STATUS_NOT_INITIALIZED;
}
if (device_class == CLASS_B) {
return LORAWAN_STATUS_UNSUPPORTED;
}