libexail 0.1.0

A rust library for communicating with Exail devices through their binary protocol
Documentation
//! Extended navigation data block structs (bits 0–7 of the extended nav bitmask).

use super::{block_enum, parse_blocks};
use crate::error::Result;
use binrw::BinRead;
use serde::Serialize;
use std::io::Cursor;

block_enum! {
    /// An extended navigation data block (bits 0–7 of the extended nav bitmask).
    pub enum ExtendedNavigationBlock {
        0 => RotationAccelerationVesselFrame(RotationAccelerationVesselFrame, 12),
        1 => RotationAccelerationStdDev(RotationAccelerationStdDev, 12),
        2 => RawRotationRateVesselFrame(RawRotationRateVesselFrame, 12),
        3 => VehicleAttitudeHeading(VehicleAttitudeHeading, 12),
        4 => VehicleAttitudeHeadingStdDev(VehicleAttitudeHeadingStdDev, 12),
        5 => VehiclePosition(VehiclePosition, 21),
        6 => VehiclePositionStdDev(VehiclePositionStdDev, 16),
        7 => SetAndDrift(SetAndDrift, 8),
    }
    read_fn();
}

/// Parse extended navigation blocks from the cursor given the bitmask.
pub fn parse_extended_navigation_blocks(
    bitmask: u32,
    cursor: &mut Cursor<&[u8]>,
) -> Result<Vec<ExtendedNavigationBlock>> {
    parse_blocks(bitmask, 8, |bit| {
        ExtendedNavigationBlock::read(bit, cursor).map(Some)
    })
}

/// Rotation accelerations in vessel frame (bit 0, 12 bytes).
/// Derivative of compensated rotation rates.
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct RotationAccelerationVesselFrame {
    /// In deg/s^2.
    pub xv1: f32,
    /// In deg/s^2.
    pub xv2: f32,
    /// In deg/s^2.
    pub xv3: f32,
}

/// Rotation acceleration standard deviation (bit 1, 12 bytes).
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct RotationAccelerationStdDev {
    /// In deg/s^2.
    pub xv1: f32,
    /// In deg/s^2.
    pub xv2: f32,
    /// In deg/s^2.
    pub xv3: f32,
}

/// Raw rotation rate in vessel frame, not compensated from Earth rotation (bit 2, 12 bytes).
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct RawRotationRateVesselFrame {
    /// In deg/s.
    pub xv1: f32,
    /// In deg/s.
    pub xv2: f32,
    /// In deg/s.
    pub xv3: f32,
}

/// Vehicle attitude and heading (bit 3, 12 bytes).
/// Available only when turret feature is activated.
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct VehicleAttitudeHeading {
    /// In degrees, inside [0, 360).
    pub heading: f32,
    /// In degrees, positive when right side up, inside [-180, 180).
    pub roll: f32,
    /// In degrees, positive when front down, inside [-90, 90].
    pub pitch: f32,
}

/// Vehicle attitude and heading standard deviation (bit 4, 12 bytes).
/// Available only when turret feature is activated.
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct VehicleAttitudeHeadingStdDev {
    /// In degrees, inside [0, 360).
    pub heading_std_dev: f32,
    /// In degrees, inside [0, 360).
    pub roll_std_dev: f32,
    /// In degrees, inside [0, 360).
    pub pitch_std_dev: f32,
}

/// Vehicle position in WGS84 at selected lever arm (bit 5, 21 bytes).
/// Available only when turret feature is activated.
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct VehiclePosition {
    /// In degrees, positive North, inside [-90, 90].
    pub latitude: f64,
    /// In degrees, increasing toward East, inside [0, 360).
    pub longitude: f64,
    /// 0: Geoid (Mean Sea Level), 1: Ellipsoid.
    pub altitude_reference: u8,
    /// In meters, positive up.
    pub altitude: f32,
}

/// Vehicle position standard deviation (bit 6, 16 bytes).
/// Available only when turret feature is activated.
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct VehiclePositionStdDev {
    /// In meters.
    pub north_std_dev: f32,
    /// In meters.
    pub east_std_dev: f32,
    /// Dimensionless.
    pub north_east_correlation: f32,
    /// In meters.
    pub altitude_std_dev: f32,
}

/// Set and drift in geographical frame (bit 7, 8 bytes).
/// Water current set and drift.
#[derive(Debug, Clone, BinRead, Serialize)]
#[brw(big)]
pub struct SetAndDrift {
    /// Direction of the current in degrees, inside [0, 360).
    pub set: f32,
    /// Amplitude of the current in m/s.
    pub drift: f32,
}