MSFUtils

Struct MSFUtils 

Source
pub struct MSFUtils { /* private fields */ }
Expand description

MSF decoder class

Implementations§

Source§

impl MSFUtils

Source

pub fn new() -> Self

Initialize a new MSFUtils instance.

Source

pub fn reset(&mut self)

Reset the MSFUtils instance including the radio_datetime field.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 101)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
Source

pub fn is_first_minute(&self) -> bool

Return if this is the first minute that is decoded.

Examples found in repository?
examples/detect_jumps.rs (line 41)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
Source

pub fn is_new_minute(&self) -> bool

Return if a new minute (0111_1110 marker) has arrived.

Examples found in repository?
examples/decode_datetime_pretend_live.rs (line 201)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn is_past_new_minute(&self) -> bool

Return if the 500 ms long begin-of-minute marker has arrived.

Examples found in repository?
examples/decode_datetime_pretend_live.rs (line 202)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn force_new_minute(&mut self)

Force the arrival of a new minute (0111_1110 version).

This could be useful when reading from a log file.

This method must be called before increase_second().

Examples found in repository?
examples/decode_datetime_logfile.rs (line 94)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 62)
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}
examples/detect_jumps.rs (line 67)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
Source

pub fn force_past_new_minute(&mut self)

Force the arrival of a new minute (begin-of-minute version).

This could be useful when reading from a log file.

This method must be called before increase_second().

Examples found in repository?
examples/decode_datetime_logfile.rs (line 64)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 29)
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}
examples/detect_jumps.rs (line 31)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
Source

pub fn is_new_second(&self) -> bool

Returns if a new second has arrived.

Source

pub fn get_second(&self) -> u8

Get the second counter.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 97)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 65)
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}
examples/detect_jumps.rs (line 70)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
examples/decode_datetime_pretend_live.rs (line 193)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_current_bit_a(&self) -> Option<bool>

Get the value of the current A bit.

Examples found in repository?
examples/decode_datetime_pretend_live.rs (line 199)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_current_bit_b(&self) -> Option<bool>

Get the value of the current B bit.

Examples found in repository?
examples/decode_datetime_pretend_live.rs (line 200)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn set_current_bit_a(&mut self, value: Option<bool>)

Set the value of the current A bit and clear the flag indicating arrival of a new minute.

This could be useful when reading from a log file.

This method must be called before increase_second().

§Arguments
  • value - the value to set the current bit to.
Examples found in repository?
examples/decode_datetime_logfile.rs (line 49)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 14)
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}
examples/detect_jumps.rs (line 16)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
Source

pub fn set_current_bit_b(&mut self, value: Option<bool>)

Set the value of the current B bit and clear the flag indicating arrival of a new minute.

This could be useful when reading from a log file.

This method must be called before increase_second().

§Arguments
  • value - the value to set the current bit to.
Examples found in repository?
examples/decode_datetime_logfile.rs (line 50)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 15)
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}
examples/detect_jumps.rs (line 17)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
Source

pub fn get_radio_datetime(&self) -> RadioDateTimeUtils

Get a copy of the date/time structure.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 75)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 40)
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}
examples/detect_jumps.rs (line 44)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
examples/decode_datetime_pretend_live.rs (line 217)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_parity_1(&self) -> Option<bool>

Get the year parity bit, Some(true) means OK.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 79)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/decode_datetime_pretend_live.rs (line 221)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_parity_2(&self) -> Option<bool>

Get the month/day parity bit, Some(true) means OK.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 80)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/decode_datetime_pretend_live.rs (line 222)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_parity_3(&self) -> Option<bool>

Get the weekday parity bit, Some(true) means OK.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 81)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/decode_datetime_pretend_live.rs (line 223)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_parity_4(&self) -> Option<bool>

Get the hour/minute parity bit, Some(true) means OK.

Examples found in repository?
examples/decode_datetime_logfile.rs (line 82)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/decode_datetime_pretend_live.rs (line 224)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_dut1(&self) -> Option<i8>

👎Deprecated since 1.2.0: Please use get_dut1() from radio_datetime_utils directly
Source

pub fn get_jump_dut1(&self) -> bool

👎Deprecated since 1.2.0: Please use get_jump_dut1() from radio_datetime_utils directly
Source

pub fn get_spike_limit(&self) -> u32

Return the current spike limit in microseconds.

Examples found in repository?
examples/decode_datetime_pretend_live.rs (line 205)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn set_spike_limit(&mut self, value: u32)

Set the new spike limit in microseconds, [0(off)..ACTIVE_0_LIMIT)

§Arguments
  • value - the value to set the spike limit to.
Source

pub fn handle_new_edge(&mut self, is_high_edge: bool, t: u32)

Determine the bit value if a new edge is received and checks if a new minute has started. None values indicate reception errors.

This function can deal with spikes, which are arbitrarily set to spike_limit microseconds.

This method must be called before increase_second().

§Arguments
  • is_high_edge - indicates that the edge has gone from low to high(as opposed to high-to-low).
  • t - time stamp of the received edge, in microseconds.
Examples found in repository?
examples/decode_datetime_pretend_live.rs (line 189)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn get_minute_length(&self) -> u8

Determine the length of this minute in seconds.

Source

pub fn end_of_minute_marker_present(&self) -> bool

Return if the end-of-minute marker (0111_1110) is present in the A bits.

This method must be called before increase_second().

Examples found in repository?
examples/decode_datetime_logfile.rs (line 73)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 38)
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}
examples/detect_jumps.rs (line 40)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
Source

pub fn increase_second(&mut self) -> bool

Increase or reset second.

Returns if the second counter was increased/wrapped normally (true) or due to an overflow (false).

This method must be called after decode_time(), handle_new_edge(), set_current_bit_a(), set_current_bit_b(), end_of_minute_marker_present() force_new_minute(), and force_past_new_minute().

Examples found in repository?
examples/decode_datetime_logfile.rs (line 96)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 64)
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}
examples/detect_jumps.rs (line 69)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
examples/decode_datetime_pretend_live.rs (line 205)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}
Source

pub fn add_minute(&mut self) -> bool

Call add_minute() on self.radio_datetime and passes on that result.

This could be useful for consumers just wanting to advance their current date/time.

Source

pub fn decode_time(&mut self, need_add_minute: bool, strict_checks: bool)

Decode the time broadcast during the last minute and clear first_minute when appropriate.

This method must be called before increase_second().

§Arguments
  • need_add_minute - add a minute to self.radio_datetime, in case add_minute() was not called before.
  • strict_checks - checks all parities, DUT1 validity, and EOM marker presence when setting date/time and clearing self.first_minute.
Examples found in repository?
examples/decode_datetime_logfile.rs (line 74)
42fn main() {
43    let mut msf = MSFUtils::default();
44
45    const MSG: &str = "4 00000000.22000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330";
46    for m in MSG.chars() {
47        match m {
48            '0' => {
49                msf.set_current_bit_a(Some(false));
50                msf.set_current_bit_b(Some(false));
51            }
52            '1' => {
53                msf.set_current_bit_a(Some(true));
54                msf.set_current_bit_b(Some(false));
55            }
56            '2' => {
57                msf.set_current_bit_a(Some(false));
58                msf.set_current_bit_b(Some(true));
59            }
60            '3' => {
61                msf.set_current_bit_a(Some(true));
62                msf.set_current_bit_b(Some(true));
63            }
64            '4' => msf.force_past_new_minute(),
65            '_' => {
66                msf.set_current_bit_a(None);
67                msf.set_current_bit_b(None);
68            }
69            _ => continue,
70            // also skip increasing the second counter, as this character is only syntactic sugar
71        }
72        // 0111.1110 train seen?
73        if msf.end_of_minute_marker_present() {
74            msf.decode_time(true, false);
75            let rdt = msf.get_radio_datetime();
76            println!("DUT1={:?}", rdt.get_dut1());
77            println!(
78                "Parities={:?} {:?} {:?} {:?}",
79                msf.get_parity_1(),
80                msf.get_parity_2(),
81                msf.get_parity_3(),
82                msf.get_parity_4()
83            );
84            println!(
85                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
86                rdt.get_year(),
87                rdt.get_month(),
88                rdt.get_day(),
89                rdt.get_hour(),
90                rdt.get_minute(),
91                str_weekday(rdt.get_weekday()),
92                parse_dst(rdt.get_dst())
93            );
94            msf.force_new_minute();
95        }
96        if !msf.increase_second() {
97            println!("Bad increase_second at second {}", msf.get_second());
98        }
99    }
100    println!("Before reset: {:#?}", msf);
101    msf.reset();
102    println!("After reset: {:#?}", msf);
103}
More examples
Hide additional examples
examples/datetime_utc.rs (line 39)
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}
examples/detect_jumps.rs (line 43)
6fn main() {
7    let mut msf = MSFUtils::default();
8    const MSGS: [&str; 2] = [
9        "4 00000000.00000000 0010.0100 0.0100 01.0010 101 10.0000 000.0010 01313330",
10        "4 20000000.00000000 0010.0100 0.0100 01.0010 101 10.0001 000.1000 01313130",
11    ];
12    for msg in MSGS {
13        for m in msg.chars() {
14            match m {
15                '0' => {
16                    msf.set_current_bit_a(Some(false));
17                    msf.set_current_bit_b(Some(false));
18                }
19                '1' => {
20                    msf.set_current_bit_a(Some(true));
21                    msf.set_current_bit_b(Some(false));
22                }
23                '2' => {
24                    msf.set_current_bit_a(Some(false));
25                    msf.set_current_bit_b(Some(true));
26                }
27                '3' => {
28                    msf.set_current_bit_a(Some(true));
29                    msf.set_current_bit_b(Some(true));
30                }
31                '4' => msf.force_past_new_minute(),
32                '_' => {
33                    msf.set_current_bit_a(None);
34                    msf.set_current_bit_b(None);
35                }
36                _ => continue,
37                // skip increasing the second counter, as this character is only syntactic sugar
38            }
39            // 0111.1110 train seen?
40            if msf.end_of_minute_marker_present() {
41                let fm = msf.is_first_minute();
42                // cache because decode_time() clears this on a successful decode
43                msf.decode_time(true, false);
44                let rdt = msf.get_radio_datetime();
45                println!(
46                    "Date/time={:?}-{:?}-{:?} {:?}:{:?} {:?} DUT1={:?}",
47                    rdt.get_year(),
48                    rdt.get_month(),
49                    rdt.get_day(),
50                    rdt.get_hour(),
51                    rdt.get_minute(),
52                    rdt.get_weekday(),
53                    rdt.get_dut1()
54                );
55                if !fm {
56                    println!(
57                        "Jumps={} {} {} {} {} {} {}",
58                        rdt.get_jump_year(),
59                        rdt.get_jump_month(),
60                        rdt.get_jump_day(),
61                        rdt.get_jump_hour(),
62                        rdt.get_jump_minute(),
63                        rdt.get_jump_weekday(),
64                        rdt.get_jump_dut1()
65                    );
66                }
67                msf.force_new_minute();
68            }
69            if !msf.increase_second() {
70                println!("Bad increase_second at second {}", msf.get_second());
71            }
72        }
73    }
74}
examples/decode_datetime_pretend_live.rs (line 216)
42fn main() {
43    // Pretend to do live decoding, e.g. by detecting the time differences in microseconds from
44    // edges read from a GPIO pin. Samples need to be in absolute time since some point, not in
45    // relative time to each other. Format is (time-in-us-since-some-point, edge-becomes-high).
46    // The boolean value is the inverse of the radio signal.
47    const SAMPLES: [(u32, bool); 135] = [
48        (480097898, false),
49        (480909129, true),
50        (480998372, false),
51        (481905456, true),
52        (482396098, false),
53        (482906504, true),
54        (482993883, false),
55        (483908888, true),
56        (483993519, false),
57        (483993578, false),
58        (483993623, false),
59        (484905643, true),
60        (484999472, false),
61        (485909536, true),
62        (485997179, false),
63        (486908192, true),
64        (486998019, false),
65        (487906286, true),
66        (487997465, false),
67        (488900307, true),
68        (488999571, false),
69        (489904756, true),
70        (489996274, false),
71        (490905915, true),
72        (490993902, false),
73        (491904343, true),
74        (491998425, false),
75        (492905411, true),
76        (492994929, false),
77        (493907275, true),
78        (494000510, false),
79        (494909312, true),
80        (494997767, false),
81        (495907859, true),
82        (495999521, false),
83        (496903804, true),
84        (496996022, false),
85        (497904393, true),
86        (497998389, false),
87        (498902023, true),
88        (498995599, false),
89        (499906248, true),
90        (499994605, false),
91        (500911975, true),
92        (501097918, false),
93        (501906651, true),
94        (502000289, false),
95        (502907018, true),
96        (502999103, false),
97        (503905111, true),
98        (503998501, false),
99        (504903060, true),
100        (505093147, false),
101        (505905830, true),
102        (505997306, false),
103        (506908387, true),
104        (507092576, false),
105        (507909534, true),
106        (507993459, false),
107        (508903628, true),
108        (509001819, false),
109        (509902333, true),
110        (509998524, false),
111        (510906592, true),
112        (511093691, false),
113        (511903057, true),
114        (511999019, false),
115        (512905544, true),
116        (512998127, false),
117        (513904291, true),
118        (513996323, false),
119        (514909090, true),
120        (515094873, false),
121        (515906002, true),
122        (515999869, false),
123        (516905713, true),
124        (517094858, false),
125        (517905143, true),
126        (518096078, false),
127        (518902241, true),
128        (519094998, false),
129        (519903930, true),
130        (519998402, false),
131        (520905710, true),
132        (520995714, false),
133        (521907100, true),
134        (522094065, false),
135        (522905204, true),
136        (523000056, false),
137        (523000091, false),
138        (523000103, true),
139        (523000116, false),
140        (523000129, false),
141        (523904895, true),
142        (523995464, false),
143        (524906217, true),
144        (525000486, false),
145        (525904862, true),
146        (526094321, false),
147        (526905690, true),
148        (527090263, false),
149        (527911351, true),
150        (527994518, false),
151        (528903925, true),
152        (529093867, false),
153        (529903335, true),
154        (530092889, false),
155        (530902052, true),
156        (530994385, false),
157        (531904428, true),
158        (531995603, false),
159        (532904460, true),
160        (532997952, false),
161        (533908377, true),
162        (533994459, false),
163        (534908716, true),
164        (535095720, false),
165        (535906164, true),
166        (536192900, false),
167        (536903709, true),
168        (537192272, false),
169        (537907007, true),
170        (538192799, false),
171        (538910068, true),
172        (539095963, false),
173        (539906169, true),
174        (540094776, false),
175        (540905086, true),
176        (540996129, false),
177        (541903768, true),
178        (542391315, false),
179        (542903986, true),
180        (542993789, false),
181        (543902386, true),
182        (543996392, false),
183    ];
184
185    let mut msf = MSFUtils::default();
186    let mut old_time = SAMPLES[0].0;
187    let mut old_second = 0xff;
188    for s in SAMPLES {
189        msf.handle_new_edge(s.1, s.0);
190        if s.1 {
191            println!(
192                "{}{} {:?} {:?} {} {}",
193                if msf.get_second() == old_second {
194                    "* "
195                } else {
196                    ""
197                },
198                msf.get_second(),
199                msf.get_current_bit_a(),
200                msf.get_current_bit_b(),
201                msf.is_new_minute(),
202                msf.is_past_new_minute(),
203            );
204            old_second = msf.get_second();
205            if (s.0 - old_time > msf.get_spike_limit()) && !msf.increase_second() {
206                println!(
207                    "Bad increase_second at second {}->{}",
208                    old_second,
209                    msf.get_second()
210                );
211            }
212        } else if msf.is_new_minute() {
213            // This happens _before_ the above two println!() in time, because
214            // handle_new_edge() just found the 0111_1110 bit train at the high-to-low edge.
215            println!("New minute! Time to decode!");
216            msf.decode_time(true, true);
217            let rdt = msf.get_radio_datetime();
218            println!("DUT1={:?}", rdt.get_dut1());
219            println!(
220                "Parities={:?} {:?} {:?} {:?}",
221                msf.get_parity_1(),
222                msf.get_parity_2(),
223                msf.get_parity_3(),
224                msf.get_parity_4()
225            );
226            println!(
227                "Date/time={:?}-{:?}-{:?} {:?}:{:?} {} {}",
228                rdt.get_year(),
229                rdt.get_month(),
230                rdt.get_day(),
231                rdt.get_hour(),
232                rdt.get_minute(),
233                str_weekday(rdt.get_weekday()),
234                parse_dst(rdt.get_dst())
235            );
236        }
237        old_time = s.0;
238    }
239}

Trait Implementations§

Source§

impl Debug for MSFUtils

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MSFUtils

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.