From 010e69888ec11bf9f2af67abc22d67c85749c842 Mon Sep 17 00:00:00 2001 From: Alex van de Sandt Date: Tue, 7 Jul 2026 16:14:13 -0500 Subject: [PATCH] Update rand and socketcan deps --- Cargo.lock | 352 ++++++++++++++++++++++++++-- Cargo.toml | 6 +- candid_server/src/bin/vcan_rand.rs | 14 +- candid_server/src/can_reader.rs | 12 +- candid_server/src/client_handler.rs | 32 +-- candid_server/src/main.rs | 4 +- 6 files changed, 361 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65dc20f..09acbe1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,15 +39,15 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "bitflags" -version = "0.4.0" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" [[package]] name = "byteorder" @@ -70,10 +70,33 @@ version = "0.3.0" dependencies = [ "byteorder", "clap", - "rand 0.5.6", + "rand 0.10.2", "socketcan", ] +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures", + "rand_core 0.10.1", +] + [[package]] name = "clap" version = "2.34.0" @@ -98,12 +121,48 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + +[[package]] +name = "embedded-can" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9d2e857f87ac832df68fa498d18ddc679175cf3d2e4aa893988e5601baf9438" +dependencies = [ + "nb", +] + [[package]] name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "rand_core 0.10.1", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -115,15 +174,18 @@ dependencies = [ [[package]] name = "hex" -version = "0.2.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "itertools" -version = "0.4.19" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a9b56eb56058f43dc66e58f40a214b2ccbc9f3df51861b63d51dec7b65bc3f" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] [[package]] name = "libc" @@ -132,28 +194,88 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] -name = "nix" -version = "0.5.1" +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "memoffset" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ - "bitflags 0.4.0", + "autocfg 1.5.1", +] + +[[package]] +name = "nb" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d" + +[[package]] +name = "neli" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93062a0dce6da2517ea35f301dfc88184ce18d3601ec786a727a87bf535deca9" +dependencies = [ + "byteorder", "libc", + "log", + "neli-proc-macros", ] [[package]] -name = "rand" -version = "0.5.6" +name = "neli-proc-macros" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" +checksum = "0c8034b7fbb6f9455b2a96c19e6edf8dc9fc34c70449938d8ee3b4df363f61fe" dependencies = [ - "cloudabi", - "fuchsia-cprng", + "either", + "proc-macro2", + "quote", + "serde", + "syn 1.0.109", +] + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags 2.13.0", + "cfg-if", + "cfg_aliases", "libc", - "rand_core 0.3.1", - "winapi", + "memoffset", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" +dependencies = [ + "proc-macro2", ] +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "rand" version = "0.6.5" @@ -173,6 +295,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom", + "rand_core 0.10.1", +] + [[package]] name = "rand_chacha" version = "0.1.1" @@ -198,6 +331,12 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + [[package]] name = "rand_hc" version = "0.1.0" @@ -269,17 +408,63 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", +] + +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "socketcan" -version = "1.7.0" +version = "3.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3101efc6ef5af6f1c1a488241b469757b7a183baca63af958cd90e4696446c80" +checksum = "ea24328be148eea05f36bc3991b1c174c586853e04d1480b92429b2df6aea865" dependencies = [ + "bitflags 2.13.0", + "embedded-can", "hex", "itertools", "libc", + "log", + "nb", + "neli", "nix", - "try_from", + "socket2", + "thiserror", ] [[package]] @@ -288,6 +473,28 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "textwrap" version = "0.11.0" @@ -298,10 +505,30 @@ dependencies = [ ] [[package]] -name = "try_from" -version = "0.2.2" +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "923a7ee3e97dbfe8685261beb4511cc9620a1252405d02693d43169729570111" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-width" @@ -336,3 +563,76 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 8424085..f9442fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,6 @@ keywords = ["CAN", "SocketCAN"] [workspace.dependencies] byteorder = "^1.3" -clap = "^2.32" -rand = "^0.5" -socketcan = "^1.7" +clap = "^2.3.1" +rand = "0.10.2" +socketcan = "3.6.2" diff --git a/candid_server/src/bin/vcan_rand.rs b/candid_server/src/bin/vcan_rand.rs index a029610..607b86c 100644 --- a/candid_server/src/bin/vcan_rand.rs +++ b/candid_server/src/bin/vcan_rand.rs @@ -1,22 +1,20 @@ -extern crate rand; -extern crate socketcan; - -use rand::prelude::*; -use socketcan::{CANFrame, CANSocket}; +use socketcan::{CanFrame, CanSocket, EmbeddedFrame, ExtendedId, Socket}; use std::thread; use std::time::Duration; fn main() { // Open a write socket - let write_socket = CANSocket::open("vcan0").unwrap(); + let write_socket = CanSocket::open("vcan0").unwrap(); write_socket.set_write_timeout(Duration::new(5, 0)).unwrap(); for i in 1..10 { - let data: u64 = random(); + let id = ExtendedId::new(i + 0x123).unwrap(); + + let data: u64 = rand::random(); let data = data.to_ne_bytes(); write_socket - .write_frame(&CANFrame::new(i + 0x123, &data, false, false).unwrap()) + .write_frame(&CanFrame::new(id, &data).unwrap()) .unwrap(); thread::sleep(Duration::from_millis(100)); diff --git a/candid_server/src/can_reader.rs b/candid_server/src/can_reader.rs index d4f5cb1..83c0071 100644 --- a/candid_server/src/can_reader.rs +++ b/candid_server/src/can_reader.rs @@ -1,17 +1,17 @@ use std::sync::{mpsc, Arc, Mutex}; use std::thread; -use socketcan::{CANFrame, CANSocket}; +use socketcan::{CanFrame, CanSocket, Socket}; /// Reads from the opened CAN socket and relays each frame to each stored client pub struct CANReader { - can_socket: Arc>, - clients: Arc>>>, + can_socket: Arc>, + clients: Arc>>>, } impl CANReader { /// Creates a new `CANReader` from the given socket. Spawns one thread for reading frames - pub fn new(socket: CANSocket) -> (CANReader, thread::JoinHandle<()>) { + pub fn new(socket: CanSocket) -> (CANReader, thread::JoinHandle<()>) { let reader = CANReader { can_socket: Arc::new(Mutex::new(socket)), clients: Arc::new(Mutex::new(Vec::new())), @@ -45,12 +45,12 @@ impl CANReader { } /// Registers a client with this `CANReader` - pub fn add_client(&self, channel: mpsc::Sender) { + pub fn add_client(&self, channel: mpsc::Sender) { self.clients.lock().unwrap().push(channel); } /// Returns a copy of the underlying `CANsocket` - pub fn get_socket(&self) -> Arc> { + pub fn get_socket(&self) -> Arc> { Arc::clone(&self.can_socket) } } diff --git a/candid_server/src/client_handler.rs b/candid_server/src/client_handler.rs index 5b0e229..aa6012b 100644 --- a/candid_server/src/client_handler.rs +++ b/candid_server/src/client_handler.rs @@ -4,15 +4,14 @@ use std::sync::mpsc; use std::thread; use byteorder::{NetworkEndian, ReadBytesExt, WriteBytesExt}; - -use socketcan::{CANFrame, CANSocket}; +use socketcan::{CanFrame, CanSocket, EmbeddedFrame, ExtendedId, Socket}; /// Spawns two threads: one to read incoming frames from the client (and write them to the -/// CANSocket), and one to read incoming frames from the `CANReader` (and write them to the client) +/// CanSocket), and one to read incoming frames from the `CANReader` (and write them to the client) pub fn new_client_handler( mut connection: TcpStream, can_interface: String, - can_reader: mpsc::Receiver, + can_reader: mpsc::Receiver, ) -> (thread::JoinHandle<()>, thread::JoinHandle<()>) { let connection_clone = connection.try_clone().unwrap(); // Thread to pass frames from the server to the client @@ -37,17 +36,18 @@ pub fn new_client_handler( let mut connection = BufReader::new(connection_clone); // Possible issue: There is a new socket for each thread - let can_socket = CANSocket::open(&can_interface).unwrap(); + let can_socket = CanSocket::open(&can_interface).unwrap(); loop { // Get an incoming frame from the client - let id; - if let Ok(inner) = connection.read_u32::() { - id = inner; - } else { + let Some(id) = connection + .read_u32::() + .ok() + .and_then(ExtendedId::new) + else { println!("Connection to client {:?} dropped.", ip); break; - } + }; let mut data = [0 as u8; 8]; if connection.read_exact(&mut data).is_err() { @@ -56,7 +56,7 @@ pub fn new_client_handler( } // Write the frame to the CAN Socket - let frame = CANFrame::new(id, &data, false, false).unwrap(); + let frame = CanFrame::new(id, &data).unwrap(); can_socket.write_frame_insist(&frame).unwrap(); } }); @@ -64,9 +64,13 @@ pub fn new_client_handler( (tx_handle, rx_handle) } -fn send_frame(connection: &mut TcpStream, frame: CANFrame) -> Result<(), std::io::Error> { - connection.write_u32::(frame.id())?; - connection.write_all(&frame.data())?; +fn send_frame(connection: &mut TcpStream, frame: CanFrame) -> Result<(), std::io::Error> { + let id = match frame.id() { + socketcan::Id::Standard(id) => id.as_raw() as u32, + socketcan::Id::Extended(id) => id.as_raw(), + }; + connection.write_u32::(id)?; + connection.write_all(frame.data())?; connection.flush().unwrap(); Ok(()) } diff --git a/candid_server/src/main.rs b/candid_server/src/main.rs index 1dd3a19..fb9464e 100644 --- a/candid_server/src/main.rs +++ b/candid_server/src/main.rs @@ -23,7 +23,7 @@ use candid_server::{can_reader::CANReader, client_handler::new_client_handler}; use std::net::TcpListener; use std::sync::mpsc; -use socketcan::CANSocket; +use socketcan::{CanSocket, Socket}; use clap::{App, Arg}; @@ -53,7 +53,7 @@ fn main() { let can_interface = matches.value_of("bus").unwrap(); // Open CAN Socket - let can_socket = CANSocket::open(can_interface).expect("Could not open CAN socket"); + let can_socket = CanSocket::open(can_interface).expect("Could not open CAN socket"); // Instantiate CANReader let (can_reader, _) = CANReader::new(can_socket); -- 2.51.2