From 3236b9be0870c79ee669e3c89b58a097b1cc62fb Mon Sep 17 00:00:00 2001 From: Florian Guggi Date: Tue, 2 Sep 2025 20:11:03 +0200 Subject: [PATCH 1/2] feat: Add tool for extracting simple-archives --- .github/workflows/cross.yml | 2 + .github/workflows/rust.yml | 16 ++- Cargo.lock | 240 +++++++++++++++++++++++++++++++++++- simple-archive/Cargo.toml | 3 + simple-archive/src/main.rs | 52 ++++++++ 5 files changed, 307 insertions(+), 6 deletions(-) create mode 100644 simple-archive/src/main.rs diff --git a/.github/workflows/cross.yml b/.github/workflows/cross.yml index 95e6f98..e55b1cd 100644 --- a/.github/workflows/cross.yml +++ b/.github/workflows/cross.yml @@ -17,6 +17,7 @@ jobs: cross build --examples --bins --release --target aarch64-unknown-linux-gnu mv target/aarch64-unknown-linux-gnu/release/STS1_EDU_Scheduler . mv target/aarch64-unknown-linux-gnu/release/examples/cli . + mv target/aarch64-unknown-linux-gnu/release/simple-archive cp scheduler/config.toml . cp scheduler/scheduler.service . - name: Upload artifact @@ -28,3 +29,4 @@ jobs: config.toml scheduler.service cli + simple-archive diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d115c6a..1e7c321 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -15,7 +15,7 @@ jobs: - name: Install run: sudo apt install socat libudev-dev - name: Build - run: cargo build --release + run: cargo build --release -p STS1_EDU_Scheduler - name: Run tests run: cargo test --release --features mock @@ -29,3 +29,17 @@ jobs: run: cargo clippy -- -D warnings - name: Formatting run: cargo fmt --all --check + + tools: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: | + cargo build --release -p simple-archive + mv target/release/simple-archive ./sa + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: amd64 package + path: sa diff --git a/Cargo.lock b/Cargo.lock index 8d35db6..54690de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "STS1_EDU_Scheduler" @@ -40,6 +40,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + [[package]] name = "aho-corasick" version = "1.1.3" @@ -49,11 +55,61 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" +dependencies = [ + "windows-sys 0.60.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.60.2", +] + [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" dependencies = [ "backtrace", ] @@ -74,7 +130,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.7.4", "object", "rustc-demangle", ] @@ -115,6 +171,52 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.5.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -222,6 +324,16 @@ dependencies = [ "serde", ] +[[package]] +name = "flate2" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" +dependencies = [ + "crc32fast", + "miniz_oxide 0.8.9", +] + [[package]] name = "fuzzy-matcher" version = "0.3.7" @@ -318,6 +430,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itoa" version = "1.0.11" @@ -396,6 +514,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", +] + [[package]] name = "mio" version = "0.8.11" @@ -467,6 +594,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + [[package]] name = "parking_lot" version = "0.12.3" @@ -700,6 +833,11 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "simple-archive" version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "flate2", +] [[package]] name = "simplelog" @@ -718,6 +856,12 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.26.3" @@ -927,6 +1071,12 @@ version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -964,6 +1114,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + [[package]] name = "windows-sys" version = "0.48.0" @@ -991,6 +1147,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -1015,13 +1180,30 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm", + "windows_i686_gnullvm 0.52.6", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -1034,6 +1216,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -1046,6 +1234,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -1058,12 +1252,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[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_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -1076,6 +1282,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -1088,6 +1300,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -1100,6 +1318,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -1112,6 +1336,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "winnow" version = "0.6.18" diff --git a/simple-archive/Cargo.toml b/simple-archive/Cargo.toml index a535dd6..161bbfd 100644 --- a/simple-archive/Cargo.toml +++ b/simple-archive/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = "2021" [dependencies] +anyhow = "1.0.99" +clap = { version = "4.5.47", features = ["derive"] } +flate2 = "1.1.2" [lints] workspace = true diff --git a/simple-archive/src/main.rs b/simple-archive/src/main.rs new file mode 100644 index 0000000..013fd40 --- /dev/null +++ b/simple-archive/src/main.rs @@ -0,0 +1,52 @@ +use clap::Parser; +use std::{ + io::{Cursor, Read}, + path::PathBuf, +}; + +#[derive(clap::Parser, Debug)] +/// A small tool to extract simple-archives which are returned by the EDU scheduler +struct Args { + /// Archive to extract + file: PathBuf, + + #[arg(short, long)] + /// Path into which the archive is extracted + output: Option, + + #[arg(long, action)] + /// Do not decompress GZIP encoded data + no_decompress: bool, +} + +fn main() -> anyhow::Result<()> { + let args = Args::parse(); + + let output_path = args.output.unwrap_or(PathBuf::from(".")); + let file = std::fs::File::open(args.file)?; + let reader = simple_archive::Reader::new(file); + + for file in reader { + match file { + Ok(f) => { + let data = if args.no_decompress { + f.data + } else { + let mut decoder = flate2::read::GzDecoder::new(Cursor::new(f.data)); + if decoder.header().is_some() { + let mut buffer = Vec::new(); + decoder.read_to_end(&mut buffer)?; + buffer + } else { + decoder.into_inner().into_inner() + } + }; + + std::fs::write(output_path.join(f.path), data)?; + } + Err(e) => eprintln!("Failed to parse entry {e}"), + } + } + + Ok(()) +} From 9cdd8fef3f77fddecf095c1d90cbccdcb95dd122 Mon Sep 17 00:00:00 2001 From: Florian Guggi Date: Tue, 2 Sep 2025 20:11:23 +0200 Subject: [PATCH 2/2] fix: Update config file for COBC sim tool --- scheduler/examples/cli.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scheduler/examples/cli.rs b/scheduler/examples/cli.rs index 4c00fd0..0ebebb9 100644 --- a/scheduler/examples/cli.rs +++ b/scheduler/examples/cli.rs @@ -1,7 +1,7 @@ use std::{ error::Error, io::{Read, Write}, - path::Path, + path::{Path, PathBuf}, process::{Child, ChildStdin, ChildStdout, Stdio}, time::Duration, }; @@ -9,13 +9,14 @@ use std::{ use STS1_EDU_Scheduler::communication::{CEPPacket, CommunicationHandle}; fn main() { - let scheduler_path = - std::env::args().nth(1).expect("Pass in the directory containing the scheduler binary"); + let scheduler_path = PathBuf::from( + std::env::args().nth(1).expect("Pass in the directory containing the scheduler binary"), + ); - let mut serial = SocatSerialPort::new(&format!("{scheduler_path}/virtualserial")); + let mut serial = SocatSerialPort::new(&scheduler_path.join("virtualserial")); write_scheduler_config(&scheduler_path); let _scheduler = PoisonedChild( - std::process::Command::new(format!("{scheduler_path}/STS1_EDU_Scheduler")) + std::process::Command::new("./STS1_EDU_Scheduler") .current_dir(&scheduler_path) .spawn() .unwrap(), @@ -35,10 +36,10 @@ pub struct SocatSerialPort { } impl SocatSerialPort { - fn new(path: &str) -> Self { + fn new(path: &Path) -> Self { let mut child = std::process::Command::new("socat") .arg("stdio") - .arg(format!("pty,raw,echo=0,link={path},b921600,wait-slave")) + .arg(format!("pty,raw,echo=0,link={},b921600,wait-slave", path.display())) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn() @@ -57,9 +58,9 @@ impl SocatSerialPort { } } -fn write_scheduler_config(path: &str) { +fn write_scheduler_config(path: &Path) { std::fs::write( - format!("{path}/config.toml"), + path.join("config.toml"), " uart = \"virtualserial\" baudrate = 921600 @@ -67,6 +68,7 @@ fn write_scheduler_config(path: &str) { update_pin = 35 heartbeat_freq = 10 log_path = \"log\" + socket = \"/tmp/scheduler_socket\" ", ) .unwrap(); @@ -77,10 +79,10 @@ const COMMANDS: &[&str] = fn inquire_and_send_command( edu: &mut impl CommunicationHandle, - path: &str, + path: &Path, ) -> Result<(), Box> { let mut select = inquire::Select::new("Select command", COMMANDS.to_vec()); - if Path::new(&format!("{path}/updatepin")).exists() { + if path.join("updatepin").exists() { select.help_message = Some("Update Pin is high"); } let command = select.prompt()?;