# Swig error with add\_item\_tag

**URL:** <https://www.ruby-forum.com/t/swig-error-with-add-item-tag/240364>\
**Category:** GNU Radio\
**Created:** [April 9, 2014, 8:36pm UTC](https://www.ruby-forum.com/t/swig-error-with-add-item-tag/240364 "2014-04-09T20:36:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [April 9, 2014, 8:36pm UTC](https://www.ruby-forum.com/t/swig-error-with-add-item-tag/240364/1 "2014-04-09T20:36:15Z")

</div>

Hello,

I am working with some code from Jared B. who did some work with  
gnuradio looking at Tire Pressure Sensor Modules (tpms). See the repo  
here: [GitHub - jboone/tpms: Tire Pressure Monitoring System decoding tools.](https://github.com/jboone/tpms). I am having a hell of a time  
getting  
my setup to run his code. I get the following error:

jay@ironfist:~/tpms-master/src$ …/src/extract\_bursts.py  
~jay/ping\_903.020m\_0.400m\_20140403\_000000z\_rtlsdr.cfile  
19.6 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
T: -256, 0  
handler caught exception: Wrong number or type of arguments for  
overloaded  
function ‘block\_gateway\_sptr\_block\_\_add\_item\_tag’.  
Possible C/C++ prototypes are:  
gr::block\_gateway::block\_\_add\_item\_tag(unsigned int,gr::tag\_t const  
&)  
gr::block\_gateway::block\_\_add\_item\_tag(unsigned  
int,uint64\_t,pmt::pmt\_t  
const &,pmt::pmt\_t const &,pmt::pmt\_t const &)

Traceback (most recent call last):  
File “/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gateway.py”,  
line 55, in eval  
try: self.\_callback()  
File “/usr/local/lib/python2.7/dist-packages/gnuradio/gr/gateway.py”,  
line 144, in \_\_gr\_block\_handle  
) for i in self.\_\_out\_indexes],  
File “/home/jay/tpms-master/src/burst\_detector.py”, line 100, in  
general\_work  
self.add\_item\_tag(0, nitems\_written + index\_start - self.block\_size,  
self.\_burst\_tag\_symbol, gr.pmt.PMT\_T, gr.pmt.PMT\_F)  
File  
“/usr/local/lib/python2.7/dist-packages/gnuradio/gr/runtime\_swig.py”,  
line  
5172, in block\_\_add\_item\_tag  
return \_runtime\_swig.block\_gateway\_sptr\_block\_\_add\_item\_tag(self,  
\*args)  
NotImplementedError: Wrong number or type of arguments for overloaded  
function ‘block\_gateway\_sptr\_block\_\_add\_item\_tag’.  
Possible C/C++ prototypes are:  
gr::block\_gateway::block\_\_add\_item\_tag(unsigned int,gr::tag\_t const  
&)  
gr::block\_gateway::block\_\_add\_item\_tag(unsigned  
int,uint64\_t,pmt::pmt\_t  
const &,pmt::pmt\_t const &,pmt::pmt\_t const &)

thread[thread-per-block[1]: \<block Burst Detector (2)\>]: caught  
unrecognized exception  
^Cjay@ironfist:~/tpms-master/src$

Jared and I made an adjustment to the add\_item\_tag call in the  
burst\_detection.py code (to make sure the number of arguments passed is  
right) but still get the same error. I am not sharp enough in python to  
see what I am doing wrong, nor do I know if there have been changes made  
to  
the swig code that impacts the burst\_detection code.

Any help would be appreciated.

Thanks,

Jay

Jay R.  
Twitter: @jradcliffe02  
E-Mail: removed\_email\_address@domain.invalid  
LinkedIn + Resume: [http://www.linkedin.com/in/jradcliffe02](http://www.linkedin.com/in/jradcliffe02)

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [April 10, 2014, 9:53am UTC](https://www.ruby-forum.com/t/swig-error-with-add-item-tag/240364/2 "2014-04-10T09:53:05Z")

</div>

Hey Jay,

please make sure to provide GR version number for questions like this,  
and point us to the exact source file and line number that’s causing the  
trouble.

As for your error:

On 04/09/2014 08:34 PM, Jay R. wrote:

> ```
> gr::block_gateway::block__add_item_tag(unsigned
> 
> ```
> 
> int,uint64\_t,pmt::pmt\_t const &,pmt::pmt\_t const &,pmt::pmt\_t const &)

Python/SWIG is picky with overloading and types.  
You could try adding a tag\_t instead:  
t = gr.tag\_t()  
t.offset = tag\_sample\_index  
t.key = self.\_burst\_tag\_symbol

etc…

self.add\_item\_tag(0, t)

That said, your code should work. tag\_sample\_index isn’t a double, by  
any chance?

M

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [April 11, 2014, 12:53am UTC](https://www.ruby-forum.com/t/swig-error-with-add-item-tag/240364/3 "2014-04-11T00:53:04Z")

</div>

On Wed, Apr 09, 2014 at 12:34:59PM -0600, Jay R. wrote:

> jay@ironfist:~/tpms-master/src$ ../src/extract\_bursts.py  
> ~jay/ping\_903.020m\_0.400m\_20140403\_000000z\_rtlsdr.cfile  
> 19.6 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
> T: -256, 0  
> handler caught exception: Wrong number or type of arguments for overloaded  
> function ‘block\_gateway\_sptr\_block\_\_add\_item\_tag’.

Short answer: It’s a bug in TPMS’s extract\_bursts.py. Try this diff:

- block\_abs = numpy.abs(block\_spectrum)

- block\_abs = numpy.abs(block\_spectrum[2:-1])

Long answer: There are two problems, and the change above is a  
workaround for both.

The first problem is that the burst detection algorithm fails on your  
particular capture file because the DC offset in your file is high. So  
instead of detecting six separate bursts within your file, it detects  
one long burst consisting of the entire file. The change above causes  
the algorithm to completely ignore narrow signals (narrower than 3/256  
of your capture bandwidth) centered at 0 Hz.

I’m going to suggest this change to Jared because DC offset is a very  
common defect in SDR captures. However, it is a trade-off. In cases  
where a capture file does not suffer from DC offset, this change could  
cause the algorithm to overlook narrow, well-centered signals.

The second problem is that there is a bug that causes a negative number  
to be passed as an argument that is supposed to be an unsigned integer.  
I think this only happens when a burst is detected right at the start of  
the input file, so the above change avoids the problem. It’s just a  
workaround, not a bug fix.

Mike

---

<div class="post-metadata">

**Author:** ![jay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ed8c4c/32.png) [@jay](https://www.ruby-forum.com/u/jay)\
**Post date:** [April 11, 2014, 1:06am UTC](https://www.ruby-forum.com/t/swig-error-with-add-item-tag/240364/4 "2014-04-11T01:06:31Z")

</div>

Much appreciated. Jared and I caught the negative number last night.  
It  
then did exactly what you described, finding one huge burst. I am  
working  
with him on some of the fsk demod tools he is working on.

As far as your other message: I would love to take your course. I know  
you  
are giving it at Black Hat, but I am also teaching a class those four  
days  
there. Are there any other times you are giving it? One of the  
frustrations I am having is there is very little out there on  
demodulation.  
You can find lots of stuff on finding signals and identifying them.  
That  
part I have a decent grip on. post-demodulation I fail at. Much of it is  
I  
know what I need to do, but don’t know how to make the blocks/write the  
code to do it. How much of your course focuses on the demodulation side  
of  
things? My fear is that 80% of the courses are on the parts I am  
comfortable with. My co-worker (Don Weber) took the course, and he is  
just  
as lost as I am on this.

Thanks,

Jay

Jay R.  
Twitter: @jradcliffe02  
E-Mail: removed\_email\_address@domain.invalid  
LinkedIn + Resume: [http://www.linkedin.com/in/jradcliffe02](http://www.linkedin.com/in/jradcliffe02)
