use super::lib::*;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgImuAux {
#[cfg_attr(feature = "serde", serde(skip_serializing))]
pub sender_id: Option<u16>,
#[cfg_attr(feature = "serde", serde(rename(serialize = "imu_type")))]
pub imu_type: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "temp")))]
pub temp: i16,
#[cfg_attr(feature = "serde", serde(rename(serialize = "imu_conf")))]
pub imu_conf: u8,
}
impl ConcreteMessage for MsgImuAux {
const MESSAGE_TYPE: u16 = 2305;
const MESSAGE_NAME: &'static str = "MSG_IMU_AUX";
}
impl SbpMessage for MsgImuAux {
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
}
}
impl TryFrom<Sbp> for MsgImuAux {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgImuAux(m) => Ok(m),
_ => Err(TryFromSbpError),
}
}
}
impl WireFormat for MsgImuAux {
const MIN_LEN: usize =
<u8 as WireFormat>::MIN_LEN + <i16 as WireFormat>::MIN_LEN + <u8 as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.imu_type)
+ WireFormat::len(&self.temp)
+ WireFormat::len(&self.imu_conf)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.imu_type, buf);
WireFormat::write(&self.temp, buf);
WireFormat::write(&self.imu_conf, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgImuAux {
sender_id: None,
imu_type: WireFormat::parse_unchecked(buf),
temp: WireFormat::parse_unchecked(buf),
imu_conf: WireFormat::parse_unchecked(buf),
}
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Clone)]
pub struct MsgImuRaw {
#[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 = "tow_f")))]
pub tow_f: u8,
#[cfg_attr(feature = "serde", serde(rename(serialize = "acc_x")))]
pub acc_x: i16,
#[cfg_attr(feature = "serde", serde(rename(serialize = "acc_y")))]
pub acc_y: i16,
#[cfg_attr(feature = "serde", serde(rename(serialize = "acc_z")))]
pub acc_z: i16,
#[cfg_attr(feature = "serde", serde(rename(serialize = "gyr_x")))]
pub gyr_x: i16,
#[cfg_attr(feature = "serde", serde(rename(serialize = "gyr_y")))]
pub gyr_y: i16,
#[cfg_attr(feature = "serde", serde(rename(serialize = "gyr_z")))]
pub gyr_z: i16,
}
impl ConcreteMessage for MsgImuRaw {
const MESSAGE_TYPE: u16 = 2304;
const MESSAGE_NAME: &'static str = "MSG_IMU_RAW";
}
impl SbpMessage for MsgImuRaw {
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>> {
const IMU_RAW_TIME_STATUS_MASK: u32 = (1 << 30) | (1 << 31);
if self.tow & IMU_RAW_TIME_STATUS_MASK != 0 {
return None;
}
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 MsgImuRaw {
type Error = TryFromSbpError;
fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
match msg {
Sbp::MsgImuRaw(m) => Ok(m),
_ => Err(TryFromSbpError),
}
}
}
impl WireFormat for MsgImuRaw {
const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN
+ <u8 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN
+ <i16 as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.tow)
+ WireFormat::len(&self.tow_f)
+ WireFormat::len(&self.acc_x)
+ WireFormat::len(&self.acc_y)
+ WireFormat::len(&self.acc_z)
+ WireFormat::len(&self.gyr_x)
+ WireFormat::len(&self.gyr_y)
+ WireFormat::len(&self.gyr_z)
}
fn write<B: BufMut>(&self, buf: &mut B) {
WireFormat::write(&self.tow, buf);
WireFormat::write(&self.tow_f, buf);
WireFormat::write(&self.acc_x, buf);
WireFormat::write(&self.acc_y, buf);
WireFormat::write(&self.acc_z, buf);
WireFormat::write(&self.gyr_x, buf);
WireFormat::write(&self.gyr_y, buf);
WireFormat::write(&self.gyr_z, buf);
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
MsgImuRaw {
sender_id: None,
tow: WireFormat::parse_unchecked(buf),
tow_f: WireFormat::parse_unchecked(buf),
acc_x: WireFormat::parse_unchecked(buf),
acc_y: WireFormat::parse_unchecked(buf),
acc_z: WireFormat::parse_unchecked(buf),
gyr_x: WireFormat::parse_unchecked(buf),
gyr_y: WireFormat::parse_unchecked(buf),
gyr_z: WireFormat::parse_unchecked(buf),
}
}
}