diff --git a/Cargo.lock b/Cargo.lock index 1b9e0ce..ceebca5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,14 +16,134 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "csv-async" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "888dbb0f640d2c4c04e50f933885c7e9c95995d93cec90aba8735b4c610f26f1" +dependencies = [ + "cfg-if", + "csv-core", + "futures", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704a3c26996a80471189265814dbc2c257598b96b8a7feae2d31ace646bb9782" +dependencies = [ + "memchr", +] + [[package]] name = "flight-computer" version = "0.1.0" dependencies = [ + "csv-async", "protocols", + "serde", "tokio", ] +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "introduction" version = "0.1.0" @@ -66,6 +186,12 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "proc-macro2" version = "1.0.103" @@ -150,6 +276,12 @@ dependencies = [ "serde_core", ] +[[package]] +name = "slab" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589" + [[package]] name = "socket2" version = "0.6.1" diff --git a/flight-computer/Cargo.toml b/flight-computer/Cargo.toml index 3a39e7d..ef04a4e 100644 --- a/flight-computer/Cargo.toml +++ b/flight-computer/Cargo.toml @@ -5,7 +5,11 @@ edition = "2024" [dependencies] protocols = { version = "0.1.0", path = "../protocols" } -tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "time"] } +tokio = { version = "1.48.0", features = ["macros", "rt-multi-thread", "time", "fs"] } +csv-async = "1.3.1" +serde = "1.0.228" + [lints] workspace = true + diff --git a/flight-computer/src/input.rs b/flight-computer/src/input.rs index edb1117..28251a2 100644 --- a/flight-computer/src/input.rs +++ b/flight-computer/src/input.rs @@ -6,8 +6,10 @@ use protocols::api::{Location, SensorMessage}; use protocols::api::{TelemetryDataMessage, Velocity}; use protocols::client::MessageSender; use protocols::server::MessageReceiver; +use serde::Serialize; /// Stores the current inputs of the system, given by the avionics +#[derive(serde::Serialize)] pub struct Inputs { pub location: Location, pub velocity: Velocity, diff --git a/flight-computer/src/main.rs b/flight-computer/src/main.rs index 669c0be..10bf92e 100644 --- a/flight-computer/src/main.rs +++ b/flight-computer/src/main.rs @@ -1,16 +1,34 @@ use std::time::Duration; +use csv_async::{AsyncSerializer, AsyncWriterBuilder}; use protocols::api::{ AvionicsCommandMessage, SensorMessage, TelemetryCommandMessage, TelemetryDataMessage, }; use protocols::client::MessageSender; use protocols::server::MessageReceiver; +use std::error::Error; +use tokio::fs::File; pub mod input; pub mod state_machine; #[tokio::main] async fn main() -> Result<(), Box> { + // create csv file + let mut file_location = File::create("loc.csv").await?; + + let mut file_velocity = File::create("velocity.csv").await?; + + // initialize writer + let mut wrt = AsyncWriterBuilder::new().has_headers(true).create_writer(vec![]); + + // initialize serializer + let mut ser = AsyncSerializer::from_writer(vec![]); + + let mut wrt = AsyncWriterBuilder::new().has_headers(true).create_writer(vec![]); + let mut ser_2 = AsyncSerializer::from_writer(vec![]); + + // Initialize inputs let mut inputs = input::Inputs::default(); @@ -41,6 +59,15 @@ async fn main() -> Result<(), Box> { inputs.location.altitude, inputs.velocity.down ); + // insert data + ser.serialize(& + inputs.location + ).await?; + + ser_2.serialize(&inputs.velocity).await?; + + + } // Handle incoming telemetry commands diff --git a/foo.csv b/foo.csv new file mode 100644 index 0000000..e69de29 diff --git a/loc.csv b/loc.csv new file mode 100644 index 0000000..e69de29 diff --git a/velocity.csv b/velocity.csv new file mode 100644 index 0000000..e69de29