Skip to content

Commit

Permalink
hardcoded channel 1, 1Mbit
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Jan 14, 2025
1 parent 1d75476 commit 667fefd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ const CONFIG_500K_2M_80: XLcanFdConf = XLcanFdConf {
reserved2: 0,
};

const CONFIG_500K_1M_75: XLcanFdConf = XLcanFdConf {
arbitrationBitRate: 500_000,
sjwAbr: 2,
tseg1Abr: 5,
tseg2Abr: 2,
dataBitRate: 1_000_000,
sjwDbr: 20,
tseg1Dbr: 59,
tseg2Dbr: 20,
reserved: 0,
options: 0,
reserved1: [0, 0],
reserved2: 0,
};

#[derive(Clone)]
pub struct VectorCan {
port_handle: PortHandle,
Expand All @@ -45,6 +60,7 @@ impl VectorCan {
/// Create a new Vector Adapter based on the global channel ID
pub fn new(channel_idx: usize) -> Result<VectorCan> {
xl_open_driver()?;
let channel_idx = 1;

// Get config based on global channel number
let config = xl_get_driver_config(channel_idx)?;
Expand All @@ -58,7 +74,7 @@ impl VectorCan {
let port_handle = xl_open_port("automotive", channel_mask)?;

// Configure bitrate
xl_can_fd_set_configuration(&port_handle, channel_mask, &CONFIG_500K_2M_80)?;
xl_can_fd_set_configuration(&port_handle, channel_mask, &CONFIG_500K_1M_75)?;

xl_activate_channel(&port_handle, channel_mask)?;
info!("Connected to Vector Device. HW: {:?}", config.hw_type);
Expand Down
3 changes: 2 additions & 1 deletion src/vector/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ impl TryFrom<XLcanRxEvent> for crate::can::Frame {
let fd = frame.msgFlags & xl::XL_CAN_RXMSG_FLAG_EDL != 0;

Ok(Self {
bus: event.channelIndex as u8, // TODO: perform proper mapping based on xlGetChannelIndex,
//bus: event.channelIndex as u8, // TODO: perform proper mapping based on xlGetChannelIndex,
bus: 0, // TODO: perform proper mapping based on xlGetChannelIndex,
id,
data: frame.data[..len].into(),
loopback,
Expand Down

0 comments on commit 667fefd

Please sign in to comment.