Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
LoRaPHYAU915.cpp
00001 /** 00002 * @file LoRaPHYAU915.cpp 00003 * 00004 * @brief Implements LoRaPHY for Australian 915 MHz band 00005 * 00006 * \code 00007 * ______ _ 00008 * / _____) _ | | 00009 * ( (____ _____ ____ _| |_ _____ ____| |__ 00010 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 00011 * _____) ) ____| | | || |_| ____( (___| | | | 00012 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 00013 * (C)2013 Semtech 00014 * ___ _____ _ ___ _ _____ ___ ___ ___ ___ 00015 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| 00016 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| 00017 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| 00018 * embedded.connectivity.solutions=============== 00019 * 00020 * \endcode 00021 * 00022 * 00023 * License: Revised BSD License, see LICENSE.TXT file include in the project 00024 * 00025 * Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE ) 00026 * 00027 * Copyright (c) 2017, Arm Limited and affiliates. 00028 * SPDX-License-Identifier: BSD-3-Clause 00029 * 00030 */ 00031 00032 #include "LoRaPHYAU915.h" 00033 #include "lora_phy_ds.h" 00034 00035 /*! 00036 * Minimal datarate that can be used by the node 00037 */ 00038 #define AU915_TX_MIN_DATARATE DR_0 00039 00040 /*! 00041 * Maximal datarate that can be used by the node 00042 */ 00043 #define AU915_TX_MAX_DATARATE DR_6 00044 00045 /*! 00046 * Minimal datarate that can be used by the node 00047 */ 00048 #define AU915_RX_MIN_DATARATE DR_8 00049 00050 /*! 00051 * Maximal datarate that can be used by the node 00052 */ 00053 #define AU915_RX_MAX_DATARATE DR_13 00054 00055 /*! 00056 * Default datarate used by the node 00057 */ 00058 #define AU915_DEFAULT_DATARATE DR_0 00059 00060 /*! 00061 * Minimal Rx1 receive datarate offset 00062 */ 00063 #define AU915_MIN_RX1_DR_OFFSET 0 00064 00065 /*! 00066 * Maximal Rx1 receive datarate offset 00067 */ 00068 #define AU915_MAX_RX1_DR_OFFSET 6 00069 00070 /*! 00071 * Default Rx1 receive datarate offset 00072 */ 00073 #define AU915_DEFAULT_RX1_DR_OFFSET 0 00074 00075 /*! 00076 * Minimal Tx output power that can be used by the node 00077 */ 00078 #define AU915_MIN_TX_POWER TX_POWER_10 00079 00080 /*! 00081 * Maximal Tx output power that can be used by the node 00082 */ 00083 #define AU915_MAX_TX_POWER TX_POWER_0 00084 00085 /*! 00086 * Default Tx output power used by the node 00087 */ 00088 #define AU915_DEFAULT_TX_POWER TX_POWER_0 00089 00090 /*! 00091 * Default Max EIRP 00092 */ 00093 #define AU915_DEFAULT_MAX_EIRP 30.0f 00094 00095 /*! 00096 * Default antenna gain 00097 */ 00098 #define AU915_DEFAULT_ANTENNA_GAIN 2.15f 00099 00100 /*! 00101 * ADR Ack limit 00102 */ 00103 #define AU915_ADR_ACK_LIMIT 64 00104 00105 /*! 00106 * ADR Ack delay 00107 */ 00108 #define AU915_ADR_ACK_DELAY 32 00109 00110 /*! 00111 * Enabled or disabled the duty cycle 00112 */ 00113 #define AU915_DUTY_CYCLE_ENABLED 0 00114 00115 /*! 00116 * Maximum RX window duration 00117 */ 00118 #define AU915_MAX_RX_WINDOW 3000 00119 00120 /*! 00121 * Receive delay 1 00122 */ 00123 #define AU915_RECEIVE_DELAY1 1000 00124 00125 /*! 00126 * Receive delay 2 00127 */ 00128 #define AU915_RECEIVE_DELAY2 2000 00129 00130 /*! 00131 * Join accept delay 1 00132 */ 00133 #define AU915_JOIN_ACCEPT_DELAY1 5000 00134 00135 /*! 00136 * Join accept delay 2 00137 */ 00138 #define AU915_JOIN_ACCEPT_DELAY2 6000 00139 00140 /*! 00141 * Maximum frame counter gap 00142 */ 00143 #define AU915_MAX_FCNT_GAP 16384 00144 00145 /*! 00146 * Ack timeout 00147 */ 00148 #define AU915_ACKTIMEOUT 2000 00149 00150 /*! 00151 * Random ack timeout limits 00152 */ 00153 #define AU915_ACK_TIMEOUT_RND 1000 00154 00155 /*! 00156 * Second reception window channel frequency definition. 00157 */ 00158 #define AU915_RX_WND_2_FREQ 923300000 00159 00160 /*! 00161 * Second reception window channel datarate definition. 00162 */ 00163 #define AU915_RX_WND_2_DR DR_8 00164 00165 /*! 00166 * Band 0 definition 00167 * { DutyCycle, TxMaxPower, LastJoinTxDoneTime, LastTxDoneTime, TimeOff } 00168 */ 00169 static const band_t AU915_BAND0 = {1, AU915_MAX_TX_POWER, 0, 0, 0, 915200000, 927800000}; // 100.0 % 00170 00171 /*! 00172 * Defines the first channel for RX window 1 for US band 00173 */ 00174 #define AU915_FIRST_RX1_CHANNEL ((uint32_t) 923300000) 00175 00176 /*! 00177 * Defines the last channel for RX window 1 for US band 00178 */ 00179 #define AU915_LAST_RX1_CHANNEL ((uint32_t) 927500000) 00180 00181 /*! 00182 * Defines the step width of the channels for RX window 1 00183 */ 00184 #define AU915_STEPWIDTH_RX1_CHANNEL ((uint32_t) 600000) 00185 00186 /*! 00187 * Data rates table definition 00188 */ 00189 static const uint8_t datarates_AU915 [] = {12, 11, 10, 9, 8, 7, 8, 0, 12, 11, 10, 9, 8, 7, 0, 0}; 00190 00191 /*! 00192 * Bandwidths table definition in Hz 00193 */ 00194 static const uint32_t bandwidths_AU915 [] = { 125000, 125000, 125000, 125000, 00195 125000, 125000, 500000, 0, 500000, 500000, 500000, 500000, 500000, 500000, 00196 0, 0 }; 00197 00198 /*! 00199 * Up/Down link data rates offset definition 00200 */ 00201 static const int8_t datarate_offsets_AU915 [7][6] = { { DR_8, DR_8, DR_8, DR_8, 00202 DR_8, DR_8 }, // DR_0 00203 { DR_9, DR_8, DR_8, DR_8, DR_8, DR_8 }, // DR_1 00204 { DR_10, DR_9, DR_8, DR_8, DR_8, DR_8 }, // DR_2 00205 { DR_11, DR_10, DR_9, DR_8, DR_8, DR_8 }, // DR_3 00206 { DR_12, DR_11, DR_10, DR_9, DR_8, DR_8 }, // DR_4 00207 { DR_13, DR_12, DR_11, DR_10, DR_9, DR_8 }, // DR_5 00208 { DR_13, DR_13, DR_12, DR_11, DR_10, DR_9 }, // DR_6 00209 }; 00210 00211 /*! 00212 * Maximum payload with respect to the datarate index. Cannot operate with repeater. 00213 */ 00214 static const uint8_t max_payload_AU915 [] = { 51, 51, 51, 115, 242, 242, 00215 242, 0, 53, 129, 242, 242, 242, 242, 0, 0 }; 00216 00217 /*! 00218 * Maximum payload with respect to the datarate index. Can operate with repeater. 00219 */ 00220 static const uint8_t max_payload_with_repeater_AU915 [] = { 51, 51, 51, 115, 00221 222, 222, 222, 0, 33, 109, 222, 222, 222, 222, 0, 0 }; 00222 00223 00224 LoRaPHYAU915::LoRaPHYAU915(LoRaWANTimeHandler &lora_time) 00225 : LoRaPHY(lora_time) 00226 { 00227 bands[0] = AU915_BAND0 ; 00228 00229 // Activate Channels 00230 // 125 kHz channels Upstream only 00231 for (uint8_t i = 0; i < AU915_MAX_NB_CHANNELS - 8; i++) { 00232 channels[i].frequency = 915200000 + i * 200000; 00233 channels[i].dr_range.value = ( DR_5 << 4) | DR_0; 00234 channels[i].band = 0; 00235 } 00236 // 500 kHz channels 00237 // Upstream and downstream both 00238 for (uint8_t i = AU915_MAX_NB_CHANNELS - 8; i < AU915_MAX_NB_CHANNELS; i++) { 00239 channels[i].frequency = 915900000 + (i - ( AU915_MAX_NB_CHANNELS - 8)) * 1600000; 00240 channels[i].dr_range.value = ( DR_6 << 4) | DR_6; 00241 channels[i].band = 0; 00242 } 00243 00244 // Initialize channels default mask 00245 // All channels are default channels here 00246 // Join request needs to alternate between 125 KHz and 500 KHz channels 00247 // randomly. 00248 default_channel_mask[0] = 0xFFFF; 00249 default_channel_mask[1] = 0xFFFF; 00250 default_channel_mask[2] = 0xFFFF; 00251 default_channel_mask[3] = 0xFFFF; 00252 default_channel_mask[4] = 0x00FF; 00253 00254 memset(channel_mask, 0, sizeof(channel_mask)); 00255 memset(current_channel_mask, 0, sizeof(current_channel_mask)); 00256 00257 // Copy channels default mask 00258 copy_channel_mask(channel_mask, default_channel_mask, AU915_CHANNEL_MASK_SIZE); 00259 00260 // Copy into current channels mask 00261 // This mask is used to keep track of the channels which were used in 00262 // previous transmissions as the AU915 band doesn't allow concurrent 00263 // transmission on the same channel 00264 copy_channel_mask(current_channel_mask, channel_mask, AU915_CHANNEL_MASK_SIZE); 00265 00266 // set default channels 00267 phy_params.channels.channel_list = channels; 00268 phy_params.channels.channel_list_size = AU915_MAX_NB_CHANNELS; 00269 phy_params.channels.mask = channel_mask; 00270 phy_params.channels.default_mask = default_channel_mask; 00271 phy_params.channels.mask_size = AU915_CHANNEL_MASK_SIZE; 00272 00273 // set bands for AU915 spectrum 00274 phy_params.bands.table = (void *) bands; 00275 phy_params.bands.size = AU915_MAX_NB_BANDS; 00276 00277 // set bandwidths available in AU915 spectrum 00278 phy_params.bandwidths.table = (void *) bandwidths_AU915 ; 00279 phy_params.bandwidths.size = 16; 00280 00281 // set data rates available in AU915 spectrum 00282 phy_params.datarates.table = (void *) datarates_AU915 ; 00283 phy_params.datarates.size = 16; 00284 00285 // set payload sizes with respect to data rates 00286 phy_params.payloads.table = (void *) max_payload_AU915 ; 00287 phy_params.payloads.size = 16; 00288 phy_params.payloads_with_repeater.table = (void *) max_payload_with_repeater_AU915 ; 00289 phy_params.payloads_with_repeater.size = 16; 00290 00291 // dwell time setting 00292 phy_params.ul_dwell_time_setting = 0; 00293 phy_params.dl_dwell_time_setting = 0; 00294 phy_params.dwell_limit_datarate = AU915_DEFAULT_DATARATE; 00295 00296 phy_params.duty_cycle_enabled = AU915_DUTY_CYCLE_ENABLED; 00297 phy_params.accept_tx_param_setup_req = false; 00298 phy_params.custom_channelplans_supported = false; 00299 phy_params.cflist_supported = false; 00300 phy_params.fsk_supported = false; 00301 00302 phy_params.default_channel_cnt = AU915_MAX_NB_CHANNELS; 00303 phy_params.max_channel_cnt = AU915_MAX_NB_CHANNELS; 00304 phy_params.cflist_channel_cnt = 0; 00305 phy_params.min_tx_datarate = AU915_TX_MIN_DATARATE; 00306 phy_params.max_tx_datarate = AU915_TX_MAX_DATARATE; 00307 phy_params.min_rx_datarate = AU915_RX_MIN_DATARATE; 00308 phy_params.max_rx_datarate = AU915_RX_MAX_DATARATE; 00309 phy_params.default_datarate = AU915_DEFAULT_DATARATE; 00310 phy_params.default_max_datarate = AU915_TX_MAX_DATARATE; 00311 phy_params.min_rx1_dr_offset = AU915_MIN_RX1_DR_OFFSET; 00312 phy_params.max_rx1_dr_offset = AU915_MAX_RX1_DR_OFFSET; 00313 phy_params.default_rx1_dr_offset = AU915_DEFAULT_RX1_DR_OFFSET; 00314 phy_params.min_tx_power = AU915_MIN_TX_POWER; 00315 phy_params.max_tx_power = AU915_MAX_TX_POWER; 00316 phy_params.default_tx_power = AU915_DEFAULT_TX_POWER; 00317 phy_params.default_max_eirp = AU915_DEFAULT_MAX_EIRP; 00318 phy_params.default_antenna_gain = AU915_DEFAULT_ANTENNA_GAIN; 00319 phy_params.adr_ack_limit = AU915_ADR_ACK_LIMIT; 00320 phy_params.adr_ack_delay = AU915_ADR_ACK_DELAY; 00321 phy_params.max_rx_window = AU915_MAX_RX_WINDOW; 00322 phy_params.recv_delay1 = AU915_RECEIVE_DELAY1; 00323 phy_params.recv_delay2 = AU915_RECEIVE_DELAY2; 00324 00325 phy_params.join_accept_delay1 = AU915_JOIN_ACCEPT_DELAY1; 00326 phy_params.join_accept_delay2 = AU915_JOIN_ACCEPT_DELAY2; 00327 phy_params.max_fcnt_gap = AU915_MAX_FCNT_GAP; 00328 phy_params.ack_timeout = AU915_ACKTIMEOUT; 00329 phy_params.ack_timeout_rnd = AU915_ACK_TIMEOUT_RND; 00330 phy_params.rx_window2_datarate = AU915_RX_WND_2_DR; 00331 phy_params.rx_window2_frequency = AU915_RX_WND_2_FREQ; 00332 } 00333 00334 LoRaPHYAU915::~LoRaPHYAU915() 00335 { 00336 } 00337 00338 bool LoRaPHYAU915::rx_config(rx_config_params_t * params) 00339 { 00340 int8_t dr = params->datarate ; 00341 uint8_t max_payload = 0; 00342 int8_t phy_dr = 0; 00343 uint32_t frequency = params->frequency ; 00344 00345 if (_radio->get_status() != RF_IDLE) { 00346 return false; 00347 } 00348 00349 if (params->rx_slot == RX_SLOT_WIN_1 ) { 00350 // Apply window 1 frequency 00351 frequency = AU915_FIRST_RX1_CHANNEL 00352 + (params->channel % 8) * AU915_STEPWIDTH_RX1_CHANNEL; 00353 } 00354 00355 // Read the physical datarate from the datarates table 00356 phy_dr = datarates_AU915 [dr]; 00357 00358 _radio->lock(); 00359 00360 _radio->set_channel(frequency); 00361 00362 // Radio configuration 00363 _radio->set_rx_config(MODEM_LORA, params->bandwidth , phy_dr, 1, 0, 8, 00364 params->window_timeout , false, 0, false, 0, 0, true, 00365 params->is_rx_continuous ); 00366 00367 if (params->is_repeater_supported == true) { 00368 max_payload = max_payload_with_repeater_AU915 [dr]; 00369 } else { 00370 max_payload = max_payload_AU915 [dr]; 00371 } 00372 _radio->set_max_payload_length(MODEM_LORA, 00373 max_payload + LORA_MAC_FRMPAYLOAD_OVERHEAD); 00374 00375 _radio->unlock(); 00376 00377 return true; 00378 } 00379 00380 bool LoRaPHYAU915::tx_config(tx_config_params_t* params, int8_t* tx_power, 00381 lorawan_time_t* tx_toa) 00382 { 00383 int8_t phy_dr = datarates_AU915 [params->datarate]; 00384 00385 if (params->tx_power > bands[channels[params->channel].band].max_tx_pwr) { 00386 params->tx_power = bands[channels[params->channel].band].max_tx_pwr; 00387 } 00388 00389 uint32_t bandwidth = get_bandwidth(params->datarate); 00390 int8_t phy_tx_power = 0; 00391 00392 // Calculate physical TX power 00393 phy_tx_power = compute_tx_power(params->tx_power, params->max_eirp, 00394 params->antenna_gain); 00395 00396 // setting up radio tx configurations 00397 00398 _radio->lock(); 00399 00400 _radio->set_channel(channels[params->channel].frequency); 00401 00402 _radio->set_tx_config(MODEM_LORA, phy_tx_power, 0, bandwidth, phy_dr, 1, 8, 00403 false, true, 0, 0, false, 3000); 00404 00405 // Setup maximum payload lenght of the radio driver 00406 _radio->set_max_payload_length(MODEM_LORA, params->pkt_len); 00407 00408 *tx_toa = _radio->time_on_air(MODEM_LORA, params->pkt_len); 00409 00410 _radio->unlock(); 00411 00412 *tx_power = params->tx_power; 00413 00414 return true; 00415 } 00416 00417 uint8_t LoRaPHYAU915::link_ADR_request(adr_req_params_t* params, 00418 int8_t* dr_out, int8_t* tx_power_out, 00419 uint8_t* nb_rep_out, 00420 uint8_t* nb_bytes_parsed) 00421 { 00422 uint8_t status = 0x07; 00423 link_adr_params_t adr_settings; 00424 uint8_t next_index = 0; 00425 uint8_t bytes_processed = 0; 00426 uint16_t temp_channel_masks[AU915_CHANNEL_MASK_SIZE] = { 0, 0, 0, 0, 0}; 00427 00428 verify_adr_params_t verify_params; 00429 00430 // Initialize local copy of channels mask 00431 copy_channel_mask(temp_channel_masks, channel_mask, AU915_CHANNEL_MASK_SIZE); 00432 00433 while (bytes_processed < params->payload_size) { 00434 next_index = parse_link_ADR_req(&(params->payload [bytes_processed]), 00435 &adr_settings); 00436 00437 if (next_index == 0) { 00438 break; // break loop, since no more request has been found 00439 } 00440 00441 // Update bytes processed 00442 bytes_processed += next_index; 00443 00444 // Revert status, as we only check the last ADR request for the channel mask KO 00445 status = 0x07; 00446 00447 if (adr_settings.ch_mask_ctrl == 6) { 00448 // Enable all 125 kHz channels 00449 temp_channel_masks[0] = 0xFFFF; 00450 temp_channel_masks[1] = 0xFFFF; 00451 temp_channel_masks[2] = 0xFFFF; 00452 temp_channel_masks[3] = 0xFFFF; 00453 // Apply chMask to channels 64 to 71 00454 temp_channel_masks[4] = adr_settings.channel_mask; 00455 } else if (adr_settings.ch_mask_ctrl == 7) { 00456 // Disable all 125 kHz channels 00457 temp_channel_masks[0] = 0x0000; 00458 temp_channel_masks[1] = 0x0000; 00459 temp_channel_masks[2] = 0x0000; 00460 temp_channel_masks[3] = 0x0000; 00461 // Apply chMask to channels 64 to 71 00462 temp_channel_masks[4] = adr_settings.channel_mask; 00463 } else if (adr_settings.ch_mask_ctrl == 5) { 00464 // RFU 00465 status &= 0xFE; // Channel mask KO 00466 } else { 00467 temp_channel_masks[adr_settings.ch_mask_ctrl] = adr_settings.channel_mask; 00468 } 00469 } 00470 00471 // FCC 15.247 paragraph F mandates to hop on at least 2 125 kHz channels 00472 if ((adr_settings.datarate < DR_6) 00473 && (num_active_channels(temp_channel_masks, 0, 4) < 2)) { 00474 status &= 0xFE; // Channel mask KO 00475 } 00476 00477 verify_params.status = status; 00478 verify_params.adr_enabled = params->adr_enabled ; 00479 verify_params.datarate = adr_settings.datarate; 00480 verify_params.tx_power = adr_settings.tx_power; 00481 verify_params.nb_rep = adr_settings.nb_rep; 00482 verify_params.current_datarate = params->current_datarate ; 00483 verify_params.current_tx_power = params->current_tx_power ; 00484 verify_params.current_nb_rep = params->current_nb_rep ; 00485 verify_params.channel_mask = temp_channel_masks; 00486 00487 00488 // Verify the parameters and update, if necessary 00489 status = verify_link_ADR_req(&verify_params, &adr_settings.datarate, 00490 &adr_settings.tx_power, &adr_settings.nb_rep); 00491 00492 // Update cchannel mask if everything is correct 00493 if (status == 0x07) { 00494 // Copy Mask 00495 copy_channel_mask(channel_mask, temp_channel_masks, AU915_CHANNEL_MASK_SIZE); 00496 00497 current_channel_mask[0] &= channel_mask[0]; 00498 current_channel_mask[1] &= channel_mask[1]; 00499 current_channel_mask[2] &= channel_mask[2]; 00500 current_channel_mask[3] &= channel_mask[3]; 00501 current_channel_mask[4] = channel_mask[4]; 00502 } 00503 00504 // Update status variables 00505 *dr_out = adr_settings.datarate; 00506 *tx_power_out = adr_settings.tx_power; 00507 *nb_rep_out = adr_settings.nb_rep; 00508 *nb_bytes_parsed = bytes_processed; 00509 00510 return status; 00511 } 00512 00513 uint8_t LoRaPHYAU915::accept_rx_param_setup_req(rx_param_setup_req_t* params) 00514 { 00515 uint8_t status = 0x07; 00516 uint32_t freq = params->frequency; 00517 00518 // Verify radio frequency 00519 _radio->lock(); 00520 00521 if ((_radio->check_rf_frequency(freq) == false) 00522 || (freq < AU915_FIRST_RX1_CHANNEL) 00523 || (freq > AU915_LAST_RX1_CHANNEL) 00524 || (((freq - (uint32_t) AU915_FIRST_RX1_CHANNEL) 00525 % (uint32_t) AU915_STEPWIDTH_RX1_CHANNEL) != 0)) { 00526 status &= 0xFE; // Channel frequency KO 00527 } 00528 00529 _radio->unlock(); 00530 00531 // Verify datarate 00532 if (val_in_range(params->datarate, AU915_RX_MIN_DATARATE, AU915_RX_MAX_DATARATE) == 0) { 00533 status &= 0xFD; // Datarate KO 00534 } 00535 00536 if ((params->datarate == DR_7) || (params->datarate > DR_13)) { 00537 status &= 0xFD; // Datarate KO 00538 } 00539 00540 // Verify datarate offset 00541 if (val_in_range(params->dr_offset, AU915_MIN_RX1_DR_OFFSET, AU915_MAX_RX1_DR_OFFSET) == 0) { 00542 status &= 0xFB; // Rx1DrOffset range KO 00543 } 00544 00545 return status; 00546 } 00547 00548 int8_t LoRaPHYAU915::get_alternate_DR(uint8_t nb_trials) 00549 { 00550 int8_t datarate = 0; 00551 00552 // Re-enable 500 kHz default channels 00553 channel_mask[4] = 0x00FF; 00554 00555 if ((nb_trials & 0x01) == 0x01) { 00556 datarate = DR_6; 00557 } else { 00558 datarate = DR_0; 00559 } 00560 00561 return datarate; 00562 } 00563 00564 lorawan_status_t LoRaPHYAU915::set_next_channel(channel_selection_params_t* next_chan_params, 00565 uint8_t* channel, lorawan_time_t* time, 00566 lorawan_time_t* aggregated_timeOff) 00567 { 00568 uint8_t nb_enabled_channels = 0; 00569 uint8_t delay_tx = 0; 00570 uint8_t enabled_channels[AU915_MAX_NB_CHANNELS] = { 0 }; 00571 lorawan_time_t next_tx_delay = 0; 00572 00573 // Count 125kHz channels 00574 if (num_active_channels(current_channel_mask, 0, 4) == 0) { 00575 // Reactivate 125 kHz default channels 00576 copy_channel_mask(current_channel_mask, channel_mask, 4); 00577 } 00578 00579 // Check other channels 00580 if (next_chan_params->current_datarate >= DR_6) { 00581 if ((current_channel_mask[4] & 0x00FF) == 0) { 00582 // fall back to 500 kHz default channels 00583 current_channel_mask[4] = channel_mask[4]; 00584 } 00585 } 00586 00587 if (next_chan_params->aggregate_timeoff <= _lora_time.get_elapsed_time(next_chan_params->last_aggregate_tx_time)) { 00588 // Reset Aggregated time off 00589 *aggregated_timeOff = 0; 00590 00591 // Update bands Time OFF 00592 next_tx_delay = update_band_timeoff(next_chan_params->joined, 00593 next_chan_params->dc_enabled, 00594 bands, AU915_MAX_NB_BANDS); 00595 00596 // Search how many channels are enabled 00597 nb_enabled_channels = enabled_channel_count(next_chan_params->joined, 00598 next_chan_params->current_datarate, 00599 current_channel_mask, 00600 enabled_channels, &delay_tx); 00601 } else { 00602 delay_tx++; 00603 next_tx_delay = next_chan_params->aggregate_timeoff - _lora_time.get_elapsed_time(next_chan_params->last_aggregate_tx_time); 00604 } 00605 00606 if (nb_enabled_channels > 0) { 00607 // We found a valid channel 00608 *channel = enabled_channels[get_random(0, nb_enabled_channels - 1)]; 00609 // Disable the channel in the mask 00610 disable_channel(current_channel_mask, *channel, 00611 AU915_MAX_NB_CHANNELS - 8); 00612 00613 *time = 0; 00614 return LORAWAN_STATUS_OK; 00615 } else { 00616 if (delay_tx > 0) { 00617 // Delay transmission due to AggregatedTimeOff or to a band time off 00618 *time = next_tx_delay; 00619 return LORAWAN_STATUS_DUTYCYCLE_RESTRICTED; 00620 } 00621 // Datarate not supported by any channel 00622 *time = 0; 00623 return LORAWAN_STATUS_NO_CHANNEL_FOUND; 00624 } 00625 } 00626 00627 uint8_t LoRaPHYAU915::apply_DR_offset(int8_t dr, int8_t dr_offset) 00628 { 00629 int8_t datarate = datarate_offsets_AU915 [dr][dr_offset]; 00630 00631 if (datarate < 0) { 00632 datarate = DR_0; 00633 } 00634 return datarate; 00635 }
Generated on Tue Jul 12 2022 12:44:31 by
