diff --git a/src/core0_audio.rs b/src/core0_audio.rs index 64969dd..bb2946b 100644 --- a/src/core0_audio.rs +++ b/src/core0_audio.rs @@ -61,7 +61,7 @@ impl TryFrom for AlarmMode { } } -const DEV_MODE: bool = false; +const DEV_MODE: bool = true; pub const MAX_GAP_MIN: u8 = 60; pub fn audio_task( i2c_config: I2CConfig, @@ -198,6 +198,9 @@ pub fn audio_task( } } } + if DEV_MODE { + duration = 5; + } let mut reschedule = false; let mut alarm_date_time: Option = None; @@ -703,6 +706,7 @@ pub fn offload( false, ) && flash_storage.has_files_to_offload() { + delay.delay_ms(2000); return Err(()); } } diff --git a/src/core1_sub_tasks.rs b/src/core1_sub_tasks.rs index 111086c..edcbffc 100644 --- a/src/core1_sub_tasks.rs +++ b/src/core1_sub_tasks.rs @@ -68,8 +68,11 @@ pub fn maybe_offload_events( } //takes tc2-agent about this long to poll again will always fail otherwise let time_since = (timer.get_counter() - counter).to_micros(); - if time_since < TIME_BETWEEN_TRANSFER { - delay.delay_us((TIME_BETWEEN_TRANSFER - time_since) as u32); + let extra_delay = attempts * 50; + if time_since < (TIME_BETWEEN_TRANSFER + extra_delay) { + delay.delay_us( + (TIME_BETWEEN_TRANSFER + extra_delay - time_since) as u32, + ); } } else { break 'transfer_event; @@ -210,6 +213,7 @@ pub fn offload_flash_storage_and_events( part_count, block_index, page_index ); } + 18474 let mut attempts = 0; 'transfer_part: loop { @@ -222,15 +226,18 @@ pub fn offload_flash_storage_and_events( if !did_transfer { attempts += 1; if attempts > 100 { + info!("Failed because attmpets {}", attempts); success = false; break 'transfer_part; } //takes tc2-agent about this long to poll again will fail a lot otherwise let time_since = (timer.get_counter() - counter).to_micros(); - if time_since < TIME_BETWEEN_TRANSFER { - delay.delay_us((TIME_BETWEEN_TRANSFER - time_since) as u32); + let extra_delay = attempts * 20; + if time_since < (TIME_BETWEEN_TRANSFER + extra_delay) { + delay.delay_us((TIME_BETWEEN_TRANSFER + extra_delay - time_since) as u32); } } else { + info!("Sucess after {}", attempts); break 'transfer_part; } } @@ -311,6 +318,8 @@ pub fn offload_flash_storage_and_events( ); flash_storage.scan(); warn!("File transfer to pi failed"); + delay.delay_ms(2000); + false } } diff --git a/src/core1_task.rs b/src/core1_task.rs index 1a3f81f..cf6542c 100644 --- a/src/core1_task.rs +++ b/src/core1_task.rs @@ -643,7 +643,10 @@ pub fn core_1_task( let mut stable_telemetry_tracker = ([0u8, 0u8], -1); let mut is_daytime = device_config.time_is_in_daylight(&synced_date_time.date_time_utc); - + info!( + "Current utc time is {}", + &synced_date_time.date_time_utc.time().hour() + ); info!( "Current time is in recording window? {}", device_config.time_is_in_recording_window(&synced_date_time.date_time_utc, &None) diff --git a/src/device_config.rs b/src/device_config.rs index 4792546..eab873b 100644 --- a/src/device_config.rs +++ b/src/device_config.rs @@ -70,6 +70,12 @@ impl DeviceConfigInner { } let (start_time, end_time) = window.unwrap_or(self.next_or_current_recording_window(date_time_utc)); + info!( + "Start {} end is {} ", + start_time.time().hour(), + end_time.time().hour() + ); + let starts_in = start_time - *date_time_utc; let starts_in_hours = starts_in.num_hours(); let starts_in_mins = starts_in.num_minutes() - (starts_in_hours * 60); @@ -144,7 +150,6 @@ impl DeviceConfigInner { tomorrow_sunrise.naive_utc() + Duration::seconds(end_offset as i64); let tomorrow_sunset = tomorrow_sunset.naive_utc() + Duration::seconds(start_offset as i64); - if *now_utc > today_sunset && *now_utc > tomorrow_sunrise { let two_days_from_now_utc = *now_utc + Duration::days(2); let (two_days_sunrise, _) = sun_times( @@ -160,11 +165,14 @@ impl DeviceConfigInner { } else if (*now_utc > today_sunset && *now_utc < tomorrow_sunrise) || (*now_utc < today_sunset && *now_utc > today_sunrise) { + info!("Calculated today sunset {}", today_sunset.time().hour()); (Some(today_sunset), Some(tomorrow_sunrise)) } else if *now_utc < tomorrow_sunset && *now_utc < today_sunrise && *now_utc > yesterday_sunset { + info!("Calculated today sunset {}", yesterday_sunset.time().hour()); + (Some(yesterday_sunset), Some(today_sunrise)) } else { panic!("Unable to calculate relative time window");