From 7ea30604958e31e49019817ca875f609525e6fe2 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Thu, 21 Nov 2024 02:25:49 -0800 Subject: [PATCH] Add channel_idx argument to Vector::new --- Cargo.toml | 2 +- src/can/adapter.rs | 2 +- src/vector/mod.rs | 10 ++++++---- tests/adapter_tests.rs | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 30d448f..0dfa7f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ vector-xl = [] # adapter tests test_panda = [] test_socketcan = [] -test_vector = [] +test_vector = ["vector-xl"] test_vcan = [] [dependencies] diff --git a/src/can/adapter.rs b/src/can/adapter.rs index 4b9793f..d6f58af 100644 --- a/src/can/adapter.rs +++ b/src/can/adapter.rs @@ -18,7 +18,7 @@ pub fn get_adapter() -> Result #[cfg(all(target_os = "windows", feature = "vector-xl"))] { - if let Ok(adapter) = crate::vector::VectorCan::new_async() { + if let Ok(adapter) = crate::vector::VectorCan::new_async(0) { return Ok(adapter); }; } diff --git a/src/vector/mod.rs b/src/vector/mod.rs index 090986c..a8b55c9 100644 --- a/src/vector/mod.rs +++ b/src/vector/mod.rs @@ -1,3 +1,4 @@ +//! Vector CAN Adapter support through the XL Driver mod bindings; pub mod error; pub mod types; @@ -21,16 +22,17 @@ pub struct VectorCan { impl VectorCan { /// Convenience function to create a new adapter and wrap in an [`AsyncCanAdapter`] - pub fn new_async() -> Result { - let vector = VectorCan::new()?; + pub fn new_async(channel_idx: usize) -> Result { + let vector = VectorCan::new(channel_idx)?; Ok(AsyncCanAdapter::new(vector)) } - pub fn new() -> Result { + /// Create a new Vector Adapter based on the global channel ID + pub fn new(channel_idx: usize) -> Result { xl_open_driver()?; // Get config based on global channel number - let config = xl_get_driver_config(0)?; + let config = xl_get_driver_config(channel_idx)?; info!("Got Application Config: {:?}", config); // TODO: This produces weird errors diff --git a/tests/adapter_tests.rs b/tests/adapter_tests.rs index d01e429..6fda5b4 100644 --- a/tests/adapter_tests.rs +++ b/tests/adapter_tests.rs @@ -110,7 +110,7 @@ async fn panda_bulk_send_async() { #[test] #[serial_test::serial] fn vector_bulk_send_sync() { - let mut vector = automotive::vector::VectorCan::new().unwrap(); + let mut vector = automotive::vector::VectorCan::new(0).unwrap(); bulk_send_sync(&mut vector); } @@ -118,7 +118,7 @@ fn vector_bulk_send_sync() { #[tokio::test] #[serial_test::serial] async fn vector_bulk_send_async() { - let vector = automotive::vector::VectorCan::new_async().unwrap(); + let vector = automotive::vector::VectorCan::new_async(0).unwrap(); bulk_send(&vector).await; }