HK reception works

This commit is contained in:
Robin Müller 2022-12-21 10:23:32 +01:00
parent b8a0ff1e2d
commit b1342776ae
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 32 additions and 22 deletions

View File

@ -4,7 +4,7 @@ mod pus;
mod requests;
mod tmtc;
use crate::requests::Request;
use crate::requests::RequestWithToken;
use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID};
use satrs_core::event_man::{
EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider,
@ -103,11 +103,12 @@ fn main() {
PusEventDispatcher::new(event_reporter, Box::new(pus_tm_backend));
let (pus_event_man_tx, pus_event_man_rx) = channel();
let pus_event_man_send_provider = MpscEventU32SendProvider::new(1, pus_event_man_tx);
let mut reporter1 = reporter_with_sender_0.clone();
let mut reporter_event_handler = reporter_with_sender_0.clone();
let mut reporter_aocs = reporter_with_sender_0.clone();
event_man.subscribe_all(pus_event_man_send_provider.id());
let mut request_map = HashMap::new();
let (acs_thread_tx, acs_thread_rx) = channel::<Request>();
let (acs_thread_tx, acs_thread_rx) = channel::<RequestWithToken>();
request_map.insert(RequestTargetId::AcsSubsystem as u32, acs_thread_tx);
// Create clones here to allow move for thread 0
@ -146,7 +147,7 @@ fn main() {
let mut sender = EventTmSender::new(tm_store_helper, tm_funnel_tx);
let mut time_provider = TimeProvider::new_with_u16_days(0, 0);
let mut report_completion = |event_req: EventRequestWithToken, timestamp: &[u8]| {
reporter1
reporter_event_handler
.completion_success(event_req.token, timestamp)
.expect("Sending completion success failed");
};
@ -179,10 +180,18 @@ fn main() {
});
println!("Starting AOCS thread");
let jh3 = thread::spawn(move || loop {
let jh3 = thread::spawn(move || {
let mut timestamp: [u8; 7] = [0; 7];
let mut time_provider = TimeProvider::new_with_u16_days(0, 0);
loop {
match acs_thread_rx.try_recv() {
Ok(request) => {
println!("ACS thread: Received request {:?}", request)
println!("ACS thread: Received HK request {:?}", request.0);
update_time(&mut time_provider, &mut timestamp);
let started_token = reporter_aocs.start_success(request.1, &timestamp).unwrap();
reporter_aocs
.completion_success(started_token, &timestamp)
.unwrap();
}
Err(e) => match e {
TryRecvError::Empty => {}
@ -192,6 +201,7 @@ fn main() {
},
}
thread::sleep(Duration::from_millis(500));
}
});
jh0.join().expect("Joining UDP TMTC server thread failed");

View File

@ -1,5 +1,5 @@
use crate::hk::{CollectionIntervalFactor, HkRequest};
use crate::requests::Request;
use crate::requests::{Request, RequestWithToken};
use crate::tmtc::TmStore;
use satrs_core::events::EventU32;
use satrs_core::pool::StoreAddr;
@ -27,7 +27,7 @@ pub struct PusReceiver {
pub tm_store: TmStore,
pub verif_reporter: StdVerifReporterWithSender,
event_request_tx: Sender<EventRequestWithToken>,
request_map: HashMap<u32, Sender<Request>>,
request_map: HashMap<u32, Sender<RequestWithToken>>,
stamper: TimeProvider,
time_stamp: [u8; 7],
}
@ -39,7 +39,7 @@ impl PusReceiver {
tm_store: TmStore,
verif_reporter: StdVerifReporterWithSender,
event_request_tx: Sender<EventRequestWithToken>,
request_map: HashMap<u32, Sender<Request>>,
request_map: HashMap<u32, Sender<RequestWithToken>>,
) -> Self {
Self {
tm_helper: PusTmWithCdsShortHelper::new(apid),
@ -163,7 +163,7 @@ impl PusReceiver {
let send_request = |request: HkRequest| {
let sender = self.request_map.get(&addressable_id.target_id).unwrap();
sender
.send(Request::HkRequest(request))
.send(RequestWithToken(Request::HkRequest(request), token))
.unwrap_or_else(|_| panic!("Sending HK request {:?} failed", request));
};
if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 {

View File

@ -7,4 +7,4 @@ pub enum Request {
}
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct RequestWithToken(Request, VerificationToken<TcStateAccepted>);
pub struct RequestWithToken(pub Request, pub VerificationToken<TcStateAccepted>);

View File

@ -10,7 +10,7 @@ use std::time::Duration;
use crate::ccsds::CcsdsReceiver;
use crate::pus::PusReceiver;
use crate::requests::Request;
use crate::requests::RequestWithToken;
use crate::UdpTmtcServer;
use satrs_core::pool::{SharedPool, StoreAddr};
use satrs_core::pus::event_man::EventRequestWithToken;
@ -25,7 +25,7 @@ pub struct CoreTmtcArgs {
pub tm_sender: Sender<StoreAddr>,
pub event_sender: Sender<(EventU32, Option<Params>)>,
pub event_request_tx: Sender<EventRequestWithToken>,
pub request_map: HashMap<u32, Sender<Request>>,
pub request_map: HashMap<u32, Sender<RequestWithToken>>,
}
#[derive(Clone)]