add basic test bin
This commit is contained in:
parent
904eb607b1
commit
a2c1a38b48
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -240,6 +240,7 @@ dependencies = [
|
||||
name = "fsrc-example"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"fsrc-core",
|
||||
"spacepackets",
|
||||
]
|
||||
|
@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
|
||||
|
||||
[dependencies]
|
||||
crossbeam-channel = "0.5"
|
||||
|
||||
[dependencies.spacepackets]
|
||||
path = "../spacepackets"
|
||||
|
||||
|
44
fsrc-example/src/bin/test.rs
Normal file
44
fsrc-example/src/bin/test.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use crossbeam_channel::{bounded, Receiver, Sender};
|
||||
use std::thread;
|
||||
|
||||
trait FieldDataProvider: Send {
|
||||
fn get_data(&self) -> &[u8];
|
||||
}
|
||||
|
||||
struct FixedFieldDataWrapper {
|
||||
data: [u8; 8],
|
||||
}
|
||||
|
||||
impl FixedFieldDataWrapper {
|
||||
pub fn from_two_u32(p0: u32, p1: u32) -> Self {
|
||||
let mut data = [0; 8];
|
||||
data[0..4].copy_from_slice(p0.to_be_bytes().as_slice());
|
||||
data[4..8].copy_from_slice(p1.to_be_bytes().as_slice());
|
||||
Self { data }
|
||||
}
|
||||
}
|
||||
|
||||
impl FieldDataProvider for FixedFieldDataWrapper {
|
||||
fn get_data(&self) -> &[u8] {
|
||||
self.data.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
type FieldDataTraitObj = Box<dyn FieldDataProvider>;
|
||||
|
||||
fn main() {
|
||||
let (s0, r0): (
|
||||
Sender<FieldDataTraitObj>,
|
||||
Receiver<FieldDataTraitObj>,
|
||||
) = bounded(5);
|
||||
let data_wrapper = FixedFieldDataWrapper::from_two_u32(2, 3);
|
||||
s0.send(Box::new(data_wrapper)).unwrap();
|
||||
let jh0 = thread::spawn(move || {
|
||||
let data = r0.recv().unwrap();
|
||||
let raw = data.get_data();
|
||||
println!("Received data {:?}", raw);
|
||||
});
|
||||
let jh1 = thread::spawn(|| {});
|
||||
jh0.join().unwrap();
|
||||
jh1.join().unwrap();
|
||||
}
|
Loading…
Reference in New Issue
Block a user