set up new example repo
This commit is contained in:
16
fsrc-example/src/bin/client.rs
Normal file
16
fsrc-example/src/bin/client.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use spacepackets::tc::PusTc;
|
||||
use spacepackets::SpHeader;
|
||||
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||
|
||||
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);
|
||||
let client = UdpSocket::bind("127.0.0.1:7300").expect("Connecting to UDP server failed");
|
||||
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));
|
||||
}
|
15
fsrc-example/src/bin/obsw.rs
Normal file
15
fsrc-example/src/bin/obsw.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||
|
||||
fn main() {
|
||||
let mut recv_buf = [0; 1024];
|
||||
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||
let socket = UdpSocket::bind(&addr).expect("Error opening UDP socket");
|
||||
loop {
|
||||
let (num_bytes, src) = socket.recv_from(&mut recv_buf).expect("UDP Receive error");
|
||||
println!(
|
||||
"Received TM with len {num_bytes} from {src}: {:x?}",
|
||||
&recv_buf[0..num_bytes]
|
||||
);
|
||||
}
|
||||
}
|
4
fsrc-example/src/lib.rs
Normal file
4
fsrc-example/src/lib.rs
Normal file
@ -0,0 +1,4 @@
|
||||
use std::net::Ipv4Addr;
|
||||
|
||||
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||
pub const SERVER_PORT: u16 = 7301;
|
Reference in New Issue
Block a user