sat-rs/fsrc-example/src/bin/client.rs

39 lines
1.5 KiB
Rust
Raw Normal View History

2022-08-18 01:32:02 +02:00
use fsrc_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];
2022-09-03 13:47:25 +02:00
println!("Packing and sending PUS ping command TC[17,1]");
2022-08-18 01:32:02 +02:00
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-08-18 01:32:02 +02:00
let size = pus_tc.write_to(&mut buf).expect("Creating PUS TC failed");
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-03 13:47:25 +02:00
if let Ok(_len) = client.recv(&mut buf) {
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 {
println!(
"Received TM[{}, {}] with {} bytes",
pus_tm.service(),
pus_tm.subservice(),
size
);
}
2022-08-29 00:44:34 +02:00
} else {
println!("No reply received for 2 seconds or timeout");
}
2022-08-18 01:32:02 +02:00
}