Skip to content

Commit

Permalink
convert block constructors to typed variants
Browse files Browse the repository at this point in the history
  • Loading branch information
bastibl committed Nov 15, 2024
1 parent 4ba03dc commit 7d62a94
Show file tree
Hide file tree
Showing 70 changed files with 238 additions and 200 deletions.
6 changes: 3 additions & 3 deletions examples/adsb/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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;
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;
Expand Down Expand Up @@ -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<Self> {
TypedBlock::new(
BlockMetaBuilder::new("Decoder").build(),
StreamIoBuilder::new().build(),
MessageIoBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions examples/adsb/src/demodulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand All @@ -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<Self> {
TypedBlock::new(
BlockMetaBuilder::new("Demodulator").build(),
StreamIoBuilder::new().add_input::<f32>("in").build(),
MessageIoBuilder::new().add_output("out").build(),
Expand Down
6 changes: 3 additions & 3 deletions examples/adsb/src/preamble_detector.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<Self> {
TypedBlock::new(
BlockMetaBuilder::new("PreambleDetector").build(),
StreamIoBuilder::new()
.add_input::<f32>("in_samples")
Expand Down
10 changes: 5 additions & 5 deletions examples/adsb/src/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<Self> {
Tracker::new_with_optional_args(None)
}

pub fn with_pruning(after: Duration) -> Block {
pub fn with_pruning(after: Duration) -> TypedBlock<Self> {
Tracker::new_with_optional_args(Some(after))
}

fn new_with_optional_args(prune_after: Option<Duration>) -> Block {
fn new_with_optional_args(prune_after: Option<Duration>) -> TypedBlock<Self> {
let aircraft_register = AircraftRegister {
register: HashMap::new(),
};
Block::new(
TypedBlock::new(
BlockMetaBuilder::new("Tracker").build(),
StreamIoBuilder::new().build(),
MessageIoBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions examples/android-hw/src/fft_shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ 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;
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<T> {
Expand All @@ -18,8 +18,8 @@ pub struct FftShift<T> {

impl<T: Copy + Send + 'static> FftShift<T> {
#[allow(clippy::new_ret_no_self)]
pub fn new() -> Block {
Block::new(
pub fn new() -> TypedBlock<Self> {
TypedBlock::new(
BlockMetaBuilder::new("FftShift").build(),
StreamIoBuilder::new()
.add_input::<T>("in")
Expand Down
3 changes: 1 addition & 2 deletions examples/audio/play_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ fn main() -> Result<()> {
let mut fg = Flowgraph::new();

let src = FileSource::new("rick.mp3");
let inner = src.kernel::<FileSource>().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)?;
Expand Down
1 change: 1 addition & 0 deletions examples/audio/play_selectable_tone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions examples/audio/play_stereo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ fn main() -> Result<()> {
let mut fg = Flowgraph::new();

let src = FileSource::new("rick.mp3");
let inner = src.kernel::<FileSource>().unwrap();

// resample to 48kHz
let resample = FirBuilder::resampling::<f32, f32>(48_000, inner.sample_rate() as usize);
let resample = FirBuilder::resampling::<f32, f32>(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;
Expand Down
6 changes: 3 additions & 3 deletions examples/ctrlport-demo.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<()> {
Expand All @@ -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<Self> {
TypedBlock::new(
BlockMetaBuilder::new("CtrlPortDemo").build(),
StreamIoBuilder::new().build(),
MessageIoBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions examples/debug/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -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<Self> {
TypedBlock::new(
BlockMetaBuilder::new("Panic").build(),
StreamIoBuilder::new().build(),
MessageIoBuilder::<Self>::new().build(),
Expand Down
6 changes: 3 additions & 3 deletions examples/debug/tag_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<()> {
Expand Down Expand Up @@ -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<Self> {
TypedBlock::new(
BlockMetaBuilder::new("PeriodicTagger").build(),
StreamIoBuilder::new()
.add_input::<f32>("in")
Expand Down
6 changes: 3 additions & 3 deletions examples/egui/src/channel_sink.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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;
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;
Expand All @@ -18,8 +18,8 @@ pub struct ChannelSink {
}

impl ChannelSink {
pub fn new(tx: Sender<Box<[f32; FFT_SIZE]>>) -> Block {
Block::new(
pub fn new(tx: Sender<Box<[f32; FFT_SIZE]>>) -> TypedBlock<Self> {
TypedBlock::new(
BlockMetaBuilder::new("ChannelSink").build(),
StreamIoBuilder::new().add_input::<f32>("in").build(),
MessageIoBuilder::<Self>::new().build(),
Expand Down
7 changes: 4 additions & 3 deletions examples/firdes/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -41,9 +42,9 @@ fn main() -> Result<()> {
firdes::kaiser::bandpass::<f32>(lower_cutoff, higher_cutoff, transition_bw, max_ripple);
println!("Filter has {} taps", filter_taps.len());

let filter_block = match enable_filter {
true => FirBuilder::new::<f32, f32, _>(filter_taps),
_ => FirBuilder::new::<f32, f32, _>([1.0_f32]),
let filter_block: Block = match enable_filter {
true => FirBuilder::new::<f32, f32, _>(filter_taps).into(),
_ => FirBuilder::new::<f32, f32, _>([1.0_f32]).into(),
};

let snk = AudioSink::new(DOWNSAMPLED_FREQ, 1);
Expand Down
6 changes: 3 additions & 3 deletions examples/keyfob/src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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;
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;

Expand All @@ -25,8 +25,8 @@ pub struct Decoder {
}

impl Decoder {
pub fn new() -> Block {
Block::new(
pub fn new() -> TypedBlock<Self> {
TypedBlock::new(
BlockMetaBuilder::new("Decoder").build(),
StreamIoBuilder::new().add_input::<u8>("in").build(),
MessageIoBuilder::<Self>::new().build(),
Expand Down
5 changes: 3 additions & 2 deletions examples/keyfob/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -39,8 +40,8 @@ fn main() -> Result<()> {

let mut fg = Flowgraph::new();

let src = match args.file {
Some(file) => FileSource::<Complex32>::new(file, false),
let src: Block = match args.file {
Some(file) => FileSource::<Complex32>::new(file, false).into(),
None => {
let mut src = SourceBuilder::new()
.sample_rate(args.sample_rate)
Expand Down
8 changes: 4 additions & 4 deletions examples/lora/src/bin/loopback.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/lora/src/bin/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions examples/lora/src/bin/tx_meshtastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7d62a94

Please sign in to comment.