@@ -206,6 +206,8 @@ static const uint8_t max_payloads_with_repeater_CN470[] = {51, 51, 51, 115, 222,
206
206
207
207
LoRaPHYCN470::LoRaPHYCN470 ()
208
208
{
209
+ static const uint16_t fsb_mask[] = MBED_CONF_LORA_FSB_MASK_CHINA;
210
+
209
211
bands[0 ] = CN470_BAND0;
210
212
211
213
// Channels
@@ -218,12 +220,9 @@ LoRaPHYCN470::LoRaPHYCN470()
218
220
}
219
221
220
222
// Initialize the channels default mask
221
- default_channel_mask[0 ] = 0xFFFF ;
222
- default_channel_mask[1 ] = 0xFFFF ;
223
- default_channel_mask[2 ] = 0xFFFF ;
224
- default_channel_mask[3 ] = 0xFFFF ;
225
- default_channel_mask[4 ] = 0xFFFF ;
226
- default_channel_mask[5 ] = 0xFFFF ;
223
+ for (uint8_t i = 0 ; i < CN470_MAX_NB_CHANNELS; i++) {
224
+ default_channel_mask[i] = 0xFFFF & fsb_mask[i];
225
+ }
227
226
228
227
// Update the channels mask
229
228
copy_channel_mask (channel_mask, default_channel_mask, CN470_CHANNEL_MASK_SIZE);
@@ -302,6 +301,64 @@ LoRaPHYCN470::~LoRaPHYCN470()
302
301
{
303
302
}
304
303
304
+ lorawan_status_t LoRaPHYCN470::set_next_channel (channel_selection_params_t *params,
305
+ uint8_t *channel, lorawan_time_t *time,
306
+ lorawan_time_t *aggregate_timeoff)
307
+ {
308
+ uint8_t channel_count = 0 ;
309
+ uint8_t delay_tx = 0 ;
310
+
311
+ uint8_t enabled_channels[CN470_MAX_NB_CHANNELS] = {0 };
312
+
313
+ lorawan_time_t next_tx_delay = 0 ;
314
+ band_t *band_table = (band_t *) phy_params.bands .table ;
315
+
316
+ if (num_active_channels (phy_params.channels .mask , 0 ,
317
+ phy_params.channels .mask_size ) == 0 ) {
318
+
319
+ // Reactivate default channels
320
+ copy_channel_mask (phy_params.channels .mask ,
321
+ phy_params.channels .default_mask ,
322
+ phy_params.channels .mask_size );
323
+ }
324
+
325
+ if (params->aggregate_timeoff
326
+ <= _lora_time->get_elapsed_time (params->last_aggregate_tx_time )) {
327
+ // Reset Aggregated time off
328
+ *aggregate_timeoff = 0 ;
329
+
330
+ // Update bands Time OFF
331
+ next_tx_delay = update_band_timeoff (params->joined ,
332
+ params->dc_enabled ,
333
+ band_table, phy_params.bands .size );
334
+
335
+ // Search how many channels are enabled
336
+ channel_count = enabled_channel_count (params->current_datarate ,
337
+ phy_params.channels .mask ,
338
+ enabled_channels, &delay_tx);
339
+ } else {
340
+ delay_tx++;
341
+ next_tx_delay = params->aggregate_timeoff -
342
+ _lora_time->get_elapsed_time (params->last_aggregate_tx_time );
343
+ }
344
+
345
+ if (channel_count > 0 ) {
346
+ // We found a valid channel
347
+ *channel = enabled_channels[get_random (0 , channel_count - 1 )];
348
+ *time = 0 ;
349
+ return LORAWAN_STATUS_OK;
350
+ }
351
+
352
+ if (delay_tx > 0 ) {
353
+ // Delay transmission due to AggregatedTimeOff or to a band time off
354
+ *time = next_tx_delay;
355
+ return LORAWAN_STATUS_DUTYCYCLE_RESTRICTED;
356
+ }
357
+
358
+ *time = 0 ;
359
+ return LORAWAN_STATUS_NO_CHANNEL_FOUND;
360
+ }
361
+
305
362
bool LoRaPHYCN470::rx_config (rx_config_params_t * config)
306
363
{
307
364
int8_t dr = config->datarate ;
@@ -332,7 +389,8 @@ bool LoRaPHYCN470::rx_config(rx_config_params_t* config)
332
389
_radio->set_channel (frequency);
333
390
334
391
// Radio configuration
335
- _radio->set_rx_config (MODEM_LORA, config->bandwidth , phy_dr, 1 , 0 , 8 ,
392
+ _radio->set_rx_config (MODEM_LORA, config->bandwidth , phy_dr, 1 , 0 ,
393
+ MBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH,
336
394
config->window_timeout , false , 0 , false , 0 , 0 , true ,
337
395
config->is_rx_continuous );
338
396
@@ -371,7 +429,8 @@ bool LoRaPHYCN470::tx_config(tx_config_params_t* config, int8_t* tx_power,
371
429
372
430
_radio->set_channel (channels[config->channel ].frequency );
373
431
374
- _radio->set_tx_config (MODEM_LORA, phy_tx_power, 0 , 0 , phy_dr, 1 , 8 , false , true ,
432
+ _radio->set_tx_config (MODEM_LORA, phy_tx_power, 0 , 0 , phy_dr, 1 ,
433
+ MBED_CONF_LORA_UPLINK_PREAMBLE_LENGTH, false , true ,
375
434
0 , 0 , false , 3000 );
376
435
// Setup maximum payload lenght of the radio driver
377
436
_radio->set_max_payload_length (MODEM_LORA, config->pkt_len );
@@ -421,12 +480,9 @@ uint8_t LoRaPHYCN470::link_ADR_request(adr_req_params_t* params,
421
480
if (adr_settings.ch_mask_ctrl == 6 ) {
422
481
423
482
// Enable all 125 kHz channels
424
- temp_channel_masks[0 ] = 0xFFFF ;
425
- temp_channel_masks[1 ] = 0xFFFF ;
426
- temp_channel_masks[2 ] = 0xFFFF ;
427
- temp_channel_masks[3 ] = 0xFFFF ;
428
- temp_channel_masks[4 ] = 0xFFFF ;
429
- temp_channel_masks[5 ] = 0xFFFF ;
483
+ for (uint8_t i = 0 ; i < CN470_CHANNEL_MASK_SIZE; i++) {
484
+ temp_channel_masks[i] = 0xFFFF ;
485
+ }
430
486
431
487
} else if ( adr_settings.ch_mask_ctrl == 7 ) {
432
488
0 commit comments