# Packet Header Generator

**URL:** <https://www.ruby-forum.com/t/packet-header-generator/233065>\
**Category:** GNU Radio\
**Created:** [November 14, 2014, 9:15pm UTC](https://www.ruby-forum.com/t/packet-header-generator/233065 "2014-11-14T21:15:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [November 14, 2014, 9:15pm UTC](https://www.ruby-forum.com/t/packet-header-generator/233065/1 "2014-11-14T21:15:20Z")

</div>

I’m trying to use the Packet Header Generator block  
(not the Default one) from within GRC to generate a  
packet header formatted to my own specification in  
order to match an existing protocol.

I assume that an appropriate “formatter object” can  
be submitted to this block to instruct it to build an  
arbitrary header, but I’m having difficulty finding  
any documentation or example of using a formatter object.  
All I found points to the packet\_header\_default::header\_formatter  
method, which composes a fixed format that is of no use to me.

Any help point me in the right direction? Am I just missing  
it or is there no “generic” header formatter capability?

@(^.^)@ Ed

---

<div class="post-metadata">

**Author:** ![Ed\_Criscuolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@Ed\_Criscuolo](https://www.ruby-forum.com/u/Ed_Criscuolo)\
**Post date:** [November 14, 2014, 10:51pm UTC](https://www.ruby-forum.com/t/packet-header-generator/233065/2 "2014-11-14T22:51:04Z")

</div>

On Fri, Nov 14, 2014 at 3:14 PM, Ed Criscuolo  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> method, which composes a fixed format that is of no use to me.
> 
> Any help point me in the right direction? Am I just missing  
> it or is there no “generic” header formatter capability?
> 
> @(^.^)@ Ed

Hey Ed,

Funny enough, I was just working on this today. I’m adding a similar  
packet  
header generator for async (PDU-based) packets. The concept is similar  
with  
a default base class that you’d overload for your own purposes for  
packet  
formatting. I’ll be documenting this behavior more in the blocks  
themselves, and this should eventually become the basis for another  
level  
of our tutorials.

I have it working here in simulation, but I know there’s going to be  
some  
trouble going over the air. I suspect I’ll have something that’s is  
worth  
sharing and reasonably documented early next week.

Tom

---

<div class="post-metadata">

**Author:** ![Ed\_Criscuolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@Ed\_Criscuolo](https://www.ruby-forum.com/u/Ed_Criscuolo)\
**Post date:** [November 15, 2014, 5:50pm UTC](https://www.ruby-forum.com/t/packet-header-generator/233065/3 "2014-11-15T17:50:07Z")

</div>

On 11/14/14 4:49 PM, Tom R. wrote:

> ```
> arbitrary header, but I'm having difficulty finding
> 
> ```
> 
> some trouble going over the air. I suspect I’ll have something that’s is  
> worth sharing and reasonably documented early next week.
> 
> Tom

OK. Meanwhile, is there some clever Python hack I can use in the  
interim? I’m trying to get a timetag in a specific format  
(64-bit integer, LSB=250 picoSeconds) into the header I’m generating.  
It has to increment by 0x0000000000028000 for each packet.

For example, for my sequence number field, I needed a 16-bit unsigned  
number that skipped over any value where the last 5 bits are ‘1’,  
and rolled over at 2\*\*16. I used a repeating short vector source  
with the Python list comprehension

[s for s in range(0,32768)+range(-32768,0) if s%32 != 31]

as the vector entry in the GR block. This got merged with the  
other header fields via stream mux block. It worked great.

But for the timetag, I don’t have the rollover which allowed  
me to pregenerate a a fixed (large) vector. Any ideas?

@(^.^)@ Ed

---

<div class="post-metadata">

**Author:** ![Ed\_Criscuolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@Ed\_Criscuolo](https://www.ruby-forum.com/u/Ed_Criscuolo)\
**Post date:** [November 17, 2014, 9:49pm UTC](https://www.ruby-forum.com/t/packet-header-generator/233065/4 "2014-11-17T21:49:04Z")

</div>

On 11/14/2014 10:49 PM, Tom R. wrote:

> Funny enough, I was just working on this today. I’m adding a similar  
> packet header generator for async (PDU-based) packets. The concept is  
> similar with a default base class that you’d overload for your own  
> purposes for packet formatting. I’ll be documenting this behavior more  
> in the blocks themselves, and this should eventually become the basis  
> for another level of our tutorials.
> 
> I have it working here in simulation, but I know there’s going to be  
> some trouble going over the air. I suspect I’ll have something that’s is  
> worth sharing and reasonably documented early next week.

Ed,

if you check out the OFDM code, is uses its own custom packet header  
generator. Follow those examples to see how it’s done (or wait until Tom  
has his stuff ready).

Cheers,  
M

---

<div class="post-metadata">

**Author:** ![Ed\_Criscuolo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@Ed\_Criscuolo](https://www.ruby-forum.com/u/Ed_Criscuolo)\
**Post date:** [November 18, 2014, 5:15pm UTC](https://www.ruby-forum.com/t/packet-header-generator/233065/5 "2014-11-18T17:15:02Z")

</div>

On Mon, Nov 17, 2014 at 3:47 PM, Martin B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > 
> 
> Ed,
> 
> if you check out the OFDM code, is uses its own custom packet header  
> generator. Follow those examples to see how it’s done (or wait until Tom  
> has his stuff ready).
> 
> Cheers,  
> M

Hey Ed,

You can check out my work-in-progress branch here:

[https://github.com/trondeau/gnuradio/tree/packet\_handling](https://github.com/trondeau/gnuradio/tree/packet_handling)

It has what you need to add headers to PDUs in two different styles. The  
default is our normal access code plus the frame length repeated twice.  
The  
second does the same header plus a 16 bit frame counter. The second is  
partly to show how to manage the inheritance. Note that this is a WIP  
and  
some commits will likely get squashed and reworked to clean up the  
history  
before merging.

This concept is based off of Martin’s OFDM packet header  
generators/formatters, but these are now classes designed around PDUs.  
The  
default async formatter works well inserted directly into our chat app  
from  
the Guided Tutorials after the CRC32.

As an aside, one project that I have for 3.8 is to clean up our digital  
modulation support. We have a lot of blocks that have a lot of overlap  
in  
their capabilities, but are designed for very small differences in the  
application. I’d like to try to reduce the overlap and remove some  
duplication.

Tom
