@@ -112,22 +112,22 @@ void LoRaPHY::handle_send(uint8_t *buf, uint8_t size)
112
112
_radio->unlock ();
113
113
}
114
114
115
- uint8_t LoRaPHY::request_new_channel (new_channel_req_params_t * params )
115
+ uint8_t LoRaPHY::request_new_channel (int8_t channel_id, channel_params_t * new_channel )
116
116
{
117
117
if (!phy_params.custom_channelplans_supported ) {
118
118
return 0 ;
119
119
}
120
120
121
121
uint8_t status = 0x03 ;
122
122
123
- if (params-> new_channel ->frequency == 0 ) {
123
+ if (new_channel->frequency == 0 ) {
124
124
// Remove
125
- if (remove_channel (params-> channel_id ) == false ) {
125
+ if (remove_channel (channel_id) == false ) {
126
126
status &= 0xFC ;
127
127
}
128
128
} else {
129
129
130
- switch (add_channel (params-> new_channel , params-> channel_id )) {
130
+ switch (add_channel (new_channel, channel_id)) {
131
131
case LORAWAN_STATUS_OK:
132
132
{
133
133
break ;
@@ -175,7 +175,7 @@ bool LoRaPHY::verify_channel_DR(uint8_t nb_channels, uint16_t* channel_mask,
175
175
if (mask_bit_test (channel_mask, i)) {
176
176
// Check datarate validity for enabled channels
177
177
if (val_in_range (dr, (channels[i].dr_range .fields .min & 0x0F ),
178
- (channels[i].dr_range .fields .max & 0x0F ))) {
178
+ (channels[i].dr_range .fields .max & 0x0F ))) {
179
179
// At least 1 channel has been found we can return OK.
180
180
return true ;
181
181
}
@@ -247,22 +247,18 @@ void LoRaPHY::copy_channel_mask(uint16_t* dest_mask, uint16_t* src_mask, uint8_t
247
247
}
248
248
}
249
249
250
- void LoRaPHY::set_last_tx_done (set_band_txdone_params_t * last_tx_params )
250
+ void LoRaPHY::set_last_tx_done (uint8_t channel, bool joined, lorawan_time_t last_tx_done_time )
251
251
{
252
- if (!last_tx_params) {
253
- return ;
254
- }
255
-
256
252
band_t *band_table = (band_t *) phy_params.bands .table ;
257
253
channel_params_t *channel_list = phy_params.channels .channel_list ;
258
254
259
- if (last_tx_params-> joined == true ) {
260
- band_table[channel_list[last_tx_params-> channel ].band ].last_tx_time = last_tx_params-> last_tx_done_time ;
255
+ if (joined == true ) {
256
+ band_table[channel_list[channel].band ].last_tx_time = last_tx_done_time;
261
257
return ;
262
258
}
263
259
264
- band_table[channel_list[last_tx_params-> channel ].band ].last_tx_time = last_tx_params-> last_tx_done_time ;
265
- band_table[channel_list[last_tx_params-> channel ].band ].last_join_tx_time = last_tx_params-> last_tx_done_time ;
260
+ band_table[channel_list[channel].band ].last_tx_time = last_tx_done_time;
261
+ band_table[channel_list[channel].band ].last_join_tx_time = last_tx_done_time;
266
262
267
263
}
268
264
@@ -692,7 +688,7 @@ bool LoRaPHY::verify_nb_join_trials(uint8_t nb_join_trials)
692
688
return true ;
693
689
}
694
690
695
- void LoRaPHY::apply_cf_list (cflist_params_t * cf_list )
691
+ void LoRaPHY::apply_cf_list (const uint8_t * payload, uint8_t size )
696
692
{
697
693
// if the underlying PHY doesn't support CF-List, ignore the request
698
694
if (!phy_params.cflist_supported ) {
@@ -703,10 +699,10 @@ void LoRaPHY::apply_cf_list(cflist_params_t* cf_list)
703
699
704
700
// Setup default datarate range
705
701
new_channel.dr_range .value = (phy_params.default_max_datarate << 4 )
706
- | phy_params.default_datarate ;
702
+ | phy_params.default_datarate ;
707
703
708
704
// Size of the optional CF list
709
- if (cf_list-> size != 16 ) {
705
+ if (size != 16 ) {
710
706
return ;
711
707
}
712
708
@@ -721,9 +717,9 @@ void LoRaPHY::apply_cf_list(cflist_params_t* cf_list)
721
717
channel_id < phy_params.max_channel_cnt ; i+=phy_params.default_channel_cnt , channel_id++) {
722
718
if (channel_id < (phy_params.cflist_channel_cnt + phy_params.default_channel_cnt )) {
723
719
// Channel frequency
724
- new_channel.frequency = (uint32_t ) cf_list-> payload [i];
725
- new_channel.frequency |= ((uint32_t ) cf_list-> payload [i + 1 ] << 8 );
726
- new_channel.frequency |= ((uint32_t ) cf_list-> payload [i + 2 ] << 16 );
720
+ new_channel.frequency = (uint32_t ) payload[i];
721
+ new_channel.frequency |= ((uint32_t ) payload[i + 1 ] << 8 );
722
+ new_channel.frequency |= ((uint32_t ) payload[i + 2 ] << 16 );
727
723
new_channel.frequency *= 100 ;
728
724
729
725
// Initialize alternative frequency to 0
@@ -1057,11 +1053,11 @@ uint8_t LoRaPHY::accept_rx_param_setup_req(rx_param_setup_req_t* params)
1057
1053
return status;
1058
1054
}
1059
1055
1060
- bool LoRaPHY::accept_tx_param_setup_req (tx_param_setup_req_t *params )
1056
+ bool LoRaPHY::accept_tx_param_setup_req (uint8_t ul_dwell_time, uint8_t dl_dwell_time )
1061
1057
{
1062
1058
if (phy_params.accept_tx_param_setup_req ) {
1063
- phy_params.ul_dwell_time_setting = params-> ul_dwell_time ;
1064
- phy_params.dl_dwell_time_setting = params-> dl_dwell_time ;
1059
+ phy_params.ul_dwell_time_setting = ul_dwell_time;
1060
+ phy_params.dl_dwell_time_setting = dl_dwell_time;
1065
1061
}
1066
1062
1067
1063
return phy_params.accept_tx_param_setup_req ;
@@ -1084,7 +1080,7 @@ bool LoRaPHY::verify_frequency(uint32_t freq)
1084
1080
return false ;
1085
1081
}
1086
1082
1087
- uint8_t LoRaPHY::dl_channel_request (dl_channel_req_params_t * params )
1083
+ uint8_t LoRaPHY::dl_channel_request (uint8_t channel_id, uint32_t rx1_frequency )
1088
1084
{
1089
1085
if (!phy_params.dl_channel_req_supported ) {
1090
1086
return 0 ;
@@ -1093,18 +1089,18 @@ uint8_t LoRaPHY::dl_channel_request(dl_channel_req_params_t* params)
1093
1089
uint8_t status = 0x03 ;
1094
1090
1095
1091
// Verify if the frequency is supported
1096
- if (verify_frequency (params-> rx1_frequency ) == false ) {
1092
+ if (verify_frequency (rx1_frequency) == false ) {
1097
1093
status &= 0xFE ;
1098
1094
}
1099
1095
1100
1096
// Verify if an uplink frequency exists
1101
- if (phy_params.channels .channel_list [params-> channel_id ].frequency == 0 ) {
1097
+ if (phy_params.channels .channel_list [channel_id].frequency == 0 ) {
1102
1098
status &= 0xFD ;
1103
1099
}
1104
1100
1105
1101
// Apply Rx1 frequency, if the status is OK
1106
1102
if (status == 0x03 ) {
1107
- phy_params.channels .channel_list [params-> channel_id ].rx1_frequency = params-> rx1_frequency ;
1103
+ phy_params.channels .channel_list [channel_id].rx1_frequency = rx1_frequency;
1108
1104
}
1109
1105
1110
1106
return status;
@@ -1158,23 +1154,24 @@ int8_t LoRaPHY::get_alternate_DR(uint8_t nb_trials)
1158
1154
return datarate;
1159
1155
}
1160
1156
1161
- void LoRaPHY::calculate_backoff (backoff_params_t * calc_backoff)
1157
+ void LoRaPHY::calculate_backoff (bool joined, bool last_tx_was_join_req, bool dc_enabled, uint8_t channel,
1158
+ lorawan_time_t elapsed_time, lorawan_time_t tx_toa)
1162
1159
{
1163
1160
band_t *band_table = (band_t *) phy_params.bands .table ;
1164
1161
channel_params_t *channel_list = phy_params.channels .channel_list ;
1165
1162
1166
- uint8_t band_idx = channel_list[calc_backoff-> channel ].band ;
1163
+ uint8_t band_idx = channel_list[channel].band ;
1167
1164
uint16_t duty_cycle = band_table[band_idx].duty_cycle ;
1168
1165
uint16_t join_duty_cycle = 0 ;
1169
1166
1170
1167
// Reset time-off to initial value.
1171
1168
band_table[band_idx].off_time = 0 ;
1172
1169
1173
- if (calc_backoff-> joined == false ) {
1170
+ if (joined == false ) {
1174
1171
// Get the join duty cycle
1175
- if (calc_backoff-> elapsed_time < 3600000 ) {
1172
+ if (elapsed_time < 3600000 ) {
1176
1173
join_duty_cycle = BACKOFF_DC_1_HOUR;
1177
- } else if (calc_backoff-> elapsed_time < (3600000 + 36000000 )) {
1174
+ } else if (elapsed_time < (3600000 + 36000000 )) {
1178
1175
join_duty_cycle = BACKOFF_DC_10_HOURS;
1179
1176
} else {
1180
1177
join_duty_cycle = BACKOFF_DC_24_HOURS;
@@ -1186,12 +1183,12 @@ void LoRaPHY::calculate_backoff(backoff_params_t* calc_backoff)
1186
1183
1187
1184
// No back-off if the last frame was not a join request and when the
1188
1185
// duty cycle is not enabled
1189
- if (calc_backoff-> dc_enabled == false &&
1190
- calc_backoff-> last_tx_was_join_req == false ) {
1186
+ if (dc_enabled == false &&
1187
+ last_tx_was_join_req == false ) {
1191
1188
band_table[band_idx].off_time = 0 ;
1192
1189
} else {
1193
1190
// Apply band time-off.
1194
- band_table[band_idx].off_time = calc_backoff-> tx_toa * duty_cycle - calc_backoff-> tx_toa ;
1191
+ band_table[band_idx].off_time = tx_toa * duty_cycle - tx_toa;
1195
1192
}
1196
1193
}
1197
1194
@@ -1350,7 +1347,7 @@ bool LoRaPHY::remove_channel(uint8_t channel_id)
1350
1347
1351
1348
1352
1349
// Remove the channel from the list of channels
1353
- const channel_params_t empty_channel = { 0 , 0 , { 0 }, 0 };
1350
+ const channel_params_t empty_channel = { 0 , 0 , {0 }, 0 };
1354
1351
phy_params.channels .channel_list [channel_id] = empty_channel;
1355
1352
1356
1353
return disable_channel (phy_params.channels .mask , channel_id,
0 commit comments