datetime_utc/
datetime_utc.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// Copyright 2024 René Ladan <rene0+codeberg@freedom.nl>
3
4use msf60_utils::MSFUtils;
5
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 1] =
9        ["4 00000000 00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330"];
10    for msg in MSGS {
11        for m in msg.chars() {
12            match m {
13                '0' => {
14                    msf.set_current_bit_a(Some(false));
15                    msf.set_current_bit_b(Some(false));
16                }
17                '1' => {
18                    msf.set_current_bit_a(Some(true));
19                    msf.set_current_bit_b(Some(false));
20                }
21                '2' => {
22                    msf.set_current_bit_a(Some(false));
23                    msf.set_current_bit_b(Some(true));
24                }
25                '3' => {
26                    msf.set_current_bit_a(Some(true));
27                    msf.set_current_bit_b(Some(true));
28                }
29                '4' => msf.force_past_new_minute(),
30                '_' => {
31                    msf.set_current_bit_a(None);
32                    msf.set_current_bit_b(None);
33                }
34                _ => continue,
35                // skip increasing the second counter, as this character is only syntactic sugar
36            }
37            // 0111.1110 train seen?
38            if msf.end_of_minute_marker_present() {
39                msf.decode_time(true, false);
40                let mut rdt = msf.get_radio_datetime();
41                println!(
42                    "Date/time (local)={:?}-{:?}-{:?} {:?}:{:?} {:?} {:#2x?}",
43                    rdt.get_year(),
44                    rdt.get_month(),
45                    rdt.get_day(),
46                    rdt.get_hour(),
47                    rdt.get_minute(),
48                    rdt.get_weekday(),
49                    rdt.get_dst()
50                );
51                rdt = rdt.get_utc().unwrap();
52                println!(
53                    "Date/time (UTC)=  {:?}-{:?}-{:?} {:?}:{:?} {:?} {:#2x?}",
54                    rdt.get_year(),
55                    rdt.get_month(),
56                    rdt.get_day(),
57                    rdt.get_hour(),
58                    rdt.get_minute(),
59                    rdt.get_weekday(),
60                    rdt.get_dst()
61                );
62                msf.force_new_minute();
63            }
64            if !msf.increase_second() {
65                println!("Bad increase_second at second {}", msf.get_second());
66            }
67        }
68    }
69}