style(v0.3): rustfmt power FSM/service/integration
Прогон cargo fmt (гейт lint): многострочное форматирование match-веток FSM, PowerMock/PowerService-литералов, integration-вызовов. Без изменений логики. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Alexander <akotenev2003@gmail.com>
This commit is contained in:
@@ -13,7 +13,10 @@ pub enum State {
|
|||||||
Off,
|
Off,
|
||||||
Accessory,
|
Accessory,
|
||||||
Running,
|
Running,
|
||||||
ShuttingDown { phase: Phase, reason: ShutdownReason },
|
ShuttingDown {
|
||||||
|
phase: Phase,
|
||||||
|
reason: ShutdownReason,
|
||||||
|
},
|
||||||
Sleep, // зарезервировано (полные sleep/wake — v1/v2)
|
Sleep, // зарезервировано (полные sleep/wake — v1/v2)
|
||||||
BatteryCutoff, // зарезервировано (long-park — v1/v2)
|
BatteryCutoff, // зарезервировано (long-park — v1/v2)
|
||||||
}
|
}
|
||||||
@@ -44,7 +47,9 @@ pub struct PowerFsm {
|
|||||||
|
|
||||||
impl Default for PowerFsm {
|
impl Default for PowerFsm {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { state: State::Running }
|
Self {
|
||||||
|
state: State::Running,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +83,10 @@ impl PowerFsm {
|
|||||||
/// Источник питания — сигнал потребителям «времени мало» при shutdown.
|
/// Источник питания — сигнал потребителям «времени мало» при shutdown.
|
||||||
pub fn source(&self) -> PowerSource {
|
pub fn source(&self) -> PowerSource {
|
||||||
match self.state {
|
match self.state {
|
||||||
State::ShuttingDown { reason: ShutdownReason::UnderVoltage, .. } => PowerSource::LowBattery,
|
State::ShuttingDown {
|
||||||
|
reason: ShutdownReason::UnderVoltage,
|
||||||
|
..
|
||||||
|
} => PowerSource::LowBattery,
|
||||||
State::ShuttingDown { .. } => PowerSource::HoldupCap,
|
State::ShuttingDown { .. } => PowerSource::HoldupCap,
|
||||||
_ => PowerSource::Vehicle12v,
|
_ => PowerSource::Vehicle12v,
|
||||||
}
|
}
|
||||||
@@ -104,7 +112,10 @@ impl PowerFsm {
|
|||||||
}
|
}
|
||||||
// ACC-off: линия ACC сменилась (AccChanged) + старт shutdown.
|
// ACC-off: линия ACC сменилась (AccChanged) + старт shutdown.
|
||||||
(Accessory | Running, E::AccOff) => {
|
(Accessory | Running, E::AccOff) => {
|
||||||
self.state = ShuttingDown { phase: Abortable, reason: ShutdownReason::AccOff };
|
self.state = ShuttingDown {
|
||||||
|
phase: Abortable,
|
||||||
|
reason: ShutdownReason::AccOff,
|
||||||
|
};
|
||||||
vec![
|
vec![
|
||||||
Action::AccChanged(false),
|
Action::AccChanged(false),
|
||||||
Action::ShutdownImminent(ShutdownReason::AccOff),
|
Action::ShutdownImminent(ShutdownReason::AccOff),
|
||||||
@@ -112,14 +123,30 @@ impl PowerFsm {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
// under-voltage/thermal: ACC не менялся → без AccChanged.
|
// under-voltage/thermal: ACC не менялся → без AccChanged.
|
||||||
(Accessory | Running, E::UnderVoltage) => self.begin_shutdown(ShutdownReason::UnderVoltage),
|
(Accessory | Running, E::UnderVoltage) => {
|
||||||
|
self.begin_shutdown(ShutdownReason::UnderVoltage)
|
||||||
|
}
|
||||||
(Accessory | Running, E::ThermalTrip) => self.begin_shutdown(ShutdownReason::Thermal),
|
(Accessory | Running, E::ThermalTrip) => self.begin_shutdown(ShutdownReason::Thermal),
|
||||||
(ShuttingDown { phase: Abortable, .. }, E::AccOn) => {
|
(
|
||||||
|
ShuttingDown {
|
||||||
|
phase: Abortable, ..
|
||||||
|
},
|
||||||
|
E::AccOn,
|
||||||
|
) => {
|
||||||
self.state = Running;
|
self.state = Running;
|
||||||
vec![Action::ShutdownAborted, Action::AccChanged(true)]
|
vec![Action::ShutdownAborted, Action::AccChanged(true)]
|
||||||
}
|
}
|
||||||
(ShuttingDown { phase: Abortable, reason }, E::GraceExpired) => {
|
(
|
||||||
self.state = ShuttingDown { phase: Committed, reason };
|
ShuttingDown {
|
||||||
|
phase: Abortable,
|
||||||
|
reason,
|
||||||
|
},
|
||||||
|
E::GraceExpired,
|
||||||
|
) => {
|
||||||
|
self.state = ShuttingDown {
|
||||||
|
phase: Committed,
|
||||||
|
reason,
|
||||||
|
};
|
||||||
vec![Action::Commit]
|
vec![Action::Commit]
|
||||||
}
|
}
|
||||||
// committed/off/sleep/battery_cutoff + всё прочее — no-op (committed не abort-ится)
|
// committed/off/sleep/battery_cutoff + всё прочее — no-op (committed не abort-ится)
|
||||||
@@ -128,7 +155,10 @@ impl PowerFsm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn begin_shutdown(&mut self, reason: ShutdownReason) -> Vec<Action> {
|
fn begin_shutdown(&mut self, reason: ShutdownReason) -> Vec<Action> {
|
||||||
self.state = State::ShuttingDown { phase: Phase::Abortable, reason };
|
self.state = State::ShuttingDown {
|
||||||
|
phase: Phase::Abortable,
|
||||||
|
reason,
|
||||||
|
};
|
||||||
vec![Action::ShutdownImminent(reason), Action::StartGrace]
|
vec![Action::ShutdownImminent(reason), Action::StartGrace]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -146,7 +176,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn accessory_engine_on_to_running_and_back() {
|
fn accessory_engine_on_to_running_and_back() {
|
||||||
let mut f = PowerFsm { state: State::Accessory };
|
let mut f = PowerFsm {
|
||||||
|
state: State::Accessory,
|
||||||
|
};
|
||||||
assert_eq!(f.step(Event::EngineOn), vec![]);
|
assert_eq!(f.step(Event::EngineOn), vec![]);
|
||||||
assert_eq!(f.state(), State::Running);
|
assert_eq!(f.state(), State::Running);
|
||||||
assert_eq!(f.step(Event::EngineOff), vec![]);
|
assert_eq!(f.step(Event::EngineOff), vec![]);
|
||||||
@@ -193,20 +225,43 @@ mod tests {
|
|||||||
f.step(Event::AccOff);
|
f.step(Event::AccOff);
|
||||||
assert_eq!(f.step(Event::GraceExpired), vec![Action::Commit]);
|
assert_eq!(f.step(Event::GraceExpired), vec![Action::Commit]);
|
||||||
assert_eq!(f.step(Event::AccOn), vec![]); // committed: abort игнорируется
|
assert_eq!(f.step(Event::AccOn), vec![]); // committed: abort игнорируется
|
||||||
assert!(matches!(f.state(), State::ShuttingDown { phase: Phase::Committed, .. }));
|
assert!(matches!(
|
||||||
|
f.state(),
|
||||||
|
State::ShuttingDown {
|
||||||
|
phase: Phase::Committed,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reserved_states_noop() {
|
fn reserved_states_noop() {
|
||||||
let mut f = PowerFsm { state: State::Sleep };
|
let mut f = PowerFsm {
|
||||||
|
state: State::Sleep,
|
||||||
|
};
|
||||||
assert_eq!(f.step(Event::AccOn), vec![]);
|
assert_eq!(f.step(Event::AccOn), vec![]);
|
||||||
assert_eq!(f.state(), State::Sleep);
|
assert_eq!(f.state(), State::Sleep);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn ignition_projection() {
|
fn ignition_projection() {
|
||||||
assert_eq!(PowerFsm { state: State::Running }.ignition(), IgnitionState::Running);
|
assert_eq!(
|
||||||
assert_eq!(PowerFsm { state: State::Accessory }.ignition(), IgnitionState::Accessory);
|
PowerFsm {
|
||||||
assert_eq!(PowerFsm { state: State::Off }.ignition(), IgnitionState::Off);
|
state: State::Running
|
||||||
|
}
|
||||||
|
.ignition(),
|
||||||
|
IgnitionState::Running
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
PowerFsm {
|
||||||
|
state: State::Accessory
|
||||||
|
}
|
||||||
|
.ignition(),
|
||||||
|
IgnitionState::Accessory
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
PowerFsm { state: State::Off }.ignition(),
|
||||||
|
IgnitionState::Off
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ pub struct PowerService {
|
|||||||
|
|
||||||
impl Default for PowerService {
|
impl Default for PowerService {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self { fsm: Arc::new(Mutex::new(PowerFsm::new())) }
|
Self {
|
||||||
|
fsm: Arc::new(Mutex::new(PowerFsm::new())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +40,9 @@ impl PowerService {
|
|||||||
|
|
||||||
#[cfg(feature = "dev-mocks")]
|
#[cfg(feature = "dev-mocks")]
|
||||||
pub fn mock(&self) -> PowerMock {
|
pub fn mock(&self) -> PowerMock {
|
||||||
PowerMock { fsm: Arc::clone(&self.fsm) }
|
PowerMock {
|
||||||
|
fsm: Arc::clone(&self.fsm),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,16 @@ async fn shutdown_imminent_then_abort() {
|
|||||||
let svc = PowerService::new();
|
let svc = PowerService::new();
|
||||||
let mock = svc.mock();
|
let mock = svc.mock();
|
||||||
let server = zbus::Connection::session().await.unwrap();
|
let server = zbus::Connection::session().await.unwrap();
|
||||||
server.object_server().at(names::power::PATH, svc).await.unwrap();
|
server
|
||||||
server.object_server().at(names::power::PATH, mock).await.unwrap();
|
.object_server()
|
||||||
|
.at(names::power::PATH, svc)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
server
|
||||||
|
.object_server()
|
||||||
|
.at(names::power::PATH, mock)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
server.request_name(names::power::NAME).await.unwrap();
|
server.request_name(names::power::NAME).await.unwrap();
|
||||||
|
|
||||||
let client = zbus::Connection::session().await.unwrap();
|
let client = zbus::Connection::session().await.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user