power_abstractions + request id schedule implementation #32

Merged
muellerr merged 8 commits from power_abstractions into main 2023-02-14 16:00:19 +01:00
11 changed files with 130 additions and 47 deletions

11
satrs-core/src/hk.rs Normal file
View File

@ -0,0 +1,11 @@
use crate::tmtc::AddressableId;
pub type CollectionIntervalFactor = u32;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum HkRequest {
OneShot(AddressableId),
Enable(AddressableId),
Disable(AddressableId),
ModifyCollectionInterval(AddressableId, CollectionIntervalFactor),
}

View File

@ -25,6 +25,7 @@ pub mod events;
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
pub mod executable; pub mod executable;
pub mod hal; pub mod hal;
pub mod hk;
pub mod objects; pub mod objects;
pub mod params; pub mod params;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
@ -32,6 +33,7 @@ pub mod params;
pub mod pool; pub mod pool;
pub mod power; pub mod power;
pub mod pus; pub mod pus;
pub mod request;
pub mod res_code; pub mod res_code;
pub mod seq_count; pub mod seq_count;
pub mod tmtc; pub mod tmtc;

0
satrs-core/src/mode.rs Normal file
View File

View File

@ -27,7 +27,7 @@ pub enum SwitchState {
pub type SwitchId = u16; pub type SwitchId = u16;
/// Generic trait for a device capable of turning on and off switches. /// Generic trait for a device capable of turning on and off switches.
pub trait PowerSwitcher { pub trait PowerSwitcherCommandSender {
type Error; type Error;
fn send_switch_on_cmd(&mut self, switch_id: SwitchId) -> Result<(), Self::Error>; fn send_switch_on_cmd(&mut self, switch_id: SwitchId) -> Result<(), Self::Error>;
@ -45,12 +45,16 @@ pub trait PowerSwitcher {
) -> Result<(), <T as PowerSwitch>::Error> { ) -> Result<(), <T as PowerSwitch>::Error> {
switch.switch_off() switch.switch_off()
} }
}
pub trait PowerSwitchInfo {
type Error;
/// Retrieve the switch state /// Retrieve the switch state
fn get_switch_state(&mut self, switch_id: SwitchId) -> SwitchState; fn get_switch_state(&mut self, switch_id: SwitchId) -> Result<SwitchState, Self::Error>;
fn get_is_switch_on(&mut self, switch_id: SwitchId) -> bool { fn get_is_switch_on(&mut self, switch_id: SwitchId) -> Result<bool, Self::Error> {
self.get_switch_state(switch_id) == SwitchState::On Ok(self.get_switch_state(switch_id)? == SwitchState::On)
} }
/// The maximum delay it will take to change a switch. /// The maximum delay it will take to change a switch.
@ -59,3 +63,54 @@ pub trait PowerSwitcher {
/// see the switch changed. /// see the switch changed.
fn switch_delay_ms(&self) -> u32; fn switch_delay_ms(&self) -> u32;
} }
pub trait PowerSwitchProvider: PowerSwitcherCommandSender + PowerSwitchInfo {
type Error;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::power::PowerSwitcherCommandSender;
use std::boxed::Box;
struct Pcdu {
switch_rx: std::sync::mpsc::Receiver<(SwitchId, u16)>,
}
enum DeviceState {
OFF,
SwitchingPower,
ON,
SETUP,
IDLE,
}
struct MyComplexDevice {
power_switcher: Box<dyn PowerSwitcherCommandSender<Error = ()>>,
switch_id: SwitchId,
some_state: u16,
dev_state: DeviceState,
mode: u32,
submode: u16,
}
impl MyComplexDevice {
pub fn periodic_op(&mut self) {
// .. mode command coming in
let mode = 1;
if mode == 1 {
if self.dev_state == DeviceState::OFF {
self.power_switcher
.send_switch_on_cmd(self.switch_id)
.expect("sending siwthc cmd failed");
self.dev_state = DeviceState::SwitchingPower;
}
if self.dev_state == DeviceState::SwitchingPower {
if self.power_switcher.get_is_switch_on() {
self.dev_state = DeviceState::ON;
self.mode = 1;
}
}
}
}
}
}

View File

@ -0,0 +1 @@

View File

@ -1,16 +1,4 @@
use satrs_core::tmtc::AddressableId;
pub type CollectionIntervalFactor = u32;
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum AcsHkIds { pub enum AcsHkIds {
TestMgmSet = 1, TestMgmSet = 1,
} }
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum HkRequest {
OneShot(AddressableId),
Enable(AddressableId),
Disable(AddressableId),
ModifyCollectionInterval(AddressableId, CollectionIntervalFactor),
}

View File

@ -1,3 +1,4 @@
use satrs_core::events::{EventU32TypedSev, SeverityInfo};
use std::net::Ipv4Addr; use std::net::Ipv4Addr;
use satrs_mib::res_code::{ResultU16, ResultU16Info}; use satrs_mib::res_code::{ResultU16, ResultU16Info};
@ -17,6 +18,9 @@ pub enum GroupId {
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED; pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
pub const SERVER_PORT: u16 = 7301; pub const SERVER_PORT: u16 = 7301;
pub const TEST_EVENT: EventU32TypedSev<SeverityInfo> =
EventU32TypedSev::<SeverityInfo>::const_new(0, 0);
pub mod tmtc_err { pub mod tmtc_err {
use super::*; use super::*;

View File

@ -4,7 +4,7 @@ mod pus;
mod requests; mod requests;
mod tmtc; mod tmtc;
use crate::hk::{AcsHkIds, HkRequest}; use crate::hk::AcsHkIds;
use crate::requests::{Request, RequestWithToken}; use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{ use crate::tmtc::{
core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmStore, PUS_APID, core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmStore, PUS_APID,
@ -13,6 +13,7 @@ use satrs_core::event_man::{
EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider, EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider,
}; };
use satrs_core::events::EventU32; use satrs_core::events::EventU32;
use satrs_core::hk::HkRequest;
use satrs_core::pool::{LocalPool, PoolCfg, StoreAddr}; use satrs_core::pool::{LocalPool, PoolCfg, StoreAddr};
use satrs_core::pus::event_man::{ use satrs_core::pus::event_man::{
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken, DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,

View File

@ -1,7 +1,8 @@
use crate::hk::{CollectionIntervalFactor, HkRequest};
use crate::requests::{Request, RequestWithToken}; use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{PusTcSource, TmStore}; use crate::tmtc::{PusTcSource, TmStore};
use satrs_core::events::EventU32; use satrs_core::events::EventU32;
use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
use satrs_core::params::Params;
use satrs_core::pool::StoreAddr; use satrs_core::pool::StoreAddr;
use satrs_core::pus::event; use satrs_core::pus::event;
use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken}; use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken};
@ -17,7 +18,7 @@ use satrs_core::{
spacepackets::ecss::PusPacket, spacepackets::tc::PusTc, spacepackets::time::cds::TimeProvider, spacepackets::ecss::PusPacket, spacepackets::tc::PusTc, spacepackets::time::cds::TimeProvider,
spacepackets::time::TimeWriter, spacepackets::SpHeader, spacepackets::time::TimeWriter, spacepackets::SpHeader,
}; };
use satrs_example::{hk_err, tmtc_err}; use satrs_example::{hk_err, tmtc_err, TEST_EVENT};
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::rc::Rc; use std::rc::Rc;
@ -31,6 +32,7 @@ pub struct PusReceiver {
#[allow(dead_code)] #[allow(dead_code)]
tc_source: PusTcSource, tc_source: PusTcSource,
event_request_tx: Sender<EventRequestWithToken>, event_request_tx: Sender<EventRequestWithToken>,
event_sender: Sender<(EventU32, Option<Params>)>,
request_map: HashMap<u32, Sender<RequestWithToken>>, request_map: HashMap<u32, Sender<RequestWithToken>>,
stamper: TimeProvider, stamper: TimeProvider,
time_stamp: [u8; 7], time_stamp: [u8; 7],
@ -52,6 +54,7 @@ pub struct PusTcArgs {
pub request_map: HashMap<u32, Sender<RequestWithToken>>, pub request_map: HashMap<u32, Sender<RequestWithToken>>,
/// Required for scheduling of telecommands. /// Required for scheduling of telecommands.
pub tc_source: PusTcSource, pub tc_source: PusTcSource,
pub event_sender: Sender<(EventU32, Option<Params>)>,
pub scheduler: Rc<RefCell<PusScheduler>>, pub scheduler: Rc<RefCell<PusScheduler>>,
} }
@ -64,6 +67,7 @@ impl PusReceiver {
verif_reporter: tm_arguments.verif_reporter, verif_reporter: tm_arguments.verif_reporter,
tc_source: tc_arguments.tc_source, tc_source: tc_arguments.tc_source,
event_request_tx: tc_arguments.event_request_tx, event_request_tx: tc_arguments.event_request_tx,
event_sender: tc_arguments.event_sender,
request_map: tc_arguments.request_map, request_map: tc_arguments.request_map,
stamper: TimeProvider::new_with_u16_days(0, 0), stamper: TimeProvider::new_with_u16_days(0, 0),
time_stamp: [0; 7], time_stamp: [0; 7],
@ -110,22 +114,37 @@ impl PusServiceProvider for PusReceiver {
impl PusReceiver { impl PusReceiver {
fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) { fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
if PusPacket::subservice(pus_tc) == 1 { match PusPacket::subservice(pus_tc) {
1 => {
println!("Received PUS ping command TC[17,1]"); println!("Received PUS ping command TC[17,1]");
println!("Sending ping reply PUS TM[17,2]"); println!("Sending ping reply PUS TM[17,2]");
let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None);
let addr = self.tm_store.add_pus_tm(&ping_reply);
let start_token = self let start_token = self
.verif_reporter .verif_reporter
.start_success(token, Some(&self.time_stamp)) .start_success(token, Some(&self.time_stamp))
.expect("Error sending start success"); .expect("Error sending start success");
let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None);
let addr = self.tm_store.add_pus_tm(&ping_reply);
self.tm_tx self.tm_tx
.send(addr) .send(addr)
.expect("Sending TM to TM funnel failed"); .expect("Sending TM to TM funnel failed");
self.verif_reporter self.verif_reporter
.completion_success(start_token, Some(&self.time_stamp)) .completion_success(start_token, Some(&self.time_stamp))
.expect("Error sending completion success"); .expect("Error sending completion success");
} else { }
128 => {
self.update_time_stamp();
self.event_sender
.send((TEST_EVENT.into(), None))
.expect("Sending test event failed");
let start_token = self
.verif_reporter
.start_success(token, Some(&self.time_stamp))
.expect("Error sending start success");
self.verif_reporter
.completion_success(start_token, Some(&self.time_stamp))
.expect("Error sending completion success");
}
_ => {
self.update_time_stamp(); self.update_time_stamp();
self.verif_reporter self.verif_reporter
.start_failure( .start_failure(
@ -139,6 +158,7 @@ impl PusReceiver {
.expect("Sending start failure TM failed"); .expect("Sending start failure TM failed");
} }
} }
}
fn update_time_stamp(&mut self) { fn update_time_stamp(&mut self) {
self.stamper self.stamper

View File

@ -1,4 +1,4 @@
use crate::hk::HkRequest; use satrs_core::hk::HkRequest;
use satrs_core::pus::verification::{TcStateAccepted, VerificationToken}; use satrs_core::pus::verification::{TcStateAccepted, VerificationToken};
#[derive(Copy, Clone, Eq, PartialEq, Debug)] #[derive(Copy, Clone, Eq, PartialEq, Debug)]

View File

@ -177,6 +177,7 @@ pub fn core_tmtc_task(args: OtherArgs, mut tc_args: TcArgs, tm_args: TmArgs) {
event_request_tx: args.event_request_tx, event_request_tx: args.event_request_tx,
request_map: args.request_map, request_map: args.request_map,
tc_source: tc_args.tc_source.clone(), tc_source: tc_args.tc_source.clone(),
event_sender: args.event_sender,
scheduler: sched_clone, scheduler: sched_clone,
}; };
let mut pus_receiver = PusReceiver::new(PUS_APID, pus_tm_args, pus_tc_args); let mut pus_receiver = PusReceiver::new(PUS_APID, pus_tm_args, pus_tc_args);