set up new example repo

This commit is contained in:
Robin Müller 2022-08-18 01:32:02 +02:00
parent 1bf8138a94
commit e3a1d98741
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
11 changed files with 57 additions and 94 deletions

12
Cargo.lock generated
View File

@ -223,6 +223,7 @@ dependencies = [
"bus",
"downcast-rs",
"num",
"once_cell",
"postcard",
"serde",
"spacepackets",
@ -230,6 +231,13 @@ dependencies = [
"zerocopy",
]
[[package]]
name = "fsrc-example"
version = "0.1.0"
dependencies = [
"spacepackets",
]
[[package]]
name = "hash32"
version = "0.2.1"
@ -417,9 +425,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.13.0"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e"
[[package]]
name = "parking_lot_core"

View File

@ -3,4 +3,5 @@
members = [
"fsrc-core",
"spacepackets",
"fsrc-example"
]

View File

@ -21,6 +21,7 @@ default-features = false
postcard = { version = "1.0.1", features = ["use-std"] }
serde = "1.0.143"
zerocopy = "0.6.1"
once_cell = "1.13.1"
[features]
default = ["use_std"]

View File

@ -1,23 +0,0 @@
extern crate core;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket};
use std::thread;
fn main() {
let server_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 7301);
let socket = UdpSocket::bind(&server_addr.clone()).expect("Error opening UDP socket");
let mut recv_buf = [0; 1024];
let jh = thread::spawn(move || {
let dummy_data = [1, 2, 3, 4];
let client = UdpSocket::bind("127.0.0.1:7300").expect("Connecting to UDP server failed");
client
.send_to(&dummy_data, &server_addr)
.expect(&*format!("Sending to {:?} failed", server_addr));
});
let (num_bytes, src) = socket.recv_from(&mut recv_buf).expect("UDP Receive error");
println!(
"Received {num_bytes} bytes from {src}: {:x?}",
&recv_buf[0..num_bytes]
);
jh.join().expect("Joining thread failed");
}

View File

@ -1,67 +0,0 @@
use postcard::{from_bytes, to_stdvec};
use serde::{Deserialize, Serialize};
use zerocopy::byteorder::{I32, U16};
use zerocopy::{AsBytes, FromBytes, NetworkEndian, Unaligned};
#[derive(AsBytes, FromBytes, Unaligned, Debug, Eq, PartialEq)]
#[repr(C, packed)]
struct ZeroCopyTest {
some_bool: u8,
some_u16: U16<NetworkEndian>,
some_i32: I32<NetworkEndian>,
some_float: [u8; 4],
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct PostcardTest {
some_bool: u8,
some_u16: u16,
some_i32: i32,
some_float: f32,
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct SliceSerTest<'slice> {
some_u8: u8,
some_u32: u32,
some_slice: &'slice [u8],
}
fn main() {
let pc_test = PostcardTest {
some_bool: true as u8,
some_u16: 0x42,
some_i32: -200,
some_float: 7.7_f32,
};
let out = to_stdvec(&pc_test).unwrap();
println!("{:#04x?}", out);
let sample_hk = ZeroCopyTest {
some_bool: true as u8,
some_u16: U16::from(0x42),
some_i32: I32::from(-200),
some_float: 7.7_f32.to_be_bytes(),
};
let mut slice = [0; 11];
sample_hk.write_to(slice.as_mut_slice());
println!("{:#04x?}", slice);
let ser_vec;
{
let test_buf = [0, 1, 2, 3];
let test_with_slice = SliceSerTest {
some_u8: 12,
some_u32: 1,
some_slice: test_buf.as_slice(),
};
ser_vec = to_stdvec(&test_with_slice).unwrap();
println!("{:#04x?}", out);
}
{
let test_deser: SliceSerTest = from_bytes(ser_vec.as_slice()).unwrap();
println!("{:?}", test_deser);
}
}

View File

@ -151,7 +151,7 @@ impl<E: 'static> CcsdsDistributor<E> {
/// This function can be used to retrieve a reference to the concrete instance of the APID
/// handler after it was passed to the distributor. See the
/// [module documentation][crate::tmtc::ccsds_distrib] for an example.
/// [module documentation][crate::tmtc::ccsds_distrib] for an fsrc-example.
pub fn apid_handler_ref<T: ApidPacketHandler<Error = E>>(&self) -> Option<&T> {
self.apid_handler.downcast_ref::<T>()
}

View File

@ -42,7 +42,7 @@ pub trait ReceivesTc {
fn pass_tc(&mut self, tc_raw: &[u8]) -> Result<(), Self::Error>;
}
/// Generic trait for object which can receive CCSDS space packets, for example ECSS PUS packets
/// Generic trait for object which can receive CCSDS space packets, for fsrc-example ECSS PUS packets
/// for CCSDS File Delivery Protocol (CFDP) packets.
///
/// This trait is implemented by both the [crate::tmtc::pus_distrib::PusDistributor] and the

8
fsrc-example/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "fsrc-example"
version = "0.1.0"
edition = "2021"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
[dependencies.spacepackets]
path = "../spacepackets"

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;