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

26 lines
989 B
Rust
Raw Normal View History

2022-08-18 01:32:02 +02:00
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
use spacepackets::tc::PusTc;
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-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");
if let Ok(len) = client.recv(&mut buf) {
println!("Received TM with {} bytes", len);
} else {
println!("No reply received for 2 seconds or timeout");
}
2022-08-18 01:32:02 +02:00
}