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
extern crate chrono;
extern crate nom;
pub use crate::error::Error;
pub mod error;
pub mod fields;
pub mod messages;
mod parser_utils;
pub mod sentence;
pub use sentence::*;
pub fn parse(input: &str) -> Result<Sentence, Error> {
let parse_result = parse_sentence(input)?;
Ok(parse_result.1)
}
#[cfg(test)]
mod talker_tests {
use super::*;
use fields::identity::*;
use fields::parameter::*;
use fields::speed::*;
#[test]
fn test_parse_valid() {
let input = "$GPVTG,77.52,T,,M,0.004,N,0.008,K,A*06\r\n";
let expected_sentence = Sentence {
sentence_type: SentenceType::Parametric,
talker: Talker::GPS,
message: Message::VTG(messages::VTGMessage {
cogt: Some(77.52),
cogt_unit: Some(CourseOverGroundUnit::DegreesTrue),
cogm: None,
cogm_unit: Some(CourseOverGroundUnit::DegreesMagnetic),
sogn: Some(0.004),
sogn_unit: Some(SpeedOverGroundUnit::Knots),
sogk: Some(0.008),
sogk_unit: Some(SpeedOverGroundUnit::KilometersPerHour),
pos_mode: Fix::AutonomousGNSSFix,
}),
};
assert_eq!(expected_sentence, parse(input).unwrap());
}
#[test]
fn test_parse_missing_crlf() {
let input = "$GPVTG,77.52,T,,M,0.004,N,0.008,K,A*06";
let expected_error = Err(Error::ParseError(nom::Err::Error((
"06",
nom::error::ErrorKind::TakeUntil,
))));
assert_eq!(expected_error, parse(input));
}
}