nmea0183/
satellite.rs

1//! Structures that describe satellites in views .
2
3use crate::common;
4
5///Information about satellite in view.
6#[derive(Debug, PartialEq, Clone, Default)]
7pub struct Satellite {
8    /// Satellite pseudo-random noise number.
9    pub prn: u16,
10    /// Angle of elevation of the satellite above the horizontal plane in degrees, 90° maximum.
11    pub elevation: u8,
12    /// Degrees from True North, 000° through 359°
13    pub azimuth: u16,
14    /// Signal-to-Noise Ratio . 00 through 99 dB (null when not tracking) .
15    pub snr: Option<u8>,
16}
17
18impl Satellite {
19    pub(crate) fn parse<'a>(
20        fields: &mut core::str::Split<'a, char>,
21    ) -> Result<Option<Self>, &'static str> {
22        let prn = common::parse_u16(fields.next())?;
23        let elevation = common::parse_u8(fields.next())?;
24        let azimuth = common::parse_u16(fields.next())?;
25        let snr = common::parse_u8(fields.next())?;
26
27        if let (Some(prn), Some(elevation), Some(azimuth)) = (prn, elevation, azimuth) {
28            Ok(Some(Self {
29                prn,
30                elevation,
31                azimuth,
32                snr,
33            }))
34        } else {
35            Ok(None)
36        }
37    }
38}