oca 0.2.0

An experiment with no_std
Documentation
use crate::{
    ocp1::pdu::Parameters,
    types::{OcaEvent, OcaMethod},
};

pub mod ev1 {
    use super::*;

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub struct Notification1<'a> {
        pub target: OcaMethod,
        pub parameters: Notification1Parameters<'a>,
    }

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub struct Notification1Parameters<'a> {
        pub context: &'a [u8],
        pub event_data: Notification1EventData<'a>,
    }

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub struct Notification1EventData<'a> {
        pub event: OcaEvent,
        pub parameters: Parameters<'a>,
    }
}

pub mod ev2 {
    use super::*;

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub struct Notification2<'a> {
        pub event: OcaEvent,
        pub r#type: Notification2Type<'a>,
    }

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub enum Notification2Type<'a> {
        Event(&'a [u8]),
        Exception(Notification2ExceptionData<'a>),
    }

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub struct Notification2ExceptionData<'a> {
        pub r#type: Notification2ExceptionType,
        pub try_again: bool,
        pub data: &'a [u8],
    }

    #[derive(Debug, Copy, Clone, Eq, PartialEq)]
    pub enum Notification2ExceptionType {
        Unspecified,
        CancelledByDevice,
        ObjectDeleted,
        DeviceError,
        Other(u8),
    }

    impl From<u8> for Notification2ExceptionType {
        fn from(value: u8) -> Notification2ExceptionType {
            match value {
                0 => Notification2ExceptionType::Unspecified,
                1 => Notification2ExceptionType::CancelledByDevice,
                2 => Notification2ExceptionType::ObjectDeleted,
                3 => Notification2ExceptionType::DeviceError,
                _ => Notification2ExceptionType::Other(value),
            }
        }
    }

    impl From<Notification2ExceptionType> for u8 {
        fn from(value: Notification2ExceptionType) -> u8 {
            match value {
                Notification2ExceptionType::Unspecified => 0,
                Notification2ExceptionType::CancelledByDevice => 1,
                Notification2ExceptionType::ObjectDeleted => 2,
                Notification2ExceptionType::DeviceError => 3,
                Notification2ExceptionType::Other(v) => v,
            }
        }
    }
}