(&mut self)
| 329 | } |
| 330 | |
| 331 | async fn fragmentation_session_setup(&mut self) -> Result<Option<(FuotaJob, DateTime<Utc>)>> { |
| 332 | let fuota_devices = fuota::get_devices(self.job.fuota_deployment_id.into(), -1, 0).await?; |
| 333 | let fuota_devices_completed_mc_group_setup_count = fuota_devices |
| 334 | .iter() |
| 335 | .filter(|d| d.mc_group_setup_completed_at.is_some()) |
| 336 | .count(); |
| 337 | |
| 338 | // Filter on devices that have completed the previous step, but not yet the FragSessionSetup. |
| 339 | let fuota_devices: Vec<fuota::FuotaDeploymentDevice> = fuota_devices |
| 340 | .into_iter() |
| 341 | .filter(|d| { |
| 342 | d.mc_group_setup_completed_at.is_some() |
| 343 | && d.frag_session_setup_completed_at.is_none() |
| 344 | }) |
| 345 | .collect(); |
| 346 | |
| 347 | // Proceed with next step after reaching the max attempts. |
| 348 | if self.job.attempt_count > self.job.max_retry_count { |
| 349 | info!("Set timeout error to devices that did not respond to FragSessionSetupReq"); |
| 350 | fuota::set_device_timeout_error( |
| 351 | self.fuota_deployment.id.into(), |
| 352 | false, |
| 353 | false, |
| 354 | true, |
| 355 | false, |
| 356 | ) |
| 357 | .await?; |
| 358 | |
| 359 | if !fuota_devices.is_empty() { |
| 360 | self.job.warning_msg = format!( |
| 361 | "{} devices did not complete the fragmentation session setup", |
| 362 | fuota_devices.len() |
| 363 | ); |
| 364 | } |
| 365 | return Ok(Some((FuotaJob::McSession, Utc::now()))); |
| 366 | } |
| 367 | |
| 368 | info!("Sending FragSessionSetupReq commands to devices"); |
| 369 | self.job.attempt_count += 1; |
| 370 | |
| 371 | if fuota_devices_completed_mc_group_setup_count == 0 { |
| 372 | self.job.error_msg = "There are no devices available to complete this step".into(); |
| 373 | return Ok(Some((FuotaJob::DeleteMcGroup, Utc::now()))); |
| 374 | } |
| 375 | |
| 376 | let fragment_size = self.fuota_deployment.fragmentation_fragment_size as usize; |
| 377 | let fragments = |
| 378 | (self.fuota_deployment.payload.len() as f32 / fragment_size as f32).ceil() as usize; |
| 379 | let padding = |
| 380 | (fragment_size - (self.fuota_deployment.payload.len() % fragment_size)) % fragment_size; |
| 381 | |
| 382 | for fuota_dev in &fuota_devices { |
| 383 | let descriptor = { |
| 384 | let mut d = [0u8; 4]; |
| 385 | if self.fuota_deployment.fragmentation_descriptor.len() == 4 { |
| 386 | d.copy_from_slice(&self.fuota_deployment.fragmentation_descriptor); |
| 387 | } |
| 388 | d |
no test coverage detected