Skip to content

Commit 1310392

Browse files
author
Antti Kauppila
committed
LoRa: Removed unneeded function and cleaned up some code
1 parent d1bbd21 commit 1310392

File tree

3 files changed

+57
-66
lines changed

3 files changed

+57
-66
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ lorawan_status_t LoRaWANStack::connect()
150150
const static uint32_t nwk_id = (MBED_CONF_LORA_DEVICE_ADDRESS & LORAWAN_NETWORK_ID_MASK);
151151

152152
connection_params.connect_type = LORAWAN_CONNECTION_ABP;
153-
connection_params.connection_u.abp.nwk_id = const_cast<uint8_t *>(nwk_id);
154-
connection_params.connection_u.abp.dev_addr = const_cast<uint8_t *>(dev_addr);
153+
connection_params.connection_u.abp.nwk_id = nwk_id;
154+
connection_params.connection_u.abp.dev_addr = dev_addr;
155155
connection_params.connection_u.abp.nwk_skey = const_cast<uint8_t *>(nwk_skey);
156156
connection_params.connection_u.abp.app_skey = const_cast<uint8_t *>(app_skey);
157157

@@ -640,61 +640,63 @@ void LoRaWANStack::mcps_indication_handler(loramac_mcps_indication_t *mcps_indic
640640
}
641641
#endif
642642

643-
if (mcps_indication->is_data_recvd == true) {
644-
switch (mcps_indication->port) {
645-
case 224: {
643+
if (!mcps_indication->is_data_recvd) {
644+
return;
645+
}
646+
647+
switch (mcps_indication->port) {
648+
case 224: {
646649
#if defined(LORAWAN_COMPLIANCE_TEST)
647-
tr_debug("Compliance test command received.");
648-
compliance_test_handler(mcps_indication);
650+
tr_debug("Compliance test command received.");
651+
compliance_test_handler(mcps_indication);
649652
#else
650-
tr_info("Compliance test disabled.");
653+
tr_info("Compliance test disabled.");
651654
#endif
652-
break;
653-
}
654-
default: {
655-
if (is_port_valid(mcps_indication->port) == true ||
656-
mcps_indication->type == MCPS_PROPRIETARY) {
657-
658-
// Valid message arrived.
659-
_rx_msg.type = LORAMAC_RX_MCPS_INDICATION;
660-
_rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size;
661-
_rx_msg.msg.mcps_indication.port = mcps_indication->port;
662-
_rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer;
663-
664-
// Notify application about received frame..
665-
tr_debug("Received %d bytes", _rx_msg.msg.mcps_indication.buffer_size);
666-
_rx_msg.receive_ready = true;
667-
668-
if (_callbacks.events) {
669-
const int ret = _queue->call(_callbacks.events, RX_DONE);
670-
MBED_ASSERT(ret != 0);
671-
(void)ret;
672-
}
655+
break;
656+
}
657+
default: {
658+
if (is_port_valid(mcps_indication->port) == true ||
659+
mcps_indication->type == MCPS_PROPRIETARY) {
673660

674-
//TODO: below if clauses can be combined,
675-
// because those are calling same function with same parameters
661+
// Valid message arrived.
662+
_rx_msg.type = LORAMAC_RX_MCPS_INDICATION;
663+
_rx_msg.msg.mcps_indication.buffer_size = mcps_indication->buffer_size;
664+
_rx_msg.msg.mcps_indication.port = mcps_indication->port;
665+
_rx_msg.msg.mcps_indication.buffer = mcps_indication->buffer;
676666

677-
// If fPending bit is set we try to generate an empty packet
678-
// with CONFIRMED flag set. We always set a CONFIRMED flag so
679-
// that we could retry a certain number of times if the uplink
680-
// failed for some reason
681-
if (_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status) {
682-
handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true);
683-
}
667+
// Notify application about received frame..
668+
tr_debug("Received %d bytes", _rx_msg.msg.mcps_indication.buffer_size);
669+
_rx_msg.receive_ready = true;
684670

685-
// Class C and node received a confirmed message so we need to
686-
// send an empty packet to acknowledge the message.
687-
// This scenario is unspecified by LoRaWAN 1.0.2 specification,
688-
// but version 1.1.0 says that network SHALL not send any new
689-
// confirmed messages until ack has been sent
690-
if (_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED) {
691-
handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true);
692-
}
693-
} else {
694-
// Invalid port, ports 0, 224 and 225-255 are reserved.
671+
if (_callbacks.events) {
672+
const int ret = _queue->call(_callbacks.events, RX_DONE);
673+
MBED_ASSERT(ret != 0);
674+
(void)ret;
695675
}
696-
break;
676+
677+
//TODO: below if clauses can be combined,
678+
// because those are calling same function with same parameters
679+
680+
// If fPending bit is set we try to generate an empty packet
681+
// with CONFIRMED flag set. We always set a CONFIRMED flag so
682+
// that we could retry a certain number of times if the uplink
683+
// failed for some reason
684+
if (_loramac.get_device_class() != CLASS_C && mcps_indication->fpending_status) {
685+
handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true);
686+
}
687+
688+
// Class C and node received a confirmed message so we need to
689+
// send an empty packet to acknowledge the message.
690+
// This scenario is unspecified by LoRaWAN 1.0.2 specification,
691+
// but version 1.1.0 says that network SHALL not send any new
692+
// confirmed messages until ack has been sent
693+
if (_loramac.get_device_class() == CLASS_C && mcps_indication->type == MCPS_CONFIRMED) {
694+
handle_tx(mcps_indication->port, NULL, 0, MSG_CONFIRMED_FLAG, true);
695+
}
696+
} else {
697+
// Invalid port, ports 0, 224 and 225-255 are reserved.
697698
}
699+
break;
698700
}
699701
}
700702
}

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,8 @@ void LoRaMac::on_rx_window1_timer_event(void)
964964
_lora_phy.rx_config(&_params.rx_window1_config,
965965
(int8_t*) &_mcps_indication.rx_datarate);
966966

967-
rx_window_setup(_params.rx_window1_config.is_rx_continuous,
968-
_params.sys_params.max_rx_win_time);
967+
_lora_phy.setup_rx_window(_params.rx_window1_config.is_rx_continuous,
968+
_params.sys_params.max_rx_win_time);
969969
}
970970

971971
void LoRaMac::on_rx_window2_timer_event(void)
@@ -978,18 +978,17 @@ void LoRaMac::on_rx_window2_timer_event(void)
978978
_params.rx_window2_config.is_repeater_supported = _params.is_repeater_supported;
979979
_params.rx_window2_config.rx_slot = RX_SLOT_WIN_2;
980980

981+
_params.rx_window2_config.is_rx_continuous = true;
982+
981983
if (_device_class != CLASS_C) {
982984
_params.rx_window2_config.is_rx_continuous = false;
983-
} else {
984-
// Setup continuous listening for class c
985-
_params.rx_window2_config.is_rx_continuous = true;
986985
}
987986

988987
if (_lora_phy.rx_config(&_params.rx_window2_config,
989988
(int8_t*) &_mcps_indication.rx_datarate) == true) {
990989

991-
rx_window_setup(_params.rx_window2_config.is_rx_continuous,
992-
_params.sys_params.max_rx_win_time);
990+
_lora_phy.setup_rx_window(_params.rx_window2_config.is_rx_continuous,
991+
_params.sys_params.max_rx_win_time);
993992

994993
_params.rx_slot = RX_SLOT_WIN_2;
995994
}
@@ -1037,11 +1036,6 @@ void LoRaMac::on_ack_timeout_timer_event(void)
10371036
}
10381037
}
10391038

1040-
void LoRaMac::rx_window_setup(bool rx_continuous, uint32_t max_rx_window_time)
1041-
{
1042-
_lora_phy.setup_rx_window(rx_continuous, max_rx_window_time);
1043-
}
1044-
10451039
bool LoRaMac::validate_payload_length(uint8_t length, int8_t datarate,
10461040
uint8_t fopts_len)
10471041
{

features/lorawan/lorastack/mac/LoRaMac.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,6 @@ class LoRaMac {
452452
*/
453453
void on_ack_timeout_timer_event(void);
454454

455-
/**
456-
* Initializes and opens the reception window
457-
*/
458-
void rx_window_setup(bool rx_continuous, uint32_t max_rx_window_time);
459-
460455
/**
461456
* Validates if the payload fits into the frame, taking the datarate
462457
* into account.

0 commit comments

Comments
 (0)