diff --git a/Cargo.lock b/Cargo.lock index 1d8bc60..a09bb11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -240,6 +240,7 @@ dependencies = [ name = "fsrc-example" version = "0.1.0" dependencies = [ + "crossbeam-channel", "fsrc-core", "spacepackets", ] diff --git a/fsrc-example/Cargo.toml b/fsrc-example/Cargo.toml index 8f29e3b..ede00be 100644 --- a/fsrc-example/Cargo.toml +++ b/fsrc-example/Cargo.toml @@ -4,6 +4,9 @@ version = "0.1.0" edition = "2021" authors = ["Robin Mueller "] +[dependencies] +crossbeam-channel = "0.5" + [dependencies.spacepackets] path = "../spacepackets" diff --git a/fsrc-example/src/bin/test.rs b/fsrc-example/src/bin/test.rs new file mode 100644 index 0000000..026ccfc --- /dev/null +++ b/fsrc-example/src/bin/test.rs @@ -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; + +fn main() { + let (s0, r0): ( + Sender, + Receiver, + ) = 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(); +}