probably need to re-work the mode model..

This commit is contained in:
Robin Mueller
2026-03-10 15:47:44 +01:00
parent ae9edf5888
commit df517af85b
15 changed files with 683 additions and 836 deletions
+3 -1
View File
@@ -152,7 +152,7 @@ pub trait Message {
fn message_type(&self) -> MessageType;
}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone)]
pub enum DeviceMode {
Off = 0,
On = 1,
@@ -163,8 +163,10 @@ pub enum DeviceMode {
#[non_exhaustive]
pub enum HkRequestType {
OneShot,
/// Enable periodic HK generation with a specified frequency.
EnablePeriodic(core::time::Duration),
DisablePeriodic,
/// Modify periodic HK generation interval.
ModifyInterval(core::time::Duration),
}
+24 -2
View File
@@ -1,5 +1,5 @@
pub mod request {
use crate::HkRequestType;
use crate::{HkRequestType, Message};
#[derive(Debug, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub enum HkId {
@@ -16,6 +16,22 @@ pub mod request {
pub enum Request {
Ping,
Hk(HkRequest),
Mode(crate::DeviceMode),
}
impl Request {
fn message_type(&self) -> crate::MessageType {
match self {
Request::Ping => crate::MessageType::Verification,
Request::Hk(_hk_request) => crate::MessageType::Hk,
Request::Mode(_mode) => crate::MessageType::Mode,
}
}
}
impl Message for Request {
fn message_type(&self) -> crate::MessageType {
self.message_type()
}
}
}
@@ -41,7 +57,7 @@ pub mod response {
Hk(HkResponse),
}
impl Message for Response {
impl Response {
fn message_type(&self) -> crate::MessageType {
match self {
Response::Ok => crate::MessageType::Verification,
@@ -49,4 +65,10 @@ pub mod response {
}
}
}
impl Message for Response {
fn message_type(&self) -> crate::MessageType {
self.message_type()
}
}
}
+22
View File
@@ -93,15 +93,37 @@ impl SwitchRequest {
}
pub mod request {
use crate::{DeviceMode, Message};
use super::*;
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
pub enum Request {
Mode(DeviceMode),
Ping,
GetSwitches,
EnableSwitches(SwitchesBitfield),
DisableSwitches(SwitchesBitfield),
}
impl Request {
pub fn message_type(&self) -> crate::MessageType {
match self {
Request::Mode(_mode) => crate::MessageType::Mode,
Request::Ping => crate::MessageType::Verification,
Request::GetSwitches => crate::MessageType::Action,
Request::EnableSwitches(_switches) | Request::DisableSwitches(_switches) => {
crate::MessageType::Action
}
}
}
}
impl Message for Request {
fn message_type(&self) -> crate::MessageType {
self.message_type()
}
}
}
pub mod response {