// SPDX-License-Identifier: MIT OR Apache-2.0 // Copyright 2024 René Ladan use radio_datetime_utils::{DST_ANNOUNCED, DST_PROCESSED, DST_SUMMER}; use msf60_utils::MSFUtils; // quick and dirty parsing function fn parse_dst(dst: Option) -> String { if dst.is_none() { return String::from("*"); } let mut res = String::from(""); let s_dst = dst.unwrap(); if s_dst & DST_ANNOUNCED != 0 { res += "announced "; } if s_dst & DST_PROCESSED != 0 { res += "processed "; } if s_dst & DST_SUMMER != 0 { res += "summer"; } res } fn str_weekday(day: Option) -> String { String::from(match day { Some(0) => "Sunday", Some(1) => "Monday", Some(2) => "Tuesday", Some(3) => "Wednesday", Some(4) => "Thursday", Some(5) => "Friday", Some(6) => "Saturday", Some(7) => "?", None => "None", _ => "", }) } fn main() { let mut msf = MSFUtils::default(); const MSG: &str = "4 00000000 00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330"; for m in MSG.chars() { match m { '0' => { msf.set_current_bit_a(Some(false)); msf.set_current_bit_b(Some(false)); } '1' => { msf.set_current_bit_a(Some(true)); msf.set_current_bit_b(Some(false)); } '2' => { msf.set_current_bit_a(Some(false)); msf.set_current_bit_b(Some(true)); } '3' => { msf.set_current_bit_a(Some(true)); msf.set_current_bit_b(Some(true)); } '4' => msf.force_past_new_minute(), '_' => { msf.set_current_bit_a(None); msf.set_current_bit_b(None); } _ => continue, // also skip increasing the second counter, as this character is only syntactic sugar } // 0111.1110 train seen? if msf.end_of_minute_marker_present() { msf.decode_time(true, false); println!("DUT1={:?}", msf.get_dut1()); let rdt = msf.get_radio_datetime(); println!( "Parities={:?} {:?} {:?} {:?}", msf.get_parity_1(), msf.get_parity_2(), msf.get_parity_3(), msf.get_parity_4() ); println!( "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}", rdt.get_year(), rdt.get_month(), rdt.get_day(), rdt.get_hour(), rdt.get_minute(), str_weekday(rdt.get_weekday()), parse_dst(rdt.get_dst()) ); msf.force_new_minute(); } if !msf.increase_second() { println!("Bad increase_second at second {}", msf.get_second()); } } }