Skip to content

Commit

Permalink
debug ping
Browse files Browse the repository at this point in the history
  • Loading branch information
gferraro committed Dec 23, 2024
1 parent 0696b58 commit a1b23d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/core0_audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl TryFrom<u8> 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,
Expand Down Expand Up @@ -198,6 +198,9 @@ pub fn audio_task(
}
}
}
if DEV_MODE {
duration = 5;
}

let mut reschedule = false;
let mut alarm_date_time: Option<NaiveDateTime> = None;
Expand Down Expand Up @@ -703,6 +706,7 @@ pub fn offload(
false,
) && flash_storage.has_files_to_offload()
{
delay.delay_ms(2000);
return Err(());
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/core1_sub_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/core1_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion src/device_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand All @@ -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");
Expand Down

0 comments on commit a1b23d7

Please sign in to comment.