2022-11-20 19:54:14 +01:00
|
|
|
use satrs_core::pus::verification::RequestId;
|
|
|
|
use satrs_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
2022-09-03 13:47:25 +02:00
|
|
|
use spacepackets::ecss::PusPacket;
|
2022-08-18 01:32:02 +02:00
|
|
|
use spacepackets::tc::PusTc;
|
2022-09-03 13:47:25 +02:00
|
|
|
use spacepackets::tm::PusTm;
|
2022-08-18 01:32:02 +02:00
|
|
|
use spacepackets::SpHeader;
|
|
|
|
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
2022-08-29 00:44:34 +02:00
|
|
|
use std::time::Duration;
|
2022-08-18 01:32:02 +02:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut buf = [0; 32];
|
|
|
|
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);
|
2022-08-28 00:28:29 +02:00
|
|
|
let client = UdpSocket::bind("127.0.0.1:7302").expect("Connecting to UDP server failed");
|
2022-09-11 14:51:25 +02:00
|
|
|
let tc_req_id = RequestId::new(&pus_tc);
|
|
|
|
println!(
|
2022-09-11 14:58:51 +02:00
|
|
|
"Packing and sending PUS ping command TC[17,1] with request ID {}",
|
2022-09-11 14:51:25 +02:00
|
|
|
tc_req_id
|
|
|
|
);
|
2022-09-11 20:51:14 +02:00
|
|
|
let size = pus_tc
|
|
|
|
.write_to_bytes(&mut buf)
|
|
|
|
.expect("Creating PUS TC failed");
|
2022-08-18 01:32:02 +02:00
|
|
|
client
|
|
|
|
.send_to(&buf[0..size], &addr)
|
|
|
|
.expect(&*format!("Sending to {:?} failed", addr));
|
2022-08-29 00:44:34 +02:00
|
|
|
client
|
|
|
|
.set_read_timeout(Some(Duration::from_secs(2)))
|
|
|
|
.expect("Setting read timeout failed");
|
2022-09-11 14:51:25 +02:00
|
|
|
loop {
|
|
|
|
let res = client.recv(&mut buf);
|
|
|
|
match res {
|
|
|
|
Ok(_len) => {
|
2022-09-13 10:43:07 +02:00
|
|
|
let (pus_tm, size) = PusTm::from_bytes(&buf, 7).expect("Parsing PUS TM failed");
|
2022-09-11 14:51:25 +02:00
|
|
|
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 {
|
2022-09-11 14:58:51 +02:00
|
|
|
println!(
|
|
|
|
"Received TM[1,1] acceptance success for request ID {}",
|
|
|
|
req_id
|
|
|
|
)
|
|
|
|
} else if pus_tm.subservice() == 2 {
|
|
|
|
println!(
|
|
|
|
"Received TM[1,2] acceptance failure for request ID {}",
|
|
|
|
req_id
|
|
|
|
)
|
2022-09-11 14:51:25 +02:00
|
|
|
} else if pus_tm.subservice() == 3 {
|
2022-09-11 14:58:51 +02:00
|
|
|
println!("Received TM[1,3] start success for request ID {}", req_id)
|
|
|
|
} else if pus_tm.subservice() == 4 {
|
|
|
|
println!("Received TM[1,2] start failure for request ID {}", req_id)
|
2022-09-11 14:51:25 +02:00
|
|
|
} else if pus_tm.subservice() == 5 {
|
2022-09-11 14:58:51 +02:00
|
|
|
println!("Received TM[1,5] step success for request ID {}", req_id)
|
|
|
|
} else if pus_tm.subservice() == 6 {
|
|
|
|
println!("Received TM[1,6] step failure for request ID {}", req_id)
|
2022-09-11 14:51:25 +02:00
|
|
|
} else if pus_tm.subservice() == 7 {
|
|
|
|
println!(
|
|
|
|
"Received TM[1,7] completion success for request ID {}",
|
|
|
|
req_id
|
|
|
|
)
|
2022-09-11 14:58:51 +02:00
|
|
|
} else if pus_tm.subservice() == 8 {
|
|
|
|
println!(
|
|
|
|
"Received TM[1,8] completion failure for request ID {}",
|
|
|
|
req_id
|
|
|
|
);
|
2022-09-11 14:51:25 +02:00
|
|
|
}
|
|
|
|
} 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());
|
|
|
|
}
|
2022-09-03 13:47:25 +02:00
|
|
|
}
|
2022-08-29 00:44:34 +02:00
|
|
|
}
|
2022-08-18 01:32:02 +02:00
|
|
|
}
|