diff --git a/src/blocking.rs b/src/blocking.rs index b2f7ea4..b3625ea 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -17,6 +17,7 @@ use structopt::StructOpt; use crate::std::string::ToString; use crate::{Transmit, Receive, State}; +use crate::params::Param; /// BlockingOptions for blocking radio functions #[derive(Clone, PartialEq, Debug)] @@ -60,6 +61,7 @@ impl From for BlockingError { # use radio::*; # use radio::mock::*; use radio::blocking::{BlockingTransmit, BlockingOptions}; +use radio::params::Basic; # let mut radio = MockRadio::new(&[ # Transaction::start_transmit(vec![0xaa, 0xbb], None), @@ -69,7 +71,7 @@ use radio::blocking::{BlockingTransmit, BlockingOptions}; # ]); # // Transmit using a blocking call -let res = radio.do_transmit(&[0xaa, 0xbb], BlockingOptions::default()); +let res = radio.do_transmit(&[0xaa, 0xbb], &Basic, BlockingOptions::default()); assert_eq!(res, Ok(())); @@ -77,18 +79,18 @@ assert_eq!(res, Ok(())); ``` "##)] /// -pub trait BlockingTransmit { - fn do_transmit(&mut self, data: &[u8], tx_options: BlockingOptions) -> Result<(), BlockingError>; +pub trait BlockingTransmit { + fn do_transmit(&mut self, data: &[u8], params: &P, tx_options: BlockingOptions) -> Result<(), BlockingError>; } -impl BlockingTransmit for T +impl BlockingTransmit for T where - T: Transmit + DelayUs, + T: Transmit + DelayUs, E: core::fmt::Debug, { - fn do_transmit(&mut self, data: &[u8], tx_options: BlockingOptions) -> Result<(), BlockingError> { + fn do_transmit(&mut self, data: &[u8], params: &P, tx_options: BlockingOptions) -> Result<(), BlockingError> { // Enter transmit mode - self.start_transmit(data)?; + self.start_transmit(data, params)?; let t = tx_options.timeout.as_micros(); let mut c = 0; @@ -121,6 +123,7 @@ where # use radio::*; # use radio::mock::*; use radio::blocking::{BlockingReceive, BlockingOptions}; +use radio::params::Basic; let data = [0xaa, 0xbb]; let info = BasicInfo::new(-81, 0); @@ -136,10 +139,11 @@ let info = BasicInfo::new(-81, 0); # let mut buff = [0u8; 128]; +let params = Basic; let mut i = BasicInfo::new(0, 0); // Receive using a blocking call -let res = radio.do_receive(&mut buff, &mut i, BlockingOptions::default()); +let res = radio.do_receive(&mut buff, ¶ms, &mut i, BlockingOptions::default()); assert_eq!(res, Ok(data.len())); assert_eq!(&buff[..data.len()], &data); @@ -148,19 +152,19 @@ assert_eq!(&buff[..data.len()], &data); ``` "##)] /// -pub trait BlockingReceive { - fn do_receive(&mut self, buff: &mut [u8], info: &mut I, rx_options: BlockingOptions) -> Result>; +pub trait BlockingReceive { + fn do_receive(&mut self, buff: &mut [u8], params: &P, info: &mut P::Info, rx_options: BlockingOptions) -> Result>; } -impl BlockingReceive for T +impl BlockingReceive for T where - T: Receive + DelayUs, - I: core::fmt::Debug, + T: Receive + DelayUs, + P: Param, E: core::fmt::Debug, { - fn do_receive(&mut self, buff: &mut [u8], info: &mut I, rx_options: BlockingOptions) -> Result> { + fn do_receive(&mut self, buff: &mut [u8], params: &P, info: &mut P::Info, rx_options: BlockingOptions) -> Result> { // Start receive mode - self.start_receive()?; + self.start_receive(params)?; let t = rx_options.timeout.as_micros(); let mut c = 0; diff --git a/src/helpers.rs b/src/helpers.rs index b01414b..6549d05 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,11 +1,11 @@ //! Provides common helpers for implementing radio utilities -//! +//! //! ## https://github.com/ryankurte/rust-radio //! ## Copyright 2020 Ryan Kurte use structopt::StructOpt; use humantime::{Duration as HumanDuration}; -use embedded_hal::blocking::delay::DelayUs; +use embedded_hal::delay::blocking::DelayUs; extern crate std; use std::prelude::v1::*; @@ -22,6 +22,7 @@ use rolling_stats::Stats; use crate::{Transmit, Receive, ReceiveInfo, Power, Rssi}; use crate::blocking::*; +use crate::params::Param; /// Basic operations supported by the helpers package @@ -48,25 +49,26 @@ pub enum Operation { LinkTest(PingPongOptions), } -pub fn do_operation(radio: &mut T, operation: Operation) -> Result<(), BlockingError> +pub fn do_operation(radio: &mut T, operation: Operation, params: &P) -> Result<(), BlockingError> where - T: Transmit + Power + Receive + Rssi + Power + DelayUs, - I: ReceiveInfo + Default + std::fmt::Debug, + T: Transmit + Power + Receive + Rssi + Power + DelayUs, + P: Param, + P::Info: Default, E: std::fmt::Debug, { let mut buff = [0u8; 1024]; - let mut info = I::default(); + let mut info = P::Info::default(); // TODO: the rest match operation { - Operation::Transmit(options) => do_transmit(radio, options)?, - Operation::Receive(options) => do_receive(radio, &mut buff, &mut info, options).map(|_| ())?, - Operation::Echo(options) => do_echo(radio, &mut buff, &mut info, options).map(|_| ())?, - Operation::Rssi(options) => do_rssi(radio, options).map(|_| ())?, - Operation::LinkTest(options) => do_ping_pong(radio, options).map(|_| ())?, + Operation::Transmit(options) => do_transmit(radio, params, options)?, + Operation::Receive(options) => do_receive(radio, &mut buff, params, &mut info, options).map(|_| ())?, + Operation::Echo(options) => do_echo(radio, &mut buff, params, &mut info, options).map(|_| ())?, + Operation::Rssi(options) => do_rssi(radio, params, options).map(|_| ())?, + Operation::LinkTest(options) => do_ping_pong(radio, params, options).map(|_| ())?, //_ => warn!("unsuppored command: {:?}", opts.command), } - + Ok(()) } @@ -89,9 +91,9 @@ pub struct TransmitOptions { pub blocking_options: BlockingOptions, } -pub fn do_transmit(radio: &mut T, options: TransmitOptions) -> Result<(), BlockingError> +pub fn do_transmit(radio: &mut T, params: &P, options: TransmitOptions) -> Result<(), BlockingError> where - T: Transmit + Power + DelayUs, + T: Transmit + Power + DelayUs, E: core::fmt::Debug, { // Set output power if specified @@ -101,11 +103,11 @@ where loop { // Transmit packet - radio.do_transmit(&options.data, options.blocking_options.clone())?; + radio.do_transmit(&options.data, params, options.blocking_options.clone())?; // Delay for repeated transmission or exit match &options.period { - Some(p) => radio.try_delay_us(p.as_micros() as u32).unwrap(), + Some(p) => radio.delay_us(p.as_micros() as u32).unwrap(), None => break, } } @@ -154,28 +156,28 @@ impl PcapOptions { (None, Some(pipe)) => { // Ensure file doesn't already exist let _ = std::fs::remove_file(pipe); - + // Create pipe let n = CString::new(pipe.as_str()).unwrap(); let status = unsafe { libc::mkfifo(n.as_ptr(), 0o644) }; - + // Manual status code handling // TODO: return io::Error if status != 0 { panic!("Error creating fifo: {}", status); } - + // Open pipe let f = OpenOptions::new() .write(true) .open(pipe) .expect("Error opening PCAP pipe"); - + Some(f) } (None, None) => None, - + _ => unimplemented!() }; @@ -201,17 +203,17 @@ impl PcapOptions { } /// Receive from the radio using the provided configuration -pub fn do_receive(radio: &mut T, mut buff: &mut [u8], mut info: &mut I, options: ReceiveOptions) -> Result +pub fn do_receive(radio: &mut T, mut buff: &mut [u8], params: &P, mut info: &mut P::Info, options: ReceiveOptions) -> Result where - T: Receive + DelayUs, - I: std::fmt::Debug, + T: Receive + DelayUs, + P: Param, E: std::fmt::Debug, { // Create and open pcap file for writing let mut pcap_writer = options.pcap_options.open().expect("Error opening pcap file / pipe"); // Start receive mode - radio.start_receive()?; + radio.start_receive(params)?; loop { if radio.check_receive(true)? { @@ -224,18 +226,18 @@ where if let Some(p) = &mut pcap_writer { let t = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); - + p.write(t.as_secs() as u32, t.as_nanos() as u32 % 1_000_000, &buff[0..n], n as u32).expect("Error writing pcap file"); } - - if !options.continuous { + + if !options.continuous { return Ok(n) } - radio.start_receive()?; + radio.start_receive(params)?; } - radio.try_delay_us(options.blocking_options.poll_interval.as_micros() as u32).unwrap(); + radio.delay_us(options.blocking_options.poll_interval.as_micros() as u32).unwrap(); } } @@ -251,14 +253,14 @@ pub struct RssiOptions { pub continuous: bool, } -pub fn do_rssi(radio: &mut T, options: RssiOptions) -> Result<(), E> +pub fn do_rssi(radio: &mut T, params: &P, options: RssiOptions) -> Result<(), E> where - T: Receive + Rssi + DelayUs, - I: std::fmt::Debug, + T: Receive + Rssi + DelayUs, + P: Param, E: std::fmt::Debug, { // Enter receive mode - radio.start_receive()?; + radio.start_receive(params)?; // Poll for RSSI loop { @@ -268,7 +270,7 @@ where radio.check_receive(true)?; - radio.try_delay_us(options.period.as_micros() as u32).unwrap(); + radio.delay_us(options.period.as_micros() as u32).unwrap(); if !options.continuous { break @@ -284,7 +286,7 @@ pub struct EchoOptions { /// Run continuously #[structopt(long = "continuous")] pub continuous: bool, - + /// Power in dBm (range -18dBm to 13dBm) #[structopt(long = "power")] pub power: Option, @@ -302,10 +304,10 @@ pub struct EchoOptions { } -pub fn do_echo(radio: &mut T, mut buff: &mut [u8], mut info: &mut I, options: EchoOptions) -> Result> +pub fn do_echo(radio: &mut T, mut buff: &mut [u8], params: &P, mut info: &mut P::Info, options: EchoOptions) -> Result> where - T: Receive + Transmit + Power + DelayUs, - I: ReceiveInfo + std::fmt::Debug, + T: Receive + Transmit + Power + DelayUs, + P: Param, E: std::fmt::Debug, { // Set output power if specified @@ -314,7 +316,7 @@ where } // Start receive mode - radio.start_receive()?; + radio.start_receive(params)?; loop { if radio.check_receive(true)? { @@ -334,17 +336,17 @@ where } // Wait for turnaround delay - radio.try_delay_us(options.delay.as_micros() as u32).unwrap(); + radio.delay_us(options.delay.as_micros() as u32).unwrap(); // Transmit respobnse - radio.do_transmit(&buff[..n], options.blocking_options.clone())?; - + radio.do_transmit(&buff[..n], params, options.blocking_options.clone())?; + // Exit if non-continuous if !options.continuous { return Ok(n) } } // Wait for poll delay - radio.try_delay_us(options.blocking_options.poll_interval.as_micros() as u32).unwrap(); + radio.delay_us(options.blocking_options.poll_interval.as_micros() as u32).unwrap(); } } @@ -381,10 +383,11 @@ pub struct LinkTestInfo { } -pub fn do_ping_pong(radio: &mut T, options: PingPongOptions) -> Result> +pub fn do_ping_pong(radio: &mut T, params: &P, options: PingPongOptions) -> Result> where - T: Receive + Transmit + Power + DelayUs, - I: ReceiveInfo + Default + std::fmt::Debug, + T: Receive + Transmit + Power + DelayUs, + P: Param, + P::Info: Default, E: std::fmt::Debug, { let mut link_info = LinkTestInfo{ @@ -394,7 +397,7 @@ where remote_rssi: Stats::new(), }; - let mut info = I::default(); + let mut info = P::Info::default(); let mut buff = [0u8; 32]; // Set output power if specified @@ -410,10 +413,10 @@ where debug!("Sending message {}", i); // Send message - radio.do_transmit(&buff[0..n], options.blocking_options.clone())?; + radio.do_transmit(&buff[0..n], params, options.blocking_options.clone())?; // Await response - let n = match radio.do_receive(&mut buff, &mut info, options.blocking_options.clone()) { + let n = match radio.do_receive(&mut buff, params, &mut info, options.blocking_options.clone()) { Ok(n) => n, Err(BlockingError::Timeout) => { debug!("Timeout awaiting response {}", i); @@ -443,7 +446,7 @@ where } // Wait for send delay - radio.try_delay_us(options.delay.as_micros() as u32).unwrap(); + radio.delay_us(options.delay.as_micros() as u32).unwrap(); } Ok(link_info) diff --git a/src/lib.rs b/src/lib.rs index 39014fc..819d501 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,6 @@ extern crate log; extern crate embedded_hal; - #[cfg(feature="std")] extern crate std; @@ -24,6 +23,8 @@ pub mod config; pub mod blocking; +pub mod params; + #[cfg(feature="nonblocking")] pub mod nonblocking; #[cfg(feature="helpers")] @@ -32,20 +33,20 @@ pub mod helpers; pub mod mock; /// Radio trait combines Base, Configure, Send and Receive for a generic radio object -pub trait Radio: Transmit + Receive + State {} +pub trait Radio: Transmit

+ Receive

+ State {} /// Transmit trait for radios that can transmit packets /// /// `start_transmit` should be called to load data into the radio, with `check_transmit` called /// periodically (or using interrupts) to continue and finalise the transmission. -pub trait Transmit { +pub trait Transmit

{ /// Radio error type Error; /// Start sending a packet on the provided channel /// /// Returns an error if send was not started - fn start_transmit(&mut self, data: &[u8]) -> Result<(), Self::Error>; + fn start_transmit(&mut self, data: &[u8], params: &P) -> Result<(), Self::Error>; /// Check for send completion /// @@ -58,16 +59,14 @@ pub trait Transmit { /// `start_receive` should be used to setup the radio in receive mode, with `check_receive` called /// periodically (or using interrupts) to poll for packet reception. Once a packet has been received, /// `get_received` fetches the received packet (and associated info) from the radio. -pub trait Receive { +pub trait Receive { /// Radio error type Error; - /// Packet received info - type Info; /// Set receiving on the specified channel /// /// Returns an error if receive mode was not entered - fn start_receive(&mut self) -> Result<(), Self::Error>; + fn start_receive(&mut self, params: &P) -> Result<(), Self::Error>; /// Check for reception /// @@ -81,7 +80,7 @@ pub trait Receive { /// /// This copies received data into the provided buffer and returns the number of bytes received /// as well as information about the received packet - fn get_received(&mut self, info: &mut Self::Info, buff: &mut [u8]) -> Result; + fn get_received(&mut self, info: &mut P::Info, buff: &mut [u8]) -> Result; } /// ReceiveInfo trait for receive information objects @@ -245,6 +244,7 @@ pub trait Registers { } } +use crate::params::Param; #[cfg(feature="structopt")] use crate::std::str::FromStr; diff --git a/src/mock.rs b/src/mock.rs index 7e4f513..2462c8c 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -7,16 +7,18 @@ //! ## Copyright 2020 Ryan Kurte extern crate std; + use std::vec::Vec; use std::fmt::Debug; use std::convert::Infallible; -use embedded_hal::blocking::delay::DelayUs; +use embedded_hal::delay::blocking::DelayUs; extern crate embedded_hal_mock; use embedded_hal_mock::common::Generic; use crate::{State, Busy, Transmit, Receive, Power, Channel, Rssi, Interrupts, BasicInfo}; +use crate::params::Basic; /// Generic mock radio /// @@ -64,7 +66,6 @@ where /// Concrete mock radio using mock types pub type MockRadio = Radio; - /// MockState for use with mock radio #[derive(Debug, Clone, PartialEq)] pub enum MockState { @@ -277,7 +278,7 @@ where { type Error = Infallible; - fn try_delay_us(&mut self, ms: u32) -> Result<(), Self::Error> { + fn delay_us(&mut self, ms: u32) -> Result<(), Self::Error> { let n = self.next().expect("no expectation for delay_us call"); assert_eq!(&n.request, &Request::DelayUs(ms)); @@ -471,7 +472,7 @@ where } } -impl Transmit for Radio +impl Transmit for Radio where St: PartialEq + Debug + Clone, Reg: PartialEq + Debug + Clone, @@ -482,7 +483,7 @@ where { type Error = E; - fn start_transmit(&mut self, data: &[u8]) -> Result<(), Self::Error> { + fn start_transmit(&mut self, data: &[u8], _: &Basic) -> Result<(), Self::Error> { let n = self.next().expect("no expectation for Transmit::start_transmit call"); assert_eq!(&n.request, &Request::StartTransmit(data.to_vec())); @@ -515,7 +516,7 @@ where } } -impl Receive for Radio +impl Receive for Radio where St: PartialEq + Debug + Clone, Reg: PartialEq + Debug + Clone, @@ -524,10 +525,10 @@ where Irq: PartialEq + Debug + Clone, E: PartialEq + Debug + Clone, { - type Info = Inf; type Error = E; + type Info = Inf; - fn start_receive(&mut self) -> Result<(), Self::Error> { + fn start_receive(&mut self, _: &Basic) -> Result<(), Self::Error> { let n = self.next().expect("no expectation for Receive::start_receive call"); assert_eq!(&n.request, &Request::StartReceive); @@ -566,7 +567,7 @@ where let res = match &n.response { Response::Received(d, i) => { - &mut buff[..d.len()].copy_from_slice(&d); + buff[..d.len()].copy_from_slice(&d); *info = i.clone(); Ok(d.len()) @@ -638,7 +639,7 @@ mod test { fn test_radio_mock_start_transmit() { let mut radio = MockRadio::new(&[Transaction::start_transmit(vec![0xaa, 0xbb, 0xcc], None)]); - let _res = radio.start_transmit(&[0xaa, 0xbb, 0xcc]).unwrap(); + let _res = radio.start_transmit(&[0xaa, 0xbb, 0xcc], &Basic).unwrap(); radio.done(); } @@ -660,7 +661,7 @@ mod test { fn test_radio_mock_start_receive() { let mut radio = MockRadio::new(&[Transaction::start_receive(None)]); - let _res = radio.start_receive().unwrap(); + let _res = radio.start_receive(&Basic).unwrap(); radio.done(); } diff --git a/src/nonblocking.rs b/src/nonblocking.rs index ad08fe8..629a317 100644 --- a/src/nonblocking.rs +++ b/src/nonblocking.rs @@ -11,19 +11,20 @@ use core::task::{Context, Poll}; use core::pin::Pin; use crate::{Transmit, Receive, Power}; +use crate::params::Param; /// Options for async driver calls pub struct AsyncOptions { /// Power option, for transmit operations pub power: Option, - + /// Timeout option for underlying radio operations #[deprecated(note = "Timeouts must (currently) be implemented outside this module")] pub timeout: Option, - + /// Period for polling on operation status with custom wakers pub poll_period: Duration, - + /// Waker function to be called in the `Poll` method pub wake_fn: Option<&'static fn(cx: &mut Context, d: Duration)>, } @@ -31,7 +32,7 @@ pub struct AsyncOptions { impl Default for AsyncOptions { #[allow(deprecated)] fn default() -> Self { - Self { + Self { power: None, timeout: None, poll_period: Duration::from_millis(10), @@ -54,7 +55,7 @@ impl From for AsyncError { } /// Async transmit function implemented over `radio::Transmit` and `radio::Power` using the provided `AsyncOptions` -/// +/// #[cfg_attr(feature = "mock", doc = r##" ``` extern crate async_std; @@ -81,30 +82,32 @@ assert_eq!(res, Ok(())); ``` "##)] -/// AsyncTransmit function provides an async implementation for transmitting packets -pub trait AsyncTransmit<'a, E> { +/// AsyncTransmit function provides an async implementation for transmitting packets +pub trait AsyncTransmit<'a, P, E> { type Output: Future>>; - fn async_transmit(&'a mut self, data: &'a [u8], tx_options: AsyncOptions) -> Result; + fn async_transmit(&'a mut self, data: &'a [u8], params: &'a P, tx_options: AsyncOptions) -> Result; } /// Future object containing a radio for transmit operation -pub struct TransmitFuture<'a, T, E> { +pub struct TransmitFuture<'a, T, P, E> { radio: &'a mut T, + params: &'a P, options: AsyncOptions, _err: PhantomData, } /// `AsyncTransmit` object for all `Transmit` devices -impl <'a, T, E> AsyncTransmit<'a, E> for T +impl <'a, T, P, E> AsyncTransmit<'a, P, E> for T where - T: Transmit + Power + 'a, + T: Transmit + Power + 'a, + P: 'a, E: core::fmt::Debug + Unpin, { - type Output = TransmitFuture<'a, T, E>; + type Output = TransmitFuture<'a, T, P, E>; - fn async_transmit(&'a mut self, data: &'a [u8], tx_options: AsyncOptions) -> Result + fn async_transmit(&'a mut self, data: &'a [u8], params: &'a P, tx_options: AsyncOptions) -> Result { // Set output power if specified if let Some(p) = tx_options.power { @@ -112,11 +115,12 @@ where } // Start transmission - self.start_transmit(data)?; + self.start_transmit(data, params)?; // Create transmit future - let f: TransmitFuture<_, E> = TransmitFuture{ - radio: self, + let f: TransmitFuture<_, P, E> = TransmitFuture{ + radio: self, + params, options: tx_options, _err: PhantomData }; @@ -126,9 +130,9 @@ where } -impl <'a, T, E> Future for TransmitFuture<'a, T, E> -where - T: Transmit + Power, +impl <'a, T, P, E> Future for TransmitFuture<'a, T, P, E> +where + T: Transmit + Power, E: core::fmt::Debug + Unpin, { type Output = Result<(), AsyncError>; @@ -141,7 +145,7 @@ where if s.radio.check_transmit()? { return Poll::Ready(Ok(())) }; - + // Spawn task to re-execute waker if let Some(w) = s.options.wake_fn { w(cx, period); @@ -156,7 +160,7 @@ where /// Async transmit function implemented over `radio::Transmit` and `radio::Power` using the provided `AsyncOptions` -/// +/// #[cfg_attr(feature = "mock", doc = r##" ``` extern crate async_std; @@ -194,16 +198,17 @@ assert_eq!(&buff[..data.len()], &data); "##)] /// AsyncReceive trait support futures-based polling on receive -pub trait AsyncReceive<'a, I, E> { +pub trait AsyncReceive<'a, P: Param, E> { type Output: Future>>; - fn async_receive(&'a mut self, info: &'a mut I, buff: &'a mut [u8], rx_options: AsyncOptions) -> Result; + fn async_receive(&'a mut self, params: &'a P, info: &'a mut P::Info, buff: &'a mut [u8], rx_options: AsyncOptions) -> Result; } /// Receive future wraps a radio and buffer to provide a pollable future for receiving packets -pub struct ReceiveFuture<'a, T, I, E> { +pub struct ReceiveFuture<'a, T, P: Param, E> { radio: &'a mut T, - info: &'a mut I, + params: &'a P, + info: &'a mut P::Info, buff: &'a mut [u8], options: AsyncOptions, _err: PhantomData, @@ -211,23 +216,24 @@ pub struct ReceiveFuture<'a, T, I, E> { /// Generic implementation of `AsyncReceive` for all `Receive` capable radio devices -impl <'a, T, I, E> AsyncReceive<'a, I, E> for T +impl <'a, T, P, E> AsyncReceive<'a, P, E> for T where - T: Receive + 'a, - I: core::fmt::Debug + 'a, + T: Receive + 'a, + P: Param + 'a, E: core::fmt::Debug + Unpin, { - type Output = ReceiveFuture<'a, T, I, E>; + type Output = ReceiveFuture<'a, T, P, E>; - fn async_receive(&'a mut self, info: &'a mut I, buff: &'a mut [u8], rx_options: AsyncOptions) -> Result { + fn async_receive(&'a mut self, params: &'a P, info: &'a mut P::Info, buff: &'a mut [u8], rx_options: AsyncOptions) -> Result { // Start receive mode - self.start_receive()?; + self.start_receive(params)?; // Create receive future - let f: ReceiveFuture<_, I, E> = ReceiveFuture { - radio: self, - info, - buff, + let f: ReceiveFuture<_, P, E> = ReceiveFuture { + radio: self, + params, + info, + buff, options: rx_options, _err: PhantomData }; @@ -236,10 +242,10 @@ where } } -impl <'a, T, I, E> Future for ReceiveFuture<'a, T, I, E> -where - T: Receive, - I: core::fmt::Debug, +impl <'a, T, P, E> Future for ReceiveFuture<'a, T, P, E> +where + T: Receive, + P: Param, E: core::fmt::Debug + Unpin, { type Output = Result>; diff --git a/src/params/mod.rs b/src/params/mod.rs new file mode 100644 index 0000000..568dd6e --- /dev/null +++ b/src/params/mod.rs @@ -0,0 +1,16 @@ +use core::fmt::Debug; + +use crate::{BasicInfo, ReceiveInfo}; + +/// The parameters of types of packages +pub trait Param { + /// Packet received info + type Info: ReceiveInfo + Debug; +} + +/// No parameters necessary, for `Transmit` and `Receive` +pub struct Basic; + +impl Param for Basic { + type Info = BasicInfo; +}