use super::lib::*;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgOdometry {
#[cfg_attr(feature = "serde", serde(skip_serializing))]
pub sender_id: Option<u16>,
#[cfg_attr(feature = "serde", serde(rename(serialize = "tow")))]
pub tow: u32,
#[cfg_attr(feature = "serde", serde(rename(serialize = "velocity")))]
pub velocity: i32,
#[cfg_attr(feature = "serde", serde(rename(serialize = "flags")))]
pub flags: u8,
}
impl ConcreteMessage for MsgOdometry {
const MESSAGE_TYPE: u16 = 2307;
const MESSAGE_NAME: &'static str = "MSG_ODOMETRY";
}
impl SbpMessage for MsgOdometry {
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;
let gps_time = match time::GpsTime::new(0, tow_s) {
Ok(gps_time) => gps_time.tow(),
Err(e) => return Some(Err(e.into())),
};
Some(Ok(time::MessageTime::Rover(gps_time.into())))
}
}
impl TryFrom<Sbp> for MsgOdometry {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgOdometry(m) => Ok(m),
_ => Err(TryFromSbpError),
}
}
}
impl WireFormat for MsgOdometry {
const MIN_LEN: usize =
<u32 as WireFormat>::MIN_LEN + <i32 as WireFormat>::MIN_LEN + <u8 as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.tow) + WireFormat::len(&self.velocity) + WireFormat::len(&self.flags)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.tow, buf);
WireFormat::write(&self.velocity, buf);
WireFormat::write(&self.flags, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgOdometry {
sender_id: None,
tow: WireFormat::parse_unchecked(buf),
velocity: WireFormat::parse_unchecked(buf),
flags: WireFormat::parse_unchecked(buf),
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgWheeltick {
#[cfg_attr(feature = "serde", serde(skip_serializing))]
pub sender_id: Option<u16>,
#[cfg_attr(feature = "serde", serde(rename(serialize = "time")))]
pub time: u64,
#[cfg_attr(feature = "serde", serde(rename(serialize = "flags")))]
pub flags: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "source")))]
pub source: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "ticks")))]
pub ticks: i32,
}
impl ConcreteMessage for MsgWheeltick {
const MESSAGE_TYPE: u16 = 2308;
const MESSAGE_NAME: &'static str = "MSG_WHEELTICK";
}
impl SbpMessage for MsgWheeltick {
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>> {
if self.flags != 1 {
return None;
}
let tow_s = (self.time as f64) / 1000000.0;
let gps_time = match time::GpsTime::new(0, tow_s) {
Ok(gps_time) => gps_time.tow(),
Err(e) => return Some(Err(e.into())),
};
Some(Ok(time::MessageTime::Rover(gps_time.into())))
}
}
impl TryFrom<Sbp> for MsgWheeltick {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgWheeltick(m) => Ok(m),
_ => Err(TryFromSbpError),
}
}
}
impl WireFormat for MsgWheeltick {
const MIN_LEN: usize = <u64 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <i32 as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.time)
+ WireFormat::len(&self.flags)
+ WireFormat::len(&self.source)
+ WireFormat::len(&self.ticks)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.time, buf);
WireFormat::write(&self.flags, buf);
WireFormat::write(&self.source, buf);
WireFormat::write(&self.ticks, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgWheeltick {
sender_id: None,
time: WireFormat::parse_unchecked(buf),
flags: WireFormat::parse_unchecked(buf),
source: WireFormat::parse_unchecked(buf),
ticks: WireFormat::parse_unchecked(buf),
}
}
}