Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions features/lorawan/LoRaWANStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,17 +603,14 @@ void LoRaWANStack::process_transmission(void)
_ctrl_flags &= ~TX_DONE_FLAG;
tr_debug("Awaiting ACK");
_device_current_state = DEVICE_STATE_AWAITING_ACK;
return;
}

// Class A unconfirmed message sent, TX_DONE event will be sent to
// application when RX2 windows is elapsed, i.e., in process_reception_timeout()
_ctrl_flags &= ~TX_ONGOING_FLAG;
_ctrl_flags |= TX_DONE_FLAG;

// In Class C, reception timeout never happens, so we handle the state
// progression for TX_DONE in UNCONFIRMED case here
if (_loramac.get_device_class() == CLASS_C) {
} else if (_loramac.get_device_class() == CLASS_A) {
// Class A unconfirmed message sent, TX_DONE event will be sent to
// application when RX2 windows is elapsed, i.e., in process_reception_timeout()
_ctrl_flags &= ~TX_ONGOING_FLAG;
_ctrl_flags |= TX_DONE_FLAG;
} else if (_loramac.get_device_class() == CLASS_C) {
// In Class C, reception timeout never happens, so we handle the state
// progression for TX_DONE in UNCONFIRMED case here
_loramac.post_process_mcps_req();
state_controller(DEVICE_STATE_STATUS_CHECK);
state_machine_run_to_completion();
Expand Down Expand Up @@ -669,9 +666,10 @@ void LoRaWANStack::process_reception(const uint8_t *const payload, uint16_t size
state_controller(DEVICE_STATE_STATUS_CHECK);
}
}
} else {
} else if (_loramac.get_device_class() == CLASS_A) {
// handle UNCONFIRMED case here, RX slots were turned off due to
// valid packet reception
// valid packet reception. For Class C, an outgoing UNCONFIRMED message
// gets its handling in process_transmission.
_loramac.post_process_mcps_req();
_ctrl_flags |= TX_DONE_FLAG;
state_controller(DEVICE_STATE_STATUS_CHECK);
Expand Down Expand Up @@ -805,8 +803,12 @@ void LoRaWANStack::send_event_to_application(const lorawan_event_t event) const

void LoRaWANStack::send_automatic_uplink_message(const uint8_t port)
{
// we will silently ignore the automatic uplink event if the user is already
// sending something
const int16_t ret = handle_tx(port, NULL, 0, MSG_CONFIRMED_FLAG, true, true);
if (ret < 0) {
if (ret == LORAWAN_STATUS_WOULD_BLOCK) {
_automatic_uplink_ongoing = false;
} else if (ret < 0) {
tr_debug("Failed to generate AUTOMATIC UPLINK, error code = %d", ret);
send_event_to_application(AUTOMATIC_UPLINK_ERROR);
}
Expand Down
23 changes: 10 additions & 13 deletions features/lorawan/lorastack/mac/LoRaMac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ void LoRaMac::post_process_mcps_req()
if (_params.is_ul_frame_counter_fixed == false) {
_params.ul_frame_counter++;
}
} else {
_mcps_confirmation.status = LORAMAC_EVENT_INFO_STATUS_ERROR;
}
} else {
//UNCONFIRMED or PROPRIETARY
Expand Down Expand Up @@ -671,7 +673,7 @@ void LoRaMac::on_radio_rx_done(const uint8_t *const payload, uint16_t size,
{
if (_device_class == CLASS_C && !_continuous_rx2_window_open) {
open_rx2_window();
} else {
} else if (_device_class != CLASS_C){
_lora_time.stop(_params.timers.rx_window1_timer);
_lora_phy->put_radio_to_sleep();
}
Expand Down Expand Up @@ -1078,13 +1080,13 @@ lorawan_status_t LoRaMac::schedule_tx()
uint8_t dr_offset = _lora_phy->apply_DR_offset(_params.sys_params.channel_data_rate,
_params.sys_params.rx1_dr_offset);

_lora_phy->compute_rx_win_params(dr_offset, _params.sys_params.min_rx_symb,
_params.sys_params.max_sys_rx_error,
_lora_phy->compute_rx_win_params(dr_offset, MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window1_config);

_lora_phy->compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
_params.sys_params.min_rx_symb,
_params.sys_params.max_sys_rx_error,
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window2_config);

if (!_is_nwk_joined) {
Expand Down Expand Up @@ -1353,8 +1355,8 @@ void LoRaMac::set_device_class(const device_class_t &device_class,
_params.is_node_ack_requested = false;
_lora_phy->put_radio_to_sleep();
_lora_phy->compute_rx_win_params(_params.sys_params.rx2_channel.datarate,
_params.sys_params.min_rx_symb,
_params.sys_params.max_sys_rx_error,
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
MBED_CONF_LORA_MAX_SYS_RX_ERROR,
&_params.rx_window2_config);
}

Expand Down Expand Up @@ -1730,9 +1732,6 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue)
_params.timers.aggregated_timeoff = 0;

_lora_phy->reset_to_default_values(&_params, true);

_params.sys_params.max_sys_rx_error = 10;
_params.sys_params.min_rx_symb = 6;
_params.sys_params.retry_num = 1;

reset_mac_parameters();
Expand All @@ -1755,9 +1754,7 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue)
_params.timers.mac_init_time = _lora_time.get_current_time();

_params.sys_params.adr_on = MBED_CONF_LORA_ADR_ON;

_params.is_nwk_public = MBED_CONF_LORA_PUBLIC_NETWORK;
_lora_phy->setup_public_network_mode(MBED_CONF_LORA_PUBLIC_NETWORK);
_params.sys_params.channel_data_rate = _lora_phy->get_default_max_tx_datarate();

return LORAWAN_STATUS_OK;
}
Expand Down
18 changes: 14 additions & 4 deletions features/lorawan/lorastack/phy/LoRaPHY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,16 @@ void LoRaPHY::reset_to_default_values(loramac_protocol_params *params, bool init

params->sys_params.channel_tx_power = get_default_tx_power();

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

params->sys_params.rx1_dr_offset = phy_params.default_rx1_dr_offset;

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

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

params->sys_params.uplink_dwell_time = phy_params.ul_dwell_time_setting;

Expand Down Expand Up @@ -560,6 +563,11 @@ uint8_t LoRaPHY::get_default_tx_datarate()
return phy_params.default_datarate;
}

uint8_t LoRaPHY::get_default_max_tx_datarate()
{
return phy_params.default_max_datarate;
}

uint8_t LoRaPHY::get_default_tx_power()
{
return phy_params.default_tx_power;
Expand Down Expand Up @@ -845,7 +853,8 @@ bool LoRaPHY::rx_config(rx_config_params_t *rx_conf)
false, rx_conf->is_rx_continuous);
} else {
modem = MODEM_LORA;
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0, 8,
_radio->set_rx_config(modem, rx_conf->bandwidth, phy_dr, 1, 0,
MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
rx_conf->window_timeout, false, 0, false, 0, 0,
true, rx_conf->is_rx_continuous);
}
Expand Down Expand Up @@ -895,7 +904,8 @@ bool LoRaPHY::tx_config(tx_config_params_t *tx_conf, int8_t *tx_power,
3000);
} else {
modem = MODEM_LORA;
_radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1, 8,
_radio->set_tx_config(modem, phy_tx_power, 0, bandwidth, phy_dr, 1,
MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH,
false, true, 0, 0, false, 3000);
}

Expand Down
8 changes: 8 additions & 0 deletions features/lorawan/lorastack/phy/LoRaPHY.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,14 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
*/
uint8_t get_default_tx_datarate();

/**
* @brief get_default_max_tx_datarate Gets the maximum achievable data rate for
* LoRa modulation. This will always be the highest data rate achievable with
* LoRa as defined in the regional specifications.
* @return Maximum achievable data rate with LoRa modulation.
*/
uint8_t get_default_max_tx_datarate();

/**
* @brief get_default_tx_power Gets the default TX power
* @return Default TX power
Expand Down
2 changes: 1 addition & 1 deletion features/lorawan/lorastack/phy/LoRaPHYAS923.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
*/
#define AS923_DEFAULT_DATARATE DR_2

#define AS923_DEFAULT_MAX_DATARATE DR_7
#define AS923_DEFAULT_MAX_DATARATE DR_5

/*!
* The minimum datarate which is used when the
Expand Down
12 changes: 12 additions & 0 deletions features/lorawan/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
"automatic-uplink-message": {
"help": "Stack will automatically send an uplink message when lora server requires immediate response",
"value": true
},
"max-sys-rx-error": {
"help": "Maximum timing error of the receiver in ms. The receiver will turn on in [-RxError : + RxError]",
"value": 10
},
"downlink-preamble-length": {
"help": "Number of preamble symbols need to be captured (out of 8) for successful demodulation",
"value": 5
},
"uplink-preamble-length": {
"help": "Number of preamble symbols to transmit. Must be <= 8",
"value": 8
}
}
}
11 changes: 0 additions & 11 deletions features/lorawan/system/lorawan_data_structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,6 @@ typedef struct {
* The data rate in channels.
*/
int8_t channel_data_rate;
/*!
* The system overall timing error in milliseconds.
* [-SystemMaxRxError : +SystemMaxRxError]
* Default: +/-10 ms
*/
uint32_t max_sys_rx_error;
/*!
* The minimum number of symbols required to detect an RX frame.
* Default: 6 symbols
*/
uint8_t min_rx_symb;
/*!
* LoRaMac maximum time a reception window stays open.
*/
Expand Down