restart on garbage

This commit is contained in:
Dominic 2023-10-08 23:36:58 +02:00
parent 4da353ab28
commit 3c7a6186d4
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -87,22 +87,42 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
const SECONDS: usize = 60; const SECONDS: usize = 60;
let mut bytes = [0u64; SECONDS]; let mut bytes = [0u64; SECONDS];
let mut timing = [0u64; SECONDS]; let mut timing = [0u64; SECONDS];
for i in 0 .. SECONDS { let mut i = 0;
while i < SECONDS {
tco.wait_for_falling_edge().await; tco.wait_for_falling_edge().await;
bytes[i] = start.elapsed().as_millis(); bytes[i] = start.elapsed().as_millis();
tco.wait_for_rising_edge().await; tco.wait_for_rising_edge().await;
timing[i] = start.elapsed().as_millis(); timing[i] = start.elapsed().as_millis();
start = Instant::now(); start = Instant::now();
// verify that the transmission wasn't just noise of the previous one
if i > 0 && bytes[i] < 100 && timing[i - 1] - bytes[i - 1] < 100 {
bytes[i - 1] += timing[i - 1] + bytes[i];
timing[i - 1] += timing[i];
}
// and verify that the transmission wasn't a minute marker
else if timing[i] >= 1500 {
info!("Retrying");
i = 0;
}
// otherwise advance the second
else {
i += 1;
}
} }
pon.set_high(); pon.set_high();
info!("Done"); info!("Done");
let mut garbage = false;
for i in 0 .. SECONDS { for i in 0 .. SECONDS {
let data = match (bytes[i], timing[i]) { let data = match (bytes[i], timing[i]) {
(75 ..= 174, 900 ..= 1100) => "0", (75 ..= 174, 900 ..= 1100) => "0",
(175 ..= 300, 900 ..= 1100) => "1", (175 ..= 300, 900 ..= 1100) => "1",
_ => "GARBAGE" _ => {
garbage = true;
"GARBAGE"
}
}; };
println!( println!(
"Bit {:02}: on for {:04} ms of {:04} ms total -- {:02}: {}", "Bit {:02}: on for {:04} ms of {:04} ms total -- {:02}: {}",
@ -111,8 +131,10 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
Timer::after(Duration::from_millis(50)).await; Timer::after(Duration::from_millis(50)).await;
} }
if !garbage {
Timer::after(interval).await; Timer::after(interval).await;
} }
}
} }
#[embassy_executor::main] #[embassy_executor::main]
@ -122,11 +144,11 @@ async fn main(spawner: Spawner) {
let pon = Output::new(p.PA0, Level::High, Speed::Low); let pon = Output::new(p.PA0, Level::High, Speed::Low);
let tco = ExtiInput::new(Input::new(p.PA1, Pull::None), p.EXTI1); let tco = ExtiInput::new(Input::new(p.PA1, Pull::None), p.EXTI1);
unwrap!(spawner.spawn(query_time(pon, tco, Duration::from_secs(300)))); unwrap!(spawner.spawn(query_time(pon, tco, Duration::from_secs(120))));
LED.init(Output::new(p.PA5, Level::Low, Speed::Low)).await; LED.init(Output::new(p.PA5, Level::Low, Speed::Low)).await;
let button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13); let button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13);
unwrap!(spawner.spawn(blinker(Duration::from_millis(120)))); unwrap!(spawner.spawn(blinker(Duration::from_millis(500))));
unwrap!(spawner.spawn(button_handler(button))); unwrap!(spawner.spawn(button_handler(button)));
} }