no mutex lock for verif reporter required anymore

This commit is contained in:
Robin Müller 2022-11-27 01:19:34 +01:00
parent b8efa8e518
commit 48b686bd95
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
3 changed files with 38 additions and 35 deletions

View File

@ -24,7 +24,7 @@ use spacepackets::time::{CdsShortTimeProvider, TimeWriter};
use spacepackets::tm::PusTm;
use std::net::{IpAddr, SocketAddr};
use std::sync::mpsc::channel;
use std::sync::{mpsc, Arc, Mutex, RwLock};
use std::sync::{mpsc, Arc, RwLock};
use std::thread;
struct TmFunnel {
@ -83,10 +83,7 @@ fn main() {
8,
)
.unwrap();
let reporter_with_sender_0 = Arc::new(Mutex::new(VerificationReporterWithSender::new(
&verif_cfg,
Box::new(sender),
)));
let reporter_with_sender_0 = VerificationReporterWithSender::new(&verif_cfg, Box::new(sender));
// Create event handling components
let (event_request_tx, event_request_rx) = channel::<EventRequestWithToken>();
@ -99,7 +96,7 @@ 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 reporter1 = reporter_with_sender_0.clone();
let mut reporter1 = reporter_with_sender_0.clone();
event_man.subscribe_all(pus_event_man_send_provider.id());
// Create clones here to allow move for thread 0
@ -136,11 +133,8 @@ fn main() {
let mut timestamp: [u8; 7] = [0; 7];
let mut sender = EventTmSender::new(tm_store_helper, tm_funnel_tx);
let mut time_provider = CdsShortTimeProvider::new(0, 0);
let report_completion = |event_req: EventRequestWithToken, timestamp: &[u8]| {
let mut reporter = reporter1
.lock()
.expect("Locking Verification reporter failed");
reporter
let mut report_completion = |event_req: EventRequestWithToken, timestamp: &[u8]| {
reporter1
.completion_success(event_req.token, timestamp)
.expect("Sending completion success failed");
};

View File

@ -4,7 +4,7 @@ use satrs_core::pool::StoreAddr;
use satrs_core::pus::event::Subservices;
use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken};
use satrs_core::pus::verification::{
FailParams, SharedStdVerifReporterWithSender, TcStateAccepted, VerificationToken,
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
};
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use satrs_core::tmtc::PusServiceProvider;
@ -18,7 +18,7 @@ pub struct PusReceiver {
pub tm_helper: PusTmWithCdsShortHelper,
pub tm_tx: mpsc::Sender<StoreAddr>,
pub tm_store: TmStore,
pub verif_reporter: SharedStdVerifReporterWithSender,
pub verif_reporter: StdVerifReporterWithSender,
event_request_tx: mpsc::Sender<EventRequestWithToken>,
stamper: CdsShortTimeProvider,
time_stamp: [u8; 7],
@ -29,7 +29,7 @@ impl PusReceiver {
apid: u16,
tm_tx: mpsc::Sender<StoreAddr>,
tm_store: TmStore,
verif_reporter: SharedStdVerifReporterWithSender,
verif_reporter: StdVerifReporterWithSender,
event_request_tx: mpsc::Sender<EventRequestWithToken>,
) -> Self {
Self {
@ -53,25 +53,23 @@ impl PusServiceProvider for PusReceiver {
_header: &SpHeader,
pus_tc: &PusTc,
) -> Result<(), Self::Error> {
let mut reporter = self
.verif_reporter
.lock()
.expect("Locking Verification Reporter failed");
let init_token = reporter.add_tc(pus_tc);
let init_token = self.verif_reporter.add_tc(pus_tc);
self.stamper
.update_from_now()
.expect("Updating time for time stamp failed");
self.stamper
.write_to_bytes(&mut self.time_stamp)
.expect("Writing time stamp failed");
let accepted_token = reporter
let accepted_token = self
.verif_reporter
.acceptance_success(init_token, &self.time_stamp)
.expect("Acceptance success failure");
drop(reporter);
if service == 17 {
self.handle_test_service(pus_tc, accepted_token);
} else if service == 5 {
self.handle_event_service(pus_tc, accepted_token);
} else {
// TODO: Unknown service verification failure
}
Ok(())
}
@ -84,19 +82,27 @@ impl PusReceiver {
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 mut reporter = self
let start_token = self
.verif_reporter
.lock()
.expect("Error locking verification reporter");
let start_token = reporter
.start_success(token, &self.time_stamp)
.expect("Error sending start success");
self.tm_tx
.send(addr)
.expect("Sending TM to TM funnel failed");
reporter
self.verif_reporter
.completion_success(start_token, &self.time_stamp)
.expect("Error sending completion success");
} else {
// TODO: Unknown Subservice returncode
// TODO: Generate unknown subservice completion failure
self.update_time_stamp();
self.verif_reporter
.start_failure(
token,
FailParams::new(&self.time_stamp, &EcssEnumU16::new(2), None),
)
.expect("Sending start failure TM failed");
}
}
@ -110,24 +116,20 @@ impl PusReceiver {
}
fn handle_event_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
let send_start_failure = |verif_reporter: &mut SharedStdVerifReporterWithSender,
let send_start_failure = |verif_reporter: &mut StdVerifReporterWithSender,
timestamp: &[u8; 7],
failure_code: EcssEnumU16,
failure_data: Option<&[u8]>| {
verif_reporter
.lock()
.expect("Locking verification reporter failed")
.start_failure(
token,
FailParams::new(timestamp, &failure_code, failure_data),
)
.expect("Sending start failure TM failed");
};
let send_start_acceptance = |verif_reporter: &mut SharedStdVerifReporterWithSender,
let send_start_acceptance = |verif_reporter: &mut StdVerifReporterWithSender,
timestamp: &[u8; 7]| {
verif_reporter
.lock()
.expect("Locking verification reporter failed")
.start_success(token, timestamp)
.expect("Sending start success TM failed")
};
@ -175,6 +177,7 @@ impl PusReceiver {
.expect("Sending event request failed");
}
_ => {
// TODO: Unknown Subservice returncode
self.update_time_stamp();
send_start_failure(
&mut self.verif_reporter,

View File

@ -12,7 +12,7 @@ use crate::pus::PusReceiver;
use crate::UdpTmtcServer;
use satrs_core::pool::{SharedPool, StoreAddr};
use satrs_core::pus::event_man::EventRequestWithToken;
use satrs_core::pus::verification::SharedStdVerifReporterWithSender;
use satrs_core::pus::verification::StdVerifReporterWithSender;
use satrs_core::tmtc::{CcsdsDistributor, CcsdsError, PusDistributor};
use spacepackets::tm::PusTm;
@ -45,7 +45,7 @@ pub fn core_tmtc_task(
args: CoreTmtcArgs,
tm_server_rx: mpsc::Receiver<StoreAddr>,
addr: SocketAddr,
verif_reporter: SharedStdVerifReporterWithSender,
verif_reporter: StdVerifReporterWithSender,
) {
let pus_receiver = PusReceiver::new(
PUS_APID,
@ -111,7 +111,13 @@ fn core_tm_handling(udp_tmtc_server: &mut UdpTmtcServer, recv_addr: &SocketAddr)
.expect("Locking TM store failed");
let pg = store_lock.read_with_guard(addr);
let buf = pg.read().expect("Error reading TM pool data");
println!("Sending TM");
if buf.len() > 9 {
let service = buf[7];
let subservice = buf[8];
println!("Sending PUS TM[{},{}]", service, subservice)
} else {
println!("Sending PUS TM");
}
udp_tmtc_server
.udp_tc_server
.socket