Skip to content

Commit

Permalink
Add channel_idx argument to Vector::new
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Nov 21, 2024
1 parent 5d4ff30 commit 7ea3060
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ vector-xl = []
# adapter tests
test_panda = []
test_socketcan = []
test_vector = []
test_vector = ["vector-xl"]
test_vcan = []

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/can/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn get_adapter() -> Result<crate::can::AsyncCanAdapter, crate::error::Error>

#[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);
};
}
Expand Down
10 changes: 6 additions & 4 deletions src/vector/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Vector CAN Adapter support through the XL Driver
mod bindings;
pub mod error;
pub mod types;
Expand All @@ -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<AsyncCanAdapter> {
let vector = VectorCan::new()?;
pub fn new_async(channel_idx: usize) -> Result<AsyncCanAdapter> {
let vector = VectorCan::new(channel_idx)?;
Ok(AsyncCanAdapter::new(vector))
}

pub fn new() -> Result<VectorCan> {
/// Create a new Vector Adapter based on the global channel ID
pub fn new(channel_idx: usize) -> Result<VectorCan> {
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
Expand Down
4 changes: 2 additions & 2 deletions tests/adapter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ 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);
}

#[cfg(feature = "test_vector")]
#[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;
}

Expand Down

0 comments on commit 7ea3060

Please sign in to comment.