Skip to content

Commit 2f15dae

Browse files
author
Kimmo Vaisanen
committed
Lora: Refactor duty-cycle configuration and introduce config for JOIN request
- Duty cycle can be now only disabled with duty-cycle-on flag if region supports duty-cycle. If region does not support duty-cycle, this flag has no effect and duty cycle is always disabled. - Also introduced a new flag (duty-cycle-on-join) to disable duty cycle for JOIN requests. This flag can be used for testing only and is used to speed up JOIN request testing as backoff times for JOIN request are really long (easily several minutes per attempt). This flag works in conjunction with main duty cycle setting. Disabling duty-cycle-on-join works only if duty-cycle-on is disabled (or region settings have duty cycle disabled).
1 parent 3c25b96 commit 2f15dae

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,11 +1069,16 @@ lorawan_status_t LoRaMac::schedule_tx()
10691069
_params.timers.aggregated_timeoff = 0;
10701070
}
10711071

1072+
if (MBED_CONF_LORA_DUTY_CYCLE_ON && _lora_phy->verify_duty_cycle(true)) {
1073+
_params.is_dutycycle_on = true;
1074+
} else {
1075+
_params.is_dutycycle_on = false;
1076+
}
1077+
10721078
calculate_backOff(_params.last_channel_idx);
10731079

10741080
next_channel.aggregate_timeoff = _params.timers.aggregated_timeoff;
10751081
next_channel.current_datarate = _params.sys_params.channel_data_rate;
1076-
_params.is_dutycycle_on = MBED_CONF_LORA_DUTY_CYCLE_ON;
10771082
next_channel.dc_enabled = _params.is_dutycycle_on;
10781083
next_channel.joined = _is_nwk_joined;
10791084
next_channel.last_aggregate_tx_time = _params.timers.aggregated_last_tx_time;
@@ -1157,9 +1162,6 @@ lorawan_status_t LoRaMac::schedule_tx()
11571162
void LoRaMac::calculate_backOff(uint8_t channel)
11581163
{
11591164
lorawan_time_t elapsed_time = _lora_time.get_elapsed_time(_params.timers.mac_init_time);
1160-
1161-
_params.is_dutycycle_on = MBED_CONF_LORA_DUTY_CYCLE_ON;
1162-
11631165
_lora_phy->calculate_backoff(_is_nwk_joined, _params.is_last_tx_join_request, _params.is_dutycycle_on,
11641166
channel, elapsed_time, _params.timers.tx_toa);
11651167

features/lorawan/lorastack/phy/LoRaPHY.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
270270

271271
// Update bands Time OFF
272272
for (uint8_t i = 0; i < nb_bands; i++) {
273-
274-
if (joined == false) {
273+
if (MBED_CONF_LORA_DUTY_CYCLE_ON_JOIN && joined == false) {
275274
uint32_t txDoneTime = MAX(_lora_time->get_elapsed_time(bands[i].last_join_tx_time),
276275
(duty_cycle == true) ?
277276
_lora_time->get_elapsed_time(bands[i].last_tx_time) : 0);
@@ -283,7 +282,6 @@ lorawan_time_t LoRaPHY::update_band_timeoff(bool joined, bool duty_cycle,
283282
if (bands[i].off_time != 0) {
284283
next_tx_delay = MIN(bands[i].off_time - txDoneTime, next_tx_delay);
285284
}
286-
287285
} else {
288286
// if network has been joined
289287
if (duty_cycle == true) {
@@ -451,7 +449,7 @@ uint8_t LoRaPHY::get_bandwidth(uint8_t dr)
451449
}
452450
}
453451

454-
uint8_t LoRaPHY::enabled_channel_count(bool joined, uint8_t datarate,
452+
uint8_t LoRaPHY::enabled_channel_count(uint8_t datarate,
455453
const uint16_t *channel_mask,
456454
uint8_t *channel_indices,
457455
uint8_t *delayTx)
@@ -1183,7 +1181,7 @@ void LoRaPHY::calculate_backoff(bool joined, bool last_tx_was_join_req, bool dc_
11831181
// Reset time-off to initial value.
11841182
band_table[band_idx].off_time = 0;
11851183

1186-
if (joined == false) {
1184+
if (MBED_CONF_LORA_DUTY_CYCLE_ON_JOIN && joined == false) {
11871185
// Get the join duty cycle
11881186
if (elapsed_time < 3600000) {
11891187
join_duty_cycle = BACKOFF_DC_1_HOUR;
@@ -1246,7 +1244,7 @@ lorawan_status_t LoRaPHY::set_next_channel(channel_selection_params_t *params,
12461244
band_table, phy_params.bands.size);
12471245

12481246
// Search how many channels are enabled
1249-
channel_count = enabled_channel_count(params->joined, params->current_datarate,
1247+
channel_count = enabled_channel_count(params->current_datarate,
12501248
phy_params.channels.mask,
12511249
enabled_channels, &delay_tx);
12521250
} else {

features/lorawan/lorastack/phy/LoRaPHY.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class LoRaPHY : private mbed::NonCopyable<LoRaPHY> {
632632
*/
633633
uint8_t get_bandwidth(uint8_t dr_index);
634634

635-
uint8_t enabled_channel_count(bool joined, uint8_t datarate,
635+
uint8_t enabled_channel_count(uint8_t datarate,
636636
const uint16_t *mask, uint8_t* enabledChannels,
637637
uint8_t* delayTx);
638638

features/lorawan/lorastack/phy/LoRaPHYAS923.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ lorawan_status_t LoRaPHYAS923::set_next_channel(channel_selection_params_t* next
361361
bands, AS923_MAX_NB_BANDS);
362362

363363
// Search how many channels are enabled
364-
nb_enabled_channels = enabled_channel_count(next_channel_prams->joined,
365-
next_channel_prams->current_datarate,
364+
nb_enabled_channels = enabled_channel_count(next_channel_prams->current_datarate,
366365
channel_mask,
367366
enabled_channels, &delay_tx);
368367
} else {

features/lorawan/lorastack/phy/LoRaPHYAU915.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,9 @@ lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t* next
593593
bands, AU915_MAX_NB_BANDS);
594594

595595
// Search how many channels are enabled
596-
nb_enabled_channels = enabled_channel_count(next_chan_params->joined,
597-
next_chan_params->current_datarate,
598-
current_channel_mask,
599-
enabled_channels, &delay_tx);
596+
nb_enabled_channels = enabled_channel_count(next_chan_params->current_datarate,
597+
current_channel_mask,
598+
enabled_channels, &delay_tx);
600599
} else {
601600
delay_tx++;
602601
next_tx_delay = next_chan_params->aggregate_timeoff - _lora_time->get_elapsed_time(next_chan_params->last_aggregate_tx_time);

features/lorawan/lorastack/phy/LoRaPHYKR920.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ lorawan_status_t LoRaPHYKR920::set_next_channel(channel_selection_params_t* para
430430
bands, KR920_MAX_NB_BANDS);
431431

432432
// Search how many channels are enabled
433-
nb_enabled_channels = enabled_channel_count(params->joined, params->current_datarate,
434-
channel_mask,
435-
enabled_channels, &delay_tx);
433+
nb_enabled_channels = enabled_channel_count(params->current_datarate,
434+
channel_mask,
435+
enabled_channels, &delay_tx);
436436
} else {
437437
delay_tx++;
438438
nextTxDelay = params->aggregate_timeoff - _lora_time->get_elapsed_time(params->last_aggregate_tx_time);

features/lorawan/lorastack/phy/LoRaPHYUS915.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ lorawan_status_t LoRaPHYUS915::set_next_channel(channel_selection_params_t* para
631631
next_tx_delay = update_band_timeoff(params->joined, params->dc_enabled, bands, US915_MAX_NB_BANDS);
632632

633633
// Search how many channels are enabled
634-
nb_enabled_channels = enabled_channel_count(params->joined,
635-
params->current_datarate,
634+
nb_enabled_channels = enabled_channel_count(params->current_datarate,
636635
current_channel_mask,
637636
enabled_channels, &delay_tx);
638637
} else {

features/lorawan/lorastack/phy/LoRaPHYUS915Hybrid.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,7 @@ lorawan_status_t LoRaPHYUS915Hybrid::set_next_channel(channel_selection_params_t
631631
US915_HYBRID_MAX_NB_BANDS);
632632

633633
// Search how many channels are enabled
634-
nb_enabled_channels = enabled_channel_count(params->joined,
635-
params->current_datarate,
634+
nb_enabled_channels = enabled_channel_count(params->current_datarate,
636635
current_channel_mask,
637636
enabled_channels, &delay_tx);
638637
} else {

features/lorawan/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
"help": "Enables/disables duty cycling. NOTE: Disable only for testing. Mandatory in many regions.",
5858
"value": true
5959
},
60+
"duty-cycle-on-join": {
61+
"help": "Enables/disables duty cycling for JOIN requests (disabling requires duty-cycle-on to be disabled). NOTE: Disable only for testing!",
62+
"value": true
63+
},
6064
"lbt-on": {
6165
"help": "Enables/disables LBT. NOTE: [This feature is not yet integrated].",
6266
"value": false

0 commit comments

Comments
 (0)