Skip to content

Commit

Permalink
Add github CI, improve README
Browse files Browse the repository at this point in the history
This also fixes up runner.sh for the new(ish) VPN layout.
  • Loading branch information
ThirteenFish committed Jun 21, 2024
1 parent a8534a9 commit 3ae56d6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Reference:
# - https://doc.rust-lang.org/stable/clippy/continuous_integration/github_actions.html
# - https://github.com/actions/starter-workflows/blob/main/ci/rust.yml
on: push

name: Clippy check

# Make sure CI fails on all warnings, including Clippy lints
env:
RUSTFLAGS: "-Dwarnings"
CARGO_TERM_COLOR: always

jobs:
clippy_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run fmt
run: cargo fmt
- name: Run Clippy
run: cargo clippy --all-targets --all-features
- name: Run tests
run: cargo test --verbose
55 changes: 48 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
Ensure rust is up to date: `rustup update`
Install the cross toolchain: `rustup target add armv7-unknown-linux-gnueabihf`
Install cargo-deb: `cargo install cargo-deb`
# Virtual watchdog for the [OreSat C3](https://github.com/oresat/oresat-c3-hardware)

If it complains about incompatible GLIBC versions consider using an older cross compiler toolchain
https://github.com/abhiTronix/raspberry-pi-cross-compilers
The C3 has a radiation tolerant watchdog circuit that will power cycle the whole satellite if it
hasn't been pet in the last 24 seconds (36s on startup). A "pet" is the rising edge of the GPIO
line `PET_WDT`. It should be kept high for a reasonable amount of time, at least ~10ms, but both
the level and falling edge do not reset the timeout. `PET_WDT` is also attached to an LED so having
a pattern that is pleasing to look at is a plus.

This application provides software configurable interface to the watchdog hardware. Currently the
two knobs are the initial inhibit time and ongoing reset time. It also provides a UDP interface
instead of GPIO. This was initially written as a quick-to-start shim that can postpone the watchdog
while more heavyweight processes (like [oresatd](https://github.com/oresat/oresat-c3-software))
start which can take a while, at one point it wasn't able to catch the hardware watchdog in time.

```mermaid
graph TD;
A(Inhibit) --> B(Timeout);
B --> C;
C(Packet) --> B;
C --> D(Quit);
E(High) --> F(Low);
F --> E;
```

The watchdog listens on UDP localhost:20001 for any packet, which resets the timeout. The contents
do not matter and are discarded. This currently doesn't do any kind of exclusion or voting which
is part of more proper software watchdog system, leaving that for programs up the stack.

## Building
[Install Rust](https://www.rust-lang.org/tools/install) or ensure it is up to date: `rustup update`

Build the program: `cargo b`

### Cross compiling to run on the C3
The C3 is an ARM system so to run the watchdog in its produciton environment you'll need to install
the cross toolchain: `rustup target add armv7-unknown-linux-gnueabihf` and add the `--target` flag
to all cargo commands:

Compile and run the watchdog:
`cargo r --target armv7-unknown-linux-gnueabihf`

Build a debian package:
This will also execute `runner.sh`. This script is currently set up to run the watchdog on the
[flatsat C3](https://github.com/oresat/oresat-flatsat) but you'll need to be connected to the
OreSat VPN for this to work. This script could alternatively be modified to launch a local VM for
local testing.

If it complains about incompatible GLIBC versions consider using an older cross compiler toolchain
[like this one](https://github.com/abhiTronix/raspberry-pi-cross-compilers), and set the linker in
.cargo/config.toml

### Build a debian package:
Install cargo-deb: `cargo install cargo-deb`
Version set in Cargo.toml. If doing a release be sure to also make a tag
`cargo deb --target armv7-unknown-linux-gnueabihf`
Package will be in `target/armv7-unknown-linux-gnueabihf/debian/`
2 changes: 1 addition & 1 deletion runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ bin=$1
shift

user="debian" # password: tmppwd
host="oresat-c3.local"
host="c3.oresat.org"
path="pet-wdt"

target="$user@$host"
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ impl Pingee {
while match self.socket.recv_from(&mut buf) {
Ok(_) => true,
Err(e) if e.kind() == ErrorKind::WouldBlock => false,
Err(e) => return Err(e).context("Ping socket read failed")
} {};
Err(e) => return Err(e).context("Ping socket read failed"),
} {}
if let (Some(OneShot(remaining)), OneShot(ping)) = (self.timer.get()?, PING_TIMEOUT) {
if remaining < ping {
self.timer.set(PING_TIMEOUT, TimerSetTimeFlags::empty())?;
Expand Down

0 comments on commit 3ae56d6

Please sign in to comment.