summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-03-27 23:01:57 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-03-27 23:01:57 +0100
commit02c818b05f34ce6dae8e8e077e17cc7f2fc9a92d (patch)
tree77c38ddd325c576fb4c3daa10edb1fe779e8fbc6
parent3ba980bb08fa72e0206252bf7d43a5af0ef882f2 (diff)
downloadcandump-rs-02c818b05f34ce6dae8e8e077e17cc7f2fc9a92d.tar.bz2
time and cmdline argsHEADmaster
-rw-r--r--Cargo.lock18
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs24
3 files changed, 41 insertions, 2 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 305ad91..b54a36d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -37,6 +37,7 @@ dependencies = [
"futures 0.2.0-beta (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)",
"socketcan 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -330,6 +331,11 @@ dependencies = [
]
[[package]]
+name = "redox_syscall"
+version = "0.1.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
name = "scopeguard"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -352,6 +358,16 @@ dependencies = [
]
[[package]]
+name = "time"
+version = "0.1.39"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "tokio"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -520,9 +536,11 @@ dependencies = [
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
"checksum pin-api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4806efe6dbda279bde1fe6e07de93e0a022487f290b5dee3e465793e1c34f7ad"
"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5"
+"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd"
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
"checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d"
"checksum socketcan 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3101efc6ef5af6f1c1a488241b469757b7a183baca63af958cd90e4696446c80"
+"checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098"
"checksum tokio 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "65bd27f59c223e7c9e406bcdadb453e143bcf1242e162ae6c0f0eb6d14487306"
"checksum tokio-executor 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3aca092a94dc6e736819347a990a86ed734a6543a9d6f817929fa4dc8c4334e2"
"checksum tokio-io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6af9eb326f64b2d6b68438e1953341e00ab3cf54de7e35d92bfc73af8555313a"
diff --git a/Cargo.toml b/Cargo.toml
index f3d2d82..4222a0e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,4 +7,5 @@ version = "0.1.0"
futures = "0.2.0-beta"
mio = "0.6.14"
socketcan = "1.7.0"
+time = "0.1.39"
tokio = "0.1.4"
diff --git a/src/main.rs b/src/main.rs
index b899e09..ad10aa2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@ extern crate socketcan;
extern crate tokio;
extern crate futures;
extern crate mio;
+extern crate time;
use mio::{Ready, Poll, PollOpt, Token};
use mio::event::Evented;
@@ -13,6 +14,8 @@ use tokio::prelude::*;
use std::os::unix::io::AsRawFd;
use std::io;
+use std::env;
+
// Can Stream which is tokioable et al..
pub struct EventableCANSocket {
@@ -64,6 +67,7 @@ impl Stream for CANStream {
fn poll(&mut self) -> Result<Async<Option<Self::Item>>, Self::Error> {
// We shouldn't be woken unless we're ready, but just in case, let's
// ensure...
+
let readiness = match self.socket.poll_read_ready(Ready::readable())? {
Async::NotReady => { return Ok(Async::NotReady) },
Async::Ready(r) => r
@@ -84,7 +88,18 @@ impl Stream for CANStream {
fn main() {
println!("Starting up candump-rs");
- let evented = match EventableCANSocket::from_interfacename("vcan0") {
+ let args: Vec<String> = env::args().collect();
+
+ if args.len() != 2 {
+ println!("args supplied: {}", args.len() - 1);
+ panic!("You must supply exactly one argument - the CAN interface name");
+ }
+
+ let ifname = &args[1];
+
+ println!("Creating CAN socket against {}", ifname);
+
+ let evented = match EventableCANSocket::from_interfacename(ifname) {
Ok(v) => v,
Err(e) => panic!("Unable to open socket: {}", e)
};
@@ -98,7 +113,12 @@ fn main() {
tokio::run(streamed
.map_err(|e| println!("error = {:?}", e))
.for_each(|frame| {
- println!("Received a frame: {:?}", frame);
+ let ts = time::now_utc().to_timespec();
+ print!("({}.{:06}) vcan0 {:03x}#", ts.sec, ts.nsec / 1000, frame.id());
+ for byte in frame.data().iter() {
+ print!("{:02x}", byte);
+ }
+ println!("");
Ok(())
}));