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