try decoding the dcf77 bits myself

This commit is contained in:
Dominic 2023-10-08 23:06:19 +02:00
parent e9050fa59e
commit 4da353ab28
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 44 additions and 41 deletions

View file

@ -3,11 +3,14 @@
#![feature(async_fn_track_caller, type_alias_impl_trait)]
#![warn(rust_2018_idioms)]
#![forbid(elided_lifetimes_in_paths, unsafe_code)]
// STOP HIGHLIGHTING MY ENTIRE CODE RED YOU MOTHERFUCKING PEACE OF GARBAGE SOFTWARE
// SOMETIMES I AM WRITING CODE BEFORE I INSERT A BREAK SOMEWHERE
// ARE YOU AWARE THAT CODING DOESN'T PRODUCE FINISHED CODE IN A MILLISECOND???????
#![allow(clippy::never_loop, unreachable_code)]
mod static_mutex;
use dcf77_utils::DCF77Utils;
use defmt::{assert, info, println, unwrap};
use defmt::{info, println, unwrap};
use defmt_rtt as _;
use embassy_executor::Spawner;
use embassy_stm32::{
@ -62,34 +65,51 @@ async fn query_time(mut pon: POn, mut tco: Tco, interval: Duration) {
loop {
pon.set_low();
info!("Waiting");
tco.wait_for_falling_edge().await;
info!("Receiving");
let mut dcf77 = DCF77Utils::new();
let start = Instant::now();
// we need to find the minute marker
// that means we won't receive a transmission for an entire second
tco.wait_for_rising_edge().await;
loop {
tco.wait_for_any_edge().await;
let elapsed = start.elapsed();
while elapsed.as_secs() > dcf77.get_second() as u64 {
dcf77.increase_second();
}
dcf77.handle_new_edge(tco.is_low(), start.elapsed().as_millis() as u32);
if dcf77.get_second() + 1 == dcf77.get_next_minute_length() {
dcf77.decode_time();
let datetime = dcf77.get_radio_datetime();
println!(
"{}.{}.{} {}:{}",
datetime.get_day(),
datetime.get_month(),
datetime.get_year(),
datetime.get_hour(),
datetime.get_minute()
);
tco.wait_for_falling_edge().await;
let start = Instant::now();
tco.wait_for_rising_edge().await;
// our starting edge should have at least 800ms from the previous second,
// and then a full second.
if start.elapsed().as_millis() > 1500 {
break;
}
}
let mut start = Instant::now();
info!("Receiving");
// we always start on the rising edge, with `start` set already
const SECONDS: usize = 60;
let mut bytes = [0u64; SECONDS];
let mut timing = [0u64; SECONDS];
for i in 0 .. SECONDS {
tco.wait_for_falling_edge().await;
bytes[i] = start.elapsed().as_millis();
tco.wait_for_rising_edge().await;
timing[i] = start.elapsed().as_millis();
start = Instant::now();
}
pon.set_high();
info!("Done");
for i in 0 .. SECONDS {
let data = match (bytes[i], timing[i]) {
(75 ..= 174, 900 ..= 1100) => "0",
(175 ..= 300, 900 ..= 1100) => "1",
_ => "GARBAGE"
};
println!(
"Bit {:02}: on for {:04} ms of {:04} ms total -- {:02}: {}",
i, bytes[i], timing[i], i, data
);
Timer::after(Duration::from_millis(50)).await;
}
Timer::after(interval).await;
}
@ -107,6 +127,6 @@ async fn main(spawner: Spawner) {
LED.init(Output::new(p.PA5, Level::Low, Speed::Low)).await;
let button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13);
unwrap!(spawner.spawn(blinker(Duration::from_millis(500))));
unwrap!(spawner.spawn(blinker(Duration::from_millis(120))));
unwrap!(spawner.spawn(button_handler(button)));
}