# Question about Benchmark\_rx.py file code

**URL:** <https://www.ruby-forum.com/t/question-about-benchmark-rx-py-file-code/132414>\
**Category:** GNU Radio\
**Created:** [March 19, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/question-about-benchmark-rx-py-file-code/132414 "2008-03-19T23:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 19, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/question-about-benchmark-rx-py-file-code/132414/1 "2008-03-19T23:03:13Z")

</div>

Hi I’m trying to troubleshoot a piece of code that was handed to me.?  
The basic application uses GNU radio and a USRP in transmitting digital  
signals and the application uses the following file provided in GNU  
radio “benchmark\_rx.py” which can be found in the following directory  
“gnuradio/trunk/gnuradio-examples/python/digital/benchmark\_rx.py”.

The application occasionally crashes on line 66 in the benchmark file,  
the line is “(pktno,) = struct.unpack(’!H’, payload[0:2])”.? The error I  
get is that struct.unpack should be passed a string of at least size 2

When looking at the code it seems that it should have ‘H’ versus ‘!H’ if  
the intend was to convert the object to a C unsigned short object.? And  
if the intention is to pass !H then it should be passed as “!H” using  
double ? quotes.? when I changed the code to either ‘H’ or “!H” the code  
works without any runtime errors.

My question is, is the ‘!H’ a bug in the GNU radio code?? Thanks.

Al Fayez

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 19, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/question-about-benchmark-rx-py-file-code/132414/2 "2008-03-19T23:59:03Z")

</div>

On Wed, Mar 19, 2008 at 06:02:17PM -0400, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi I’m trying to troubleshoot a piece of code that was handed to  
> me.? The basic application uses GNU radio and a USRP in transmitting  
> digital signals and the application uses the following file provided  
> in GNU radio “benchmark\_rx.py” which can be found in the following  
> directory  
> “gnuradio/trunk/gnuradio-examples/python/digital/benchmark\_rx.py”.

> The application occasionally crashes on line 66 in the benchmark  
> file, the line is “(pktno,) = struct.unpack(‘!H’, payload[0:2])”.?  
> The error I get is that struct.unpack should be passed a string of  
> at least size 2

That means that the code is being handed a string of length \< 2 bytes.

> When looking at the code it seems that it should have ‘H’ versus  
> ‘!H’ if the intend was to convert the object to a C unsigned short  
> object.? And if the intention is to pass !H then it should be passed  
> as “!H” using double ? quotes.? when I changed the code to either  
> ‘H’ or “!H” the code works without any runtime errors.

If you’ll take a look at the python documentation for struct.unpack,  
you’ll see that the “!” forces network endian order. That’s what we  
want. If you look at the python documentation you’ll discover the  
differences between ‘foo’ and “foo” – nothing.

> My question is, is the ‘!H’ a bug in the GNU radio code?? Thanks.

Nope.

Eric

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 20, 2008, 12:25am UTC](https://www.ruby-forum.com/t/question-about-benchmark-rx-py-file-code/132414/3 "2008-03-20T00:25:28Z")

</div>

Eric B. wrote:

> On Wed, Mar 19, 2008 at 06:02:17PM -0400, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The application occasionally crashes on line 66 in the benchmark  
> > file, the line is “(pktno,) = struct.unpack(‘!H’, payload[0:2])”.?  
> > The error I get is that struct.unpack should be passed a string of  
> > at least size 2
> 
> That means that the code is being handed a string of length \< 2 bytes.

Not getting the bug after your changes was probably coincidental. I’ve  
seen this happen on occasion when a packet is receive erroneously and  
the header is corrupted. The framer state machine looks for the repeated  
packet length after correlating with the access code. What’s probably  
happening is the header is being read in as double 0’s, so it passes on  
a packet of length zero. When unpacking, Python is throwing an  
exception.

The right thing to do here is catch the exception and mark it as a  
missed packet.

Tom
