vehicle_signals/
lib.rs

1#![doc = include_str!("../README.md")]
2
3
4
5pub mod units;
6/// This is version 2 of the Vehicle Signal Interface.
7/// The major number of the interface is part of the module path.
8pub mod v3 {
9    // Check project root for LICENCE
10    use serde_derive::{Deserialize, Serialize};
11    pub use crate::units;
12    use chrono::{Utc, Timelike};
13
14    #[repr(C)]
15    #[derive(Serialize, Deserialize, PartialEq, Clone)]
16    /// The side of the vehicle an attribute or signal is related to.
17    /// This type is used as a key inside topics.
18    pub enum Side {
19        Left = 1,
20        Right = 2,
21    }
22
23    impl Default for Side {
24        fn default() -> Self {
25            Side::Right
26        }
27    }
28
29    #[repr(C)]
30    #[derive(Serialize, Deserialize, PartialEq, Clone)]
31    /// Front or Rear of the vehicle
32    /// This type is used as a key inside topics.
33    pub enum Position {
34        Front = 1,
35        Rear = 2,
36    }
37
38    impl Default for Position {
39        fn default() -> Self {
40            Position::Front
41        }
42    }
43
44    /// A global IEEE 1588/802.1AS timestamp is 80 bits in total, divided into two parts
45    #[repr(C)]
46    #[derive(Serialize, Deserialize, PartialEq, Clone)]
47    pub struct Timestamp {
48        ///seconds since epoch
49        pub sec: u64,
50        /// nanoseconds
51        pub nsec: u32,
52    }
53
54    impl Default for Timestamp {
55        fn default() -> Self {
56            let now = Utc::now();
57            Self { sec: now.timestamp() as u64, nsec: now.timestamp_subsec_nanos() }
58        }
59    }
60
61    include!("bindings.rs");
62}
63
64#[cfg(test)]
65mod tests {
66    #[test]
67    fn it_works() {
68        assert_eq!(2 + 2, 4);
69    }
70}