From 7d62a947ac692573a99235ec8dd27023ce513c17 Mon Sep 17 00:00:00 2001 From: Bastian Bloessl Date: Fri, 15 Nov 2024 15:52:54 +0100 Subject: [PATCH] convert block constructors to typed variants --- examples/adsb/src/decoder.rs | 6 ++--- examples/adsb/src/demodulator.rs | 6 ++--- examples/adsb/src/preamble_detector.rs | 6 ++--- examples/adsb/src/tracker.rs | 10 ++++---- examples/android-hw/src/fft_shift.rs | 6 ++--- examples/audio/play_file.rs | 3 +-- examples/audio/play_selectable_tone.rs | 1 + examples/audio/play_stereo.rs | 9 ++++--- examples/ctrlport-demo.rs | 6 ++--- examples/debug/panic.rs | 6 ++--- examples/debug/tag_debug.rs | 6 ++--- examples/egui/src/channel_sink.rs | 6 ++--- examples/firdes/src/main.rs | 7 +++--- examples/keyfob/src/decoder.rs | 6 ++--- examples/keyfob/src/main.rs | 5 ++-- examples/lora/src/bin/loopback.rs | 8 +++---- examples/lora/src/bin/tx.rs | 1 + examples/lora/src/bin/tx_meshtastic.rs | 1 + examples/lora/src/decoder.rs | 6 ++--- examples/lora/src/deinterleaver.rs | 6 ++--- examples/lora/src/fft_demod.rs | 9 ++++--- examples/lora/src/frame_sync.rs | 13 +++++----- examples/lora/src/gray_mapping.rs | 6 ++--- examples/lora/src/hamming_dec.rs | 6 ++--- examples/lora/src/header_decoder.rs | 6 ++--- examples/lora/src/packet_forwarder_client.rs | 17 +++++++------ examples/lora/src/stream_adder.rs | 6 ++--- examples/lora/src/transmitter.rs | 6 ++--- examples/m17/src/decoder_block.rs | 6 ++--- examples/m17/src/encoder_block.rs | 6 ++--- examples/m17/src/symbol_sync.rs | 6 ++--- examples/macros/src/main.rs | 14 +++++------ examples/rattlegram/src/bin/rx.rs | 7 +++--- examples/rattlegram/src/decoder.rs | 6 ++--- examples/spectrum/src/vulkan.rs | 6 ++--- examples/spectrum/src/wasm/web.rs | 6 ++--- examples/ssb/Cargo.toml | 1 - examples/ssb/receive.rs | 9 +++---- examples/ssb/transmit.rs | 7 +++--- examples/wlan/src/bin/loopback.rs | 1 + examples/wlan/src/bin/rx.rs | 1 + examples/wlan/src/bin/rx_udp.rs | 1 + examples/wlan/src/bin/tx.rs | 1 + examples/wlan/src/decoder.rs | 6 ++--- examples/wlan/src/encoder.rs | 6 ++--- examples/wlan/src/frame_equalizer.rs | 20 ++++++++-------- examples/wlan/src/mac.rs | 6 ++--- examples/wlan/src/mapper.rs | 6 ++--- examples/wlan/src/prefix.rs | 6 ++--- examples/wlan/src/sync_long.rs | 6 ++--- examples/wlan/src/sync_short.rs | 6 ++--- examples/wlan/tests/prefix-vs-tags.rs | 1 + examples/zigbee/src/bin/rx.rs | 5 ++-- examples/zigbee/src/clock_recovery_mm.rs | 6 ++--- examples/zigbee/src/decoder.rs | 6 ++--- examples/zigbee/src/iq_delay.rs | 6 ++--- examples/zigbee/src/mac.rs | 6 ++--- examples/zigbee/src/modulator.rs | 2 +- perf/zynq/zynq.rs | 5 +++- src/blocks/audio/wav_sink.rs | 2 +- src/blocks/signal_source/mod.rs | 20 ++++++++++------ src/blocks/zeromq/pub_sink.rs | 2 +- src/blocks/zeromq/sub_source.rs | 2 +- src/runtime/block.rs | 25 ++++++++++++++++---- src/runtime/mod.rs | 1 + src/runtime/tag.rs | 1 + tests/bad_block.rs | 6 ++--- tests/fail.rs | 14 +++++------ tests/flow.rs | 1 + tests/message_handler.rs | 7 +++--- 70 files changed, 238 insertions(+), 200 deletions(-) diff --git a/examples/adsb/src/decoder.rs b/examples/adsb/src/decoder.rs index ab429ffe5..70ae1274a 100644 --- a/examples/adsb/src/decoder.rs +++ b/examples/adsb/src/decoder.rs @@ -4,7 +4,6 @@ use futuresdr::anyhow::bail; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -12,6 +11,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; use futuresdr::tracing::info; @@ -45,8 +45,8 @@ pub struct Decoder { impl Decoder { #[allow(clippy::new_ret_no_self)] - pub fn new(forward_failed_crc: bool) -> Block { - Block::new( + pub fn new(forward_failed_crc: bool) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Decoder").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() diff --git a/examples/adsb/src/demodulator.rs b/examples/adsb/src/demodulator.rs index 6660fea24..7c07b2bf3 100644 --- a/examples/adsb/src/demodulator.rs +++ b/examples/adsb/src/demodulator.rs @@ -3,7 +3,6 @@ use crate::SYMBOL_ONE_TAPS; use crate::SYMBOL_ZERO_TAPS; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -13,6 +12,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; #[derive(Clone, Debug)] @@ -28,8 +28,8 @@ pub struct Demodulator { impl Demodulator { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Demodulator").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::new().add_output("out").build(), diff --git a/examples/adsb/src/preamble_detector.rs b/examples/adsb/src/preamble_detector.rs index 9ee53feec..af456379a 100644 --- a/examples/adsb/src/preamble_detector.rs +++ b/examples/adsb/src/preamble_detector.rs @@ -1,7 +1,6 @@ use crate::N_SAMPLES_PER_HALF_SYM; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -10,6 +9,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; pub struct PreambleDetector { @@ -38,8 +38,8 @@ impl PreambleDetector { } #[allow(clippy::new_ret_no_self)] - pub fn new(detection_threshold: f32) -> Block { - Block::new( + pub fn new(detection_threshold: f32) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("PreambleDetector").build(), StreamIoBuilder::new() .add_input::("in_samples") diff --git a/examples/adsb/src/tracker.rs b/examples/adsb/src/tracker.rs index ff25bdcbe..908037c1a 100644 --- a/examples/adsb/src/tracker.rs +++ b/examples/adsb/src/tracker.rs @@ -2,7 +2,6 @@ use futuresdr::anyhow::Result; use futuresdr::async_io::Timer; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -11,6 +10,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::info; use futuresdr::tracing::warn; @@ -33,19 +33,19 @@ pub struct Tracker { impl Tracker { /// Creates a new tracker without pruning. #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { + pub fn new() -> TypedBlock { Tracker::new_with_optional_args(None) } - pub fn with_pruning(after: Duration) -> Block { + pub fn with_pruning(after: Duration) -> TypedBlock { Tracker::new_with_optional_args(Some(after)) } - fn new_with_optional_args(prune_after: Option) -> Block { + fn new_with_optional_args(prune_after: Option) -> TypedBlock { let aircraft_register = AircraftRegister { register: HashMap::new(), }; - Block::new( + TypedBlock::new( BlockMetaBuilder::new("Tracker").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() diff --git a/examples/android-hw/src/fft_shift.rs b/examples/android-hw/src/fft_shift.rs index 5b743c4c6..34b934ef2 100644 --- a/examples/android-hw/src/fft_shift.rs +++ b/examples/android-hw/src/fft_shift.rs @@ -2,7 +2,6 @@ use std::marker::PhantomData; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -10,6 +9,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; pub struct FftShift { @@ -18,8 +18,8 @@ pub struct FftShift { impl FftShift { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("FftShift").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/audio/play_file.rs b/examples/audio/play_file.rs index 11cc884b0..133f656ce 100644 --- a/examples/audio/play_file.rs +++ b/examples/audio/play_file.rs @@ -8,8 +8,7 @@ fn main() -> Result<()> { let mut fg = Flowgraph::new(); let src = FileSource::new("rick.mp3"); - let inner = src.kernel::().unwrap(); - let snk = AudioSink::new(inner.sample_rate(), inner.channels()); + let snk = AudioSink::new(src.kernel.sample_rate(), src.kernel.channels()); let src = fg.add_block(src)?; let snk = fg.add_block(snk)?; diff --git a/examples/audio/play_selectable_tone.rs b/examples/audio/play_selectable_tone.rs index f0c84eb2b..68ad557e3 100644 --- a/examples/audio/play_selectable_tone.rs +++ b/examples/audio/play_selectable_tone.rs @@ -5,6 +5,7 @@ use futuresdr::blocks::audio::AudioSink; use futuresdr::blocks::Selector; use futuresdr::blocks::SelectorDropPolicy as DropPolicy; use futuresdr::blocks::SignalSourceBuilder; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/audio/play_stereo.rs b/examples/audio/play_stereo.rs index fb1c04053..72c21b7fc 100644 --- a/examples/audio/play_stereo.rs +++ b/examples/audio/play_stereo.rs @@ -13,12 +13,15 @@ fn main() -> Result<()> { let mut fg = Flowgraph::new(); let src = FileSource::new("rick.mp3"); - let inner = src.kernel::().unwrap(); // resample to 48kHz - let resample = FirBuilder::resampling::(48_000, inner.sample_rate() as usize); + let resample = FirBuilder::resampling::(48_000, src.kernel.sample_rate() as usize); - assert_eq!(inner.channels(), 1, "We expect mp3 to be single channel."); + assert_eq!( + src.kernel.channels(), + 1, + "We expect mp3 to be single channel." + ); let mono_to_stereo = ApplyNM::<_, _, _, 1, 2>::new(move |v: &[f32], d: &mut [f32]| { d[0] = v[0] * GAIN_L; d[1] = v[0] * GAIN_R; diff --git a/examples/ctrlport-demo.rs b/examples/ctrlport-demo.rs index 8fc55c45c..b505f148a 100644 --- a/examples/ctrlport-demo.rs +++ b/examples/ctrlport-demo.rs @@ -1,7 +1,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Flowgraph; @@ -11,6 +10,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; fn main() -> Result<()> { @@ -28,8 +28,8 @@ pub struct CtrlPortDemo { impl CtrlPortDemo { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("CtrlPortDemo").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() diff --git a/examples/debug/panic.rs b/examples/debug/panic.rs index ba75074e7..58928d7f6 100644 --- a/examples/debug/panic.rs +++ b/examples/debug/panic.rs @@ -5,7 +5,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::macros::connect; use futuresdr::runtime::scheduler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Flowgraph; @@ -15,6 +14,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; #[derive(Debug, Clone, ValueEnum)] @@ -69,8 +69,8 @@ struct Panic { impl Panic { #[allow(clippy::new_ret_no_self)] - pub fn new(w: PanicWhere) -> Block { - Block::new( + pub fn new(w: PanicWhere) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Panic").build(), StreamIoBuilder::new().build(), MessageIoBuilder::::new().build(), diff --git a/examples/debug/tag_debug.rs b/examples/debug/tag_debug.rs index 6fecfc01e..aa20bc078 100644 --- a/examples/debug/tag_debug.rs +++ b/examples/debug/tag_debug.rs @@ -2,7 +2,6 @@ use futuresdr::anyhow::Result; use futuresdr::blocks::TagDebug; use futuresdr::blocks::VectorSource; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Flowgraph; @@ -13,6 +12,7 @@ use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; fn main() -> Result<()> { @@ -44,8 +44,8 @@ pub struct PeriodicTagger { impl PeriodicTagger { #[allow(clippy::new_ret_no_self)] - pub fn new(period: usize) -> Block { - Block::new( + pub fn new(period: usize) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("PeriodicTagger").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/egui/src/channel_sink.rs b/examples/egui/src/channel_sink.rs index 66eaee399..402b51742 100644 --- a/examples/egui/src/channel_sink.rs +++ b/examples/egui/src/channel_sink.rs @@ -1,7 +1,6 @@ use futuresdr::anyhow::Result; use futuresdr::futures::channel::mpsc::Sender; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -9,6 +8,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use crate::FFT_SIZE; @@ -18,8 +18,8 @@ pub struct ChannelSink { } impl ChannelSink { - pub fn new(tx: Sender>) -> Block { - Block::new( + pub fn new(tx: Sender>) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("ChannelSink").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::::new().build(), diff --git a/examples/firdes/src/main.rs b/examples/firdes/src/main.rs index 98859c432..748b036e4 100644 --- a/examples/firdes/src/main.rs +++ b/examples/firdes/src/main.rs @@ -1,6 +1,7 @@ use futuresdr::blocks::audio::AudioSink; use futuresdr::blocks::FirBuilder; use futuresdr::blocks::Source; +use futuresdr::runtime::Block; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; @@ -41,9 +42,9 @@ fn main() -> Result<()> { firdes::kaiser::bandpass::(lower_cutoff, higher_cutoff, transition_bw, max_ripple); println!("Filter has {} taps", filter_taps.len()); - let filter_block = match enable_filter { - true => FirBuilder::new::(filter_taps), - _ => FirBuilder::new::([1.0_f32]), + let filter_block: Block = match enable_filter { + true => FirBuilder::new::(filter_taps).into(), + _ => FirBuilder::new::([1.0_f32]).into(), }; let snk = AudioSink::new(DOWNSAMPLED_FREQ, 1); diff --git a/examples/keyfob/src/decoder.rs b/examples/keyfob/src/decoder.rs index 264eb743b..303105620 100644 --- a/examples/keyfob/src/decoder.rs +++ b/examples/keyfob/src/decoder.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -8,6 +7,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::info; @@ -25,8 +25,8 @@ pub struct Decoder { } impl Decoder { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Decoder").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::::new().build(), diff --git a/examples/keyfob/src/main.rs b/examples/keyfob/src/main.rs index f94b6f7ae..c26736198 100644 --- a/examples/keyfob/src/main.rs +++ b/examples/keyfob/src/main.rs @@ -8,6 +8,7 @@ use futuresdr::futuredsp::firdes; use futuresdr::futuredsp::windows; use futuresdr::macros::connect; use futuresdr::num_complex::Complex32; +use futuresdr::runtime::Block; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; @@ -39,8 +40,8 @@ fn main() -> Result<()> { let mut fg = Flowgraph::new(); - let src = match args.file { - Some(file) => FileSource::::new(file, false), + let src: Block = match args.file { + Some(file) => FileSource::::new(file, false).into(), None => { let mut src = SourceBuilder::new() .sample_rate(args.sample_rate) diff --git a/examples/lora/src/bin/loopback.rs b/examples/lora/src/bin/loopback.rs index b145c2527..d4b4dcc09 100644 --- a/examples/lora/src/bin/loopback.rs +++ b/examples/lora/src/bin/loopback.rs @@ -1,18 +1,18 @@ -use std::fmt::Debug; -use std::time::Duration; - use clap::Parser; - use futuresdr::anyhow::anyhow; use futuresdr::anyhow::Result; use futuresdr::async_io::Timer; use futuresdr::blocks::BlobToUdp; use futuresdr::macros::connect; use futuresdr::runtime::buffer::circular::Circular; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; use futuresdr::tracing::info; +use std::fmt::Debug; +use std::time::Duration; + use lora::utils::Bandwidth; use lora::utils::CodeRate; use lora::utils::SpreadingFactor; diff --git a/examples/lora/src/bin/tx.rs b/examples/lora/src/bin/tx.rs index 92b095f45..f809d773d 100644 --- a/examples/lora/src/bin/tx.rs +++ b/examples/lora/src/bin/tx.rs @@ -3,6 +3,7 @@ use futuresdr::anyhow::Result; use futuresdr::async_io::Timer; use futuresdr::blocks::seify::SinkBuilder; use futuresdr::macros::connect; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/lora/src/bin/tx_meshtastic.rs b/examples/lora/src/bin/tx_meshtastic.rs index 3a6b6d0fc..aecd745ae 100644 --- a/examples/lora/src/bin/tx_meshtastic.rs +++ b/examples/lora/src/bin/tx_meshtastic.rs @@ -2,6 +2,7 @@ use clap::Parser; use futuresdr::anyhow::Result; use futuresdr::blocks::seify::SinkBuilder; use futuresdr::macros::connect; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/lora/src/decoder.rs b/examples/lora/src/decoder.rs index 7c012d583..14061a4a6 100644 --- a/examples/lora/src/decoder.rs +++ b/examples/lora/src/decoder.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -10,6 +9,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::info; @@ -19,8 +19,8 @@ use crate::Frame; pub struct Decoder; impl Decoder { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Decoder").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() diff --git a/examples/lora/src/deinterleaver.rs b/examples/lora/src/deinterleaver.rs index 617b161bf..65c2d8af4 100644 --- a/examples/lora/src/deinterleaver.rs +++ b/examples/lora/src/deinterleaver.rs @@ -2,7 +2,6 @@ use std::collections::HashMap; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -13,6 +12,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::warn; @@ -27,7 +27,7 @@ pub struct Deinterleaver { } impl Deinterleaver { - pub fn new(soft_decoding: bool) -> Block { + pub fn new(soft_decoding: bool) -> TypedBlock { let mut sio = StreamIoBuilder::new(); if soft_decoding { sio = sio.add_input::<[LLR; MAX_SF]>("in"); @@ -36,7 +36,7 @@ impl Deinterleaver { sio = sio.add_input::("in"); sio = sio.add_output::("out"); } - Block::new( + TypedBlock::new( BlockMetaBuilder::new("Deinterleaver").build(), sio.build(), MessageIoBuilder::new().build(), diff --git a/examples/lora/src/fft_demod.rs b/examples/lora/src/fft_demod.rs index 74aee9667..f7f80e4ad 100644 --- a/examples/lora/src/fft_demod.rs +++ b/examples/lora/src/fft_demod.rs @@ -1,13 +1,11 @@ +use rustfft::FftPlanner; use std::collections::HashMap; use std::sync::Arc; -use rustfft::FftPlanner; - use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; use futuresdr::num_complex::Complex64; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -18,6 +16,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::warn; @@ -62,7 +61,7 @@ pub struct FftDemod { } impl FftDemod { - pub fn new(soft_decoding: bool, sf_initial: usize) -> Block { + pub fn new(soft_decoding: bool, sf_initial: usize) -> TypedBlock { let m_samples_per_symbol = 1_usize << sf_initial; let fft_plan = FftPlanner::new().plan_fft_forward(m_samples_per_symbol); let fs = Self { @@ -91,7 +90,7 @@ impl FftDemod { } else { sio = sio.add_output::("out") } - Block::new( + TypedBlock::new( BlockMetaBuilder::new("FftDemod").build(), sio.build(), MessageIoBuilder::new().build(), diff --git a/examples/lora/src/frame_sync.rs b/examples/lora/src/frame_sync.rs index eb3b08039..c1c150552 100644 --- a/examples/lora/src/frame_sync.rs +++ b/examples/lora/src/frame_sync.rs @@ -1,3 +1,6 @@ +use rustfft::Fft; +use rustfft::FftDirection; +use rustfft::FftPlanner; use std::collections::HashMap; use std::f32::consts::PI; use std::str::FromStr; @@ -5,16 +8,11 @@ use std::sync::Arc; use std::time::SystemTime; use std::time::UNIX_EPOCH; -use rustfft::Fft; -use rustfft::FftDirection; -use rustfft::FftPlanner; - use futuresdr::anyhow::Result; use futuresdr::futures::channel::mpsc; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -24,6 +22,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; use futuresdr::tracing::info; @@ -185,7 +184,7 @@ impl FrameSync { net_id_caching_policy: Option<&str>, collect_receive_statistics: bool, startup_timestamp: Option, - ) -> Block { + ) -> TypedBlock { let net_id_caching_policy_tmp = match NetIdCachingPolicy::from_str(net_id_caching_policy.unwrap_or("header_crc_ok")) { Ok(tmp) => tmp, Err(_) => panic!("Supplied invalid value for parameter net_id_caching_policy. Possible values: 'none', 'seen', 'header_crc_ok', 'payload_crc_ok'"), @@ -208,7 +207,7 @@ impl FrameSync { let fft_detect = FftPlanner::new().plan_fft(m_number_of_bins_tmp, FftDirection::Forward); - Block::new( + TypedBlock::new( BlockMetaBuilder::new("FrameSync").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/lora/src/gray_mapping.rs b/examples/lora/src/gray_mapping.rs index deca0a8f1..2cc942bf0 100644 --- a/examples/lora/src/gray_mapping.rs +++ b/examples/lora/src/gray_mapping.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -11,6 +10,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use std::cmp::min; use std::collections::HashMap; @@ -23,7 +23,7 @@ pub struct GrayMapping { } impl GrayMapping { - pub fn new(soft_decoding: bool) -> Block { + pub fn new(soft_decoding: bool) -> TypedBlock { let mut sio = StreamIoBuilder::new(); if soft_decoding { sio = sio.add_input::<[LLR; MAX_SF]>("in"); @@ -32,7 +32,7 @@ impl GrayMapping { sio = sio.add_input::("in"); sio = sio.add_output::("out"); } - Block::new( + TypedBlock::new( BlockMetaBuilder::new("GrayMapping").build(), sio.build(), MessageIoBuilder::new().build(), diff --git a/examples/lora/src/hamming_dec.rs b/examples/lora/src/hamming_dec.rs index 552fd22ff..073b7190a 100644 --- a/examples/lora/src/hamming_dec.rs +++ b/examples/lora/src/hamming_dec.rs @@ -4,7 +4,6 @@ use std::collections::VecDeque; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -15,6 +14,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use crate::utils::*; @@ -47,7 +47,7 @@ pub struct HammingDec { } impl HammingDec { - pub fn new(soft_decoding: bool) -> Block { + pub fn new(soft_decoding: bool) -> TypedBlock { let mut sio = StreamIoBuilder::new(); if soft_decoding { sio = sio.add_input::<[LLR; 8]>("in"); // In reality: cw_len = cr_app + 4 < 8 @@ -55,7 +55,7 @@ impl HammingDec { sio = sio.add_input::("in"); } sio = sio.add_output::("out"); - Block::new( + TypedBlock::new( BlockMetaBuilder::new("HammingDec").build(), sio.build(), MessageIoBuilder::new().add_output("out").build(), diff --git a/examples/lora/src/header_decoder.rs b/examples/lora/src/header_decoder.rs index e6fadcc43..0d0345eec 100644 --- a/examples/lora/src/header_decoder.rs +++ b/examples/lora/src/header_decoder.rs @@ -3,7 +3,6 @@ use std::collections::HashMap; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -14,6 +13,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; use futuresdr::tracing::info; @@ -58,8 +58,8 @@ pub struct HeaderDecoder { } impl HeaderDecoder { - pub fn new(mode: HeaderMode, ldro_mode: bool) -> Block { - Block::new( + pub fn new(mode: HeaderMode, ldro_mode: bool) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("HeaderDecoder").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::new() diff --git a/examples/lora/src/packet_forwarder_client.rs b/examples/lora/src/packet_forwarder_client.rs index 25081d5b4..4bc07f31c 100644 --- a/examples/lora/src/packet_forwarder_client.rs +++ b/examples/lora/src/packet_forwarder_client.rs @@ -1,8 +1,3 @@ -use std::net::SocketAddr; -use std::str::FromStr; -use std::time::Duration; -use std::time::SystemTime; - use chrono::prelude::DateTime; use chrono::prelude::Utc; use semtech_udp::client_runtime::Event; @@ -17,6 +12,10 @@ use semtech_udp::CodingRate; use semtech_udp::DataRate; use semtech_udp::MacAddress; use semtech_udp::SpreadingFactor; +use std::net::SocketAddr; +use std::str::FromStr; +use std::time::Duration; +use std::time::SystemTime; use tokio::runtime::Runtime; use triggered::Trigger; @@ -26,7 +25,6 @@ use futuresdr::futures::SinkExt; use futuresdr::futures_lite::StreamExt; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -34,6 +32,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; /// Forward messages. @@ -46,7 +45,7 @@ pub struct PacketForwarderClient { } impl PacketForwarderClient { - pub fn new(mac_addr: &str, server_addr: &str) -> Block { + pub fn new(mac_addr: &str, server_addr: &str) -> TypedBlock { let mac_address = MacAddress::from_str(mac_addr).unwrap(); let (to_forwarder_sender, mut to_forwarder_receiver) = mpsc::channel::(1); let host = SocketAddr::from_str(server_addr).unwrap(); @@ -96,8 +95,8 @@ impl PacketForwarderClient { }); }); - Block::new( - BlockMetaBuilder::new("MessageCopy").build(), + TypedBlock::new( + BlockMetaBuilder::new("PacketForwarder").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() .add_input("in", Self::handler) diff --git a/examples/lora/src/stream_adder.rs b/examples/lora/src/stream_adder.rs index 27203907f..f84d657f2 100644 --- a/examples/lora/src/stream_adder.rs +++ b/examples/lora/src/stream_adder.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -8,6 +7,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use std::cmp::min; use std::marker::PhantomData; @@ -22,13 +22,13 @@ impl StreamAdder where T: Copy + Send + Sync + Add + 'static, { - pub fn new(num_inputs: usize) -> Block { + pub fn new(num_inputs: usize) -> TypedBlock { let mut sio = StreamIoBuilder::new(); for i in 0..num_inputs { sio = sio.add_input::(&format!("in{}", i)); } sio = sio.add_output::("out"); - Block::new( + TypedBlock::new( BlockMetaBuilder::new("StreamAdder").build(), sio.build(), MessageIoBuilder::new().build(), diff --git a/examples/lora/src/transmitter.rs b/examples/lora/src/transmitter.rs index f8aba7862..87306cf9f 100644 --- a/examples/lora/src/transmitter.rs +++ b/examples/lora/src/transmitter.rs @@ -2,7 +2,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -11,6 +10,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::warn; use std::collections::VecDeque; @@ -39,8 +39,8 @@ impl Transmitter { sync_words: Vec, preamble_len: usize, pad: usize, - ) -> Block { - Block::new( + ) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Transmitter").build(), StreamIoBuilder::new() .add_output::("out") diff --git a/examples/m17/src/decoder_block.rs b/examples/m17/src/decoder_block.rs index 0bfa548a1..0fe9af7f7 100644 --- a/examples/m17/src/decoder_block.rs +++ b/examples/m17/src/decoder_block.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -8,6 +7,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use crate::Decoder; @@ -17,8 +17,8 @@ pub struct DecoderBlock { } impl DecoderBlock { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("M17Decoder").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/m17/src/encoder_block.rs b/examples/m17/src/encoder_block.rs index 32c1be44f..01bb50277 100644 --- a/examples/m17/src/encoder_block.rs +++ b/examples/m17/src/encoder_block.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -8,6 +7,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use crate::Encoder; @@ -20,8 +20,8 @@ pub struct EncoderBlock { } impl EncoderBlock { - pub fn new(lsf: LinkSetupFrame) -> Block { - Block::new( + pub fn new(lsf: LinkSetupFrame) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("M17Encoder").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/m17/src/symbol_sync.rs b/examples/m17/src/symbol_sync.rs index c6b89f6ee..ca5627656 100644 --- a/examples/m17/src/symbol_sync.rs +++ b/examples/m17/src/symbol_sync.rs @@ -2,7 +2,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; use futuresdr::num_integer::Integer; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -10,6 +9,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use std::collections::VecDeque; @@ -1761,7 +1761,7 @@ impl SymbolSync { ted_gain: f32, max_deviation: f32, osps: usize, - ) -> Block { + ) -> TypedBlock { assert!(sps > 1.0); assert!(osps >= 1); @@ -1804,7 +1804,7 @@ impl SymbolSync { s.interp.sync_reset(sps); // let filter_delay = (s.interp.ntaps() + 1) / 2; - Block::new( + TypedBlock::new( BlockMetaBuilder::new("SymbolSync").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/macros/src/main.rs b/examples/macros/src/main.rs index 9e7ef2a27..a5fd5e377 100644 --- a/examples/macros/src/main.rs +++ b/examples/macros/src/main.rs @@ -8,7 +8,6 @@ use futuresdr::blocks::VectorSource; use futuresdr::macros::async_trait; use futuresdr::macros::connect; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Flowgraph; @@ -19,6 +18,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; fn main() -> Result<()> { @@ -75,8 +75,8 @@ pub struct Dummy; impl Dummy { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Dummy").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new().build(), @@ -103,8 +103,8 @@ pub struct Strange; impl Strange { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Strange").build(), StreamIoBuilder::new().add_output::("foo bar").build(), MessageIoBuilder::new().build(), @@ -131,8 +131,8 @@ pub struct Handler; impl Handler { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Handler").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() diff --git a/examples/rattlegram/src/bin/rx.rs b/examples/rattlegram/src/bin/rx.rs index 936c06053..361bf3eb5 100644 --- a/examples/rattlegram/src/bin/rx.rs +++ b/examples/rattlegram/src/bin/rx.rs @@ -3,6 +3,7 @@ use futuresdr::anyhow::Result; use futuresdr::blocks::audio::AudioSource; use futuresdr::blocks::audio::FileSource; use futuresdr::macros::connect; +use futuresdr::runtime::Block; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; @@ -21,10 +22,10 @@ fn main() -> Result<()> { let mut fg = Flowgraph::new(); - let src = if let Some(f) = args.file { - FileSource::new(&f) + let src: Block = if let Some(f) = args.file { + FileSource::new(&f).into() } else { - AudioSource::new(48000, 1) + AudioSource::new(48000, 1).into() }; let snk = DecoderBlock::new(); diff --git a/examples/rattlegram/src/decoder.rs b/examples/rattlegram/src/decoder.rs index 7e5d0b1e9..cd89618e0 100644 --- a/examples/rattlegram/src/decoder.rs +++ b/examples/rattlegram/src/decoder.rs @@ -1,7 +1,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -9,6 +8,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::info; use rustfft::Fft; @@ -30,8 +30,8 @@ pub struct DecoderBlock { } impl DecoderBlock { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("RattegramDecoder").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::new().build(), diff --git a/examples/spectrum/src/vulkan.rs b/examples/spectrum/src/vulkan.rs index 167968ad4..8b68ce427 100644 --- a/examples/spectrum/src/vulkan.rs +++ b/examples/spectrum/src/vulkan.rs @@ -23,7 +23,6 @@ use futuresdr::runtime::buffer::vulkan::BufferEmpty; use futuresdr::runtime::buffer::vulkan::ReaderH2D; use futuresdr::runtime::buffer::vulkan::WriterD2H; use futuresdr::runtime::buffer::BufferReaderCustom; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -31,6 +30,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; @@ -67,13 +67,13 @@ pub struct Vulkan { } impl Vulkan { - pub fn new(broker: Arc, capacity: u64) -> Block { + pub fn new(broker: Arc, capacity: u64) -> TypedBlock { let memory_allocator = StandardMemoryAllocator::new_default(broker.device().clone()); let descriptor_set_allocator = StandardDescriptorSetAllocator::new(broker.device().clone()); let command_buffer_allocator = StandardCommandBufferAllocator::new(broker.device().clone(), Default::default()); - Block::new( + TypedBlock::new( BlockMetaBuilder::new("Vulkan").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/spectrum/src/wasm/web.rs b/examples/spectrum/src/wasm/web.rs index 28bbc4e34..80ce01286 100644 --- a/examples/spectrum/src/wasm/web.rs +++ b/examples/spectrum/src/wasm/web.rs @@ -18,7 +18,6 @@ use futuresdr::blocks::FftDirection; use futuresdr::blocks::MovingAvg; use futuresdr::macros::async_trait; use futuresdr::macros::connect; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Flowgraph; @@ -30,6 +29,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; const FFT_SIZE: usize = 2048; @@ -220,8 +220,8 @@ unsafe impl Send for Sink {} impl Sink { #[allow(clippy::new_ret_no_self)] - pub fn new(data: Vec>>>>) -> Block { - Block::new( + pub fn new(data: Vec>>>>) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Sink").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::new().build(), diff --git a/examples/ssb/Cargo.toml b/examples/ssb/Cargo.toml index 62b681cea..92540ac00 100644 --- a/examples/ssb/Cargo.toml +++ b/examples/ssb/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] clap = { version = "4", features = ["derive"] } futuresdr = { path = "../..", features=["soapy", "audio"] } -num-complex = "0.4" hound = "3.5" [[bin]] diff --git a/examples/ssb/receive.rs b/examples/ssb/receive.rs index 7bd25c75f..dd90c101a 100644 --- a/examples/ssb/receive.rs +++ b/examples/ssb/receive.rs @@ -5,10 +5,11 @@ use futuresdr::blocks::audio::AudioSink; use futuresdr::blocks::Apply; use futuresdr::blocks::FileSource; use futuresdr::blocks::FirBuilder; +use futuresdr::num_complex::Complex32; use futuresdr::num_integer::gcd; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; -use num_complex::Complex32; // Inspired by https://wiki.gnuradio.org/index.php/Simulation_example:_Single_Sideband_transceiver @@ -55,7 +56,7 @@ fn main() -> Result<()> { // To be downloaded from https://www.csun.edu/~skatz/katzpage/sdr_project/sdr/ssb_lsb_256k_complex2.dat.zip let file_name = args.filename; let mut src = FileSource::::new(&file_name, true); - src.set_instance_name(format!("File {file_name}")); + src.set_instance_name(&format!("File {file_name}")); const FILE_LEVEL_ADJUSTMENT: f32 = 0.0001; let mut osc = Complex32::new(1.0, 0.0); @@ -67,11 +68,11 @@ fn main() -> Result<()> { osc *= shift; v * osc * FILE_LEVEL_ADJUSTMENT }); - freq_xlating.set_instance_name(format!("freq_xlating {center_freq}")); + freq_xlating.set_instance_name(&format!("freq_xlating {center_freq}")); let mut low_pass_filter = FirBuilder::resampling::(audio_rate as usize, file_rate as usize); - low_pass_filter.set_instance_name(format!("resampler {audio_rate} {file_rate}")); + low_pass_filter.set_instance_name(&format!("resampler {audio_rate} {file_rate}")); const VOLUME_ADJUSTEMENT: f32 = 0.5; const MID_AUDIO_SPECTRUM_FREQ: u32 = 1500; diff --git a/examples/ssb/transmit.rs b/examples/ssb/transmit.rs index fa2716a44..08cf9b35c 100644 --- a/examples/ssb/transmit.rs +++ b/examples/ssb/transmit.rs @@ -70,14 +70,13 @@ fn main() -> Result<()> { let mut fg = Flowgraph::new(); let source = FileSource::new(&cli.input); - let src_kernel = source.kernel::().unwrap(); assert!( - src_kernel.channels() == 1, + source.kernel.channels() == 1, "Input audio must be mono but found {} channels", - src_kernel.channels() + source.kernel.channels() ); - let audio_rate = src_kernel.sample_rate() as f64; + let audio_rate = source.kernel.sample_rate() as f64; let file_rate = cli.sample_rate; // Using a bandpass instead, can help to tame low frequencies bleeding diff --git a/examples/wlan/src/bin/loopback.rs b/examples/wlan/src/bin/loopback.rs index 8c76bb4ff..a7c000a6d 100644 --- a/examples/wlan/src/bin/loopback.rs +++ b/examples/wlan/src/bin/loopback.rs @@ -16,6 +16,7 @@ use futuresdr::blocks::WebsocketPmtSink; use futuresdr::num_complex::Complex32; use futuresdr::runtime::buffer::circular::Circular; use futuresdr::runtime::copy_tag_propagation; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/wlan/src/bin/rx.rs b/examples/wlan/src/bin/rx.rs index 9dac9343b..22e164ad5 100644 --- a/examples/wlan/src/bin/rx.rs +++ b/examples/wlan/src/bin/rx.rs @@ -13,6 +13,7 @@ use futuresdr::blocks::WebsocketPmtSink; use futuresdr::macros::connect; use futuresdr::num_complex::Complex32; use futuresdr::runtime::copy_tag_propagation; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/wlan/src/bin/rx_udp.rs b/examples/wlan/src/bin/rx_udp.rs index b879e0111..c9b0410cd 100644 --- a/examples/wlan/src/bin/rx_udp.rs +++ b/examples/wlan/src/bin/rx_udp.rs @@ -13,6 +13,7 @@ use futuresdr::blocks::WebsocketPmtSink; use futuresdr::macros::connect; use futuresdr::num_complex::Complex32; use futuresdr::runtime::copy_tag_propagation; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/wlan/src/bin/tx.rs b/examples/wlan/src/bin/tx.rs index 7689553e8..c49ad2adf 100644 --- a/examples/wlan/src/bin/tx.rs +++ b/examples/wlan/src/bin/tx.rs @@ -8,6 +8,7 @@ use futuresdr::blocks::Fft; use futuresdr::blocks::FftDirection; use futuresdr::runtime::buffer::circular::Circular; use futuresdr::runtime::copy_tag_propagation; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/wlan/src/decoder.rs b/examples/wlan/src/decoder.rs index f08dd20aa..576272b88 100644 --- a/examples/wlan/src/decoder.rs +++ b/examples/wlan/src/decoder.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -11,6 +10,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::warn; @@ -34,8 +34,8 @@ pub struct Decoder { } impl Decoder { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Decoder").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::new() diff --git a/examples/wlan/src/encoder.rs b/examples/wlan/src/encoder.rs index 6564c3b67..b83506582 100644 --- a/examples/wlan/src/encoder.rs +++ b/examples/wlan/src/encoder.rs @@ -6,7 +6,6 @@ use crate::MAX_PSDU_SIZE; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -16,6 +15,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::warn; use std::collections::VecDeque; @@ -39,8 +39,8 @@ pub struct Encoder { } impl Encoder { - pub fn new(default_mcs: Mcs) -> Block { - Block::new( + pub fn new(default_mcs: Mcs) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Encoder").build(), StreamIoBuilder::new().add_output::("out").build(), MessageIoBuilder::new() diff --git a/examples/wlan/src/frame_equalizer.rs b/examples/wlan/src/frame_equalizer.rs index 482e28029..e0a8d0ace 100644 --- a/examples/wlan/src/frame_equalizer.rs +++ b/examples/wlan/src/frame_equalizer.rs @@ -1,14 +1,6 @@ -use crate::FrameParam; -use crate::Mcs; -use crate::Modulation; -use crate::ViterbiDecoder; -use crate::LONG; -use crate::POLARITY; - use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -19,9 +11,17 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::info; +use crate::FrameParam; +use crate::Mcs; +use crate::Modulation; +use crate::ViterbiDecoder; +use crate::LONG; +use crate::POLARITY; + const INTERLEAVER_PATTERN: [usize; 48] = [ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, @@ -102,8 +102,8 @@ pub struct FrameEqualizer { } impl FrameEqualizer { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("FrameEqualizer").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/wlan/src/mac.rs b/examples/wlan/src/mac.rs index f5addb7c2..7c3a803b8 100644 --- a/examples/wlan/src/mac.rs +++ b/examples/wlan/src/mac.rs @@ -4,7 +4,6 @@ use crate::MAX_PSDU_SIZE; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -12,6 +11,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; use futuresdr::tracing::warn; @@ -22,7 +22,7 @@ pub struct Mac { } impl Mac { - pub fn new(src_mac: [u8; 6], dst_mac: [u8; 6], bss_mac: [u8; 6]) -> Block { + pub fn new(src_mac: [u8; 6], dst_mac: [u8; 6], bss_mac: [u8; 6]) -> TypedBlock { let mut current_frame = [0; MAX_PSDU_SIZE]; // frame control @@ -34,7 +34,7 @@ impl Mac { current_frame[10..16].copy_from_slice(&dst_mac); current_frame[16..22].copy_from_slice(&bss_mac); - Block::new( + TypedBlock::new( BlockMetaBuilder::new("Mac").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new() diff --git a/examples/wlan/src/mapper.rs b/examples/wlan/src/mapper.rs index e85b6588d..3a71dd670 100644 --- a/examples/wlan/src/mapper.rs +++ b/examples/wlan/src/mapper.rs @@ -5,7 +5,6 @@ use crate::POLARITY; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -15,6 +14,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; pub struct Mapper { @@ -27,8 +27,8 @@ pub struct Mapper { } impl Mapper { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Mapper").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/wlan/src/prefix.rs b/examples/wlan/src/prefix.rs index f4e0bb9c0..9449c59ae 100644 --- a/examples/wlan/src/prefix.rs +++ b/examples/wlan/src/prefix.rs @@ -1,7 +1,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -11,6 +10,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; pub struct Prefix { @@ -19,8 +19,8 @@ pub struct Prefix { } impl Prefix { - pub fn new(pad_front: usize, pad_tail: usize) -> Block { - Block::new( + pub fn new(pad_front: usize, pad_tail: usize) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Prefix").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/wlan/src/sync_long.rs b/examples/wlan/src/sync_long.rs index d194029ad..2c3c458c5 100644 --- a/examples/wlan/src/sync_long.rs +++ b/examples/wlan/src/sync_long.rs @@ -1,7 +1,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -11,6 +10,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; const SEARCH_WINDOW: usize = 320; @@ -29,8 +29,8 @@ pub struct SyncLong { } impl SyncLong { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("SyncLong").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/wlan/src/sync_short.rs b/examples/wlan/src/sync_short.rs index de41d8545..2db302e7f 100644 --- a/examples/wlan/src/sync_short.rs +++ b/examples/wlan/src/sync_short.rs @@ -1,7 +1,6 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -10,6 +9,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; const MIN_GAP: usize = 480; @@ -28,8 +28,8 @@ pub struct SyncShort { } impl SyncShort { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("SyncShort").build(), StreamIoBuilder::new() .add_input::("in_sig") diff --git a/examples/wlan/tests/prefix-vs-tags.rs b/examples/wlan/tests/prefix-vs-tags.rs index 25ff41773..56025d8e6 100644 --- a/examples/wlan/tests/prefix-vs-tags.rs +++ b/examples/wlan/tests/prefix-vs-tags.rs @@ -6,6 +6,7 @@ use futuresdr::blocks::NullSink; use futuresdr::num_complex::Complex32; use futuresdr::runtime::buffer::circular::Circular; use futuresdr::runtime::copy_tag_propagation; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Pmt; use futuresdr::runtime::Runtime; diff --git a/examples/zigbee/src/bin/rx.rs b/examples/zigbee/src/bin/rx.rs index a55bac42e..daa4285fd 100644 --- a/examples/zigbee/src/bin/rx.rs +++ b/examples/zigbee/src/bin/rx.rs @@ -7,6 +7,7 @@ use futuresdr::blocks::FileSource; use futuresdr::blocks::NullSink; use futuresdr::macros::connect; use futuresdr::num_complex::Complex32; +use futuresdr::runtime::Block; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; @@ -47,8 +48,8 @@ fn main() -> Result<()> { let mut fg = Flowgraph::new(); - let src = match args.file { - Some(file) => FileSource::::new(file, false), + let src: Block = match args.file { + Some(file) => FileSource::::new(file, false).into(), None => SourceBuilder::new() .frequency(args.freq) .sample_rate(args.sample_rate) diff --git a/examples/zigbee/src/clock_recovery_mm.rs b/examples/zigbee/src/clock_recovery_mm.rs index 7e5e35d56..fa3e16b07 100644 --- a/examples/zigbee/src/clock_recovery_mm.rs +++ b/examples/zigbee/src/clock_recovery_mm.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -8,6 +7,7 @@ use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; pub struct ClockRecoveryMm { @@ -28,8 +28,8 @@ impl ClockRecoveryMm { mu: f32, gain_mu: f32, omega_relative_limit: f32, - ) -> Block { - Block::new( + ) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("ClockRecoveryMm").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/zigbee/src/decoder.rs b/examples/zigbee/src/decoder.rs index c5e47f104..3045558d4 100644 --- a/examples/zigbee/src/decoder.rs +++ b/examples/zigbee/src/decoder.rs @@ -1,6 +1,5 @@ use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -9,6 +8,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; const CHIP_MAPPING: [u32; 16] = [ @@ -56,8 +56,8 @@ pub struct Decoder { } impl Decoder { - pub fn new(threshold: u32) -> Block { - Block::new( + pub fn new(threshold: u32) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("Decoder").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::::new().add_output("out").build(), diff --git a/examples/zigbee/src/iq_delay.rs b/examples/zigbee/src/iq_delay.rs index b76084bd8..241bb5649 100644 --- a/examples/zigbee/src/iq_delay.rs +++ b/examples/zigbee/src/iq_delay.rs @@ -3,7 +3,6 @@ use std::collections::VecDeque; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::num_complex::Complex32; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::ItemTag; @@ -13,6 +12,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; #[derive(PartialEq, Eq)] @@ -30,8 +30,8 @@ pub struct IqDelay { } impl IqDelay { - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("IQ Delay").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/examples/zigbee/src/mac.rs b/examples/zigbee/src/mac.rs index 0f95e3d07..8ddcab28d 100644 --- a/examples/zigbee/src/mac.rs +++ b/examples/zigbee/src/mac.rs @@ -3,7 +3,6 @@ use std::collections::VecDeque; use futuresdr::anyhow::Result; use futuresdr::macros::async_trait; use futuresdr::macros::message_handler; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Kernel; @@ -13,6 +12,7 @@ use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; use futuresdr::runtime::Tag; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; use futuresdr::tracing::info; @@ -36,7 +36,7 @@ pub struct Mac { } impl Mac { - pub fn new() -> Block { + pub fn new() -> TypedBlock { let mut b = [0; 256]; b[0] = 0x0; b[1] = 0x0; @@ -53,7 +53,7 @@ impl Mac { b[12] = SOURCE_ADDRESS.to_le_bytes()[0]; b[13] = SOURCE_ADDRESS.to_le_bytes()[1]; - Block::new( + TypedBlock::new( BlockMetaBuilder::new("Mac").build(), StreamIoBuilder::new().add_output::("out").build(), MessageIoBuilder::new() diff --git a/examples/zigbee/src/modulator.rs b/examples/zigbee/src/modulator.rs index 8ee238e4d..f9509f4f4 100644 --- a/examples/zigbee/src/modulator.rs +++ b/examples/zigbee/src/modulator.rs @@ -336,5 +336,5 @@ fn make_nibble(i: u8) -> impl Iterator + Send { } pub fn modulator() -> Block { - ApplyIntoIter::new(|i: &u8| make_nibble(i & 0x0F).chain(make_nibble(i >> 4))) + ApplyIntoIter::new(|i: &u8| make_nibble(i & 0x0F).chain(make_nibble(i >> 4))).into() } diff --git a/perf/zynq/zynq.rs b/perf/zynq/zynq.rs index 24f7f7a7d..180dd9061 100644 --- a/perf/zynq/zynq.rs +++ b/perf/zynq/zynq.rs @@ -10,6 +10,7 @@ use futuresdr::blocks::Zynq; use futuresdr::blocks::ZynqSync; use futuresdr::runtime::buffer::zynq::D2H; use futuresdr::runtime::buffer::zynq::H2D; +use futuresdr::runtime::Block; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; @@ -41,18 +42,20 @@ fn main() -> Result<()> { .collect(); let src = VectorSource::::new(orig.clone()); - let zynq = if sync { + let zynq: Block = if sync { ZynqSync::::new( "uio4", "uio5", vec!["udmabuf0", "udmabuf1", "udmabuf2", "udmabuf3"], )? + .into() } else { Zynq::::new( "uio4", "uio5", vec!["udmabuf0", "udmabuf1", "udmabuf2", "udmabuf3"], )? + .into() }; let snk = VectorSinkBuilder::::new().init_capacity(items).build(); diff --git a/src/blocks/audio/wav_sink.rs b/src/blocks/audio/wav_sink.rs index 6a1ad8697..13aad4d5e 100644 --- a/src/blocks/audio/wav_sink.rs +++ b/src/blocks/audio/wav_sink.rs @@ -50,7 +50,7 @@ impl WavSink { spec: hound::WavSpec, ) -> TypedBlock { let writer = hound::WavWriter::create(file_name, spec).unwrap(); - TYpedBlock::new( + TypedBlock::new( BlockMetaBuilder::new("WavSink").build(), StreamIoBuilder::new().add_input::("in").build(), MessageIoBuilder::new().build(), diff --git a/src/blocks/signal_source/mod.rs b/src/blocks/signal_source/mod.rs index be9a2a4d7..18e74a8a2 100644 --- a/src/blocks/signal_source/mod.rs +++ b/src/blocks/signal_source/mod.rs @@ -9,6 +9,7 @@ use crate::runtime::MessageIo; use crate::runtime::MessageIoBuilder; use crate::runtime::StreamIo; use crate::runtime::StreamIoBuilder; +use crate::runtime::TypedBlock; use crate::runtime::WorkIo; mod fxpt_phase; @@ -35,8 +36,8 @@ where A: Copy + Send + 'static + std::ops::Mul + std::ops::Add, { /// Create SignalSource block - pub fn new(phase_to_amplitude: F, nco: NCO, amplitude: A, offset: A) -> Block { - Block::new( + pub fn new(phase_to_amplitude: F, nco: NCO, amplitude: A, offset: A) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("SignalSource").build(), StreamIoBuilder::new().add_output::("out").build(), MessageIoBuilder::::new().build(), @@ -160,13 +161,15 @@ impl SignalSourceBuilder { nco, self.amplitude, self.offset, - ), + ) + .into(), WaveForm::Sin => SignalSource::new( |phase: FixedPointPhase| phase.sin(), nco, self.amplitude, self.offset, - ), + ) + .into(), WaveForm::Square => SignalSource::new( |phase: FixedPointPhase| { if phase.value < 0 { @@ -178,7 +181,8 @@ impl SignalSourceBuilder { nco, self.amplitude, self.offset, - ), + ) + .into(), } } } @@ -231,7 +235,8 @@ impl SignalSourceBuilder { nco, self.amplitude, self.offset, - ), + ) + .into(), WaveForm::Square => SignalSource::new( |phase: FixedPointPhase| { let t = phase.value >> 30; @@ -246,7 +251,8 @@ impl SignalSourceBuilder { nco, self.amplitude, self.offset, - ), + ) + .into(), } } } diff --git a/src/blocks/zeromq/pub_sink.rs b/src/blocks/zeromq/pub_sink.rs index 8ffa61c6a..28bea0b17 100644 --- a/src/blocks/zeromq/pub_sink.rs +++ b/src/blocks/zeromq/pub_sink.rs @@ -108,7 +108,7 @@ impl PubSinkBuilder { } /// Build PubSink - pub fn build(self) -> Block { + pub fn build(self) -> TypedBlock> { PubSink::::new(self.address, self.min_item) } } diff --git a/src/blocks/zeromq/sub_source.rs b/src/blocks/zeromq/sub_source.rs index b1150341a..d5c592cda 100644 --- a/src/blocks/zeromq/sub_source.rs +++ b/src/blocks/zeromq/sub_source.rs @@ -93,7 +93,7 @@ impl SubSourceBuilder { } /// Build ZMQ source - pub fn build(self) -> Block { + pub fn build(self) -> TypedBlock> { SubSource::::new(self.address) } } diff --git a/src/runtime/block.rs b/src/runtime/block.rs index f5a7f1479..030c30441 100644 --- a/src/runtime/block.rs +++ b/src/runtime/block.rs @@ -100,10 +100,14 @@ pub trait Kernel: Send { } #[async_trait] +/// Block interface, implemented for [TypedBlock]s pub trait BlockT: Send + Any { // ##### BLOCK + /// Cast block to [std::any::Any]. fn as_any(&self) -> &dyn Any; + /// Cast block to [std::any::Any] mutably. fn as_any_mut(&mut self) -> &mut dyn Any; + /// Run the block. async fn run( &mut self, block_id: usize, @@ -112,27 +116,43 @@ pub trait BlockT: Send + Any { ) -> Result<(), Error>; // ##### META + /// Get instance name (see [`BlockMeta::instance_name`]) fn instance_name(&self) -> Option<&str>; + /// Set instance name (see [`BlockMeta::set_instance_name`]) fn set_instance_name(&mut self, name: &str); + /// Get type name (see [`BlockMeta::type_name`]) fn type_name(&self) -> &str; + /// Check whether this block is blocking. + /// + /// Blocking blocks will be spawned in a separate thread. fn is_blocking(&self) -> bool; // ##### STREAM IO #[allow(clippy::type_complexity)] + /// Set tag propagation function fn set_tag_propagation( &mut self, f: Box, ); + /// Get stream input ports fn stream_inputs(&self) -> &Vec; + /// Get stream input port fn stream_input(&self, id: usize) -> &StreamInput; + /// Map stream input port name ot id fn stream_input_name_to_id(&self, name: &str) -> Option; + /// Get stream output ports fn stream_outputs(&self) -> &Vec; + /// Get stream output port fn stream_output(&self, id: usize) -> &StreamOutput; + /// Map stream output port name to id fn stream_output_name_to_id(&self, name: &str) -> Option; // ##### MESSAGE IO + /// Map message input port name to id fn message_input_name_to_id(&self, name: &str) -> Option; + /// Get message output ports fn message_outputs(&self) -> &Vec; + /// Map message output port name to id fn message_output_name_to_id(&self, name: &str) -> Option; } @@ -159,11 +179,6 @@ impl TypedBlock { } } - /// Set instance name of block. - pub fn set_instance_name(&mut self, name: impl Into) { - self.meta.set_instance_name(name) - } - async fn call_handler( io: &mut WorkIo, mio: &mut MessageIo, diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 47a6266bc..0003f68a1 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -42,6 +42,7 @@ mod tag; mod topology; pub use block::Block; +pub use block::BlockT; pub use block::Kernel; pub use block::TypedBlock; pub use block::WorkIo; diff --git a/src/runtime/tag.rs b/src/runtime/tag.rs index 22d398fca..7bdc4802a 100644 --- a/src/runtime/tag.rs +++ b/src/runtime/tag.rs @@ -79,6 +79,7 @@ pub fn default_tag_propagation(_inputs: &mut [StreamInput], _outputs: &mut [Stre /// /// ```rust, no_run /// # use futuresdr::blocks::Fft; +/// # use futuresdr::runtime::BlockT; /// # use futuresdr::runtime::copy_tag_propagation; /// let mut fft = Fft::new(1024); /// fft.set_tag_propagation(Box::new(copy_tag_propagation)); diff --git a/tests/bad_block.rs b/tests/bad_block.rs index 619cd5b7a..f04cc1525 100644 --- a/tests/bad_block.rs +++ b/tests/bad_block.rs @@ -7,7 +7,6 @@ use futuresdr::blocks::NullSource; use futuresdr::blocks::Throttle; use futuresdr::macros::async_trait; use futuresdr::macros::connect; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Error; @@ -18,6 +17,7 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; use futuresdr::tracing::debug; use std::cmp; @@ -37,8 +37,8 @@ pub struct BadBlock { } impl BadBlock { - pub fn to_block(self) -> Block { - Block::new( + pub fn to_block(self) -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("BadBlock").build(), StreamIoBuilder::new() .add_input::("in") diff --git a/tests/fail.rs b/tests/fail.rs index 79ad496cd..8e9686000 100644 --- a/tests/fail.rs +++ b/tests/fail.rs @@ -2,7 +2,6 @@ use futuresdr::anyhow::bail; use futuresdr::anyhow::Result; use futuresdr::blocks::MessageSink; use futuresdr::macros::async_trait; -use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; use futuresdr::runtime::Flowgraph; @@ -12,14 +11,15 @@ use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Runtime; use futuresdr::runtime::StreamIo; use futuresdr::runtime::StreamIoBuilder; +use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; struct FailInit; impl FailInit { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("FailInit").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new().build(), @@ -44,8 +44,8 @@ struct FailWork; impl FailWork { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("FailWork").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new().build(), @@ -71,8 +71,8 @@ struct FailDeinit; impl FailDeinit { #[allow(clippy::new_ret_no_self)] - pub fn new() -> Block { - Block::new( + pub fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("FailDeinit").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new().build(), diff --git a/tests/flow.rs b/tests/flow.rs index 904ea72fb..e934ecb00 100644 --- a/tests/flow.rs +++ b/tests/flow.rs @@ -6,6 +6,7 @@ use futuresdr::blocks::NullSource; use futuresdr::blocks::VectorSink; use futuresdr::blocks::VectorSinkBuilder; use futuresdr::runtime::scheduler::FlowScheduler; +use futuresdr::runtime::BlockT; use futuresdr::runtime::Flowgraph; use futuresdr::runtime::Runtime; use futuresdr_macros::connect; diff --git a/tests/message_handler.rs b/tests/message_handler.rs index bc321aa3d..b17873a1d 100644 --- a/tests/message_handler.rs +++ b/tests/message_handler.rs @@ -5,22 +5,23 @@ mod isolated_scope { #[test] fn message_handler_compiles() { use futuresdr::macros::message_handler; - use futuresdr::runtime::Block; use futuresdr::runtime::BlockMeta; use futuresdr::runtime::BlockMetaBuilder; + use futuresdr::runtime::BlockT; use futuresdr::runtime::Kernel; use futuresdr::runtime::MessageIo; use futuresdr::runtime::MessageIoBuilder; use futuresdr::runtime::Pmt; use futuresdr::runtime::StreamIoBuilder; + use futuresdr::runtime::TypedBlock; use futuresdr::runtime::WorkIo; struct MsgThing; impl MsgThing { #[allow(clippy::new_ret_no_self)] - fn new() -> Block { - Block::new( + fn new() -> TypedBlock { + TypedBlock::new( BlockMetaBuilder::new("MsgThing").build(), StreamIoBuilder::new().build(), MessageIoBuilder::new()