Skip to content

Commit

Permalink
Consolidate state structure to an enum. Move message decleration of r… (
Browse files Browse the repository at this point in the history
#8)

* Consolidate state structure to an enum. Move message decleration of reset reason back to stm32h7xx-hal crate.

* Change path to git crate resolution.

* Strip unnecessary feature flags and document.
  • Loading branch information
NoahSprenger authored Jan 10, 2025
1 parent a78e3e4 commit 3ac02d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 45 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ proptest-derive = { version = "0.3.0", optional = true }
messages-proc-macros-lib = { path = "messages-proc-macros-lib" }
chrono = { git = "https://github.com/uorocketry/chrono", features = ["serde"], default-features = false }
ublox = { git = "https://github.com/uorocketry/ublox", features = ["serde"], default-features = false }
# The actual version imported does not matter as reset reason is not behind or affected by any feature flags.
stm32h7xx-hal = { git = "https://github.com/uorocketry/stm32h7xx-hal", features = ["defmt", "stm32h735"] }

[dev-dependencies]
proptest = "1.2.0"
Expand All @@ -28,4 +30,4 @@ postcard = { version = "1.0.4", features = ["alloc"] }

[features]
default = ["mavlink/embedded-hal-02", "mavlink/uorocketry"]
std = ["chrono/std", "chrono/arbitrary", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"]
std = ["stm32h7xx-hal/arbitrary", "chrono/std", "chrono/arbitrary", "mavlink/std", "mavlink/tcp", "mavlink/udp", "mavlink/direct-serial", "mavlink/serde", "dep:proptest", "dep:proptest-derive"]
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct CanMessage {
#[common_derives]

Check warning on line 69 in src/lib.rs

View workflow job for this annotation

GitHub Actions / test

non-local `impl` definition, `impl` blocks should be written at the same level as their item
#[derive(From)]
pub enum Common {
ResetReason(sensor::ResetReason),
ResetReason(stm32h7xx_hal::rcc::ResetReason),
Command(command::Command),
Log(Log),
}
Expand Down
33 changes: 0 additions & 33 deletions src/sensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,6 @@ pub enum SbgData {
GpsPos(GpsPos),
}

/* Replace with new health monitor */

#[common_derives]
pub enum ResetReason {
/// The mcu went from not having power to having power and resetting
PowerOnReset,
/// The reset pin was asserted
PinReset,
/// The brownout detector triggered
BrownoutReset,
/// The software did a soft reset through the SCB peripheral
SystemReset,
/// The software did a soft reset through the RCC periperal
CpuReset,
/// The window watchdog triggered
WindowWatchdogReset,
/// The independent watchdog triggered
IndependentWatchdogReset,
/// Either of the two watchdogs triggered (but we don't know which one)
GenericWatchdogReset,
/// The DStandby mode was exited
D1ExitsDStandbyMode,
/// The DStandby mode was exited
D2ExitsDStandbyMode,
/// A state has been entered erroneously
D1EntersDStandbyErroneouslyOrCpuEntersCStopErroneously,
/// The reason could not be determined
Unknown {
/// The raw register value
rcc_rsr: u32,
},
}

#[common_derives]
pub struct GpsPos {
#[doc = "< Latitude in degrees, positive north."]
Expand Down
20 changes: 10 additions & 10 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use messages_proc_macros_lib::common_derives;

#[common_derives]
pub struct State {
pub data: StateData,
}
// #[common_derives]
// pub struct State {
// pub data: StateData,
// }

#[common_derives]
pub enum StateData {
pub enum State {
Initializing,
WaitForTakeoff,
Ascent,
Expand All @@ -16,8 +16,8 @@ pub enum StateData {
Abort,
}

impl State {
pub fn new(data: impl Into<StateData>) -> Self {
State { data: data.into() }
}
}
// impl State {
// pub fn new(data: impl Into<StateData>) -> Self {
// State { data: data.into() }
// }
// }

0 comments on commit 3ac02d0

Please sign in to comment.