1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! MT(6) Raw Data Serial Out Packet Format
//!
//! **From firmware revision v1.88 the raw data output packet is supported.**
//!
//! Data provided from the MT-RX is in the following format:
//! - `MT6UUUNNNRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRYYYY`
//!
//! Where:
//! - `MT6` is fixed and actually “MT6”
//! - `UUU`- is a 3 character MT-RX configurable ID – by default this is “001”
//! - `NNN` -is a 3 decimal digit cycling packet sequence number from 000 to 511. This sequence number
//! increments after each new test or distress message is received. After 511 the sequence cycles to 000
//! and begins again.
//! - `RRR`.. is 36 characters of raw data in a hex format.
//! - `YYYY` – is a 4 character checksum (calculated from R – the first raw data character)
use crateParseError;
/// MT Raw Data Serial Out Packet Format.
/// Returns whether `message` is a valid MT(6) message.
///
/// ## Examples
/// ```
/// use wte_mt_rx_parser::mt_raw;
/// println!("is it MT6? {}", mt_raw::is_mt("MT6001001FFFE2FA00E0000CBAB959DB0903788C71B79F84B"));
/// ```
/// Tries to parse a "Raw Data Serial Out Packet Format" `message`.
///
/// ## Notes
/// - Checksum is not calculated here. Use [`compute_checksum`] if you require
/// it to be correct.
///
/// ## Examples
/// ```
/// use wte_mt_rx_parser::mt_raw;
/// let parsed = mt_raw::parse("MT6001001FFFE2FA00E0000CBAB959DB0903788C71B79F84B").unwrap();
/// println!("parsed: {:?}", parsed);
/// ```
///
/// ## Message format
/// Data provided should be in the following format:
/// - `MT6001001FFFE2FA00E0000CBAB959DB0903788C71B79F84B`
/// Calculate checksum of `data_source`.
///
/// ## Examples
/// ```
/// use wte_mt_rx_parser::mt_raw;
/// if mt_raw::compute_checksum("FFFE2FA00E0000CBAB959DB0903788C71B79".as_bytes()) == 0xf84b {
/// println!("valid checksum!");
/// } else {
/// println!("not a valid checksum!");
/// }
/// ```