verification reply handling working

This commit is contained in:
Robin Müller 2022-09-11 14:51:25 +02:00
parent a261f15589
commit ab2fa4c050
No known key found for this signature in database
GPG Key ID: 9C287E88FED11DF3
4 changed files with 78 additions and 73 deletions

View File

@ -74,6 +74,7 @@
use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;
use core::fmt::{Display, Formatter};
use core::hash::{Hash, Hasher};
use core::marker::PhantomData;
use core::mem::size_of;
@ -101,6 +102,12 @@ pub struct RequestId {
psc: PacketSequenceCtrl,
}
impl Display for RequestId {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "Request ID {:#08x}", self.raw())
}
}
impl Hash for RequestId {
fn hash<H: Hasher>(&self, state: &mut H) {
self.raw().hash(state);

View File

@ -1,3 +1,4 @@
use fsrc_core::pus::verification::RequestId;
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
use spacepackets::ecss::PusPacket;
use spacepackets::tc::PusTc;
@ -8,11 +9,16 @@ use std::time::Duration;
fn main() {
let mut buf = [0; 32];
println!("Packing and sending PUS ping command TC[17,1]");
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
let mut sph = SpHeader::tc(0x02, 0, 0).unwrap();
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true);
let client = UdpSocket::bind("127.0.0.1:7302").expect("Connecting to UDP server failed");
let tc_req_id = RequestId::new(&pus_tc);
println!(
"Packing and sending PUS ping command TC[17,1] with {}",
tc_req_id
);
let size = pus_tc.write_to(&mut buf).expect("Creating PUS TC failed");
client
.send_to(&buf[0..size], &addr)
@ -20,10 +26,35 @@ fn main() {
client
.set_read_timeout(Some(Duration::from_secs(2)))
.expect("Setting read timeout failed");
if let Ok(_len) = client.recv(&mut buf) {
let (pus_tm, size) = PusTm::new_from_raw_slice(&buf, 7).expect("Parsing PUS TM failed");
loop {
let res = client.recv(&mut buf);
match res {
Ok(_len) => {
let (pus_tm, size) =
PusTm::new_from_raw_slice(&buf, 7).expect("Parsing PUS TM failed");
if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
println!("Received PUS Ping Reply TM[17,2]")
} else if pus_tm.service() == 1 {
if pus_tm.source_data().is_none() {
println!("Invalid verification TM, no source data");
}
let src_data = pus_tm.source_data().unwrap();
if src_data.len() < 4 {
println!("Invalid verification TM source data, less than 4 bytes")
}
let req_id = RequestId::from_bytes(src_data).unwrap();
if pus_tm.subservice() == 1 {
println!("Received TM[1,1] acceptance success for {}", req_id)
} else if pus_tm.subservice() == 3 {
println!("Received TM[1,3] start success for {}", req_id)
} else if pus_tm.subservice() == 5 {
println!("Received TM[1,5] step success for {}", req_id)
} else if pus_tm.subservice() == 7 {
println!(
"Received TM[1,7] completion success for request ID {}",
req_id
)
}
} else {
println!(
"Received TM[{}, {}] with {} bytes",
@ -32,7 +63,17 @@ fn main() {
size
);
}
} else {
println!("No reply received for 2 seconds or timeout");
}
Err(ref e)
if e.kind() == std::io::ErrorKind::WouldBlock
|| e.kind() == std::io::ErrorKind::TimedOut =>
{
println!("No reply received for 2 seconds");
break;
}
_ => {
println!("UDP receive error {:?}", res.unwrap_err());
}
}
}
}

View File

@ -1,6 +1,8 @@
use crate::tmtc::TmStore;
use fsrc_core::pool::StoreAddr;
use fsrc_core::pus::verification::SharedStdVerifReporterWithSender;
use fsrc_core::pus::verification::{
SharedStdVerifReporterWithSender, StateAccepted, VerificationToken,
};
use fsrc_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use fsrc_core::tmtc::PusServiceProvider;
use spacepackets::tc::{PusTc, PusTcSecondaryHeaderT};
@ -55,27 +57,37 @@ impl PusServiceProvider for PusReceiver {
self.stamper
.write_to_bytes(&mut self.time_stamp)
.expect("Writing time stamp failed");
let _accepted_token = reporter
let accepted_token = reporter
.acceptance_success(init_token, &self.time_stamp)
.expect("Acceptance success failure");
drop(reporter);
if service == 17 {
self.handle_test_service(pus_tc);
self.handle_test_service(pus_tc, accepted_token);
}
Ok(())
}
}
impl PusReceiver {
fn handle_test_service(&mut self, pus_tc: &PusTc) {
fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken<StateAccepted>) {
if pus_tc.subservice() == 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 mut reporter = 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
.completion_success(start_token, &self.time_stamp)
.expect("Error sending completion success");
}
}
}

View File

@ -1,55 +0,0 @@
// use std::sync::{Arc, Mutex};
//
// trait ProvidesFoo {
// fn magic(&mut self);
// }
//
// struct Foo {
// magic_value: u32,
// }
//
// impl Default for Foo {
// fn default() -> Self {
// Self { magic_value: 42 }
// }
// }
//
// impl ProvidesFoo for Foo {
// fn magic(&mut self) {
// println!("ProvidesFoo magic {}", self.magic_value);
// }
// }
//
// type SharedFooConcrete = Arc<Mutex<Box<Foo>>>;
// type SharedFooTraitObj = Arc<Mutex<Box<dyn ProvidesFoo + Send + Sync>>>;
//
// #[allow(dead_code)]
// struct FooProvider {
// foo_as_trait_obj: SharedFooTraitObj,
// }
//
// impl FooProvider {
// fn magic_and_then_some(&mut self) {
// let mut fooguard = self.foo_as_trait_obj.lock().unwrap();
// fooguard.magic();
// println!("Additional magic");
// }
// }
//
// #[allow(dead_code)]
// fn uses_shared_foo_boxed_trait_obj(foo: SharedFooTraitObj) {
// let mut foo_provider = FooProvider {
// foo_as_trait_obj: foo,
// };
// foo_provider.magic_and_then_some();
// }
// fn uses_shared_foo_concrete(foo: SharedFooConcrete) {
// let mut fooguard = foo.lock().unwrap();
// fooguard.magic();
// }
//
fn main() {
// let shared_foo = Arc::new(Mutex::new(Box::new(Foo::default())));
// uses_shared_foo_concrete(shared_foo.clone());
// // uses_shared_foo_boxed_trait_obj(shared_foo);
}