From 6cf155deffc43a7f24f6866f84c72f760294436a Mon Sep 17 00:00:00 2001 From: SCool62 Date: Sun, 16 Mar 2025 14:49:48 -0700 Subject: [PATCH 1/5] Remove all the ugly rustup commands --- .github/workflows/rust.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dbea474..6313fa1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,19 +16,11 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Install nightly rust - run: rustup toolchain install nightly - - name: Make nightly default - run: rustup default nightly - - name: Install build target - run: rustup target add thumbv7em-none-eabi - - name: Print installed toolchains - run: rustup show + - uses: dtolnay/rust-toolchain@nightly + with: + targets: aarch64-apple-darwin, thumbv7em-none-eabi + components: rust-src - name: Build run: cargo build --release --target thumbv7em-none-eabi - - name: Install test target - run: rustup target add aarch64-apple-darwin - - name: Add rust src - run: rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu - name: Run tests run: cargo test -Zbuild-std --target x86_64-unknown-linux-gnu From f976ccb7004013fda2e4211a0336df22faee30e7 Mon Sep 17 00:00:00 2001 From: SCool62 Date: Sun, 16 Mar 2025 14:54:10 -0700 Subject: [PATCH 2/5] Add auto formatter action --- .github/workflows/format.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..761d5ec --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,27 @@ +name: Format + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - name: Run cargo fmt + run: cargo fmt + # Commit changes + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: format \ No newline at end of file From 4fa97bd9b54f46c55e2319b1e2c3be686802b026 Mon Sep 17 00:00:00 2001 From: SCool62 Date: Sun, 16 Mar 2025 14:59:07 -0700 Subject: [PATCH 3/5] Give permissions for commit --- .github/workflows/format.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 761d5ec..05b7760 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -10,7 +10,11 @@ env: CARGO_TERM_COLOR: always jobs: - build: + format: + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write runs-on: ubuntu-latest From ef021568bb84055556a58e99f96c4385f5899af9 Mon Sep 17 00:00:00 2001 From: SCool62 <79726681+SCool62@users.noreply.github.com> Date: Sun, 16 Mar 2025 21:59:28 +0000 Subject: [PATCH 4/5] format --- shared/src/communication/eps.rs | 55 ++++++++++++++++----------------- shared/src/communication/mod.rs | 2 +- shared/src/lib.rs | 2 +- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/shared/src/communication/eps.rs b/shared/src/communication/eps.rs index e834907..5a008ab 100644 --- a/shared/src/communication/eps.rs +++ b/shared/src/communication/eps.rs @@ -15,33 +15,31 @@ impl EpsCommand { pub fn from_bytes(bytes: &[u8]) -> Result { let mut words = bytes.split(|b| b == b";".iter().next().unwrap()); match words.next() { - Some(word) => { - match word { - b"pwe" => { - let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; - let rail_num = core::str::from_utf8(arg)?.parse::()?; - Ok(EpsCommand::EnablePowerRail(rail_num)) - }, - b"pwd" => { - let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; - let rail_num = core::str::from_utf8(arg)?.parse::()?; - Ok(EpsCommand::DisablePowerRail(rail_num)) - }, - b"soh" => return Ok(Self::StateOfHealthReq), - b"gbv" => { - let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; - let rail_num = core::str::from_utf8(arg)?.parse::()?; - Ok(EpsCommand::GetBatteryVoltage(rail_num)) - }, - b"gprs" => { - let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; - let rail_num = core::str::from_utf8(arg)?.parse::()?; - Ok(EpsCommand::GetPowerRailState(rail_num)) - }, - _ => Err(CommandParseError::UnknownCommand) + Some(word) => match word { + b"pwe" => { + let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; + let rail_num = core::str::from_utf8(arg)?.parse::()?; + Ok(EpsCommand::EnablePowerRail(rail_num)) } + b"pwd" => { + let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; + let rail_num = core::str::from_utf8(arg)?.parse::()?; + Ok(EpsCommand::DisablePowerRail(rail_num)) + } + b"soh" => return Ok(Self::StateOfHealthReq), + b"gbv" => { + let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; + let rail_num = core::str::from_utf8(arg)?.parse::()?; + Ok(EpsCommand::GetBatteryVoltage(rail_num)) + } + b"gprs" => { + let arg = words.next().ok_or(CommandParseError::IncompleteArgs)?; + let rail_num = core::str::from_utf8(arg)?.parse::()?; + Ok(EpsCommand::GetPowerRailState(rail_num)) + } + _ => Err(CommandParseError::UnknownCommand), }, - None => Err(CommandParseError::EmptyMessage) + None => Err(CommandParseError::EmptyMessage), } } } @@ -57,7 +55,7 @@ pub enum CommandParseError { #[error("ParseIntError {0}")] ParseIntError(#[from] ParseIntError), #[error("Utf8Error {0}")] - Utf8Error(#[from] Utf8Error) + Utf8Error(#[from] Utf8Error), } impl CommandParseError { @@ -68,7 +66,7 @@ impl CommandParseError { UnknownCommand => b"err;501", IncompleteArgs => b"err;502", ParseIntError(_) => b"err;503", - Utf8Error(_) => b"err;504" + Utf8Error(_) => b"err;504", } } } @@ -104,5 +102,4 @@ mod tests { let error = core::str::from_utf8(&[0xC0]).err().unwrap(); assert_eq!(b"err;504", Utf8Error(error).as_bytes()); } - -} \ No newline at end of file +} diff --git a/shared/src/communication/mod.rs b/shared/src/communication/mod.rs index 0226f3b..133b974 100644 --- a/shared/src/communication/mod.rs +++ b/shared/src/communication/mod.rs @@ -1 +1 @@ -pub mod eps; \ No newline at end of file +pub mod eps; diff --git a/shared/src/lib.rs b/shared/src/lib.rs index a8ec4a3..5f0bc50 100644 --- a/shared/src/lib.rs +++ b/shared/src/lib.rs @@ -1,3 +1,3 @@ #![no_std] -pub mod communication; \ No newline at end of file +pub mod communication; From 1048fb88dc39125cd05ebf83f7d5c0770ef3ebc5 Mon Sep 17 00:00:00 2001 From: SCool62 Date: Sun, 16 Mar 2025 15:05:14 -0700 Subject: [PATCH 5/5] Don't install unneeded targets --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6313fa1..fce5d98 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly with: - targets: aarch64-apple-darwin, thumbv7em-none-eabi + targets: thumbv7em-none-eabi components: rust-src - name: Build run: cargo build --release --target thumbv7em-none-eabi