Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7370036
clean up connection logic
notoriaga Jun 7, 2021
43ae614
fileio
notoriaga Jun 8, 2021
5bbe897
Merge branch 'main' into steve/fileio
notoriaga Jun 8, 2021
5a02a35
pull in broadcaster
notoriaga Jun 8, 2021
1f83c44
cleanup
notoriaga Jun 8, 2021
a1a7caf
fix tests
notoriaga Jun 8, 2021
ec00a5b
remove io
notoriaga Jun 8, 2021
b695f4c
fmt
notoriaga Jun 8, 2021
a4a5fc0
lints
notoriaga Jun 8, 2021
1d7a66d
remove rand
notoriaga Jun 8, 2021
42e6bda
rebuild
notoriaga Jun 8, 2021
42f83d1
fix broadcaster
notoriaga Jun 8, 2021
394d57e
lints
notoriaga Jun 9, 2021
01492f7
lintz
notoriaga Jun 9, 2021
ed6249b
return result
notoriaga Jun 9, 2021
c57e0fa
Add iter methods to receiver
notoriaga Jun 10, 2021
da60bf0
have sender accept values or refs
notoriaga Jun 10, 2021
4059e4a
Add rand
notoriaga Jun 10, 2021
ebc7298
use slotmap for broadcast
notoriaga Jun 14, 2021
0d27a91
add connection struct
notoriaga Jun 14, 2021
b6e84dc
add fileio
notoriaga Jun 14, 2021
2e13480
add jank cli
notoriaga Jun 14, 2021
eb95dfe
maybe fix benchmarks
notoriaga Jun 14, 2021
4d02116
add util bin
notoriaga Jun 14, 2021
d4a3b20
bench = false
notoriaga Jun 14, 2021
e18e124
use connection struct more
notoriaga Jun 14, 2021
b48d00a
generic read/write
notoriaga Jun 15, 2021
6bf7bdd
track offset/sequence across writes
notoriaga Jun 15, 2021
7d97f41
cleanup
notoriaga Jun 15, 2021
3239268
lint
notoriaga Jun 15, 2021
234f456
more tests
notoriaga Jun 15, 2021
e3a33c8
another test
notoriaga Jun 15, 2021
8dfa5ec
comments
notoriaga Jun 15, 2021
234174a
add sleep
notoriaga Jun 15, 2021
3f41d68
Merge branch 'main' into steve/fileio-next
notoriaga Jun 16, 2021
613e0ea
fix close when done
notoriaga Jun 16, 2021
d609102
remove comment
notoriaga Jun 16, 2021
99ef0b6
Move sender id setting/constant to MsgSender
notoriaga Jun 18, 2021
74feb40
Merge branch 'main' into steve/fileio-next
notoriaga Jun 18, 2021
d908227
build
notoriaga Jun 21, 2021
a562726
Merge remote-tracking branch 'origin/main' into steve/fileio-next
Jun 21, 2021
656169e
s/write/overwrite
notoriaga Jun 21, 2021
7d50748
Merge branch 'steve/fileio-next' of github.com:swift-nav/console_pp i…
notoriaga Jun 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Cargo.lock

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

13 changes: 10 additions & 3 deletions console_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ capnp = "0.14"
chrono = { version = "0.4", features = ["serde"] }
csv = "1"
paste = "1"
pyo3 = { version = "0.13", features = ["extension-module"] }
sbp = { git = "https://github.com/swift-nav/libsbp.git", rev = "a5c221684439f2124306a2daa44126aac5457c80", features = ["json", "swiftnav-rs"] }
pyo3 = { version = "0.13", features = ["extension-module"], optional = true }
sbp = { git = "https://github.com/swift-nav/libsbp.git", rev = "ce5e3d14ae4284c53982bc3fd79a2fa15976ff9f", features = ["json", "swiftnav-rs"] }
serde = { version = "1.0.123", features = ["derive"] }
tempfile = "3.2.0"
ordered-float = "2.0"
Expand All @@ -33,6 +33,8 @@ clap = "3.0.0-beta.2"
indexmap = { version = "1.6.2", features = ["serde"] }
serde_json = { version = "1" }
crossbeam = "0.8.1"
rand = "0.8.3"
slotmap = "1.0.3"

[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
serialport = "4.0.1"
Expand All @@ -53,7 +55,12 @@ name = "console_backend"
crate-type = ["cdylib", "lib"]
bench = false

[[bin]]
name = "fileio"
path = "src/bin/fileio.rs"
bench = false

[features]
default = []
default = ["pyo3"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this optional because I was getting weird errors trying to run the new helper with cargo run. These backend utils shouldn't need to do all the python stuff anyways. So now to run the util you can do

cargo run --no-default-features --bin fileio ...

benches = []
tests = []
15 changes: 4 additions & 11 deletions console_backend/benches/cpu_benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use glob::glob;
use sbp::sbp_tools::SBPTools;
use std::{
fs,
fs, io,
path::Path,
sync::{mpsc, Arc, Mutex},
thread, time,
Expand All @@ -12,7 +12,7 @@ use std::{
extern crate console_backend;
use console_backend::{
process_messages,
types::{ClientSender, RealtimeDelay, SharedState},
types::{ClientSender, Connection, RealtimeDelay, SharedState},
};

const BENCH_FILEPATH: &str = "./tests/data/piksi-relay.sbp";
Expand Down Expand Up @@ -61,15 +61,8 @@ fn run_process_messages(file_in_name: &str, failure: bool) {
inner: client_send_,
};
shared_state.set_running(true, client_send.clone());
match fs::File::open(file_in_name) {
Ok(fileopen) => process_messages::process_messages(
fileopen,
shared_state,
client_send,
RealtimeDelay::Off,
),
Err(e) => panic!("unable to read file, {}.", e),
}
let conn = Connection::file(file_in_name.into()).unwrap();
process_messages::process_messages(conn, shared_state, client_send, RealtimeDelay::Off);
}
recv_thread.join().expect("join should succeed");
}
Expand Down
133 changes: 133 additions & 0 deletions console_backend/src/bin/fileio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
use std::{
fs,
io::{self, Write},
};

use clap::Clap;
use crossbeam::{channel, scope};
use sbp::sbp_tools::SBPTools;

use console_backend::{
broadcaster::Broadcaster,
cli_options::Input,
fileio::Fileio,
types::{MsgSender, Result},
};

#[derive(Clap, Debug)]
#[clap(about = "Fileio operations.")]
pub enum Opts {
/// Write a file from local source to remote destination dest.
Write {
source: String,
dest: String,
#[clap(subcommand)]
input: Input,
},

/// Read a file from remote source to local dest. If no dest is provided, file is read to stdout.
Read {
source: String,
dest: Option<String>,
#[clap(subcommand)]
input: Input,
},

/// List a directory.
List {
path: String,
#[clap(subcommand)]
input: Input,
},

/// Delete a file.
Delete {
path: String,
#[clap(subcommand)]
input: Input,
},
}

fn main() -> Result<()> {
let bc = Broadcaster::new();

let (done_tx, done_rx) = channel::bounded(0);

let bc_source = bc.clone();
let run = move |rdr| {
let messages = sbp::iter_messages(rdr).log_errors(log::Level::Debug);
for msg in messages {
bc_source.send(&msg);
if done_rx.try_recv().is_ok() {
break;
}
}
};

match Opts::parse() {
Opts::Write {
source,
dest,
input,
} => {
let (rdr, wtr) = input.into_conn()?.into_io();
let sender = MsgSender::new(wtr);
scope(|s| {
s.spawn(|_| run(rdr));
let mut fileio = Fileio::new(bc, sender);
let data = fs::File::open(source)?;
fileio.overwrite(dest, data)?;
eprintln!("file written successfully.");
done_tx.send(true).unwrap();
Result::Ok(())
})
.unwrap()
}
Opts::Read {
source,
dest,
input,
} => {
let (rdr, wtr) = input.into_conn()?.into_io();
let sender = MsgSender::new(wtr);
scope(|s| {
s.spawn(|_| run(rdr));
let mut fileio = Fileio::new(bc, sender);
let dest: Box<dyn Write> = match dest {
Some(path) => Box::new(fs::File::create(path)?),
None => Box::new(io::stdout()),
};
fileio.read(source, dest)?;
done_tx.send(true).unwrap();
Result::Ok(())
})
.unwrap()
}
Opts::List { path, input } => {
let (rdr, wtr) = input.into_conn()?.into_io();
let sender = MsgSender::new(wtr);
scope(|s| {
s.spawn(|_| run(rdr));
let mut fileio = Fileio::new(bc, sender);
let files = fileio.readdir(path)?;
eprintln!("{:#?}", files);
done_tx.send(true).unwrap();
Result::Ok(())
})
.unwrap()
}
Opts::Delete { path, input } => {
let (rdr, wtr) = input.into_conn()?.into_io();
let sender = MsgSender::new(wtr);
scope(|s| {
s.spawn(|_| run(rdr));
let fileio = Fileio::new(bc, sender);
fileio.remove(path)?;
eprintln!("file deleted.");
done_tx.send(true).unwrap();
Result::Ok(())
})
.unwrap()
}
}
}
Loading