[prev in list] [next in list] [prev in thread] [next in thread]
List: gnuradio-discuss
Subject: Re: Modifying existing GNURadio blocks
From: Marcus_Müller <marcus.mueller () ettus ! com>
Date: 2023-12-30 13:16:34
Message-ID: a41605f3-d419-487b-af4e-16c23c5bd081 () ettus ! com
[Download RAW message or body]
Heyo Kimmo,
sorry for the delayed response:
On 29.12.23 01:00, Kimmo Lehtinen wrote:
> I would like to make modifications to the following two GNURadio blocks:
> 1) QT GUI number sink-------------------------------
> I would like to modify it so that it can also display integers and strings. \
> Currently it can display floats, shorts and bytes. I raised an issue about this at \
> the Github page of GNURadio, and I got the following reply:"A number of GR blocks \
> infer type from item size, and that's what this block does (in its constructor). \
> Unfortunately, float and int32 are the same size, so int32 is not usable.It would \
> be possible to add another constructor that uses an explicit type instead of item \
> size."
Warning: this is probably more involved than you hoped for. If you've worked with C++ \
before: No problem, you can at any point always ask for help. It's also super helpful \
to use "Draft PR" on github to share your current state of affairs!
If you haven't: I think this might be a bit too hard.
Yep, you would need to copy the make function as declared in number_sink.h in [0]:
static sptr make(size_t itemsize,
float average = 0,
graph_t graph_type = NUM_GRAPH_HORIZ,
int nconnections = 1,
QWidget* parent = NULL);
to a second make function that has a different signature, for example
static sptr make(item_type_t itemtype,
float average = 0,
graph_t graph_type = NUM_GRAPH_HORIZ,
int nconnections = 1,
QWidget* parent = NULL);
where item_type_t is a "Scoped enum"/class enum [1]; something like, within \
number_sink class,
enum class item_type_t { FLOAT, INT32 , INT16, INT8 }; // or whatever types you want \
to support
Then you would actually need to implement that in number_sink_impl.cc like [2]. But \
for that you need to modify the actual constructor to not take size_t itemsize as \
argument [3], but item_type_t itemtype!
You would add a field const item_type_t d_itemtype and remove d_itemsize in
number_sink_impl.h [4] and add it to the initializer list [5]; you'd want a \
switch()/case construct to set the alignment_multiple [6].
Then, you replace the switch (d_itemsize) in get_item [7] with an appropriate
switch(d_itemtype).
Test it successfully compiles!
Now you only need to do two things to \
gr-qtgui/python/qtgui/bindings/number_sink_python.cc
1. add the new class enum item_type_t to bind_number_sink [8],
2. add the new make function:
1. modify the existing definition and
2. copy it to replace size_t itemsize with number_sink::item_type_t itemtype
In detail: following [9], you need to change
py::class_<number_sink,
gr::sync_block,
gr::block,
gr::basic_block,
std::shared_ptr<number_sink>>(m, "number_sink", D(number_sink))
.def(py::init(&number_sink::make),
…………………
into
py::class_<number_sink,
gr::sync_block,
gr::block,
gr::basic_block,
std::shared_ptr<number_sink>>
number_sink_wrapper(m, "number_sink", D(number_sink));
py::enum_<number_sink::item_type_t>(number_sink_wrapper, "item_type_t");
number_sink_wrapper
.def(py::init(&number_sink::make),
……………………
Please compile the result (make sure to make clean before, we've changed bindings), \
and test it works, from python!
Now, we need to tell GRC that there's a new way to create a Qt GUI number sink! So, \
modify qtgui_humber_sink.block.yml [10] to use the new make function instead of the \
old (both in the python templates: directive, and in the C++ cpp_templates: \
directive), and add the integer option toid: type. Then make; make install and open \
GRC and try!
Definitely make sure you also add an example GRC flowgraph to the gr-qtgui/examples \
director.
Then, please make a commit with a title that starts with "qtgui: ", for example \
"qtgui: add type-based number_sink, allowing for int32", and don't forget to use the \
-s flag with git commit, so that your commit is signed off! Push to your fork of GNU \
Radio, and open a Pull Request against main.
[0]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/include/gnuradio/qtgui/number_sink.h#L55-L68
[1] https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations
[2]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L38-L43
[3]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L46
[4]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.h#L28
[5]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L50
[6]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L64
[8]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/python/qtgui/bindings/number_sink_python.cc
[9] https://pybind11.readthedocs.io/en/stable/classes.html#enumerations-and-internal-types
[10]
https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/grc/qtgui_number_sink.block.yml
> If displaying strings, there is no sense to have a bar graph, which is currently an \
> option in the 'QT GUI number sink' block. Thus, there could be a separate block for \
> displaying strings, without an option for a bar graph.
Qt GUI Label can already do that; since there's no possibility to send strings on GNU \
Radio streams, the question is more: where do your strings come from!
> 2) QT GUI time raster sink-----------------------------------
> I would like to modify it so that the parameters 'x-axis start value' and 'x-axis \
> end value' can be changed during runtime.
sounds like a good idea.
> For example, in the 'QT GUI vector sink' block the corresponding parameters can be \
> changed during runtime.
> I understand that the best way to make the modifications is to change the code and \
> then recompile the whole GNURadio.
yes
>
> The problem is that I cannot write C++ code...
So, you really can't :( I think this really means that hopefully someone with time \
finds this email and implements that!
> Is there anyone willing to change the code ? Or at least give good instructions \
> how to do that.
> I think these modifications would be useful also to other GNURadio users :-)
Ideally, you'd open a Feature Request on github,
https://github.com/gnuradio/gnuradio/issues/new?assignees=&labels=Feature+Request&projects=&template=feature_request.yml
You can simply copy and paste your email into feature description, and paste my reply \
into "More information", preceded by "Marcus says:"
Best,
Marcus
[Attachment #3 (text/html)]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Heyo Kimmo,</p>
<p>sorry for the delayed response:<br>
</p>
<div class="moz-cite-prefix">On 29.12.23 01:00, Kimmo Lehtinen
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:975663798.9351322.1703808032896@mail.yahoo.com">
<pre class="moz-quote-pre" wrap="">
I would like to make modifications to the following two GNURadio blocks:
1) QT GUI number sink-------------------------------
I would like to modify it so that it can also display integers and strings. Currently \
it can display floats, shorts and bytes. I raised an issue about this at the Github \
page of GNURadio, and I got the following reply:"A number of GR blocks infer type \
from item size, and that's what this block does (in its constructor). Unfortunately, \
float and int32 are the same size, so int32 is not usable.It would be possible to add \
another constructor that uses an explicit type instead of item size."</pre> \
</blockquote> <p>Warning: this is probably more involved than you hoped for. If
you've worked with C++ before: No problem, you can at any point
always ask for help. It's also super helpful to use "Draft PR" on
github to share your current state of affairs!</p>
<p>If you haven't: I think this might be a bit too hard.<br>
</p>
<p>Yep, you would need to copy the <font face="monospace">make</font>
function as declared in number_sink.h in [0]:<br>
</p>
<pre> static sptr make(size_t itemsize,
float average = 0,
graph_t graph_type = NUM_GRAPH_HORIZ,
int nconnections = 1,
QWidget* parent = NULL);
</pre>
<p>to a second <font face="monospace">make</font> function that has
a different signature, for example</p>
<pre> static sptr make(item_type_t itemtype,
float average = 0,
graph_t graph_type = NUM_GRAPH_HORIZ,
int nconnections = 1,
QWidget* parent = NULL);</pre>
<p>where <font face="monospace">item_type_t</font> is a "Scoped
enum"/<font face="monospace">class enum</font> [1]; something
like, within <font face="monospace">number_sink</font> class,<br>
</p>
<pre>enum class item_type_t { FLOAT, INT32 , INT16, INT8 }; // or whatever types \
you want to support</pre> <p>Then you would actually need to implement that in
number_sink_impl.cc like [2]. But for that you need to modify the
actual constructor to not take <font face="monospace">size_t
itemsize</font> as argument [3], but <font face="monospace">item_type_t
itemtype</font>!</p>
<p>You would add a field <font face="monospace">const item_type_t
d_itemtype</font> and remove <font face="monospace">d_itemsize</font>
in number_sink_impl.h [4] and add it to the initializer list [5];
you'd want a <font face="monospace">switch()/case</font>
construct to set the <font face="monospace">alignment_multiple</font>
[6].<br>
</p>
<p>Then, you replace the <font face="monospace">switch (d_itemsize)</font>
in <font face="monospace">get_item</font> [7] with an appropriate
<font face="monospace">switch(d_itemtype)</font>. <br>
</p>
<p>Test it successfully compiles!<br>
</p>
<p>Now you only need to do two things to
gr-qtgui/python/qtgui/bindings/number_sink_python.cc <br>
</p>
<ol>
<li>add the new class enum item_type_t to bind_number_sink [8],</li>
<li>add the new make function:</li>
<ol>
<li>modify the existing definition and</li>
<li>copy it to replace size_t itemsize with
number_sink::item_type_t itemtype</li>
</ol>
</ol>
<p>In detail: following [9], you need to change</p>
<pre> py::class_<number_sink,
gr::sync_block,
gr::block,
gr::basic_block,
std::shared_ptr<number_sink>>(m, "number_sink", \
D(number_sink))
.def(py::init(&number_sink::make),
…………………
</pre>
<p>into</p>
<pre> py::class_<number_sink,
gr::sync_block,
gr::block,
gr::basic_block,
std::shared_ptr<number_sink>>
number_sink_wrapper(m, "number_sink", D(number_sink));
py::enum_<number_sink::item_type_t>(number_sink_wrapper, "item_type_t");
number_sink_wrapper
.def(py::init(&number_sink::make),
……………………</pre>
<p>Please compile the result (make sure to <font face="monospace">make
clean</font> before, we've changed bindings), and test it works,
from python!</p>
<p>Now, we need to tell GRC that there's a new way to create a Qt
GUI number sink! So, modify qtgui_humber_sink.block.yml [10] to
use the new <font face="monospace">make</font> function instead
of the old (both in the python <font face="monospace">templates:</font>
directive, and in the C++ <font face="monospace">cpp_templates:</font>
directive), and add the integer option to<font face="monospace">
id: type</font>. Then <font face="monospace">make; make install</font>
and open GRC and try!<br>
</p>
<p>Definitely make sure you also add an example GRC flowgraph to the
gr-qtgui/examples director.</p>
<p>Then, please make a commit with a title that starts with "qtgui:
", for example "qtgui: add type-based number_sink, allowing for
int32", and don't forget to use the <font face="monospace">-s</font>
flag with <font face="monospace">git commit</font>, so that your
commit is signed off! Push to your fork of GNU Radio, and open a
Pull Request against main.<br>
</p>
<p>[0]
<a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/include/gnuradio/qtgui/number_sink.h#L55-L68">https://github.com/gnuradio/ \
gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/include/gnuradio/qtgui/number_sink.h#L55-L68</a><br>
[1]
<a class="moz-txt-link-freetext" \
href="https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations">https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations</a><br>
[2]
<a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/lib/number_sink_impl.cc#L38-L43">https://github.com/gnuradio/gnuradio/blob \
/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L38-L43</a><br>
[3]
<a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/lib/number_sink_impl.cc#L46">https://github.com/gnuradio/gnuradio/blob/86a \
f478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L46</a><br> \
[4] <a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/lib/number_sink_impl.h#L28">https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.h#L28</a><br>
[5]
<a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/lib/number_sink_impl.cc#L50">https://github.com/gnuradio/gnuradio/blob/86a \
f478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L50</a><br> \
[6] <a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/lib/number_sink_impl.cc#L64">https://github.com/gnuradio/gnuradio/blob/86a \
f478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/lib/number_sink_impl.cc#L64</a><br> \
[8] <a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/python/qtgui/bindings/number_sink_python.cc">https://github.com/gnuradio/g \
nuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/python/qtgui/bindings/number_sink_python.cc</a><br>
[9]
<a class="moz-txt-link-freetext" \
href="https://pybind11.readthedocs.io/en/stable/classes.html#enumerations-and-internal \
-types">https://pybind11.readthedocs.io/en/stable/classes.html#enumerations-and-internal-types</a><br>
[10]
<a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/blob/86af478a88cf0521b023ad2c924c74ea38d9ad \
cf/gr-qtgui/grc/qtgui_number_sink.block.yml">https://github.com/gnuradio/gnuradio/blob \
/86af478a88cf0521b023ad2c924c74ea38d9adcf/gr-qtgui/grc/qtgui_number_sink.block.yml</a><br>
</p>
<blockquote type="cite"
cite="mid:975663798.9351322.1703808032896@mail.yahoo.com">
<pre class="moz-quote-pre" wrap="">
If displaying strings, there is no sense to have a bar graph, which is currently an \
option in the 'QT GUI number sink' block. Thus, there could be a separate block for \
displaying strings, without an option for a bar graph. </pre> </blockquote>
Qt GUI Label can already do that; since there's no possibility to
send strings on GNU Radio streams, the question is more: where do
your strings come from!<br>
<blockquote type="cite"
cite="mid:975663798.9351322.1703808032896@mail.yahoo.com">
<pre class="moz-quote-pre" wrap="">2) QT GUI time raster \
sink----------------------------------- I would like to modify it so that the \
parameters 'x-axis start value' and 'x-axis end value' can be changed during runtime. \
</pre> </blockquote>
sounds like a good idea.<br>
<blockquote type="cite"
cite="mid:975663798.9351322.1703808032896@mail.yahoo.com">
<pre class="moz-quote-pre" wrap="">For example, in the 'QT GUI vector sink' \
block the corresponding parameters can be changed during runtime.
I understand that the best way to make the modifications is to change the code and \
then recompile the whole GNURadio.</pre> </blockquote>
yes<br>
<blockquote type="cite"
cite="mid:975663798.9351322.1703808032896@mail.yahoo.com">
<pre class="moz-quote-pre" wrap="">
The problem is that I cannot write C++ code...</pre>
</blockquote>
<p>So, you really can't :( I think this really means that hopefully
someone with time finds this email and implements that!<br>
</p>
<blockquote type="cite"
cite="mid:975663798.9351322.1703808032896@mail.yahoo.com">
<pre class="moz-quote-pre" wrap="">Is there anyone willing to change the code ? \
Or at least give good instructions how to do that.
I think these modifications would be useful also to other GNURadio users :-)</pre>
</blockquote>
<p>Ideally, you'd open a Feature Request on github,</p>
<p><a class="moz-txt-link-freetext" \
href="https://github.com/gnuradio/gnuradio/issues/new?assignees=&labels=Feature+Re \
quest&projects=&template=feature_request.yml">https://github.com/gnuradio/gnur \
adio/issues/new?assignees=&labels=Feature+Request&projects=&template=feature_request.yml</a></p>
<p>You can simply copy and paste your email into feature
description, and paste my reply into "More information", preceded
by "Marcus says:" <br>
</p>
<p><br>
</p>
<p>Best,<br>
Marcus<br>
</p>
</body>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic