#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PacketType {
Single,
Fast,
Iso,
Mixed,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FieldType {
Number,
Decimal,
Float,
Binary,
Lookup,
BitLookup,
IndirectLookup,
Date,
Time,
Duration,
StringFix,
StringLz,
StringLau,
Variable,
Mmsi,
Pgn,
IsoName,
Reserved,
Spare,
DynamicFieldKey,
DynamicFieldLength,
DynamicFieldValue,
FieldIndex,
Address,
}
#[derive(Debug, Clone, Copy)]
pub struct FieldInfo {
pub order: u8,
pub id: &'static str,
pub name: &'static str,
pub description: Option<&'static str>,
pub spn: Option<u32>,
pub continuation: Option<Continuation>,
pub continues: Option<&'static str>,
pub bit_length: Option<u32>,
pub bit_length_field: Option<&'static str>,
pub encoding: Option<&'static str>,
pub bit_length_variable: Option<bool>,
pub bit_offset: Option<u32>,
pub bit_start: Option<u32>,
pub resolution: Option<f64>,
pub signed: Option<bool>,
pub offset: Option<i64>,
pub range_min: Option<f64>,
pub range_max: Option<f64>,
pub unknown_value: Option<u64>,
pub out_of_range_value: Option<u64>,
pub reserved_value: Option<u64>,
pub unit: Option<&'static str>,
pub physical_quantity: Option<&'static str>,
pub field_type: Option<FieldType>,
pub lookup_enumeration: Option<&'static str>,
pub lookup_bit_enumeration: Option<&'static str>,
pub lookup_indirect_enumeration: Option<&'static str>,
pub lookup_indirect_enumeration_field_order: Option<u8>,
pub lookup_field_type_enumeration: Option<&'static str>,
pub trailing_zero_is_digit: Option<(u8, i64)>,
pub match_value: Option<i64>,
pub part_of_primary_key: Option<bool>,
pub condition: Option<&'static str>,
pub unit_offset: f64,
pub precision: u8,
pub is_dynamic_length_marker: bool,
pub dynamic_field_length_overhead: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Continuation {
pub bit_offset: u32,
pub bit_length: u32,
}
#[derive(Debug, Clone, Copy)]
pub struct PgnInfo {
pub pgn: u32,
pub id: &'static str,
pub description: &'static str,
pub explanation: Option<&'static str>,
pub url: Option<&'static str>,
pub packet_type: PacketType,
pub complete: Option<bool>,
pub fallback: Option<bool>,
pub missing: &'static [&'static str],
pub priority: Option<u8>,
pub transmission_interval: Option<u32>,
pub transmission_irregular: Option<bool>,
pub field_count: u32,
pub length: Option<u32>,
pub min_length: Option<u32>,
pub fields: &'static [FieldInfo],
pub repeating_field_set1_size: Option<u32>,
pub repeating_field_set1_start_field: Option<u32>,
pub repeating_field_set1_count_field: Option<u32>,
pub repeating_field_set2_size: Option<u32>,
pub repeating_field_set2_start_field: Option<u32>,
pub repeating_field_set2_count_field: Option<u32>,
pub id_is_pinned: bool,
}
#[derive(Debug, Clone, Copy)]
pub struct FieldRef {
pub pgn: &'static PgnInfo,
pub field: &'static FieldInfo,
}
#[derive(Debug, Clone, Copy)]
pub struct LookupValue {
pub value: u64,
pub name: &'static str,
pub id: Option<&'static str>,
}
pub struct LookupTable {
pub name: &'static str,
pub max_value: Option<u64>,
pub values: &'static [LookupValue],
pub by_value: &'static [(u64, u32)],
}
impl LookupTable {
pub fn get(&self, value: u64) -> Option<&'static LookupValue> {
match self.by_value.binary_search_by_key(&value, |&(v, _)| v) {
Ok(i) => Some(&self.values[self.by_value[i].1 as usize]),
Err(_) => None,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct BitLookupValue {
pub bit: u8,
pub name: &'static str,
pub id: Option<&'static str>,
}
pub struct BitLookupTable {
pub name: &'static str,
pub max_value: Option<u64>,
pub values: &'static [BitLookupValue],
pub by_bit: &'static [(u8, u32)],
}
impl BitLookupTable {
pub fn get(&self, bit: u8) -> Option<&'static BitLookupValue> {
match self.by_bit.binary_search_by_key(&bit, |&(b, _)| b) {
Ok(i) => Some(&self.values[self.by_bit[i].1 as usize]),
Err(_) => None,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct IndirectLookupValue {
pub value1: u64,
pub value2: u64,
pub name: &'static str,
pub id: Option<&'static str>,
}
pub struct IndirectLookupTable {
pub name: &'static str,
pub max_value: Option<u64>,
pub values: &'static [IndirectLookupValue],
pub by_pair: &'static [((u64, u64), u32)],
}
impl IndirectLookupTable {
pub fn get(&self, value1: u64, value2: u64) -> Option<&'static IndirectLookupValue> {
match self
.by_pair
.binary_search_by_key(&(value1, value2), |&(k, _)| k)
{
Ok(i) => Some(&self.values[self.by_pair[i].1 as usize]),
Err(_) => None,
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct LookupFieldTypeValue {
pub value: u64,
pub name: &'static str,
pub field_type: Option<&'static str>,
pub bits: Option<u32>,
pub resolution: Option<f64>,
pub unit: Option<&'static str>,
pub lookup_enumeration: Option<&'static str>,
pub lookup_bit_enumeration: Option<&'static str>,
pub signed: bool,
pub precision: u8,
pub unit_offset: f64,
}
impl LookupFieldTypeValue {
pub fn bit_length(&self) -> Option<u32> {
self.bits
}
}
pub struct LookupFieldTypeTable {
pub name: &'static str,
#[allow(dead_code)]
pub max_value: Option<u64>,
pub values: &'static [LookupFieldTypeValue],
pub by_value: &'static [(u64, u32)],
}
impl LookupFieldTypeTable {
pub fn get(&self, value: u64) -> Option<&'static LookupFieldTypeValue> {
match self.by_value.binary_search_by_key(&value, |&(v, _)| v) {
Ok(i) => Some(&self.values[self.by_value[i].1 as usize]),
Err(_) => None,
}
}
}