set up new example repo

This commit is contained in:
2022-08-18 01:32:02 +02:00
parent 1bf8138a94
commit e3a1d98741
11 changed files with 57 additions and 94 deletions

View 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));
}

View 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
View 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;