diff --git a/features/lorawan/LoRaWANStack.cpp b/features/lorawan/LoRaWANStack.cpp index 0eee8876b7..ab068a6dd3 100644 --- a/features/lorawan/LoRaWANStack.cpp +++ b/features/lorawan/LoRaWANStack.cpp @@ -150,8 +150,8 @@ lorawan_status_t LoRaWANStack::connect() const static uint32_t nwk_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK); connection_params.connect_type = LORAWAN_CONNECTION_ABP; - connection_params.connection_u.abp.nwk_id = const_cast(nwk_id); - connection_params.connection_u.abp.dev_addr = const_cast(dev_addr); + connection_params.connection_u.abp.nwk_id = nwk_id; + connection_params.connection_u.abp.dev_addr = dev_addr; connection_params.connection_u.abp.nwk_skey = const_cast(nwk_skey); connection_params.connection_u.abp.app_skey = const_cast(app_skey); @@ -640,61 +640,63 @@ void LoRaWANStack::mcps_indication_handler(loramac_mcps_indication_t *mcps_indic } #endif - if (mcps_indication->is_data_recvd == true) { - switch (mcps_indication->port) { - case 224: { + if (!mcps_indication->is_data_recvd) { + return; + } + + switch (mcps_indication->port) { + case 224: { #if defined(LORAWAN_COMPLIANCE_TEST) - tr_debug("Compliance test command received."); - compliance_test_handler(mcps_indication); + tr_debug("Compliance test command received."); + compliance_test_handler(mcps_indication); #else - tr_info("Compliance test disabled."); + tr_info("Compliance test disabled."); #endif - break; - } - default: { - if (is_port_valid(mcps_indication->port) == true || - mcps_indication->type == MCPS_PROPRIETARY) { + break; + } + default: { + if (is_port_valid(mcps_indication->port) == true || + mcps_indication->type == MCPS_PROPRIETARY) { - // Valid message arrived. - _rx_msg.type = LORAMAC_RX_MCPS_INDICATION; - _rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size; - _rx_msg.msg.mcps_indication.port = mcps_indication->port; - _rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer; + // Valid message arrived. + _rx_msg.type = LORAMAC_RX_MCPS_INDICATION; + _rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size; + _rx_msg.msg.mcps_indication.port = mcps_indication->port; + _rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer; - // Notify application about received frame.. - tr_debug("Received %d bytes", _rx_msg.msg.mcps_indication.buffer_size); - _rx_msg.receive_ready = true; + // Notify application about received frame.. + tr_debug("Received %d bytes", _rx_msg.msg.mcps_indication.buffer_size); + _rx_msg.receive_ready = true; - if (_callbacks.events) { - const int ret = _queue->call(_callbacks.events, RX_DONE); - MBED_ASSERT(ret != 0); - (void)ret; - } - - //TODO: below if clauses can be combined, - // because those are calling same function with same parameters - - // If fPending bit is set we try to generate an empty packet - // with CONFIRMED flag set. We always set a CONFIRMED flag so - // that we could retry a certain number of times if the uplink - // failed for some reason - if (_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status) { - handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true); - } - - // Class C and node received a confirmed message so we need to - // send an empty packet to acknowledge the message. - // This scenario is unspecified by LoRaWAN 1.0.2 specification, - // but version 1.1.0 says that network SHALL not send any new - // confirmed messages until ack has been sent - if (_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED) { - handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true); - } - } else { - // Invalid port, ports 0, 224 and 225-255 are reserved. + if (_callbacks.events) { + const int ret = _queue->call(_callbacks.events, RX_DONE); + MBED_ASSERT(ret != 0); + (void)ret; } - break; + + //TODO: below if clauses can be combined, + // because those are calling same function with same parameters + + // If fPending bit is set we try to generate an empty packet + // with CONFIRMED flag set. We always set a CONFIRMED flag so + // that we could retry a certain number of times if the uplink + // failed for some reason + if (_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status) { + handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true); + } + + // Class C and node received a confirmed message so we need to + // send an empty packet to acknowledge the message. + // This scenario is unspecified by LoRaWAN 1.0.2 specification, + // but version 1.1.0 says that network SHALL not send any new + // confirmed messages until ack has been sent + if (_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED) { + handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true); + } + } else { + // Invalid port, ports 0, 224 and 225-255 are reserved. } + break; } } } diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index 164887583d..5c3aec9a3f 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -964,8 +964,8 @@ void LoRaMac::on_rx_window1_timer_event(void) _lora_phy.rx_config(&_params.rx_window1_config, (int8_t*) &_mcps_indication.rx_datarate); - rx_window_setup(_params.rx_window1_config.is_rx_continuous, - _params.sys_params.max_rx_win_time); + _lora_phy.setup_rx_window(_params.rx_window1_config.is_rx_continuous, + _params.sys_params.max_rx_win_time); } void LoRaMac::on_rx_window2_timer_event(void) @@ -978,18 +978,17 @@ void LoRaMac::on_rx_window2_timer_event(void) _params.rx_window2_config.is_repeater_supported = _params.is_repeater_supported; _params.rx_window2_config.rx_slot = RX_SLOT_WIN_2; + _params.rx_window2_config.is_rx_continuous = true; + if (_device_class != CLASS_C) { _params.rx_window2_config.is_rx_continuous = false; - } else { - // Setup continuous listening for class c - _params.rx_window2_config.is_rx_continuous = true; } if (_lora_phy.rx_config(&_params.rx_window2_config, (int8_t*) &_mcps_indication.rx_datarate) == true) { - rx_window_setup(_params.rx_window2_config.is_rx_continuous, - _params.sys_params.max_rx_win_time); + _lora_phy.setup_rx_window(_params.rx_window2_config.is_rx_continuous, + _params.sys_params.max_rx_win_time); _params.rx_slot = RX_SLOT_WIN_2; } @@ -1037,11 +1036,6 @@ void LoRaMac::on_ack_timeout_timer_event(void) } } -void LoRaMac::rx_window_setup(bool rx_continuous, uint32_t max_rx_window_time) -{ - _lora_phy.setup_rx_window(rx_continuous, max_rx_window_time); -} - bool LoRaMac::validate_payload_length(uint8_t length, int8_t datarate, uint8_t fopts_len) { diff --git a/features/lorawan/lorastack/mac/LoRaMac.h b/features/lorawan/lorastack/mac/LoRaMac.h index c4825b35cf..863596e246 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.h +++ b/features/lorawan/lorastack/mac/LoRaMac.h @@ -452,11 +452,6 @@ private: */ void on_ack_timeout_timer_event(void); - /** - * Initializes and opens the reception window - */ - void rx_window_setup(bool rx_continuous, uint32_t max_rx_window_time); - /** * Validates if the payload fits into the frame, taking the datarate * into account.