continue move
This commit is contained in:
1 parent
32bd68bd38
commit
f93fd204ab
17 files changed
+258
-146
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ members = [
|
||||
"satrs-example",
|
||||
"satrs-example/models",
|
||||
"satrs-example/client",
|
||||
"satrs-minisim",
|
||||
"satrs-example/minisim",
|
||||
"satrs-shared",
|
||||
"embedded-examples/embedded-client",
|
||||
]
|
||||
|
||||
@@ -29,7 +29,7 @@ serde_json = "1"
|
||||
|
||||
satrs = { path = "../satrs", features = ["test_util"] }
|
||||
models = { path = "./models" }
|
||||
satrs-minisim = { path = "../satrs-minisim" }
|
||||
satrs-minisim = { path = "./minisim" }
|
||||
satrs-mib = { path = "../satrs-mib" }
|
||||
|
||||
[features]
|
||||
|
||||
@@ -15,12 +15,10 @@ strum = { version = "0.27", features = ["derive"] }
|
||||
num_enum = "0.7"
|
||||
humantime = "2"
|
||||
tai-time = { version = "0.3", features = ["serde"] }
|
||||
nexosim = { version = "0.3.1" }
|
||||
|
||||
[dependencies.nexosim]
|
||||
version = "0.3.1"
|
||||
|
||||
[dependencies.satrs]
|
||||
path = "../satrs"
|
||||
satrs = { path = "../../satrs" }
|
||||
models = { path = "../models" }
|
||||
|
||||
[dev-dependencies]
|
||||
delegate = "0.13"
|
||||
File renamed without changes.
@@ -1,10 +1,10 @@
|
||||
use std::{f32::consts::PI, sync::mpsc, time::Duration};
|
||||
|
||||
use models::pcdu::SwitchStateBinary;
|
||||
use nexosim::{
|
||||
model::{Context, Model},
|
||||
ports::Output,
|
||||
};
|
||||
use satrs::power::SwitchStateBinary;
|
||||
use satrs_minisim::{
|
||||
acs::{
|
||||
lis3mdl::MgmLis3MdlReply, MgmReplyCommon, MgmReplyProvider, MgmSensorValuesMicroTesla,
|
||||
@@ -179,13 +179,13 @@ impl Model for MagnetorquerModel {}
|
||||
pub mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use models::pcdu::SwitchId;
|
||||
use satrs::power::SwitchStateBinary;
|
||||
use satrs_minisim::{
|
||||
acs::{
|
||||
lis3mdl::{self, MgmLis3MdlReply},
|
||||
MgmRequestLis3Mdl, MgtDipole, MgtHkSet, MgtReply, MgtRequest,
|
||||
},
|
||||
eps::PcduSwitch,
|
||||
SerializableSimMsgPayload, SimComponent, SimMessageProvider, SimRequest,
|
||||
};
|
||||
|
||||
@@ -215,7 +215,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_basic_mgm_request_switched_on() {
|
||||
let mut sim_testbench = SimTestbench::new();
|
||||
switch_device_on(&mut sim_testbench, PcduSwitch::Mgm);
|
||||
switch_device_on(&mut sim_testbench, SwitchId::Mgm0);
|
||||
|
||||
let mut request = SimRequest::new_with_epoch_time(MgmRequestLis3Mdl::RequestSensorData);
|
||||
sim_testbench
|
||||
@@ -279,7 +279,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_basic_mgt_request_is_on() {
|
||||
let mut sim_testbench = SimTestbench::new();
|
||||
switch_device_on(&mut sim_testbench, PcduSwitch::Mgt);
|
||||
switch_device_on(&mut sim_testbench, SwitchId::Mgt);
|
||||
let request = SimRequest::new_with_epoch_time(MgtRequest::RequestHk);
|
||||
|
||||
sim_testbench
|
||||
@@ -324,7 +324,7 @@ pub mod tests {
|
||||
#[test]
|
||||
fn test_basic_mgt_request_is_on_and_torquing() {
|
||||
let mut sim_testbench = SimTestbench::new();
|
||||
switch_device_on(&mut sim_testbench, PcduSwitch::Mgt);
|
||||
switch_device_on(&mut sim_testbench, SwitchId::Mgt);
|
||||
let commanded_dipole = MgtDipole {
|
||||
x: -200,
|
||||
y: 200,
|
||||
File renamed without changes.
@@ -1,14 +1,11 @@
|
||||
use std::{sync::mpsc, time::Duration};
|
||||
|
||||
use models::pcdu::{SwitchId, SwitchMapBinaryWrapper, SwitchStateBinary};
|
||||
use nexosim::{
|
||||
model::{Context, Model},
|
||||
ports::Output,
|
||||
};
|
||||
use satrs::power::SwitchStateBinary;
|
||||
use satrs_minisim::{
|
||||
eps::{PcduReply, PcduSwitch, SwitchMapBinaryWrapper},
|
||||
SimReply,
|
||||
};
|
||||
use satrs_minisim::{eps::PcduReply, SimReply};
|
||||
|
||||
pub const SWITCH_INFO_DELAY_MS: u64 = 10;
|
||||
|
||||
@@ -45,10 +42,7 @@ impl PcduModel {
|
||||
self.reply_sender.send(reply).unwrap();
|
||||
}
|
||||
|
||||
pub async fn switch_device(
|
||||
&mut self,
|
||||
switch_and_target_state: (PcduSwitch, SwitchStateBinary),
|
||||
) {
|
||||
pub async fn switch_device(&mut self, switch_and_target_state: (SwitchId, SwitchStateBinary)) {
|
||||
let val = self
|
||||
.switcher_map
|
||||
.0
|
||||
@@ -56,12 +50,13 @@ impl PcduModel {
|
||||
.unwrap_or_else(|| panic!("switch {:?} not found", switch_and_target_state.0));
|
||||
*val = switch_and_target_state.1;
|
||||
match switch_and_target_state.0 {
|
||||
PcduSwitch::Mgm => {
|
||||
SwitchId::Mgm0 => {
|
||||
self.mgm_0_switch.send(switch_and_target_state.1).await;
|
||||
}
|
||||
PcduSwitch::Mgt => {
|
||||
SwitchId::Mgt => {
|
||||
self.mgt_switch.send(switch_and_target_state.1).await;
|
||||
}
|
||||
SwitchId::Mgm1 => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,16 +68,16 @@ pub(crate) mod tests {
|
||||
use super::*;
|
||||
use std::time::Duration;
|
||||
|
||||
use models::pcdu::SwitchMapBinary;
|
||||
use satrs_minisim::{
|
||||
eps::{PcduRequest, SwitchMapBinary},
|
||||
SerializableSimMsgPayload, SimComponent, SimMessageProvider, SimRequest,
|
||||
eps::PcduRequest, SerializableSimMsgPayload, SimComponent, SimMessageProvider, SimRequest,
|
||||
};
|
||||
|
||||
use crate::test_helpers::SimTestbench;
|
||||
|
||||
fn switch_device(
|
||||
sim_testbench: &mut SimTestbench,
|
||||
switch: PcduSwitch,
|
||||
switch: SwitchId,
|
||||
target: SwitchStateBinary,
|
||||
) {
|
||||
let request = SimRequest::new_with_epoch_time(PcduRequest::SwitchDevice {
|
||||
@@ -97,10 +92,10 @@ pub(crate) mod tests {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn switch_device_off(sim_testbench: &mut SimTestbench, switch: PcduSwitch) {
|
||||
pub(crate) fn switch_device_off(sim_testbench: &mut SimTestbench, switch: SwitchId) {
|
||||
switch_device(sim_testbench, switch, SwitchStateBinary::Off);
|
||||
}
|
||||
pub(crate) fn switch_device_on(sim_testbench: &mut SimTestbench, switch: PcduSwitch) {
|
||||
pub(crate) fn switch_device_on(sim_testbench: &mut SimTestbench, switch: SwitchId) {
|
||||
switch_device(sim_testbench, switch, SwitchStateBinary::On);
|
||||
}
|
||||
|
||||
@@ -128,7 +123,7 @@ pub(crate) mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn test_pcdu_switching_single_switch(switch: PcduSwitch, target: SwitchStateBinary) {
|
||||
fn test_pcdu_switching_single_switch(switch: SwitchId, target: SwitchStateBinary) {
|
||||
let mut sim_testbench = SimTestbench::new();
|
||||
switch_device(&mut sim_testbench, switch, target);
|
||||
let mut switcher_map = get_all_off_switch_map();
|
||||
@@ -165,17 +160,17 @@ pub(crate) mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_pcdu_switching_mgm_on() {
|
||||
test_pcdu_switching_single_switch(PcduSwitch::Mgm, SwitchStateBinary::On);
|
||||
test_pcdu_switching_single_switch(SwitchId::Mgm0, SwitchStateBinary::On);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pcdu_switching_mgt_on() {
|
||||
test_pcdu_switching_single_switch(PcduSwitch::Mgt, SwitchStateBinary::On);
|
||||
test_pcdu_switching_single_switch(SwitchId::Mgt, SwitchStateBinary::On);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pcdu_switching_mgt_off() {
|
||||
test_pcdu_switching_single_switch(PcduSwitch::Mgt, SwitchStateBinary::On);
|
||||
test_pcdu_switching_single_switch(PcduSwitch::Mgt, SwitchStateBinary::Off);
|
||||
test_pcdu_switching_single_switch(SwitchId::Mgt, SwitchStateBinary::On);
|
||||
test_pcdu_switching_single_switch(SwitchId::Mgt, SwitchStateBinary::Off);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
use nexosim::time::MonotonicTime;
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
|
||||
@@ -162,73 +161,7 @@ impl From<SimRequestError> for SimCtrlReply {
|
||||
|
||||
pub mod eps {
|
||||
use super::*;
|
||||
use satrs::power::{SwitchState, SwitchStateBinary};
|
||||
use std::collections::HashMap;
|
||||
use strum::{EnumIter, IntoEnumIterator};
|
||||
|
||||
pub type SwitchMap = HashMap<PcduSwitch, SwitchState>;
|
||||
pub type SwitchMapBinary = HashMap<PcduSwitch, SwitchStateBinary>;
|
||||
|
||||
pub struct SwitchMapWrapper(pub SwitchMap);
|
||||
pub struct SwitchMapBinaryWrapper(pub SwitchMapBinary);
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Hash,
|
||||
EnumIter,
|
||||
IntoPrimitive,
|
||||
TryFromPrimitive,
|
||||
)]
|
||||
#[repr(u16)]
|
||||
pub enum PcduSwitch {
|
||||
Mgm = 0,
|
||||
Mgt = 1,
|
||||
}
|
||||
|
||||
impl Default for SwitchMapBinaryWrapper {
|
||||
fn default() -> Self {
|
||||
let mut switch_map = SwitchMapBinary::default();
|
||||
for entry in PcduSwitch::iter() {
|
||||
switch_map.insert(entry, SwitchStateBinary::Off);
|
||||
}
|
||||
Self(switch_map)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for SwitchMapWrapper {
|
||||
fn default() -> Self {
|
||||
let mut switch_map = SwitchMap::default();
|
||||
for entry in PcduSwitch::iter() {
|
||||
switch_map.insert(entry, SwitchState::Unknown);
|
||||
}
|
||||
Self(switch_map)
|
||||
}
|
||||
}
|
||||
|
||||
impl SwitchMapWrapper {
|
||||
pub fn new_with_init_switches_off() -> Self {
|
||||
let mut switch_map = SwitchMap::default();
|
||||
for entry in PcduSwitch::iter() {
|
||||
switch_map.insert(entry, SwitchState::Off);
|
||||
}
|
||||
Self(switch_map)
|
||||
}
|
||||
|
||||
pub fn from_binary_switch_map_ref(switch_map: &SwitchMapBinary) -> Self {
|
||||
Self(
|
||||
switch_map
|
||||
.iter()
|
||||
.map(|(key, value)| (*key, SwitchState::from(*value)))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
use models::pcdu::{SwitchId, SwitchMapBinary, SwitchStateBinary};
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(u8)]
|
||||
@@ -240,7 +173,7 @@ pub mod eps {
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum PcduRequest {
|
||||
SwitchDevice {
|
||||
switch: PcduSwitch,
|
||||
switch: SwitchId,
|
||||
state: SwitchStateBinary,
|
||||
},
|
||||
RequestSwitchInfo,
|
||||
@@ -264,7 +197,7 @@ pub mod eps {
|
||||
pub mod acs {
|
||||
use std::time::Duration;
|
||||
|
||||
use satrs::power::SwitchStateBinary;
|
||||
use models::pcdu::SwitchStateBinary;
|
||||
|
||||
use super::*;
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -6,6 +6,7 @@ use spacepackets::{
|
||||
|
||||
pub mod ccsds;
|
||||
pub mod control;
|
||||
pub mod pcdu;
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use strum::IntoEnumIterator as _;
|
||||
|
||||
#[bitbybit::bitfield(u16, debug)]
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct SwitchesBitfield {
|
||||
#[bit(1, rw)]
|
||||
mgm1: bool,
|
||||
#[bit(0, rw)]
|
||||
mgm0: bool,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug,
|
||||
Copy,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
serde::Serialize,
|
||||
serde::Deserialize,
|
||||
Hash,
|
||||
strum::EnumIter,
|
||||
num_enum::IntoPrimitive,
|
||||
num_enum::TryFromPrimitive,
|
||||
)]
|
||||
#[repr(u16)]
|
||||
pub enum SwitchId {
|
||||
Mgm0 = 0,
|
||||
Mgm1 = 1,
|
||||
Mgt = 2,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SwitchStateBinary {
|
||||
Off = 0,
|
||||
On = 1,
|
||||
}
|
||||
|
||||
pub type SwitchMapBinary = HashMap<SwitchId, SwitchStateBinary>;
|
||||
|
||||
pub struct SwitchMapBinaryWrapper(pub SwitchMapBinary);
|
||||
|
||||
impl Default for SwitchMapBinaryWrapper {
|
||||
fn default() -> Self {
|
||||
let mut switch_map = SwitchMapBinary::default();
|
||||
for entry in SwitchId::iter() {
|
||||
switch_map.insert(entry, SwitchStateBinary::Off);
|
||||
}
|
||||
Self(switch_map)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SwitchRequest {
|
||||
switch_id: SwitchId,
|
||||
target_state: SwitchStateBinary,
|
||||
}
|
||||
|
||||
impl SwitchRequest {
|
||||
pub fn new(switch_id: SwitchId, target_state: SwitchStateBinary) -> Self {
|
||||
Self {
|
||||
switch_id,
|
||||
target_state,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn switch_id(&self) -> SwitchId {
|
||||
self.switch_id
|
||||
}
|
||||
|
||||
pub fn target_state(&self) -> SwitchStateBinary {
|
||||
self.target_state
|
||||
}
|
||||
}
|
||||
|
||||
pub mod request {
|
||||
use super::*;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
pub enum Request {
|
||||
Ping,
|
||||
GetSwitches,
|
||||
EnableSwitches(SwitchesBitfield),
|
||||
DisableSwitches(SwitchesBitfield),
|
||||
}
|
||||
}
|
||||
|
||||
pub mod response {
|
||||
use super::*;
|
||||
use crate::Message;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
pub enum Response {
|
||||
Ok,
|
||||
Switches(SwitchesBitfield),
|
||||
}
|
||||
|
||||
impl Message for Response {
|
||||
fn message_type(&self) -> crate::MessageType {
|
||||
match self {
|
||||
Response::Ok => crate::MessageType::Verification,
|
||||
Response::Switches(_switches) => crate::MessageType::Action,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
use derive_new::new;
|
||||
use models::ccsds::{CcsdsTcPacketOwned, CcsdsTmPacketOwned};
|
||||
use models::pcdu::SwitchId;
|
||||
use models::ComponentId;
|
||||
use satrs::hk::{HkRequest, HkRequestVariant};
|
||||
use satrs::mode_tree::{ModeChild, ModeNode};
|
||||
@@ -9,7 +9,6 @@ use satrs_minisim::acs::lis3mdl::{
|
||||
MgmLis3MdlReply, MgmLis3RawValues, FIELD_LSB_PER_GAUSS_4_SENS, GAUSS_TO_MICROTESLA_FACTOR,
|
||||
};
|
||||
use satrs_minisim::acs::MgmRequestLis3Mdl;
|
||||
use satrs_minisim::eps::PcduSwitch;
|
||||
use satrs_minisim::{SerializableSimMsgPayload, SimReply, SimRequest};
|
||||
use std::fmt::Debug;
|
||||
use std::sync::mpsc::{self};
|
||||
@@ -20,13 +19,10 @@ use satrs::mode::{
|
||||
ModeAndSubmode, ModeError, ModeProvider, ModeReply, ModeRequestHandler,
|
||||
ModeRequestHandlerMpscBounded,
|
||||
};
|
||||
use satrs::pus::{EcssTmSender, PusTmVariant};
|
||||
use satrs::request::{GenericMessage, MessageMetadata, UniqueApidTargetId};
|
||||
use satrs::request::{GenericMessage, MessageMetadata};
|
||||
use satrs_example::config::components::NO_SENDER;
|
||||
|
||||
use crate::hk::PusHkHelper;
|
||||
use crate::spi::SpiInterface;
|
||||
use crate::tmtc::sender::TmTcSender;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -156,7 +152,7 @@ impl Default for ModeHelpers {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub struct MgmHandlerLis3Mdl<
|
||||
ComInterface: SpiInterface,
|
||||
SwitchHelper: PowerSwitchInfo<PcduSwitch> + PowerSwitcherCommandSender<PcduSwitch>,
|
||||
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
|
||||
> {
|
||||
id: ComponentId,
|
||||
dev_str: &'static str,
|
||||
@@ -174,7 +170,7 @@ pub struct MgmHandlerLis3Mdl<
|
||||
|
||||
impl<
|
||||
ComInterface: SpiInterface,
|
||||
SwitchHelper: PowerSwitchInfo<PcduSwitch> + PowerSwitcherCommandSender<PcduSwitch>,
|
||||
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
|
||||
> MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
|
||||
{
|
||||
pub fn new(
|
||||
@@ -244,7 +240,7 @@ impl<
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_hk_request(&mut self, requestor_info: &MessageMetadata, hk_request: &HkRequest) {
|
||||
pub fn handle_hk_request(&mut self, _requestor_info: &MessageMetadata, hk_request: &HkRequest) {
|
||||
match hk_request.variant {
|
||||
HkRequestVariant::OneShot => {
|
||||
/*
|
||||
@@ -352,7 +348,7 @@ impl<
|
||||
if self.mode_helpers.transition_state == TransitionState::Idle {
|
||||
let result = self
|
||||
.switch_helper
|
||||
.send_switch_on_cmd(MessageMetadata::new(0, self.id as u32), PcduSwitch::Mgm);
|
||||
.send_switch_on_cmd(MessageMetadata::new(0, self.id as u32), SwitchId::Mgm0);
|
||||
if result.is_err() {
|
||||
// Could not send switch command.. still continue with transition.
|
||||
log::error!("failed to send switch on command");
|
||||
@@ -362,7 +358,7 @@ impl<
|
||||
if self.mode_helpers.transition_state == TransitionState::PowerSwitching
|
||||
&& self
|
||||
.switch_helper
|
||||
.is_switch_on(PcduSwitch::Mgm)
|
||||
.is_switch_on(SwitchId::Mgm0)
|
||||
.expect("switch info error")
|
||||
{
|
||||
self.mode_helpers.transition_state = TransitionState::Done;
|
||||
@@ -379,7 +375,7 @@ impl<
|
||||
|
||||
impl<
|
||||
ComInterface: SpiInterface,
|
||||
SwitchHelper: PowerSwitchInfo<PcduSwitch> + PowerSwitcherCommandSender<PcduSwitch>,
|
||||
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
|
||||
> ModeProvider for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
|
||||
{
|
||||
fn mode_and_submode(&self) -> ModeAndSubmode {
|
||||
@@ -389,7 +385,7 @@ impl<
|
||||
|
||||
impl<
|
||||
ComInterface: SpiInterface,
|
||||
SwitchHelper: PowerSwitchInfo<PcduSwitch> + PowerSwitcherCommandSender<PcduSwitch>,
|
||||
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
|
||||
> ModeRequestHandler for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
|
||||
{
|
||||
type Error = ModeError;
|
||||
@@ -478,7 +474,7 @@ impl<
|
||||
|
||||
impl<
|
||||
ComInterface: SpiInterface,
|
||||
SwitchHelper: PowerSwitchInfo<PcduSwitch> + PowerSwitcherCommandSender<PcduSwitch>,
|
||||
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
|
||||
> ModeNode for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
|
||||
{
|
||||
fn id(&self) -> satrs::ComponentId {
|
||||
@@ -488,7 +484,7 @@ impl<
|
||||
|
||||
impl<
|
||||
ComInterface: SpiInterface,
|
||||
SwitchHelper: PowerSwitchInfo<PcduSwitch> + PowerSwitcherCommandSender<PcduSwitch>,
|
||||
SwitchHelper: PowerSwitchInfo<SwitchId> + PowerSwitcherCommandSender<SwitchId>,
|
||||
> ModeChild for MgmHandlerLis3Mdl<ComInterface, SwitchHelper>
|
||||
{
|
||||
type Sender = mpsc::SyncSender<GenericMessage<ModeReply>>;
|
||||
@@ -597,8 +593,8 @@ mod tests {
|
||||
let mode_node =
|
||||
ModeRequestHandlerMpscBounded::new(ComponentId::Ground as u32, request_rx);
|
||||
let (tc_tx, tc_rx) = mpsc::sync_channel(10);
|
||||
let (hk_reply_tx, hk_reply_rx) = mpsc::sync_channel(10);
|
||||
let (tm_tx, tm_rx) = mpsc::sync_channel(10);
|
||||
let (hk_reply_tx, _hk_reply_rx) = mpsc::sync_channel(10);
|
||||
let (_tm_tx, tm_rx) = mpsc::sync_channel(10);
|
||||
let shared_mgm_set = Arc::default();
|
||||
let mut handler = MgmHandlerLis3Mdl::new(
|
||||
ComponentId::AcsMgm0,
|
||||
@@ -667,7 +663,7 @@ mod tests {
|
||||
assert_eq!(switch_requests.len(), 1);
|
||||
let switch_req = switch_requests.pop_front().expect("no switch request");
|
||||
assert_eq!(switch_req.target_state, SwitchStateBinary::On);
|
||||
assert_eq!(switch_req.switch_id, PcduSwitch::Mgm);
|
||||
assert_eq!(switch_req.switch_id, SwitchId::Mgm0);
|
||||
let mut switch_info_requests = testbench
|
||||
.handler
|
||||
.switch_helper
|
||||
@@ -675,7 +671,7 @@ mod tests {
|
||||
.borrow_mut();
|
||||
assert_eq!(switch_info_requests.len(), 1);
|
||||
let switch_info_req = switch_info_requests.pop_front().expect("no switch request");
|
||||
assert_eq!(switch_info_req, PcduSwitch::Mgm);
|
||||
assert_eq!(switch_info_req, SwitchId::Mgm0);
|
||||
|
||||
let mode_reply = testbench
|
||||
.mode_reply_rx_to_pus
|
||||
|
||||
+106
-22
@@ -1,34 +1,77 @@
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::VecDeque,
|
||||
collections::{HashMap, VecDeque},
|
||||
sync::{mpsc, Arc, Mutex},
|
||||
};
|
||||
|
||||
use derive_new::new;
|
||||
use models::{
|
||||
ccsds::{CcsdsTcPacketOwned, CcsdsTmPacketOwned},
|
||||
pcdu::{self, SwitchId, SwitchMapBinary, SwitchMapBinaryWrapper, SwitchRequest},
|
||||
ComponentId,
|
||||
};
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use satrs::{
|
||||
hk::{HkRequest, HkRequestVariant},
|
||||
mode::{
|
||||
ModeAndSubmode, ModeError, ModeProvider, ModeReply, ModeRequestHandler,
|
||||
ModeRequestHandlerMpscBounded,
|
||||
},
|
||||
mode_tree::{ModeChild, ModeNode},
|
||||
power::SwitchRequest,
|
||||
power::SwitchState,
|
||||
queue::GenericSendError,
|
||||
request::{GenericMessage, MessageMetadata},
|
||||
spacepackets::CcsdsPacketIdAndPsc,
|
||||
};
|
||||
use satrs_example::{config::components::NO_SENDER, DeviceMode, TimestampHelper};
|
||||
use satrs_minisim::{
|
||||
eps::{
|
||||
PcduReply, PcduRequest, PcduSwitch, SwitchMap, SwitchMapBinaryWrapper, SwitchMapWrapper,
|
||||
},
|
||||
eps::{PcduReply, PcduRequest},
|
||||
SerializableSimMsgPayload, SimReply, SimRequest,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::IntoEnumIterator as _;
|
||||
|
||||
use crate::ccsds::pack_ccsds_tm_packet_for_now;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
pub struct SwitchSet {
|
||||
pub valid: bool,
|
||||
pub switch_map: SwitchMap,
|
||||
}
|
||||
|
||||
pub type SwitchMap = HashMap<SwitchId, SwitchState>;
|
||||
|
||||
pub struct SwitchMapWrapper(pub SwitchMap);
|
||||
|
||||
impl Default for SwitchMapWrapper {
|
||||
fn default() -> Self {
|
||||
let mut switch_map = SwitchMap::default();
|
||||
for entry in SwitchId::iter() {
|
||||
switch_map.insert(entry, SwitchState::Unknown);
|
||||
}
|
||||
Self(switch_map)
|
||||
}
|
||||
}
|
||||
|
||||
impl SwitchMapWrapper {
|
||||
pub fn new_with_init_switches_off() -> Self {
|
||||
let mut switch_map = SwitchMap::default();
|
||||
for entry in SwitchId::iter() {
|
||||
switch_map.insert(entry, SwitchState::Off);
|
||||
}
|
||||
Self(switch_map)
|
||||
}
|
||||
|
||||
pub fn from_binary_switch_map_ref(switch_map: &SwitchMapBinary) -> Self {
|
||||
Self(
|
||||
switch_map
|
||||
.iter()
|
||||
.map(|(key, value)| (*key, SwitchState::from(*value)))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub type SharedSwitchSet = Arc<Mutex<SwitchSet>>;
|
||||
|
||||
pub trait SerialInterface {
|
||||
type Error: core::fmt::Debug;
|
||||
@@ -185,14 +228,6 @@ pub enum OpCode {
|
||||
PollAndRecvReplies = 1,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
|
||||
pub struct SwitchSet {
|
||||
pub valid: bool,
|
||||
pub switch_map: SwitchMap,
|
||||
}
|
||||
|
||||
pub type SharedSwitchSet = Arc<Mutex<SwitchSet>>;
|
||||
|
||||
/// Example PCDU device handler.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub struct PcduHandler<ComInterface: SerialInterface> {
|
||||
@@ -235,7 +270,7 @@ impl<ComInterface: SerialInterface> PcduHandler<ComInterface> {
|
||||
OpCode::RegularOp => {
|
||||
self.stamp_helper.update_from_now();
|
||||
// Handle requests.
|
||||
//self.handle_composite_requests();
|
||||
self.handle_telecommands();
|
||||
self.handle_mode_requests();
|
||||
self.handle_switch_requests();
|
||||
// Poll the switch states and/or telemetry regularly here.
|
||||
@@ -250,6 +285,55 @@ impl<ComInterface: SerialInterface> PcduHandler<ComInterface> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_telecommands(&mut self) {
|
||||
loop {
|
||||
match self.tc_rx.try_recv() {
|
||||
Ok(packet) => {
|
||||
let tc_id = CcsdsPacketIdAndPsc::new_from_ccsds_packet(&packet.sp_header);
|
||||
match postcard::from_bytes::<pcdu::request::Request>(&packet.payload) {
|
||||
Ok(request) => {
|
||||
log::info!(
|
||||
"received request {:?} with TC ID {:#010x}",
|
||||
request,
|
||||
tc_id.raw()
|
||||
);
|
||||
match request {
|
||||
pcdu::request::Request::Ping => {
|
||||
self.send_tm(Some(tc_id), pcdu::response::Response::Ok)
|
||||
}
|
||||
pcdu::request::Request::GetSwitches => {}
|
||||
pcdu::request::Request::EnableSwitches(switches) => todo!(),
|
||||
pcdu::request::Request::DisableSwitches(switches) => todo!(),
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("failed to deserialize request: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => match e {
|
||||
std::sync::mpsc::TryRecvError::Empty => break,
|
||||
std::sync::mpsc::TryRecvError::Disconnected => {
|
||||
log::warn!("packet sender disconnected")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_tm(&self, tc_id: Option<CcsdsPacketIdAndPsc>, response: pcdu::response::Response) {
|
||||
match pack_ccsds_tm_packet_for_now(ComponentId::Pcdu, tc_id, &response) {
|
||||
Ok(packet) => {
|
||||
if let Err(e) = self.tm_tx.send(packet) {
|
||||
log::warn!("failed to send TM packet: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("failed to pack TM packet: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_periodic_commands(&self) {
|
||||
let pcdu_req = PcduRequest::RequestSwitchInfo;
|
||||
let pcdu_req_ser = serde_json::to_string(&pcdu_req).unwrap();
|
||||
@@ -292,7 +376,7 @@ impl<ComInterface: SerialInterface> PcduHandler<ComInterface> {
|
||||
pub fn handle_switch_requests(&mut self) {
|
||||
loop {
|
||||
match self.switch_request_rx.try_recv() {
|
||||
Ok(switch_req) => match PcduSwitch::try_from(switch_req.message.switch_id()) {
|
||||
Ok(switch_req) => match SwitchId::try_from(switch_req.message.switch_id()) {
|
||||
Ok(pcdu_switch) => {
|
||||
let pcdu_req = PcduRequest::SwitchDevice {
|
||||
switch: pcdu_switch,
|
||||
@@ -438,8 +522,8 @@ impl<ComInterface: SerialInterface> ModeChild for PcduHandler<ComInterface> {
|
||||
mod tests {
|
||||
use std::sync::mpsc;
|
||||
|
||||
use satrs::{mode::ModeRequest, power::SwitchStateBinary, request::GenericMessage};
|
||||
use satrs_minisim::eps::SwitchMapBinary;
|
||||
use models::pcdu::{SwitchMapBinary, SwitchStateBinary};
|
||||
use satrs::{mode::ModeRequest, request::GenericMessage};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -533,7 +617,7 @@ mod tests {
|
||||
pub fn verify_switch_req_was_sent(
|
||||
&self,
|
||||
expected_queue_len: usize,
|
||||
switch_id: PcduSwitch,
|
||||
switch_id: SwitchId,
|
||||
target_state: SwitchStateBinary,
|
||||
) {
|
||||
// Check that there is now communication happening.
|
||||
@@ -648,7 +732,7 @@ mod tests {
|
||||
.switch_request_tx
|
||||
.send(GenericMessage::new(
|
||||
MessageMetadata::new(0, ComponentId::AcsMgm0 as u32),
|
||||
SwitchRequest::new(0, SwitchStateBinary::On),
|
||||
SwitchRequest::new(SwitchId::Mgm0, SwitchStateBinary::On),
|
||||
))
|
||||
.expect("failed to send switch request");
|
||||
testbench.handler.periodic_operation(OpCode::RegularOp);
|
||||
@@ -656,11 +740,11 @@ mod tests {
|
||||
.handler
|
||||
.periodic_operation(OpCode::PollAndRecvReplies);
|
||||
|
||||
testbench.verify_switch_req_was_sent(2, PcduSwitch::Mgm, SwitchStateBinary::On);
|
||||
testbench.verify_switch_req_was_sent(2, SwitchId::Mgm0, SwitchStateBinary::On);
|
||||
testbench.verify_switch_info_req_was_sent(1);
|
||||
let mut switch_map = SwitchMapBinaryWrapper::default().0;
|
||||
*switch_map
|
||||
.get_mut(&PcduSwitch::Mgm)
|
||||
.get_mut(&SwitchId::Mgm0)
|
||||
.expect("switch state setting failed") = SwitchStateBinary::On;
|
||||
testbench.verify_switch_reply_received(1, switch_map);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ use interface::{
|
||||
use log::info;
|
||||
use logger::setup_logger;
|
||||
use models::ComponentId;
|
||||
//use requests::GenericRequestRouter;
|
||||
use satrs::{
|
||||
hal::std::{tcp_server::ServerConfig, udp_server::UdpTcServer},
|
||||
mode::{Mode, ModeAndSubmode, ModeRequest, ModeRequestHandlerMpscBounded},
|
||||
@@ -47,7 +46,7 @@ mod acs;
|
||||
mod ccsds;
|
||||
mod control;
|
||||
mod eps;
|
||||
mod hk;
|
||||
//mod hk;
|
||||
mod interface;
|
||||
mod logger;
|
||||
mod spi;
|
||||
|
||||
Reference in new issue
Block a user