canboat_rs/pgns/
alert_configuration.rs1use crate::nmea_option::NmeaOption;
2use crate::pgn_types::PgnType;
3pub const LENGTH: usize = 20usize;
4pub const PGN: u32 = 126986u32;
5#[derive(Debug)]
6pub enum AlertType {
7 EmergencyAlarm,
8 Alarm,
9 Warning,
10 Caution,
11}
12impl bitfield::Into<u8> for AlertType {
13 fn into(self) -> u8 {
14 match self {
15 Self::EmergencyAlarm => 1u8,
16 Self::Alarm => 2u8,
17 Self::Warning => 5u8,
18 Self::Caution => 8u8,
19 }
20 }
21}
22impl bitfield::Into<NmeaOption<AlertType>> for u8 {
23 fn into(self) -> NmeaOption<AlertType> {
24 match self {
25 1u8 => NmeaOption::Some(AlertType::EmergencyAlarm),
26 2u8 => NmeaOption::Some(AlertType::Alarm),
27 5u8 => NmeaOption::Some(AlertType::Warning),
28 8u8 => NmeaOption::Some(AlertType::Caution),
29 _ => NmeaOption::None,
30 }
31 }
32}
33#[derive(Debug)]
34pub enum AlertCategory {
35 Navigational,
36 Technical,
37}
38impl bitfield::Into<u8> for AlertCategory {
39 fn into(self) -> u8 {
40 match self {
41 Self::Navigational => 0u8,
42 Self::Technical => 1u8,
43 }
44 }
45}
46impl bitfield::Into<NmeaOption<AlertCategory>> for u8 {
47 fn into(self) -> NmeaOption<AlertCategory> {
48 match self {
49 0u8 => NmeaOption::Some(AlertCategory::Navigational),
50 1u8 => NmeaOption::Some(AlertCategory::Technical),
51 _ => NmeaOption::None,
52 }
53 }
54}
55use bitfield::bitfield;
56bitfield! {
57 #[doc = "Alert Configuration"] pub struct AlertConfiguration([u8]); impl Debug; u32;
58 pub u8, from into NmeaOption < AlertType >, alert_type, _ : 3usize, 0usize; pub u8,
59 from into NmeaOption < AlertCategory >, alert_category, _ : 7usize, 4usize; pub
60 alert_system, _ : 15usize, 8usize; pub alert_sub_system, _ : 23usize, 16usize; pub
61 alert_id, _ : 39usize, 24usize; pub data_source_network_id_name, _ : 103usize,
62 40usize; pub data_source_instance, _ : 111usize, 104usize; pub
63 data_source_index_source, _ : 119usize, 112usize; pub alert_occurrence_number, _ :
64 127usize, 120usize; pub alert_control, _ : 129usize, 128usize; pub
65 user_defined_alert_assignment, _ : 131usize, 130usize; pub reserved, _ : 135usize,
66 132usize; pub reactivation_period, _ : 143usize, 136usize; pub
67 temporary_silence_period, _ : 151usize, 144usize; pub escalation_period, _ :
68 159usize, 152usize;
69}
70impl AlertConfiguration<&[u8]> {
71 pub fn is_match(&self, pgn: u32) -> bool {
72 126986u32 == pgn
73 }
74 pub fn get_pgn() -> u32 {
75 126986u32
76 }
77 pub fn get_message_type() -> PgnType {
78 PgnType::Fast
79 }
80}