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
use crate::{ddm::{DdmLatitude, DdmLongitude}, errors::PackError, stack_str::PackArrayString};

/// Represents the global position of an APRS packet
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
pub struct AprsPosition {
    longitude: DdmLongitude,
    latitude: DdmLatitude,
}

impl AprsPosition {
    pub fn new(latitude: DdmLatitude, longitude: DdmLongitude) -> Self {
        Self {
            longitude,
            latitude,
        }
    }


}

impl PackArrayString for AprsPosition {
    fn pack_into<const SIZE: usize>(
        &self,
        s: &mut arrayvec::ArrayString<SIZE>,
    ) -> Result<(), PackError> {
        
        // pack data
        self.latitude.pack_into(s)?;
        s.try_push('/')?;
        self.longitude.pack_into(s)?;
        
        Ok(())
    }
}

#[cfg(test)]
mod tests {

    use arrayvec::ArrayString;

    use super::*;

    #[test]
    fn test_position_packing() {

        // Build a buffer
        let mut buffer = ArrayString::<128>::new();

        // Add the packet
        let data = AprsPosition {
            latitude: 42.981312.into(),
            longitude: (-81.257472).into()
        };

        // Pack
        data.pack_into(&mut buffer).unwrap();

        assert_eq!(*buffer, *"4258.87N/08115.44W");

    }
}