canboat_rs/pgns/
simnet_event_reply_ap_command.rs

1use crate::nmea_option::NmeaOption;
2use crate::pgn_types::PgnType;
3pub const LENGTH: usize = 12usize;
4pub const PGN: u32 = 130851u32;
5#[derive(Debug)]
6pub enum Event {
7    Standby,
8    Automode,
9    Navmode,
10    NonFollowUpmode,
11    FollowUpmode,
12    Windmode,
13    SquareTurn,
14    CNegativeTurn,
15    UNegativeTurn,
16    SpiralTurn,
17    ZigZagTurn,
18    LazyNegativeSTurn,
19    DepthTurn,
20    Changecourse,
21    Timersync,
22    Pingportend,
23    Pingstarboardend,
24}
25impl bitfield::Into<u8> for Event {
26    fn into(self) -> u8 {
27        match self {
28            Self::Standby => 6u8,
29            Self::Automode => 9u8,
30            Self::Navmode => 10u8,
31            Self::NonFollowUpmode => 13u8,
32            Self::FollowUpmode => 14u8,
33            Self::Windmode => 15u8,
34            Self::SquareTurn => 18u8,
35            Self::CNegativeTurn => 19u8,
36            Self::UNegativeTurn => 20u8,
37            Self::SpiralTurn => 21u8,
38            Self::ZigZagTurn => 22u8,
39            Self::LazyNegativeSTurn => 23u8,
40            Self::DepthTurn => 24u8,
41            Self::Changecourse => 26u8,
42            Self::Timersync => 61u8,
43            Self::Pingportend => 112u8,
44            Self::Pingstarboardend => 113u8,
45        }
46    }
47}
48impl bitfield::Into<NmeaOption<Event>> for u8 {
49    fn into(self) -> NmeaOption<Event> {
50        match self {
51            6u8 => NmeaOption::Some(Event::Standby),
52            9u8 => NmeaOption::Some(Event::Automode),
53            10u8 => NmeaOption::Some(Event::Navmode),
54            13u8 => NmeaOption::Some(Event::NonFollowUpmode),
55            14u8 => NmeaOption::Some(Event::FollowUpmode),
56            15u8 => NmeaOption::Some(Event::Windmode),
57            18u8 => NmeaOption::Some(Event::SquareTurn),
58            19u8 => NmeaOption::Some(Event::CNegativeTurn),
59            20u8 => NmeaOption::Some(Event::UNegativeTurn),
60            21u8 => NmeaOption::Some(Event::SpiralTurn),
61            22u8 => NmeaOption::Some(Event::ZigZagTurn),
62            23u8 => NmeaOption::Some(Event::LazyNegativeSTurn),
63            24u8 => NmeaOption::Some(Event::DepthTurn),
64            26u8 => NmeaOption::Some(Event::Changecourse),
65            61u8 => NmeaOption::Some(Event::Timersync),
66            112u8 => NmeaOption::Some(Event::Pingportend),
67            113u8 => NmeaOption::Some(Event::Pingstarboardend),
68            _ => NmeaOption::None,
69        }
70    }
71}
72#[derive(Debug)]
73pub enum Direction {
74    Port,
75    Starboard,
76    Leftrudderport,
77    Rightrudderstarboard,
78}
79impl bitfield::Into<u8> for Direction {
80    fn into(self) -> u8 {
81        match self {
82            Self::Port => 2u8,
83            Self::Starboard => 3u8,
84            Self::Leftrudderport => 4u8,
85            Self::Rightrudderstarboard => 5u8,
86        }
87    }
88}
89impl bitfield::Into<NmeaOption<Direction>> for u8 {
90    fn into(self) -> NmeaOption<Direction> {
91        match self {
92            2u8 => NmeaOption::Some(Direction::Port),
93            3u8 => NmeaOption::Some(Direction::Starboard),
94            4u8 => NmeaOption::Some(Direction::Leftrudderport),
95            5u8 => NmeaOption::Some(Direction::Rightrudderstarboard),
96            _ => NmeaOption::None,
97        }
98    }
99}
100use bitfield::bitfield;
101bitfield! {
102    #[doc = "Simnet: Event Reply: AP command"] pub struct
103    SimnetEventReplyApCommand([u8]); impl Debug; u32; pub manufacturer_code, _ : 10usize,
104    0usize; pub reserved, _ : 12usize, 11usize; pub industry_code, _ : 15usize, 13usize;
105    pub proprietary_id, _ : 23usize, 16usize; pub b, _ : 39usize, 24usize; pub address, _
106    : 47usize, 40usize; pub u8, from into NmeaOption < Event >, event, _ : 55usize,
107    48usize; pub c, _ : 63usize, 56usize; pub u8, from into NmeaOption < Direction >,
108    direction, _ : 71usize, 64usize; pub angle, _ : 87usize, 72usize; pub g, _ : 95usize,
109    88usize;
110}
111impl SimnetEventReplyApCommand<&[u8]> {
112    pub fn is_match(&self, pgn: u32) -> bool {
113        130851u32 == pgn && self.manufacturer_code() == 1857u32
114            && self.industry_code() == 4u32 && self.proprietary_id() == 2u32
115    }
116    pub fn get_pgn() -> u32 {
117        130851u32
118    }
119    pub fn get_message_type() -> PgnType {
120        PgnType::Fast
121    }
122}