(&mut self)
| 1293 | } |
| 1294 | |
| 1295 | async fn _request_adr_change(&mut self) -> Result<()> { |
| 1296 | trace!("Requesting ADR change"); |
| 1297 | |
| 1298 | if self.network_conf.adr_disabled { |
| 1299 | return Ok(()); |
| 1300 | } |
| 1301 | |
| 1302 | let dr = self |
| 1303 | .region_conf |
| 1304 | .get_data_rate(true, self.uplink_frame_set.as_ref().unwrap().dr)?; |
| 1305 | |
| 1306 | let ufs = self.uplink_frame_set.as_ref().unwrap(); |
| 1307 | let dev_eui = self.device.dev_eui; |
| 1308 | let device_variables = self.device.variables.into_hashmap(); |
| 1309 | let ds = self.device.get_device_session_mut()?; |
| 1310 | |
| 1311 | let req = adr::Request { |
| 1312 | dev_eui, |
| 1313 | device_variables, |
| 1314 | region_config_id: ufs.region_config_id.clone(), |
| 1315 | region_common_name: ufs.region_common_name, |
| 1316 | mac_version: self.device_profile.mac_version, |
| 1317 | reg_params_revision: self.device_profile.reg_params_revision, |
| 1318 | adr: ds.adr, |
| 1319 | dr: self.uplink_frame_set.as_ref().unwrap().dr, |
| 1320 | tx_power_index: ds.tx_power_index as u8, |
| 1321 | nb_trans: ds.nb_trans as u8, |
| 1322 | max_tx_power_index: if ds.max_supported_tx_power_index != 0 { |
| 1323 | ds.max_supported_tx_power_index as u8 |
| 1324 | } else { |
| 1325 | let mut max_tx_power_index: u8 = 0; |
| 1326 | for n in 0..16 { |
| 1327 | if self.region_conf.get_tx_power_offset(n).is_ok() { |
| 1328 | max_tx_power_index = n as u8; |
| 1329 | } |
| 1330 | } |
| 1331 | max_tx_power_index |
| 1332 | }, |
| 1333 | required_snr_for_dr: match dr { |
| 1334 | lrwn::region::DataRateModulation::Lora(params) => { |
| 1335 | config::get_required_snr_for_sf(params.spreading_factor)? |
| 1336 | } |
| 1337 | _ => 0.0, |
| 1338 | }, |
| 1339 | installation_margin: self.network_conf.installation_margin, |
| 1340 | min_dr: self.network_conf.min_dr, |
| 1341 | max_dr: self.network_conf.max_dr, |
| 1342 | uplink_history: ds.uplink_adr_history.clone(), |
| 1343 | skip_f_cnt_check: ds.skip_f_cnt_check, |
| 1344 | }; |
| 1345 | |
| 1346 | let resp = adr::handle(&self.device_profile.adr_algorithm_id, &req).await; |
| 1347 | |
| 1348 | // The response values are different than the request values, thus we must |
| 1349 | // send a LinkADRReq to the device. |
| 1350 | if resp.dr != req.dr |
| 1351 | || resp.tx_power_index != req.tx_power_index |
| 1352 | || resp.nb_trans != req.nb_trans |
no test coverage detected