yanp/parsers/
gsv.rs

1use super::utils::*;
2use crate::errors::NmeaSentenceError;
3use crate::parse::*;
4use nom::alt;
5
6named!(parse_gsv_sat<GsvSatellite>,
7    map_res!(
8        do_parse!(
9            sat_id: opt!(map_res!(take_until!(","), parse_num::<u8>)) >>
10            char!(',') >>
11            elevation: opt!(map_res!(take_until!(","), parse_num::<f32>)) >>
12            char!(',') >>
13            true_azimuth: opt!(map_res!(take_until!(","), parse_num::<f32>)) >>
14            char!(',') >>
15            snr: opt!(alt!(map_res!(take_until!(","), parse_num::<u8>) | map_res!(take_until!(","), parse_num::<u8>))) >>
16            one_of!(",*") >>
17            (sat_id, elevation, true_azimuth, snr)
18        ),
19        |sentence: (Option<u8>, Option<f32>, Option<f32>, Option<u8>)| -> Result<GsvSatellite, NmeaSentenceError> {
20            Ok(GsvSatellite {
21                sat_id: sentence.0,
22                elevation: sentence.1,
23                true_azimuth: sentence.2,
24                snr: sentence.3,
25            })
26        }
27    )
28);
29
30fn build_gsv<'a>(
31    sentence: (
32        Option<u16>,
33        Option<u16>,
34        Option<u8>,
35        Option<GsvSatellite>,
36        Option<GsvSatellite>,
37        Option<GsvSatellite>,
38        Option<GsvSatellite>,
39    ),
40) -> Result<GsvData, NmeaSentenceError<'a>> {
41    Ok(GsvData {
42        number_of_sentences: sentence.0,
43        sentence_num: sentence.1,
44        sats_in_view: sentence.2,
45        sats_info: [sentence.3, sentence.4, sentence.5, sentence.6],
46    })
47}
48
49named!(pub (crate) parse_gsv<GsvData>,
50    map_res!(
51        do_parse!(
52            number_of_sentences: opt!(map_res!(take_until!(","), parse_num::<u16>)) >>
53            char!(',') >>
54            sentence_num: opt!(map_res!(take_until!(","), parse_num::<u16>)) >>
55            char!(',') >>
56            sats_in_view: opt!(map_res!(take_until!(","), parse_num::<u8>)) >>
57            char!(',') >>
58            sat1_info: opt!(complete!(parse_gsv_sat)) >>
59            sat2_info: opt!(complete!(parse_gsv_sat)) >>
60            sat3_info: opt!(complete!(parse_gsv_sat)) >>
61            sat4_info: opt!(complete!(parse_gsv_sat)) >>
62            (number_of_sentences, sentence_num, sats_in_view, sat1_info, sat2_info, sat3_info, sat4_info)
63        ),
64        build_gsv
65    )
66);