(
dir: &Path,
device: &Device,
firmware: &DeviceFirmware,
codec: &Option<String>,
profile: &str,
)
| 232 | } |
| 233 | |
| 234 | async fn handle_profile( |
| 235 | dir: &Path, |
| 236 | device: &Device, |
| 237 | firmware: &DeviceFirmware, |
| 238 | codec: &Option<String>, |
| 239 | profile: &str, |
| 240 | ) -> Result<()> { |
| 241 | let profile_path = dir.join("profiles").join(profile); |
| 242 | |
| 243 | info!(path = ?profile_path, "Reading profile configuration"); |
| 244 | let profile_conf: ProfileConfig = toml::from_str(&fs::read_to_string(profile_path)?)?; |
| 245 | |
| 246 | let mut dp = device_profile::DeviceProfile { |
| 247 | name: device.name.clone(), |
| 248 | region: profile_conf.profile.region, |
| 249 | mac_version: profile_conf.profile.mac_version, |
| 250 | reg_params_revision: profile_conf.profile.reg_params_revision, |
| 251 | adr_algorithm_id: "default".into(), |
| 252 | payload_codec_runtime: match codec { |
| 253 | Some(_) => Codec::JS, |
| 254 | None => Codec::NONE, |
| 255 | }, |
| 256 | uplink_interval: 60 * 60, |
| 257 | device_status_req_interval: 1, |
| 258 | supports_otaa: profile_conf.profile.supports_otaa, |
| 259 | supports_class_b: profile_conf.profile.supports_class_b, |
| 260 | supports_class_c: profile_conf.profile.supports_class_c, |
| 261 | payload_codec_script: codec.clone().unwrap_or_default(), |
| 262 | flush_queue_on_activate: true, |
| 263 | description: device.description.clone(), |
| 264 | abp_params: if !profile_conf.profile.supports_otaa { |
| 265 | Some(fields::AbpParams { |
| 266 | rx1_delay: profile_conf.profile.abp.rx1_delay as u8, |
| 267 | rx1_dr_offset: profile_conf.profile.abp.rx1_dr_offset as u8, |
| 268 | rx2_dr: profile_conf.profile.abp.rx2_dr as u8, |
| 269 | rx2_freq: profile_conf.profile.abp.rx2_freq as u32, |
| 270 | }) |
| 271 | } else { |
| 272 | None |
| 273 | }, |
| 274 | class_b_params: if profile_conf.profile.supports_class_b { |
| 275 | Some(fields::ClassBParams { |
| 276 | timeout: profile_conf.profile.class_b.timeout_secs as u16, |
| 277 | ping_slot_periodicity: profile_conf.profile.class_b.ping_slot_periodicity as u8, |
| 278 | ping_slot_dr: profile_conf.profile.class_b.ping_slot_dr as u8, |
| 279 | ping_slot_freq: profile_conf.profile.class_b.ping_slot_freq as u32, |
| 280 | class_b_downlink_only: false, |
| 281 | }) |
| 282 | } else { |
| 283 | None |
| 284 | }, |
| 285 | class_c_params: if profile_conf.profile.supports_class_c { |
| 286 | Some(fields::ClassCParams { |
| 287 | timeout: profile_conf.profile.class_c.timeout_secs as u16, |
| 288 | }) |
| 289 | } else { |
| 290 | None |
| 291 | }, |
no test coverage detected