1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use crate::prelude::*;
/// Drop samples, printing tags.
///
/// Console output is prefixed with the `name` to help differentiate the output from multiple tag debug blocks.
///
/// # Inputs
///
/// `in`: Stream to drop
///
/// # Outputs
///
/// No outputs
///
/// # Usage
/// ```
/// use futuresdr::blocks::TagDebug;
/// use futuresdr::runtime::Flowgraph;
/// use futuresdr::num_complex::Complex32;
///
/// let mut fg = Flowgraph::new();
///
/// let sink = fg.add_block(TagDebug::<Complex32>::new("foo"));
/// ```
#[derive(Block)]
pub struct TagDebug<T, I = DefaultCpuReader<T>>
where
T: Send + 'static,
I: CpuBufferReader<Item = T>,
{
#[input]
input: I,
name: String,
n_received: usize,
}
impl<T, I> TagDebug<T, I>
where
T: Send + 'static,
I: CpuBufferReader<Item = T>,
{
/// Create Tag Debug block
pub fn new(name: impl Into<String>) -> Self {
Self {
input: I::default(),
name: name.into(),
n_received: 0,
}
}
}
#[doc(hidden)]
impl<T, I> Kernel for TagDebug<T, I>
where
T: Send + 'static,
I: CpuBufferReader<Item = T>,
{
async fn work(
&mut self,
io: &mut WorkIo,
_mio: &mut MessageOutputs,
_meta: &mut BlockMeta,
) -> Result<()> {
let (i, tags) = self.input.slice_with_tags();
let n = i.len();
tags.iter().filter(|x| x.index < n).for_each(|x| {
println!(
"TagDebug {}: buf {}/abs {} -- {:?}",
&self.name,
x.index,
self.n_received + x.index,
x.tag
)
});
self.input.consume(n);
self.n_received += n;
if self.input.finished() {
io.finished = true;
}
Ok(())
}
}