Skip to content

Commit 6658739

Browse files
eraltumarcusmueller
authored andcommitted
gr-analog: sig source byte support mode, added qa tests gnuradio#1994
1 parent 34f1244 commit 6658739

File tree

9 files changed

+57
-7
lines changed

9 files changed

+57
-7
lines changed

docs/sphinx/source/analog_blocks.rst

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ gnuradio.analog
3737
.. autoblock:: gnuradio.analog.sig_source_f
3838
.. autoblock:: gnuradio.analog.sig_source_i
3939
.. autoblock:: gnuradio.analog.sig_source_s
40+
.. autoblock:: gnuradio.analog.sig_source_b
4041
.. autoblock:: gnuradio.analog.simple_squelch_cc

docs/sphinx/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ Waveform Generator Blocks
11351135
gnuradio.analog.sig_source_f
11361136
gnuradio.analog.sig_source_i
11371137
gnuradio.analog.sig_source_s
1138+
gnuradio.analog.sig_source_b
11381139

11391140

11401141
ZeroMQ Interface Blocks

gnuradio-runtime/include/gnuradio/fxpt_nco.h

+18
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ namespace gr {
113113
step ();
114114
}
115115
}
116+
117+
// compute sin for a block of phase angles
118+
void sin(std::int8_t *output, int noutput_items, double ampl=1.0)
119+
{
120+
for(int i = 0; i < noutput_items; i++) {
121+
output[i] = (std::int8_t)(gr::fxpt::sin(d_phase) * ampl);
122+
step();
123+
}
124+
}
125+
126+
// compute cos for a block of phase angles
127+
void cos(std::int8_t *output, int noutput_items, double ampl=1.0)
128+
{
129+
for(int i = 0; i < noutput_items; i++) {
130+
output[i] = (std::int8_t)(gr::fxpt::cos(d_phase) * ampl);
131+
step();
132+
}
133+
}
116134

117135
// compute sin for a block of phase angles
118136
void sin(short *output, int noutput_items, double ampl=1.0)

gr-analog/grc/analog_const_source_x.block.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ parameters:
66
- id: type
77
label: Output Type
88
dtype: enum
9-
options: [complex, float, int, short]
9+
options: [complex, float, int, short, byte]
1010
option_attributes:
11-
const_type: [complex, real, int, int]
12-
fcn: [c, f, i, s]
11+
const_type: [complex, real, int, short, gr.sizeof_char]
12+
fcn: [c, f, i, s, b]
1313
hide: part
1414
- id: const
1515
label: Constant

gr-analog/grc/analog_sig_source_x.block.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ parameters:
66
- id: type
77
label: Output Type
88
dtype: enum
9-
options: [complex, float, int, short]
9+
options: [complex, float, int, short, byte]
1010
option_attributes:
11-
fcn: [c, f, i, s]
12-
offset_type: [complex, real, int, int]
11+
fcn: [c, f, i, s, b]
12+
offset_type: [complex, real, int, short, byte]
1313
hide: part
1414
- id: samp_rate
1515
label: Sample Rate

gr-analog/include/gnuradio/analog/sig_source.h

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ template<class T>
101101
virtual void set_phase(float phase) = 0;
102102
};
103103

104+
typedef sig_source<std::int8_t> sig_source_b;
104105
typedef sig_source<std::int16_t> sig_source_s;
105106
typedef sig_source<std::int32_t> sig_source_i;
106107
typedef sig_source<float> sig_source_f;

gr-analog/lib/sig_source_impl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void sig_source_impl<T>::set_phase(float phase) {
287287
d_nco.set_phase(phase);
288288
}
289289

290-
290+
template class sig_source<std::int8_t>;
291291
template class sig_source<std::int16_t>;
292292
template class sig_source<std::int32_t>;
293293
template class sig_source<float>;

gr-analog/python/analog/qa_sig_source.py

+28
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ def test_const_i(self):
5858
dst_data = dst1.data()
5959
self.assertEqual(expected_result, dst_data)
6060

61+
def test_const_b(self):
62+
tb = self.tb
63+
expected_result = (1, 1, 1, 1)
64+
src1 = analog.sig_source_b(1e6, analog.GR_CONST_WAVE, 0, 1)
65+
op = blocks.head(gr.sizeof_char, 4)
66+
dst1 = blocks.vector_sink_b()
67+
tb.connect(src1, op)
68+
tb.connect(op, dst1)
69+
tb.run()
70+
dst_data = dst1.data()
71+
self.assertEqual(expected_result, dst_data)
72+
6173
def test_sine_f(self):
6274
tb = self.tb
6375
sqrt2 = math.sqrt(2) / 2
@@ -71,6 +83,22 @@ def test_sine_f(self):
7183
dst_data = dst1.data()
7284
self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
7385

86+
87+
def test_sine_b(self):
88+
tb = self.tb
89+
sqrt2 = math.sqrt(2) / 2
90+
temp_result = (0, sqrt2, 1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0)
91+
amp = 8
92+
expected_result = tuple([int(z * amp) for z in temp_result])
93+
src1 = analog.sig_source_b(8, analog.GR_SIN_WAVE, 1.0, amp)
94+
op = blocks.head(gr.sizeof_char, 9)
95+
dst1 = blocks.vector_sink_b()
96+
tb.connect(src1, op)
97+
tb.connect(op, dst1)
98+
tb.run()
99+
dst_data = dst1.data()
100+
self.assertFloatTuplesAlmostEqual(expected_result, dst_data)
101+
74102
def test_cosine_f(self):
75103
tb = self.tb
76104
sqrt2 = math.sqrt(2) / 2

gr-analog/swig/analog_swig.i

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ GR_SWIG_BLOCK_MAGIC2(analog, pwr_squelch_cc);
131131
GR_SWIG_BLOCK_MAGIC2(analog, pwr_squelch_ff);
132132
GR_SWIG_BLOCK_MAGIC2(analog, quadrature_demod_cf);
133133
GR_SWIG_BLOCK_MAGIC2(analog, rail_ff);
134+
GR_SWIG_BLOCK_MAGIC2_TMPL(analog, sig_source_b, sig_source<std::int8_t>);
134135
GR_SWIG_BLOCK_MAGIC2_TMPL(analog, sig_source_s, sig_source<std::int16_t>);
135136
GR_SWIG_BLOCK_MAGIC2_TMPL(analog, sig_source_i, sig_source<std::int32_t>);
136137
GR_SWIG_BLOCK_MAGIC2_TMPL(analog, sig_source_f, sig_source<float>);

0 commit comments

Comments
 (0)