Skip to content

Commit 40ff622

Browse files
author
Cruz Monrreal
authored
Merge pull request ARMmbed#7601 from hasnainvirk/abp_auto_fix
LoRaWAN: Reduced priority for automatic uplinks & higher data rate usage for connection establishment
2 parents 1e676f6 + c7f3585 commit 40ff622

File tree

7 files changed

+61
-43
lines changed

7 files changed

+61
-43
lines changed

features/lorawan/LoRaWANStack.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,14 @@ void LoRaWANStack::process_transmission(void)
605605
_ctrl_flags &= ~TX_DONE_FLAG;
606606
tr_debug("Awaiting ACK");
607607
_device_current_state = DEVICE_STATE_AWAITING_ACK;
608-
return;
609-
}
610-
611-
// Class A unconfirmed message sent, TX_DONE event will be sent to
612-
// application when RX2 windows is elapsed, i.e., in process_reception_timeout()
613-
_ctrl_flags &= ~TX_ONGOING_FLAG;
614-
_ctrl_flags |= TX_DONE_FLAG;
615-
616-
// In Class C, reception timeout never happens, so we handle the state
617-
// progression for TX_DONE in UNCONFIRMED case here
618-
if (_loramac.get_device_class() == CLASS_C) {
608+
} else if (_loramac.get_device_class() == CLASS_A) {
609+
// Class A unconfirmed message sent, TX_DONE event will be sent to
610+
// application when RX2 windows is elapsed, i.e., in process_reception_timeout()
611+
_ctrl_flags &= ~TX_ONGOING_FLAG;
612+
_ctrl_flags |= TX_DONE_FLAG;
613+
} else if (_loramac.get_device_class() == CLASS_C) {
614+
// In Class C, reception timeout never happens, so we handle the state
615+
// progression for TX_DONE in UNCONFIRMED case here
619616
_loramac.post_process_mcps_req();
620617
state_controller(DEVICE_STATE_STATUS_CHECK);
621618
state_machine_run_to_completion();
@@ -678,9 +675,10 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size
678675
state_controller(DEVICE_STATE_STATUS_CHECK);
679676
}
680677
}
681-
} else {
678+
} else if (_loramac.get_device_class() == CLASS_A) {
682679
// handle UNCONFIRMED case here, RX slots were turned off due to
683-
// valid packet reception
680+
// valid packet reception. For Class C, an outgoing UNCONFIRMED message
681+
// gets its handling in process_transmission.
684682
_loramac.post_process_mcps_req();
685683
_ctrl_flags |= TX_DONE_FLAG;
686684
state_controller(DEVICE_STATE_STATUS_CHECK);
@@ -814,8 +812,12 @@ void LoRaWANStack::send_event_to_application(const lorawan_event_t event) const
814812

815813
void LoRaWANStack::send_automatic_uplink_message(const uint8_t port)
816814
{
815+
// we will silently ignore the automatic uplink event if the user is already
816+
// sending something
817817
const int16_t ret = handle_tx(port, NULL, 0, MSG_CONFIRMED_FLAG, true, true);
818-
if (ret < 0) {
818+
if (ret == LORAWAN_STATUS_WOULD_BLOCK) {
819+
_automatic_uplink_ongoing = false;
820+
} else if (ret < 0) {
819821
tr_debug("Failed to generate AUTOMATIC UPLINK, error code = %d", ret);
820822
send_event_to_application(AUTOMATIC_UPLINK_ERROR);
821823
}

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ void LoRaMac::post_process_mcps_req()
164164
if (_params.is_ul_frame_counter_fixed == false) {
165165
_params.ul_frame_counter++;
166166
}
167+
} else {
168+
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
167169
}
168170
} else {
169171
//UNCONFIRMED or PROPRIETARY
@@ -665,7 +667,7 @@ void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
665667
{
666668
if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
667669
open_rx2_window();
668-
} else {
670+
} else if (_device_class != CLASS_C){
669671
_lora_time.stop(_params.timers.rx_window1_timer);
670672
_lora_phy->put_radio_to_sleep();
671673
}
@@ -1101,13 +1103,13 @@ lorawan_status_t LoRaMac::schedule_tx()
11011103
uint8_t dr_offset = _lora_phy->apply_DR_offset(_params.sys_params.channel_data_rate,
11021104
_params.sys_params.rx1_dr_offset);
11031105

1104-
_lora_phy->compute_rx_win_params(dr_offset, _params.sys_params.min_rx_symb,
1105-
_params.sys_params.max_sys_rx_error,
1106+
_lora_phy->compute_rx_win_params(dr_offset, MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
1107+
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
11061108
&_params.rx_window1_config);
11071109

11081110
_lora_phy->compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
1109-
_params.sys_params.min_rx_symb,
1110-
_params.sys_params.max_sys_rx_error,
1111+
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
1112+
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
11111113
&_params.rx_window2_config);
11121114

11131115
if (!_is_nwk_joined) {
@@ -1376,8 +1378,8 @@ void LoRaMac::set_device_class(const device_class_t &device_class,
13761378
_params.is_node_ack_requested = false;
13771379
_lora_phy->put_radio_to_sleep();
13781380
_lora_phy->compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
1379-
_params.sys_params.min_rx_symb,
1380-
_params.sys_params.max_sys_rx_error,
1381+
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
1382+
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
13811383
&_params.rx_window2_config);
13821384
}
13831385

@@ -1755,9 +1757,6 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue,
17551757
_params.timers.aggregated_timeoff = 0;
17561758

17571759
_lora_phy->reset_to_default_values(&_params, true);
1758-
1759-
_params.sys_params.max_sys_rx_error = 10;
1760-
_params.sys_params.min_rx_symb = 6;
17611760
_params.sys_params.retry_num = 1;
17621761

17631762
reset_mac_parameters();
@@ -1780,9 +1779,7 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue,
17801779
_params.timers.mac_init_time = _lora_time.get_current_time();
17811780

17821781
_params.sys_params.adr_on = MBED_CONF_LORA_ADR_ON;
1783-
1784-
_params.is_nwk_public = MBED_CONF_LORA_PUBLIC_NETWORK;
1785-
_lora_phy->setup_public_network_mode(MBED_CONF_LORA_PUBLIC_NETWORK);
1782+
_params.sys_params.channel_data_rate = _lora_phy->get_default_max_tx_datarate();
17861783

17871784
return LORAWAN_STATUS_OK;
17881785
}

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,16 @@ void LoRaPHY::reset_to_default_values(loramac_protocol_params *params, bool init
514514

515515
params->sys_params.channel_tx_power = get_default_tx_power();
516516

517-
params->sys_params.channel_data_rate = get_default_tx_datarate();
517+
// We shall always start with highest achievable data rate.
518+
// Subsequent decrease in data rate will mean increase in range henceforth.
519+
params->sys_params.channel_data_rate = get_default_max_tx_datarate();
518520

519521
params->sys_params.rx1_dr_offset = phy_params.default_rx1_dr_offset;
520522

521523
params->sys_params.rx2_channel.frequency = get_default_rx2_frequency();
522524

523-
params->sys_params.rx2_channel.datarate = get_default_rx2_datarate();
525+
// RX2 data rate should also start from the maximum
526+
params->sys_params.rx2_channel.datarate = get_default_max_tx_datarate();
524527

525528
params->sys_params.uplink_dwell_time = phy_params.ul_dwell_time_setting;
526529

@@ -560,6 +563,11 @@ uint8_t LoRaPHY::get_default_tx_datarate()
560563
return phy_params.default_datarate;
561564
}
562565

566+
uint8_t LoRaPHY::get_default_max_tx_datarate()
567+
{
568+
return phy_params.default_max_datarate;
569+
}
570+
563571
uint8_t LoRaPHY::get_default_tx_power()
564572
{
565573
return phy_params.default_tx_power;
@@ -845,7 +853,8 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
845853
false, rx_conf->is_rx_continuous);
846854
} else {
847855
modem = MODEM_LORA;
848-
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0, 8,
856+
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0,
857+
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
849858
rx_conf->window_timeout, false, 0, false, 0, 0,
850859
true, rx_conf->is_rx_continuous);
851860
}
@@ -895,7 +904,8 @@ bool LoRaPHY::tx_config(tx_config_params_t *tx_conf, int8_t *tx_power,
895904
3000);
896905
} else {
897906
modem = MODEM_LORA;
898-
_radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
907+
_radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1,
908+
MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH,
899909
false, true, 0, 0, false, 3000);
900910
}
901911

features/lorawan/lorastack/phy/LoRaPHY.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
423423
*/
424424
uint8_t get_default_tx_datarate();
425425

426+
/**
427+
* @brief get_default_max_tx_datarate Gets the maximum achievable data rate for
428+
* LoRa modulation. This will always be the highest data rate achievable with
429+
* LoRa as defined in the regional specifications.
430+
* @return Maximum achievable data rate with LoRa modulation.
431+
*/
432+
uint8_t get_default_max_tx_datarate();
433+
426434
/**
427435
* @brief get_default_tx_power Gets the default TX power
428436
* @return Default TX power

features/lorawan/lorastack/phy/LoRaPHYAS923.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
*/
6868
#define AS923_DEFAULT_DATARATE DR_2
6969

70-
#define AS923_DEFAULT_MAX_DATARATE DR_7
70+
#define AS923_DEFAULT_MAX_DATARATE DR_5
7171

7272
/*!
7373
* The minimum datarate which is used when the

features/lorawan/mbed_lib.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
"automatic-uplink-message": {
6565
"help": "Stack will automatically send an uplink message when lora server requires immediate response",
6666
"value": true
67+
},
68+
"max-sys-rx-error": {
69+
"help": "Maximum timing error of the receiver in ms. The receiver will turn on in [-RxError : + RxError]",
70+
"value": 10
71+
},
72+
"downlink-preamble-length": {
73+
"help": "Number of preamble symbols need to be captured (out of 8) for successful demodulation",
74+
"value": 5
75+
},
76+
"uplink-preamble-length": {
77+
"help": "Number of preamble symbols to transmit. Must be <= 8",
78+
"value": 8
6779
}
6880
}
6981
}

features/lorawan/system/lorawan_data_structures.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,6 @@ typedef struct {
166166
* The data rate in channels.
167167
*/
168168
int8_t channel_data_rate;
169-
/*!
170-
* The system overall timing error in milliseconds.
171-
* [-SystemMaxRxError : +SystemMaxRxError]
172-
* Default: +/-10 ms
173-
*/
174-
uint32_t max_sys_rx_error;
175-
/*!
176-
* The minimum number of symbols required to detect an RX frame.
177-
* Default: 6 symbols
178-
*/
179-
uint8_t min_rx_symb;
180169
/*!
181170
* LoRaMac maximum time a reception window stays open.
182171
*/

0 commit comments

Comments
 (0)