#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
pub struct Model16 {
pub nam: Option<String>,
pub cfg: Cfg,
pub ctl: Ctl,
pub addr: String,
pub msk: String,
pub gw: Option<String>,
pub dns1: Option<String>,
pub dns2: Option<String>,
pub mac: Option<String>,
pub lnk_ctl: Option<LnkCtl>,
}
#[allow(missing_docs)]
impl Model16 {
pub const NAM: crate::Point<Self, Option<String>> = crate::Point::new(0, 4, true);
pub const CFG: crate::Point<Self, Cfg> = crate::Point::new(4, 1, false);
pub const CTL: crate::Point<Self, Ctl> = crate::Point::new(5, 1, true);
pub const ADDR: crate::Point<Self, String> = crate::Point::new(6, 8, true);
pub const MSK: crate::Point<Self, String> = crate::Point::new(14, 8, true);
pub const GW: crate::Point<Self, Option<String>> = crate::Point::new(22, 8, true);
pub const DNS1: crate::Point<Self, Option<String>> = crate::Point::new(30, 8, true);
pub const DNS2: crate::Point<Self, Option<String>> = crate::Point::new(38, 8, true);
pub const MAC: crate::Point<Self, Option<String>> = crate::Point::new(46, 4, false);
pub const LNK_CTL: crate::Point<Self, Option<LnkCtl>> = crate::Point::new(50, 1, true);
}
impl crate::Group for Model16 {
const LEN: u16 = 52;
}
impl Model16 {
fn parse_group(data: &[u16]) -> Result<(&[u16], Self), crate::DecodeError> {
let nested_data = data
.get(usize::from(<Self as crate::Group>::LEN)..)
.unwrap_or(&[]);
Ok((
nested_data,
Self {
nam: Self::NAM.from_data(data)?,
cfg: Self::CFG.from_data(data)?,
ctl: Self::CTL.from_data(data)?,
addr: Self::ADDR.from_data(data)?,
msk: Self::MSK.from_data(data)?,
gw: Self::GW.from_data(data)?,
dns1: Self::DNS1.from_data(data)?,
dns2: Self::DNS2.from_data(data)?,
mac: Self::MAC.from_data(data)?,
lnk_ctl: Self::LNK_CTL.from_data(data)?,
},
))
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))]
pub enum Cfg {
#[allow(missing_docs)]
Static,
#[allow(missing_docs)]
Dhcp,
Invalid(u16),
}
impl crate::EnumValue for Cfg {
type Repr = u16;
const INVALID: Self::Repr = 65535;
fn from_repr(value: Self::Repr) -> Self {
match value {
0 => Self::Static,
1 => Self::Dhcp,
value => Self::Invalid(value),
}
}
fn to_repr(self) -> Self::Repr {
match self {
Self::Static => 0,
Self::Dhcp => 1,
Self::Invalid(value) => value,
}
}
}
impl crate::FixedSize for Cfg {
const SIZE: u16 = 1u16;
const INVALID: Self = Self::Invalid(65535);
fn is_invalid(&self) -> bool {
matches!(self, Self::Invalid(_))
}
}
bitflags::bitflags! {
#[doc = " Control"] #[doc = " "] #[doc = " Bitmask value Configure use of services"]
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
derive(::serde::Serialize, ::serde::Deserialize))] pub struct Ctl : u16 {
#[allow(missing_docs)] const EnableDns = 1; #[allow(missing_docs)] const EnableNtp =
2; }
}
impl crate::Value for Ctl {
fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
let value = u16::decode(data)?;
Ok(Self::from_bits_retain(value))
}
fn encode(self) -> Box<[u16]> {
self.bits().encode()
}
}
impl crate::FixedSize for Ctl {
const SIZE: u16 = 1u16;
const INVALID: Self = Self::from_bits_retain(65535u16);
fn is_invalid(&self) -> bool {
self.bits() == 65535u16
}
}
bitflags::bitflags! {
#[doc = " Link Control"] #[doc = " "] #[doc = " Bitmask value. Link control flags"]
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde",
derive(::serde::Serialize, ::serde::Deserialize))] pub struct LnkCtl : u16 {
#[allow(missing_docs)] const Autonegotiate = 1; #[allow(missing_docs)] const
FullDuplex = 2; #[allow(missing_docs)] const Force10mb = 4; #[allow(missing_docs)]
const Force100mb = 8; #[allow(missing_docs)] const Force1gb = 16; }
}
impl crate::Value for LnkCtl {
fn decode(data: &[u16]) -> Result<Self, crate::DecodeError> {
let value = u16::decode(data)?;
Ok(Self::from_bits_retain(value))
}
fn encode(self) -> Box<[u16]> {
self.bits().encode()
}
}
impl crate::FixedSize for LnkCtl {
const SIZE: u16 = 1u16;
const INVALID: Self = Self::from_bits_retain(65535u16);
fn is_invalid(&self) -> bool {
self.bits() == 65535u16
}
}
impl crate::Model for Model16 {
const ID: u16 = 16;
fn addr(models: &crate::Models) -> crate::ModelAddr<Self> {
models.m16
}
fn parse(data: &[u16]) -> Result<Self, crate::ParseError<Self>> {
let (_, model) = Self::parse_group(data)?;
Ok(model)
}
}