#![allow(dead_code)]
#![allow(clippy::large_enum_variant)]
pub const MAX_PGN_BYTES: usize = 230;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum FieldKind {
Number,
Float,
Lookup,
IndirectLookup,
BitLookup,
Pgn,
Date,
Time,
Duration,
Mmsi,
Decimal,
StringFix,
StringLz,
StringLau,
Binary,
Reserved,
Spare,
IsoName,
Unimplemented,
}
#[derive(Debug)]
pub struct FieldDescriptor {
pub id: &'static str,
pub name: &'static str,
pub kind: FieldKind,
pub bits_length: Option<u32>,
pub bits_length_var: Option<u32>,
pub bits_offset: Option<u32>,
pub is_signed: Option<bool>,
pub resolution: Option<f32>,
pub enum_direct_name: Option<&'static str>,
pub enum_indirect_name: Option<&'static str>,
pub enum_indirect_field_order: Option<u16>,
pub physical_unit: Option<&'static str>,
pub physical_qtity: Option<&'static str>,
}
#[derive(Debug)]
pub struct RepeatingFieldSet {
pub array_id: &'static str,
pub count_field_index: Option<usize>,
pub start_field_index: usize,
pub size: usize,
pub max_repetitions: usize,
}
#[derive(Debug)]
pub struct PgnDescriptor {
pub id: u32,
pub name: &'static str,
pub description: &'static str,
pub priority: Option<u8>,
pub fastpacket: bool,
pub length: Option<u16>,
pub field_count: Option<u8>,
pub trans_interval: Option<u16>,
pub trans_irregular: Option<bool>,
pub fields: &'static [FieldDescriptor],
pub repeating_field_sets: &'static [RepeatingFieldSet],
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PgnBytes {
pub len: usize,
pub data: [u8; MAX_PGN_BYTES],
}
impl Default for PgnBytes {
fn default() -> Self {
Self {
len: 0,
data: [0; MAX_PGN_BYTES],
}
}
}
impl PgnBytes {
pub const fn new() -> Self {
Self {
len: 0,
data: [0; MAX_PGN_BYTES],
}
}
#[inline]
pub fn len(&self) -> usize {
self.len
}
#[inline]
pub fn is_empty(&self) -> bool {
self.len == 0
}
#[inline]
pub fn clear(&mut self) {
self.len = 0;
}
#[inline]
pub fn copy_from_slice(&mut self, slice: &[u8]) {
let clamped = slice.len().min(MAX_PGN_BYTES);
self.data[..clamped].copy_from_slice(&slice[..clamped]);
self.len = clamped;
}
#[inline]
pub fn as_slice(&self) -> &[u8] {
&self.data[..self.len]
}
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [u8] {
&mut self.data[..self.len]
}
}
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Clone, PartialEq)]
pub enum PgnValue {
U64(u64),
U32(u32),
U16(u16),
U8(u8),
I64(i64),
I32(i32),
I16(i16),
I8(i8),
F64(f64),
F32(f32),
Bytes(PgnBytes),
Ignored,
}
impl PgnValue {
pub const fn kind(&self) -> &'static str {
match self {
Self::U64(_) => "U64",
Self::U32(_) => "U32",
Self::U16(_) => "U16",
Self::U8(_) => "U8",
Self::I64(_) => "I64",
Self::I32(_) => "I32",
Self::I16(_) => "I16",
Self::I8(_) => "I8",
Self::F64(_) => "F64",
Self::F32(_) => "F32",
Self::Bytes(_) => "Bytes",
Self::Ignored => "Ignored",
}
}
}