use std::ffi::c_void;
use std::os::raw::c_char;
use bitfield_struct::bitfield;
pub const BM_ERROR_DESC_MAX_SIZE: usize = 255;
pub const BM_DATA_HEADER_SIZE: usize = 8;
pub const BM_DATA_PAYLOAD_MAX_SIZE: usize = 72;
pub const BM_DATA_MAX_SIZE: usize = BM_DATA_HEADER_SIZE + BM_DATA_PAYLOAD_MAX_SIZE;
#[repr(u32)]
pub enum BMLogLevel {
None = 0,
Error = 1,
Warning = 2,
Info = 3,
Debug = 4
}
bitflags!{
#[repr(transparent)]
pub struct BMCapability: u16 {
const NONE = 0x0000;
const LIN = 0x0001;
const CAN = 0x0002;
const CAN_FD = 0x0004;
const FLEXRAY = 0x0008;
const MODBUS = 0x0010;
const ETHERNET = 0x0020;
const ALL = 0xFFFF;
}
}
#[repr(u8)]
#[derive(Debug, Copy, Clone)]
pub enum BMDataType {
Unknown = 0,
Lin = 1,
Can = 2,
FlexRay = 3,
ModBus = 4,
Ethernet = 5,
Ack = 8
}
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
pub enum BMStatus {
Ok = 0x00000,
XmtFull = 0x00001,
Overrun = 0x00002,
BusLight = 0x00004,
BusWarning = 0x00008,
BusPassive = 0x40000,
BusTimeout = 0x80000,
BusOff = 0x00010,
AnyBusError = 0x00008 | 0x00004 | 0x00010 | 0x40000,
ReceiveBufferEmpty = 0x00020,
QueueOverrun = 0x00040,
TransmitQueueFull = 0x00080,
RegTest = 0x00100,
NoDriver = 0x00200,
HardwareInUse = 0x00400,
NetInUse = 0x00800,
HardwareError = 0x01400,
InvalidBus = 0x01800,
InvalidClient = 0x01C00,
OutOfResources = 0x02000,
InvalidParameterType = 0x04000,
InvalidParameterValue = 0x08000,
Unknown = 0x10000,
InvalidData = 0x20000,
Caution = 0x2000000,
NotInitialized = 0x4000000,
InvalidOperation = 0x8000000
}
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
pub enum BMCanMode {
Normal = 0x00,
BufOff = 0x01,
InternalLoopback = 0x02,
ListenOnly = 0x03,
Configuration = 0x04,
ExternalLoopback = 0x05,
Classic = 0x06,
Restricted = 0x07
}
#[repr(u32)]
#[derive(Debug, Copy, Clone)]
pub enum BMTerminalResistor {
Auto = 0,
Enabled60 = 60,
Enabled120 = 120,
Disabled = 0xFFFF
}
#[repr(u8)]
pub enum BMMessageFlags {
Normal = 0,
Extended = 1,
Remote = 2,
BitRateSwitching = 4,
CanFD = 8,
Esi = 16
}
#[repr(u32)]
pub enum BMRxFilterType {
Invalid = 0,
Basic = 1,
Advanced = 2,
E2EPass = 3,
E2EFail = 4
}
#[repr(u32)]
pub enum BMTxTaskType {
Invalid = 0,
Fixed = 1,
IncData = 2,
IncId = 3,
RandomData = 4,
RandomId = 5
}
#[repr(u32)]
pub enum BMStatType {
None = 0,
TxMessage = 1,
RxMessage = 2,
TxByte = 3,
RxByte = 4,
TxError = 5,
RxError = 6
}
#[repr(u32)]
pub enum BMIsotpMode {
NormalTester = 0,
NormalEcu = 1,
ExtendedTester = 2,
ExtendedEcu = 3
}
#[bitfield(u16)]
#[derive(Default)]
pub struct BMDataHeader {
#[bits(4)]
pub kind: u8,
#[bits(4)]
pub flags: u8,
#[bits(4)]
pub dchn: u8,
#[bits(4)]
pub schn: u8,
}
#[repr(C)]
pub struct BMData {
pub header: BMDataHeader,
pub length: u16,
pub timestamp: u32,
pub payload: [u8; BM_DATA_PAYLOAD_MAX_SIZE],
}
#[bitfield(u32)]
pub struct BMMessageId {
#[bits(11)]
pub sid: u16,
#[bits(18)]
pub eid: u32,
#[bits(1)]
pub reserved1: bool,
#[bits(2)]
pub reserved2: u8,
}
#[bitfield(u32)]
pub struct BMTxMessageCtrl {
#[bits(4)]
pub dlc: u8,
#[bits(1)]
pub ide: bool,
#[bits(1)]
pub rtr: bool,
#[bits(1)]
pub brs: bool,
#[bits(1)]
pub fdf: bool,
#[bits(1)]
pub esi: bool,
#[bits(23)]
pub seq: u32,
}
#[bitfield(u32)]
pub struct BMRxMessageCtrl {
#[bits(4)]
pub dlc: u8,
#[bits(1)]
pub ide: bool,
#[bits(1)]
pub rtr: bool,
#[bits(1)]
pub brs: bool,
#[bits(1)]
pub fdf: bool,
#[bits(1)]
pub esi: bool,
#[bits(2)]
pub reserved1: u8,
#[bits(5)]
pub rx_filter: u8,
#[bits(16)]
pub reserved2: u16,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union BMMessageCtrl {
pub tx: BMTxMessageCtrl,
pub rx: BMRxMessageCtrl
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct BMCanMessage {
pub mid: BMMessageId,
pub ctrl: BMMessageCtrl,
pub payload: [u8; 64]
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct BMChannelInfo {
pub name: [c_char; 64],
pub sn: [u8; 16],
pub uid: [u8; 12],
pub version: [u8; 4],
pub vid: u16,
pub pid: u16,
pub port: u16,
pub cap: BMCapability,
pub reserved: [u8; 4]
}
#[repr(C)]
#[derive(Debug)]
pub struct BMCanStatusInfo {
pub tx_bus_off: u8,
reserved: u8,
pub tx_bus_passive: u8,
pub rx_bus_passive: u8,
pub tx_warn: u8,
pub rx_warn: u8,
pub tx_errors: u8,
pub rx_errors: u8
}
#[repr(C)]
pub struct BMBitrate {
pub n_bitrate: u16,
pub d_bitrate: u16,
pub n_sample_pos: u8,
pub d_sample_pos: u8,
pub clock_freq: u8,
pub reserved: u8,
pub n_btr0: u8,
pub n_btr1: u8,
pub d_btr0: u8,
pub d_btr1: u8
}
#[repr(C)]
pub struct BMRxFilter {
pub kind: u8,
pub unused: u8,
pub flags_mask: u8,
pub flags_value: u8,
pub reserved: [u8; 4],
pub id_mask: u32,
pub id_value: u32,
pub payload_mask: [u8; 8],
pub payload_value: [u8; 8]
}
#[repr(C)]
pub struct BMTxTaskIncDataPattern {
pub start_bit: u16,
pub nbits: u8,
pub format: u8,
pub min: u32,
pub max: u32,
pub step: u32
}
#[repr(C)]
pub struct BMTxTaskIncIdPattern {
pub min: u32,
pub max: u32,
pub step: u32
}
#[repr(C)]
pub struct BMTxTaskRndDataPattern {
pub start_bit: u16,
pub nbits: u8,
pub format: u8,
pub min: u32,
pub max: u32,
pub seed: u32
}
#[repr(C)]
pub struct BMTxTaskRndIdPattern {
pub min: u32,
pub max: u32,
pub seed: u32
}
#[repr(C)]
pub struct BMTxTask {
pub kind: u8,
pub unused: u8,
pub flags: u8,
pub length: u8,
pub e2e: u8,
pub reserved: u8,
pub cycle: u16,
pub n_rounds: u16,
pub n_messages: u16,
pub id: u32,
pub pattern: u32,
pub payload: [u8; 64]
}
#[repr(C)]
pub struct BMIsoTPStatus {
pub version: u8,
pub flow_control: u8,
pub st_min: u8,
pub block_size: u8,
pub transferred_bytes: u32,
pub total_bytes: u32,
pub timestamp: u32,
pub reserved: [u32; 4]
}
type BMIsotpCallbackHandle = extern fn(status: *const BMIsoTPStatus, arg: *const c_void);
#[repr(C)]
pub struct BMIsotpTimeoutConfig {
pub a: u16,
pub b: u16,
pub c: u16
}
#[repr(C)]
pub struct BMIsotpFlowControlConfig {
pub st_min: u8,
pub block_size: u8,
pub fc_frame_length: u8,
pub reserved: u8
}
#[repr(C)]
pub struct BMIsotpConfig {
pub version: u8,
pub mode: u8,
pub tester_timeout: BMIsotpTimeoutConfig,
pub ecu_timeout: BMIsotpTimeoutConfig,
pub flow_control: BMIsotpFlowControlConfig,
pub extended_address: u8,
pub padding_enabled: u8,
pub padding_value: u8,
pub long_pdu_enabled: u8,
pub padding: [u8; 2],
pub callback: BMIsotpCallbackHandle,
pub callback_user_arg: *const c_void,
pub tester_data_template: BMData,
pub ecu_data_template: BMData
}