diff --git a/src/trx-core/src/rig/controller/machine.rs b/src/trx-core/src/rig/controller/machine.rs index 1f0c77f..9a003e0 100644 --- a/src/trx-core/src/rig/controller/machine.rs +++ b/src/trx-core/src/rig/controller/machine.rs @@ -96,26 +96,115 @@ pub enum RigMachineState { } /// Data held when rig is in Ready state. +/// +/// Fields are crate-private to prevent external mutation that could bypass +/// state machine invariants. Use the constructor and accessor methods. #[derive(Debug, Clone, Serialize)] pub struct ReadyStateData { - pub rig_info: RigInfo, - pub freq: Freq, - pub mode: RigMode, - pub vfo: Option, - pub rx: Option, - pub tx_limit: Option, - pub locked: bool, + pub(crate) rig_info: RigInfo, + pub(crate) freq: Freq, + pub(crate) mode: RigMode, + pub(crate) vfo: Option, + pub(crate) rx: Option, + pub(crate) tx_limit: Option, + pub(crate) locked: bool, +} + +impl ReadyStateData { + pub fn new( + rig_info: RigInfo, + freq: Freq, + mode: RigMode, + vfo: Option, + rx: Option, + tx_limit: Option, + locked: bool, + ) -> Self { + Self { + rig_info, + freq, + mode, + vfo, + rx, + tx_limit, + locked, + } + } + + pub fn rig_info(&self) -> &RigInfo { + &self.rig_info + } + pub fn freq(&self) -> Freq { + self.freq + } + pub fn mode(&self) -> &RigMode { + &self.mode + } + pub fn vfo(&self) -> Option<&RigVfo> { + self.vfo.as_ref() + } + pub fn rx(&self) -> Option<&RigRxStatus> { + self.rx.as_ref() + } + pub fn tx_limit(&self) -> Option { + self.tx_limit + } + pub fn is_locked(&self) -> bool { + self.locked + } } /// Data held when rig is in Transmitting state. +/// +/// Fields are crate-private to prevent external mutation that could bypass +/// state machine invariants. Use the constructor and accessor methods. #[derive(Debug, Clone, Serialize)] pub struct TransmittingStateData { - pub rig_info: RigInfo, - pub freq: Freq, - pub mode: RigMode, - pub vfo: Option, - pub tx: Option, - pub locked: bool, + pub(crate) rig_info: RigInfo, + pub(crate) freq: Freq, + pub(crate) mode: RigMode, + pub(crate) vfo: Option, + pub(crate) tx: Option, + pub(crate) locked: bool, +} + +impl TransmittingStateData { + pub fn new( + rig_info: RigInfo, + freq: Freq, + mode: RigMode, + vfo: Option, + tx: Option, + locked: bool, + ) -> Self { + Self { + rig_info, + freq, + mode, + vfo, + tx, + locked, + } + } + + pub fn rig_info(&self) -> &RigInfo { + &self.rig_info + } + pub fn freq(&self) -> Freq { + self.freq + } + pub fn mode(&self) -> &RigMode { + &self.mode + } + pub fn vfo(&self) -> Option<&RigVfo> { + self.vfo.as_ref() + } + pub fn tx(&self) -> Option<&RigTxStatus> { + self.tx.as_ref() + } + pub fn is_locked(&self) -> bool { + self.locked + } } impl fmt::Display for RigMachineState {