Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

UDP Packet Encoding

by nEMESIS4 (Initiate)
on Nov 21, 2011 at 21:38 UTC ( #939330=perlquestion: print w/replies, xml ) Need Help??
nEMESIS4 has asked for the wisdom of the Perl Monks concerning the following question:


I have a quick question that I am hoping someone can point me in the right direction. We are trying to receive data from a GPS unit. I have setup a Perl server script to catch any UDP activity. The device seems to be hitting our server fine, but the packet is either encoded or encrypted in a way I do not know how to handle.

The results look like this:

1 y N(                       ,/   

Based on simply looking at this, would anyone have any suggestions to try on how to read this data? Thanks!

Replies are listed 'Best First'.
Re: UDP Packet Encoding
by ikegami (Pope) on Nov 21, 2011 at 23:57 UTC

    Taking it at your word that documentation cannot be obtained, that leaves reverse engineering the data.

    There's not that much to the packet, so most of it can probably be guessed based on what data you expect to be provided.

    • Id? (Serial number?)
    • Timestamp?
    • Longitude?
    • Latitude?
    • Altitude?
    • Speed?
    • etc

    Things to know:

    • Learning how integer and decimal numbers are stored by computers (2s complement and floating point) would be useful.

    • Familiarity with different representations of longitude and latitude could be useful.

    I was about to say that reverse engineering data is possibly more art than science, but that's not true at all. To reverse engineering data, apply scientific principles:

    1. Create a hypothesis as to the value of a byte or collection of bytes.
    2. Devise an experiment to prove the hypothesis.
    3. Execute the experiment.
    4. Rinse and repeat.

    Things to look for:

    • Which numbers change as you move the unit? That could be the coordinates.

    • Are some number ever increasing? Then it's surely a counter, maybe a timestamp.

Re: UDP Packet Encoding
by Util (Priest) on Nov 21, 2011 at 22:22 UTC
    1. post the Perl code of your UDP server.
    2. post the details of the GPS unit (make, model, link to online docs, etc.)
    3. most importantly, post a *useful* output example. Perhaps by writing the "results" to a file, and then running `hexdump` or `od -t x1` on the file, and then posting *that* output, inside <pre></pre> tags.
    I doubt that your GPS is sending encrypted data; it is probably just using some dense format that is not easily human-readable. Perhaps mentioned in the unit's documentation?
      I cannot seem to post my reply, just posting this to test.
        \Thank you for the quick response.

        1) Here is the Perl code I am using:

        #!/usr/bin/perl use IO::Socket::INET; $| = 1; my ($socket,$received_data,$peeraddress,$peerport); $socket = new IO::Socket::INET (LocalPort => '26',Proto => 'udp') or d +ie "ERROR in Socket Creation : $!\n"; while(1) { $socket->recv($recieved_data,1024); $peer_address = $socket->peerhost(); $peer_port = $socket->peerport(); print "\n($peer_address, $peer_port) said : $recieved_data"; $data = "data from server\n"; print $socket "$data"; } $socket->close();

        2) The GPS unit is made by CalAmp ( There isn't much information online about it unfortunately.

        3) Here is the Hexdump results from one of the transmissions:

        0000000 0583 3112 7900 0197 0101 0002 4e01 e6c6
        0000010 00fc 0000 0000 0000 0000 0000 0000 0000
        0000020 0000 0000 0000 0000 022c ffd0 2fcd 0f00
        0000030 0208 0019 0000
Re: UDP Packet Encoding
by bluescreen (Friar) on Nov 22, 2011 at 01:39 UTC

    Additionally if you want to reverse engineering, try to capture subsequent requests and see what changes. If your device is statically positioned the position is not likely to change much - GPS have a jitter - but still you should be able to identify a field or a portion that increments steadily it could be a timestamp or ID which I'd expect both of them to be integers

Re: UDP Packet Encoding
by sundialsvc4 (Abbot) on Nov 22, 2011 at 03:19 UTC

    Okay, okay... maybe we have to “reverse engineer” this stuff, but maybe we don’t.   What does this hardware vendor say about the packets that their equipment is designed to produce?

    A quick search for “gps” on certainly points out a lot of material.   (Take no offense at my asking this, but ...) Have you looked at all of this already?   Does any of it apply?

    Perl functions such as pack() can make short work of dealing with binary packets like this one ... but of course, there’s no sense in doing anything only to discover that it has already been done.   :-)   And I’m sure that they don’t consider the format to be secret.

    (If it comes to that... sure are looking forward to a new CPAN module from you!)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://939330]
Approved by ikegami
LanX hippo doesn't want to leave his country ... ehm .... riverbed?
[marto]: Corion, I'll talk to you later, but that are is generally fine :)
[hippo]: Just not sure that the expense and hassle is worth the benefit.
[LanX]: expense? .... meeting ppl is inspiring ...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2018-06-20 09:35 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (116 votes). Check out past polls.