Skip to content
Snippets Groups Projects
Commit d40398ef authored by Federico Lolli's avatar Federico Lolli
Browse files

added csv loading

parent 47a2c2f5
No related branches found
No related tags found
No related merge requests found
...@@ -131,6 +131,33 @@ version = "1.0.0" ...@@ -131,6 +131,33 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "csv"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe"
dependencies = [
"csv-core",
"itoa",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
dependencies = [
"memchr",
]
[[package]]
name = "itoa"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.151" version = "0.2.151"
...@@ -198,6 +225,24 @@ version = "0.3.27" ...@@ -198,6 +225,24 @@ version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "proc-macro2"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.10.2" version = "1.10.2"
...@@ -227,17 +272,45 @@ version = "0.8.2" ...@@ -227,17 +272,45 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "ryu"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.2.0" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "serial-middle" name = "serial-middle"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"clap", "clap",
"csv",
"serde",
"serialport", "serialport",
] ]
...@@ -265,6 +338,23 @@ version = "0.10.0" ...@@ -265,6 +338,23 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "2.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]] [[package]]
name = "utf8parse" name = "utf8parse"
version = "0.2.1" version = "0.2.1"
......
...@@ -7,4 +7,6 @@ edition = "2021" ...@@ -7,4 +7,6 @@ edition = "2021"
[dependencies] [dependencies]
clap = "4.4.11" clap = "4.4.11"
csv = "1.3.0"
serde = { version = "1.0.193", features = ["derive"] }
serialport = "4.2.2" serialport = "4.2.2"
This diff is collapsed.
#[derive(Debug, Clone, Default)] use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MavlinkPayloadFlightTM { pub struct MavlinkPayloadFlightTM {
// [us] Timestamp in microseconds // [us] Timestamp in microseconds
timestamp: u64, timestamp: u64,
......
...@@ -33,6 +33,14 @@ fn get_first_stm32_serial_port() -> Option<String> { ...@@ -33,6 +33,14 @@ fn get_first_stm32_serial_port() -> Option<String> {
} }
fn main() { fn main() {
let mut packets = Vec::new();
let mut rdr = csv::Reader::from_reader(std::fs::File::open("gemini.csv").unwrap());
for result in rdr.deserialize() {
let record: MavlinkPayloadFlightTM = result.unwrap();
packets.push(record);
}
// Open the first serialport available. // Open the first serialport available.
let port_name = get_first_stm32_serial_port().expect("No STM32 serial port found!"); let port_name = get_first_stm32_serial_port().expect("No STM32 serial port found!");
let mut port = serialport::new(port_name, 115200) let mut port = serialport::new(port_name, 115200)
...@@ -40,6 +48,8 @@ fn main() { ...@@ -40,6 +48,8 @@ fn main() {
.expect("Failed to open serial port"); .expect("Failed to open serial port");
let mut write_port = port.try_clone().expect("Failed to clone"); let mut write_port = port.try_clone().expect("Failed to clone");
let mut iter = packets.into_iter();
// read from buffer and print to stdout // read from buffer and print to stdout
let mut buffer = [0u8; 1000]; let mut buffer = [0u8; 1000];
loop { loop {
...@@ -49,9 +59,16 @@ fn main() { ...@@ -49,9 +59,16 @@ fn main() {
let input = String::from_utf8_lossy(&buffer[..t]); let input = String::from_utf8_lossy(&buffer[..t]);
// if we got the signal to start sending data, send it // if we got the signal to start sending data, send it
if input.contains("[WAITING]") { if input.contains("[WAITING]") {
write_port.write_packet(MavlinkPayloadFlightTM::default()); if let Some(packet) = iter.next() {
write_port.write_packet(packet);
}
}
// std::io::stdout().write_all(&input.as_bytes()).unwrap();
for line in input.lines() {
if !line.contains("[WAITING]") {
println!("{}", line);
}
} }
io::stdout().write_all(input.as_bytes()).unwrap();
} }
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (), Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (),
Err(e) => eprintln!("{:?}", e), Err(e) => eprintln!("{:?}", e),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment