Skip to content

Commit

Permalink
wip to read IFF echo
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Mar 28, 2024
1 parent 537ee50 commit bdf8d8c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tracing = "^0.1"
# socketcan = {path = "../socketcan-rs"}
# socketcan = "^3.3.0"
socketcan = {git = "https://github.com/socketcan-rs/socketcan-rs.git", rev = "3ebef4e3f54bc21e3d993d40fa160ebb7f3047b0" }
libc = "^0.2.153"

[dev-dependencies]
futures = "^0.3.30"
Expand Down
34 changes: 34 additions & 0 deletions src/socketcan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use socketcan::socket::Socket;
use socketcan::SocketOptions;
use tracing::info;
use std::collections::VecDeque;
use std::os::fd::AsRawFd;

mod frame;

Expand All @@ -20,6 +21,39 @@ impl SocketCan {
socket.set_nonblocking(true).unwrap();
socket.set_loopback(true).unwrap();
socket.set_recv_own_msgs(true).unwrap();

unsafe {
// let addr = s.local_addr();
// println!("addr: {:?}", addr);
let fd = socket.as_raw_fd();

let mut addrs: libc::sockaddr = std::mem::zeroed();
let mut len: libc::socklen_t = std::mem::size_of::<libc::sockaddr>() as libc::socklen_t;
let res = libc::getsockname(fd, &mut addrs, &mut len);
println!("fd: {} res: {}, len: {}, name: {:?}", fd, res, len, addrs);

// let mut addrs: libc::ifaddrs = std::mem::zeroed();
// let name = libc::getifaddrs(&addrs);


let mut ifr: libc::ifreq = std::mem::zeroed();
// ifr.ifr_ifru.ifru_addr

let sb = b"can0";
let mut arr : [i8;16] = [0;16];
let mut i = 0;
for c in sb {
arr[i] = *c as i8;
i = i+1;
}
ifr.ifr_name = arr;

let res = libc::ioctl(fd, libc::SIOCGIFFLAGS, &ifr);
let err = std::io::Error::last_os_error().raw_os_error().unwrap();
println!("fd: {} res: {} flags {} err {}", fd, res, ifr.ifr_ifru.ifru_flags, err);

}

Self { socket }
}

Expand Down
32 changes: 16 additions & 16 deletions tests/adapter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,20 @@ fn vcan_bulk_send_sync() {
bulk_send_sync(&mut adapter);
}

#[cfg(feature = "test_vcan")]
#[tokio::test]
#[serial_test::serial]
async fn vcan_bulk_send_async() {
let adapter = automotive::socketcan::SocketCan::new_async_from_name("vcan0").unwrap();
bulk_send(&adapter).await;
}
// #[cfg(feature = "test_vcan")]
// #[tokio::test]
// #[serial_test::serial]
// async fn vcan_bulk_send_async() {
// let adapter = automotive::socketcan::SocketCan::new_async_from_name("vcan0").unwrap();
// bulk_send(&adapter).await;
// }

#[cfg(feature = "test_vcan")]
#[tokio::test]
#[serial_test::serial]
async fn vcan_bulk_send_fd() {
let adapter = automotive::socketcan::SocketCan::new_async_from_name("vcan0").unwrap();
adapter
.send(&Frame::new(0, 0x123.into(), &[0u8; 64]).unwrap())
.await;
}
// #[cfg(feature = "test_vcan")]
// #[tokio::test]
// #[serial_test::serial]
// async fn vcan_bulk_send_fd() {
// let adapter = automotive::socketcan::SocketCan::new_async_from_name("vcan0").unwrap();
// adapter
// .send(&Frame::new(0, 0x123.into(), &[0u8; 64]).unwrap())
// .await;
// }

0 comments on commit bdf8d8c

Please sign in to comment.