pub mod bst95;
pub mod bst_d0;
pub mod canalyst;
pub mod ikonvert;
pub mod maretron;
pub mod ngt1;
pub mod ngt1_tx_list;
pub mod raw;
pub(crate) mod raw_can;
pub mod usb_can_a;
use std::time::Duration;
use crate::engine::RawFrame;
#[derive(Debug, Clone, PartialEq)]
pub enum Event {
Frame(RawFrame),
Send(Vec<u8>),
Error(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Refused {
Synthetic,
NotOnTxList,
TooLarge,
ReceiveOnly,
Unsupported,
Busy,
}
impl std::fmt::Display for Refused {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Synthetic => "synthetic PGN, never sent on the bus",
Self::NotOnTxList => "PGN is not on the named transmit list",
Self::TooLarge => "payload too large for the gateway",
Self::ReceiveOnly => "the gateway only receives",
Self::Unsupported => "the gateway cannot carry this kind of frame",
Self::Busy => "too many ISO TP transfers queued",
})
}
}
impl std::error::Error for Refused {}
pub trait Codec {
fn open(&mut self) -> Vec<u8> {
Vec::new()
}
fn receive(&mut self, bytes: &[u8], now_ms: u64, events: &mut Vec<Event>);
fn tick(&mut self, _now_ms: u64, _events: &mut Vec<Event>) {}
fn next_deadline(&self) -> Option<u64> {
None
}
fn send(&mut self, frame: &RawFrame) -> Result<Vec<u8>, Refused>;
fn send_at(&mut self, frame: &RawFrame, now_ms: u64) -> Result<Vec<u8>, Refused> {
let _ = now_ms;
self.send(frame)
}
fn close(&mut self) -> Vec<u8> {
Vec::new()
}
fn keepalive(&self) -> Option<(Duration, Vec<u8>)> {
None
}
fn failure(&self) -> Option<&str> {
None
}
}
pub const SYNTHETIC_PGN_START: u32 = 0x40000;