power_abstractions + request id schedule implementation #32
11
satrs-core/src/hk.rs
Normal file
11
satrs-core/src/hk.rs
Normal 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),
|
||||||
|
}
|
@ -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
0
satrs-core/src/mode.rs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
satrs-core/src/request.rs
Normal file
1
satrs-core/src/request.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
@ -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),
|
|
||||||
}
|
|
||||||
|
@ -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::*;
|
||||||
|
|
||||||
|
@ -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,
|
||||||
|
@ -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,33 +114,49 @@ 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) {
|
||||||
println!("Received PUS ping command TC[17,1]");
|
1 => {
|
||||||
println!("Sending ping reply PUS TM[17,2]");
|
println!("Received PUS ping command TC[17,1]");
|
||||||
let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None);
|
println!("Sending ping reply PUS TM[17,2]");
|
||||||
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);
|
||||||
self.tm_tx
|
let addr = self.tm_store.add_pus_tm(&ping_reply);
|
||||||
.send(addr)
|
self.tm_tx
|
||||||
.expect("Sending TM to TM funnel failed");
|
.send(addr)
|
||||||
self.verif_reporter
|
.expect("Sending TM to TM funnel failed");
|
||||||
.completion_success(start_token, Some(&self.time_stamp))
|
self.verif_reporter
|
||||||
.expect("Error sending completion success");
|
.completion_success(start_token, Some(&self.time_stamp))
|
||||||
} else {
|
.expect("Error sending completion success");
|
||||||
self.update_time_stamp();
|
}
|
||||||
self.verif_reporter
|
128 => {
|
||||||
.start_failure(
|
self.update_time_stamp();
|
||||||
token,
|
self.event_sender
|
||||||
FailParams::new(
|
.send((TEST_EVENT.into(), None))
|
||||||
Some(&self.time_stamp),
|
.expect("Sending test event failed");
|
||||||
&tmtc_err::INVALID_PUS_SUBSERVICE,
|
let start_token = self
|
||||||
None,
|
.verif_reporter
|
||||||
),
|
.start_success(token, Some(&self.time_stamp))
|
||||||
)
|
.expect("Error sending start success");
|
||||||
.expect("Sending start failure TM failed");
|
self.verif_reporter
|
||||||
|
.completion_success(start_token, Some(&self.time_stamp))
|
||||||
|
.expect("Error sending completion success");
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
self.update_time_stamp();
|
||||||
|
self.verif_reporter
|
||||||
|
.start_failure(
|
||||||
|
token,
|
||||||
|
FailParams::new(
|
||||||
|
Some(&self.time_stamp),
|
||||||
|
&tmtc_err::INVALID_PUS_SUBSERVICE,
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.expect("Sending start failure TM failed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)]
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user