pub use msg_ext_event::MsgExtEvent;
pub mod msg_ext_event {
#![allow(unused_imports)]
use super::*;
use crate::messages::lib::*;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, PartialEq, Clone)]
pub struct MsgExtEvent {
#[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
pub sender_id: Option<u16>,
#[cfg_attr(feature = "serde", serde(rename = "wn"))]
pub wn: u16,
#[cfg_attr(feature = "serde", serde(rename = "tow"))]
pub tow: u32,
#[cfg_attr(feature = "serde", serde(rename = "ns_residual"))]
pub ns_residual: i32,
#[cfg_attr(feature = "serde", serde(rename = "flags"))]
pub flags: u8,
#[cfg_attr(feature = "serde", serde(rename = "pin"))]
pub pin: u8,
}
impl MsgExtEvent {
pub fn time_quality(&self) -> Result<TimeQuality, u8> {
get_bit_range!(self.flags, u8, u8, 1, 1).try_into()
}
pub fn set_time_quality(&mut self, time_quality: TimeQuality) {
set_bit_range!(&mut self.flags, time_quality, u8, u8, 1, 1);
}
pub fn new_level_of_pin(&self) -> Result<NewLevelOfPin, u8> {
get_bit_range!(self.flags, u8, u8, 0, 0).try_into()
}
pub fn set_new_level_of_pin(&mut self, new_level_of_pin: NewLevelOfPin) {
set_bit_range!(&mut self.flags, new_level_of_pin, u8, u8, 0, 0);
}
}
impl ConcreteMessage for MsgExtEvent {
const MESSAGE_TYPE: u16 = 257;
const MESSAGE_NAME: &'static str = "MSG_EXT_EVENT";
}
impl SbpMessage for MsgExtEvent {
fn message_name(&self) -> &'static str {
<Self as ConcreteMessage>::MESSAGE_NAME
}
fn message_type(&self) -> u16 {
<Self as ConcreteMessage>::MESSAGE_TYPE
}
fn sender_id(&self) -> Option<u16> {
self.sender_id
}
fn set_sender_id(&mut self, new_id: u16) {
self.sender_id = Some(new_id);
}
fn encoded_len(&self) -> usize {
WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
}
#[cfg(feature = "swiftnav")]
fn gps_time(&self) -> Option<std::result::Result<time::MessageTime, time::GpsTimeError>> {
let tow_s = (self.tow as f64) / 1000.0;
#[allow(clippy::useless_conversion)]
let wn: i16 = match self.wn.try_into() {
Ok(wn) => wn,
Err(e) => return Some(Err(e.into())),
};
let gps_time = match time::GpsTime::new(wn, tow_s) {
Ok(gps_time) => gps_time,
Err(e) => return Some(Err(e.into())),
};
Some(Ok(time::MessageTime::Rover(gps_time.into())))
}
}
impl FriendlyName for MsgExtEvent {
fn friendly_name() -> &'static str {
"EXT EVENT"
}
}
impl TryFrom<Sbp> for MsgExtEvent {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgExtEvent(m) => Ok(m),
_ => Err(TryFromSbpError(msg)),
}
}
}
impl WireFormat for MsgExtEvent {
const MIN_LEN: usize = <u16 as WireFormat>::MIN_LEN
+ <u32 as WireFormat>::MIN_LEN
+ <i32 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.wn)
+ WireFormat::len(&self.tow)
+ WireFormat::len(&self.ns_residual)
+ WireFormat::len(&self.flags)
+ WireFormat::len(&self.pin)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.wn, buf);
WireFormat::write(&self.tow, buf);
WireFormat::write(&self.ns_residual, buf);
WireFormat::write(&self.flags, buf);
WireFormat::write(&self.pin, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgExtEvent {
sender_id: None,
wn: WireFormat::parse_unchecked(buf),
tow: WireFormat::parse_unchecked(buf),
ns_residual: WireFormat::parse_unchecked(buf),
flags: WireFormat::parse_unchecked(buf),
pin: WireFormat::parse_unchecked(buf),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TimeQuality {
UnknownDontHaveNavSolution = 0,
Good = 1,
}
impl std::fmt::Display for TimeQuality {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TimeQuality::UnknownDontHaveNavSolution => {
f.write_str("Unknown - don't have nav solution")
}
TimeQuality::Good => f.write_str("Good (< 1 microsecond)"),
}
}
}
impl TryFrom<u8> for TimeQuality {
type Error = u8;
fn try_from(i: u8) -> Result<Self, u8> {
match i {
0 => Ok(TimeQuality::UnknownDontHaveNavSolution),
1 => Ok(TimeQuality::Good),
i => Err(i),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NewLevelOfPin {
Low = 0,
High = 1,
}
impl std::fmt::Display for NewLevelOfPin {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
NewLevelOfPin::Low => f.write_str("Low (falling edge)"),
NewLevelOfPin::High => f.write_str("High (rising edge)"),
}
}
}
impl TryFrom<u8> for NewLevelOfPin {
type Error = u8;
fn try_from(i: u8) -> Result<Self, u8> {
match i {
0 => Ok(NewLevelOfPin::Low),
1 => Ok(NewLevelOfPin::High),
i => Err(i),
}
}
}
}