verification reply handling working
This commit is contained in:
parent
a261f15589
commit
ab2fa4c050
@ -74,6 +74,7 @@
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
use core::fmt::{Display, Formatter};
|
||||||
use core::hash::{Hash, Hasher};
|
use core::hash::{Hash, Hasher};
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use core::mem::size_of;
|
use core::mem::size_of;
|
||||||
@ -101,6 +102,12 @@ pub struct RequestId {
|
|||||||
psc: PacketSequenceCtrl,
|
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 {
|
impl Hash for RequestId {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
self.raw().hash(state);
|
self.raw().hash(state);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use fsrc_core::pus::verification::RequestId;
|
||||||
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
||||||
use spacepackets::ecss::PusPacket;
|
use spacepackets::ecss::PusPacket;
|
||||||
use spacepackets::tc::PusTc;
|
use spacepackets::tc::PusTc;
|
||||||
@ -8,11 +9,16 @@ use std::time::Duration;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut buf = [0; 32];
|
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 addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||||
let mut sph = SpHeader::tc(0x02, 0, 0).unwrap();
|
let mut sph = SpHeader::tc(0x02, 0, 0).unwrap();
|
||||||
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true);
|
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 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");
|
let size = pus_tc.write_to(&mut buf).expect("Creating PUS TC failed");
|
||||||
client
|
client
|
||||||
.send_to(&buf[0..size], &addr)
|
.send_to(&buf[0..size], &addr)
|
||||||
@ -20,19 +26,54 @@ fn main() {
|
|||||||
client
|
client
|
||||||
.set_read_timeout(Some(Duration::from_secs(2)))
|
.set_read_timeout(Some(Duration::from_secs(2)))
|
||||||
.expect("Setting read timeout failed");
|
.expect("Setting read timeout failed");
|
||||||
if let Ok(_len) = client.recv(&mut buf) {
|
loop {
|
||||||
let (pus_tm, size) = PusTm::new_from_raw_slice(&buf, 7).expect("Parsing PUS TM failed");
|
let res = client.recv(&mut buf);
|
||||||
if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
|
match res {
|
||||||
println!("Received PUS Ping Reply TM[17,2]")
|
Ok(_len) => {
|
||||||
} else {
|
let (pus_tm, size) =
|
||||||
println!(
|
PusTm::new_from_raw_slice(&buf, 7).expect("Parsing PUS TM failed");
|
||||||
"Received TM[{}, {}] with {} bytes",
|
if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
|
||||||
pus_tm.service(),
|
println!("Received PUS Ping Reply TM[17,2]")
|
||||||
pus_tm.subservice(),
|
} else if pus_tm.service() == 1 {
|
||||||
size
|
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",
|
||||||
|
pus_tm.service(),
|
||||||
|
pus_tm.subservice(),
|
||||||
|
size
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
println!("No reply received for 2 seconds or timeout");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use crate::tmtc::TmStore;
|
use crate::tmtc::TmStore;
|
||||||
use fsrc_core::pool::StoreAddr;
|
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::tm_helper::PusTmWithCdsShortHelper;
|
||||||
use fsrc_core::tmtc::PusServiceProvider;
|
use fsrc_core::tmtc::PusServiceProvider;
|
||||||
use spacepackets::tc::{PusTc, PusTcSecondaryHeaderT};
|
use spacepackets::tc::{PusTc, PusTcSecondaryHeaderT};
|
||||||
@ -55,27 +57,37 @@ impl PusServiceProvider for PusReceiver {
|
|||||||
self.stamper
|
self.stamper
|
||||||
.write_to_bytes(&mut self.time_stamp)
|
.write_to_bytes(&mut self.time_stamp)
|
||||||
.expect("Writing time stamp failed");
|
.expect("Writing time stamp failed");
|
||||||
let _accepted_token = reporter
|
let accepted_token = reporter
|
||||||
.acceptance_success(init_token, &self.time_stamp)
|
.acceptance_success(init_token, &self.time_stamp)
|
||||||
.expect("Acceptance success failure");
|
.expect("Acceptance success failure");
|
||||||
drop(reporter);
|
drop(reporter);
|
||||||
if service == 17 {
|
if service == 17 {
|
||||||
self.handle_test_service(pus_tc);
|
self.handle_test_service(pus_tc, accepted_token);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PusReceiver {
|
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 {
|
if pus_tc.subservice() == 1 {
|
||||||
println!("Received PUS ping command TC[17,1]");
|
println!("Received PUS ping command TC[17,1]");
|
||||||
println!("Sending ping reply PUS TM[17,2]");
|
println!("Sending ping reply PUS TM[17,2]");
|
||||||
let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None);
|
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 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
|
self.tm_tx
|
||||||
.send(addr)
|
.send(addr)
|
||||||
.expect("Sending TM to TM funnel failed");
|
.expect("Sending TM to TM funnel failed");
|
||||||
|
reporter
|
||||||
|
.completion_success(start_token, &self.time_stamp)
|
||||||
|
.expect("Error sending completion success");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user