From 8beead95e6e5c521025359b3af59b21c35a1e8cf Mon Sep 17 00:00:00 2001 From: "Evgeniy A. Dushistov" Date: Mon, 17 Sep 2018 22:16:59 +0300 Subject: [PATCH] fix: Debug impl for Nmea call it self comment #2 --- src/lib.rs | 8 +------- tests/file_log_parser.rs | 19 +++++++++++++++++++ tests/nmea2.log | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 tests/nmea2.log diff --git a/src/lib.rs b/src/lib.rs index d462246..7635135 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ use chrono::{NaiveDate, NaiveTime}; pub use parse::{parse, GgaData, GsaData, GsvData, ParseResult, RmcData, RmcStatusOfFix, VtgData}; /// NMEA parser -#[derive(Default)] +#[derive(Default, Debug)] pub struct Nmea { pub fix_time: Option, pub fix_date: Option, @@ -359,12 +359,6 @@ impl<'a> Nmea { } } -impl fmt::Debug for Nmea { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}", self) - } -} - impl fmt::Display for Nmea { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( diff --git a/tests/file_log_parser.rs b/tests/file_log_parser.rs index 1183084..00f50b7 100644 --- a/tests/file_log_parser.rs +++ b/tests/file_log_parser.rs @@ -37,3 +37,22 @@ fn test_parse_file_log() { .collect(); assert_eq!(expected, res); } + +#[test] +fn test_parse_issue_2() { + let mut input = BufReader::new(File::open(&Path::new("tests").join("nmea2.log")).unwrap()); + let mut nmea = nmea::Nmea::new(); + for _ in 0..100 { + let mut buffer = String::new(); + let size = input.read_line(&mut buffer).unwrap(); + eprintln!("buffer = {:?}", buffer); + if size > 0 { + if buffer.as_bytes()[0] == b'$' { + let _ = nmea.parse(&buffer); + println!("{:?}", nmea); + } + } else { + break; + } + } +} diff --git a/tests/nmea2.log b/tests/nmea2.log new file mode 100644 index 0000000..efa313e --- /dev/null +++ b/tests/nmea2.log @@ -0,0 +1,37 @@ +$GNVTG,,,,,,,,,N*2E +$GNGNS,181604.00,,,,,NN,00,99.99,,,,*59 +$GNGGA,181604.00,,,,,0,00,99.99,,,,,,*72 +$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E +$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E +$GPGSV,4,1,13,02,35,291,,03,09,129,,05,14,305,,06,38,226,*7D +$GPGSV,4,2,13,07,56,177,,09,70,067,,16,20,055,,23,41,076,*77 +$GPGSV,4,3,13,26,10,030,,29,05,341,,30,26,199,,36,30,158,*7E +$GPGSV,4,4,13,49,32,192,*4D +$GLGSV,3,1,10,66,45,091,,67,67,334,,68,17,297,,75,13,025,*68 +$GLGSV,3,2,10,76,49,059,,77,40,156,,78,00,183,,82,15,246,*68 +$GLGSV,3,3,10,83,28,298,,84,10,352,*6F +$GNGLL,,,,,181604.00,V,N*5E +$GNGRS,181604.00,1,,,,,,,,,,,,*5A +$GNGRS,181604.00,1,,,,,,,,,,,,*5A +$GNGST,181604.00,0.0000,,,,5773795,5773795,5773794*4F +$GNZDA,181604.00,12,09,2018,00,00*73 +$GNGBS,181604.00,,,,,,,*7B +$GNTXT,01,01,02,u-blox AG - www.u-blox.com*4E +$GNTXT,01,01,02,HW UBX-M8030 00080000*60 +$GNTXT,01,01,02,EXT CORE 3.01 (107900)*33 +$GNTXT,01,01,02,ROM BASE 3.01 (107888)*25 +$GNTXT,01,01,02,FWVER=SPG 3.01*46 +$GNTXT,01,01,02,PROTVER=18.00*11 +$GNTXT,01,01,02,MOD=NEO-M8N-0*67 +$GNTXT,01,01,02,FIS=0xC22536 (100111)*28 +$GNTXT,01,01,02,GPS;GLO;GAL;BDS*77 +$GNTXT,01,01,02,SBAS;IMES;QZSS*49 +$GNTXT,01,01,02,GNSS OTP=GPS;GLO*37 +$GNTXT,01,01,02,LLC=FFFFFFFF-FFFFFFED-FFFFFFFF-FFFFFFFF-FFFFFF69*23 +$GNTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*3E +$GNTXT,01,01,02,ANTSTATUS=OK*25 +$GNTXT,01,01,02,PF=3FF*4B +$GNVTG,,,,,,,,,N*2E +$GNGNS,181605.00,,,,,NN,00,99.99,,,,*58 +$GNGGA,181605.00,,,,,0,00,99.99,,,,,,*73 +