icsneoc2 0.1002002.0-rc.4

High-level Rust interface for Intrepid Control Systems vehicle network adapters
Documentation
//! Bitflags types used across the crate.
//!
//! These [`bitflags`] wrappers provide type-safe, combinable flag sets
//! for open options, CAN message properties, and disk partition state.
//! Each type converts freely to/from the corresponding C integer typedef.

use crate::sys;

// ---------------------------------------------------------------------------
// OpenOptions — bitmask flags controlling device open behaviour
// ---------------------------------------------------------------------------
bitflags::bitflags! {
    /// Options passed to [`Device::open`](crate::Device::open),
    /// [`Device::open_first`](crate::Device::open_first), and related methods.
    ///
    /// Use [`DEFAULT`](OpenOptions::DEFAULT) to go online, sync the RTC, and
    /// enable auto-update — the most common combination.
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    pub struct OpenOptions: sys::icsneoc2_open_options_t {
        /// No special behaviour.
        const NONE               = sys::ICSNEOC2_OPEN_OPTIONS_NONE as sys::icsneoc2_open_options_t;
        /// Automatically go online after opening.
        const GO_ONLINE          = sys::ICSNEOC2_OPEN_OPTIONS_GO_ONLINE as sys::icsneoc2_open_options_t;
        /// Synchronize the device real-time clock to the host.
        const SYNC_RTC           = sys::ICSNEOC2_OPEN_OPTIONS_SYNC_RTC as sys::icsneoc2_open_options_t;
        /// Enable automatic firmware updates when a newer version is available.
        const ENABLE_AUTO_UPDATE = sys::ICSNEOC2_OPEN_OPTIONS_ENABLE_AUTO_UPDATE as sys::icsneoc2_open_options_t;
        /// Force a firmware update regardless of version.
        const FORCE_UPDATE       = sys::ICSNEOC2_OPEN_OPTIONS_FORCE_UPDATE as sys::icsneoc2_open_options_t;
        /// Mirrors `icsneoc2_open_options_default` from the C API.
        const DEFAULT = sys::icsneoc2_open_options_default;
    }
}

impl From<sys::icsneoc2_open_options_t> for OpenOptions {
    fn from(val: sys::icsneoc2_open_options_t) -> Self {
        OpenOptions::from_bits_truncate(val)
    }
}

impl From<OpenOptions> for sys::icsneoc2_open_options_t {
    fn from(val: OpenOptions) -> Self {
        val.bits()
    }
}

// ---------------------------------------------------------------------------
// MessageCanFlags — bitmask flags for CAN message properties
// ---------------------------------------------------------------------------
bitflags::bitflags! {
    /// CAN frame attribute flags.
    ///
    /// Returned by [`Message::can_props`](crate::Message::can_props) and
    /// accepted by [`Message::set_can_props`](crate::Message::set_can_props).
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    pub struct MessageCanFlags: sys::icsneoc2_message_can_flags_t {
        /// Remote Transmission Request.
        const RTR = sys::ICSNEOC2_MESSAGE_CAN_FLAGS_RTR as sys::icsneoc2_message_can_flags_t;
        /// Extended (29-bit) identifier.
        const IDE = sys::ICSNEOC2_MESSAGE_CAN_FLAGS_IDE as sys::icsneoc2_message_can_flags_t;
        /// CAN FD Format indicator.
        const FDF = sys::ICSNEOC2_MESSAGE_CAN_FLAGS_FDF as sys::icsneoc2_message_can_flags_t;
        /// CAN FD Bit Rate Switch.
        const BRS = sys::ICSNEOC2_MESSAGE_CAN_FLAGS_BRS as sys::icsneoc2_message_can_flags_t;
        /// CAN FD Error State Indicator.
        const ESI = sys::ICSNEOC2_MESSAGE_CAN_FLAGS_ESI as sys::icsneoc2_message_can_flags_t;
    }
}

impl From<sys::icsneoc2_message_can_flags_t> for MessageCanFlags {
    fn from(val: sys::icsneoc2_message_can_flags_t) -> Self {
        MessageCanFlags::from_bits_truncate(val)
    }
}

impl From<MessageCanFlags> for sys::icsneoc2_message_can_flags_t {
    fn from(val: MessageCanFlags) -> Self {
        val.bits()
    }
}

// ---------------------------------------------------------------------------
// DiskFormatFlags — bitmask flags for disk partition state
// ---------------------------------------------------------------------------
bitflags::bitflags! {
    /// Describes the current state of a disk partition.
    ///
    /// Returned by [`DiskDetails::flags`](crate::DiskDetails::flags) and
    /// accepted by [`DiskDetails::set_flags`](crate::DiskDetails::set_flags).
    #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    pub struct DiskFormatFlags: sys::icsneoc2_disk_format_flags_t {
        /// The physical media is present (card inserted).
        const PRESENT     = sys::ICSNEOC2_DISK_FORMAT_FLAGS_PRESENT as sys::icsneoc2_disk_format_flags_t;
        /// The partition has been initialized.
        const INITIALIZED = sys::ICSNEOC2_DISK_FORMAT_FLAGS_INITIALIZED as sys::icsneoc2_disk_format_flags_t;
        /// The partition has been formatted with a valid filesystem.
        const FORMATTED   = sys::ICSNEOC2_DISK_FORMAT_FLAGS_FORMATTED as sys::icsneoc2_disk_format_flags_t;
    }
}

impl From<sys::icsneoc2_disk_format_flags_t> for DiskFormatFlags {
    fn from(val: sys::icsneoc2_disk_format_flags_t) -> Self {
        DiskFormatFlags::from_bits_truncate(val)
    }
}

impl From<DiskFormatFlags> for sys::icsneoc2_disk_format_flags_t {
    fn from(val: DiskFormatFlags) -> Self {
        val.bits()
    }
}