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 85 additions and 42 deletions
Showing only changes of commit 9a7f3962cf - Show all commits

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

@ -35,5 +35,7 @@ pub mod pus;
pub mod res_code;
pub mod seq_count;
pub mod tmtc;
pub mod request;
pub mod hk;
pub use spacepackets;

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

View File

@ -27,7 +27,7 @@ pub enum SwitchState {
pub type SwitchId = u16;
/// Generic trait for a device capable of turning on and off switches.
pub trait PowerSwitcher {
pub trait PowerSwitcherCommandSender {
type Error;
fn send_switch_on_cmd(&mut self, switch_id: SwitchId) -> Result<(), Self::Error>;
@ -46,6 +46,11 @@ pub trait PowerSwitcher {
switch.switch_off()
}
}
pub trait PowerSwitchInfo {
type Error;
/// Retrieve the switch state
fn get_switch_state(&mut self, switch_id: SwitchId) -> Result<SwitchState, Self::Error>;
@ -60,11 +65,15 @@ pub trait PowerSwitcher {
fn switch_delay_ms(&self) -> u32;
}
pub trait PowerSwitchProvider: PowerSwitcherCommandSender + PowerSwitchInfo {
type Error;
}
#[cfg(test)]
mod tests {
use super::*;
use std::boxed::Box;
use crate::power::PowerSwitcher;
use crate::power::PowerSwitcherCommandSender;
struct Pcdu {
@ -78,7 +87,7 @@ mod tests {
IDLE
}
struct MyComplexDevice {
power_switcher: Box<dyn PowerSwitcher<Error=()>>,
power_switcher: Box<dyn PowerSwitcherCommandSender<Error=()>>,
switch_id: SwitchId,
some_state: u16,
dev_state: DeviceState,

View File

View File

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

View File

@ -1,4 +1,5 @@
use std::net::Ipv4Addr;
use satrs_core::events::{EventU32, EventU32TypedSev, Severity, SeverityInfo};
use satrs_mib::res_code::{ResultU16, ResultU16Info};
use satrs_mib::resultcode;
@ -17,6 +18,9 @@ pub enum GroupId {
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED;
pub const SERVER_PORT: u16 = 7301;
pub const TEST_EVENT: EventU32TypedSev<SeverityInfo> =
EventU32TypedSev::<SeverityInfo>::const_new(0, 0);
pub mod tmtc_err {
use super::*;
@ -47,3 +51,5 @@ pub mod hk_err {
#[resultcode]
pub const COLLECTION_INTERVAL_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 3);
}

View File

@ -4,7 +4,7 @@ mod pus;
mod requests;
mod tmtc;
use crate::hk::{AcsHkIds, HkRequest};
use crate::hk::{AcsHkIds};
use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{
core_tmtc_task, OtherArgs, PusTcSource, TcArgs, TcStore, TmArgs, TmFunnel, TmStore, PUS_APID,
@ -37,6 +37,7 @@ use std::sync::mpsc::{channel, TryRecvError};
use std::sync::{mpsc, Arc, RwLock};
use std::thread;
use std::time::Duration;
use satrs_core::hk::HkRequest;
#[derive(Clone)]
struct EventTmSender {
@ -244,6 +245,7 @@ fn main() {
HkRequest::Disable(_) => {}
HkRequest::ModifyCollectionInterval(_, _) => {}
},
_ => {}
}
let started_token = reporter_aocs
.start_success(request.1, Some(&timestamp))

View File

@ -1,4 +1,3 @@
use crate::hk::{CollectionIntervalFactor, HkRequest};
use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{PusTcSource, TmStore};
use satrs_core::events::EventU32;
@ -17,11 +16,13 @@ use satrs_core::{
spacepackets::ecss::PusPacket, spacepackets::tc::PusTc, spacepackets::time::cds::TimeProvider,
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::collections::HashMap;
use std::rc::Rc;
use std::sync::mpsc::Sender;
use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
use satrs_core::params::Params;
pub struct PusReceiver {
pub tm_helper: PusTmWithCdsShortHelper,
@ -31,6 +32,7 @@ pub struct PusReceiver {
#[allow(dead_code)]
tc_source: PusTcSource,
event_request_tx: Sender<EventRequestWithToken>,
event_sender: Sender<(EventU32, Option<Params>)>,
request_map: HashMap<u32, Sender<RequestWithToken>>,
stamper: TimeProvider,
time_stamp: [u8; 7],
@ -52,6 +54,7 @@ pub struct PusTcArgs {
pub request_map: HashMap<u32, Sender<RequestWithToken>>,
/// Required for scheduling of telecommands.
pub tc_source: PusTcSource,
pub event_sender: Sender<(EventU32, Option<Params>)>,
pub scheduler: Rc<RefCell<PusScheduler>>,
}
@ -64,6 +67,7 @@ impl PusReceiver {
verif_reporter: tm_arguments.verif_reporter,
tc_source: tc_arguments.tc_source,
event_request_tx: tc_arguments.event_request_tx,
event_sender: tc_arguments.event_sender,
request_map: tc_arguments.request_map,
stamper: TimeProvider::new_with_u16_days(0, 0),
time_stamp: [0; 7],
@ -110,33 +114,47 @@ impl PusServiceProvider for PusReceiver {
impl PusReceiver {
fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
if PusPacket::subservice(pus_tc) == 1 {
println!("Received PUS ping command TC[17,1]");
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
.verif_reporter
.start_success(token, Some(&self.time_stamp))
.expect("Error sending start success");
self.tm_tx
.send(addr)
.expect("Sending TM to TM funnel failed");
self.verif_reporter
.completion_success(start_token, Some(&self.time_stamp))
.expect("Error sending completion success");
} else {
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");
match PusPacket::subservice(pus_tc) {
1 => {
println!("Received PUS ping command TC[17,1]");
println!("Sending ping reply PUS TM[17,2]");
let start_token = self
.verif_reporter
.start_success(token, Some(&self.time_stamp))
.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
.send(addr)
.expect("Sending TM to TM funnel failed");
self.verif_reporter
.completion_success(start_token, Some(&self.time_stamp))
.expect("Error sending completion success");
}
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.verif_reporter
.start_failure(
token,
FailParams::new(
Some(&self.time_stamp),
&tmtc_err::INVALID_PUS_SUBSERVICE,
None,
),
)
.expect("Sending start failure TM failed");
}
}
}

View File

@ -1,9 +1,10 @@
use crate::hk::HkRequest;
use satrs_core::hk::HkRequest;
use satrs_core::pus::verification::{TcStateAccepted, VerificationToken};
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Request {
HkRequest(HkRequest),
ModeRequest
}
#[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,
request_map: args.request_map,
tc_source: tc_args.tc_source.clone(),
event_sender: args.event_sender,
scheduler: sched_clone,
};
let mut pus_receiver = PusReceiver::new(PUS_APID, pus_tm_args, pus_tc_args);