Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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:

Hello,

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!

Comment on UDP Packet Encoding
Download Code
Re: UDP Packet Encoding
by Util (Priest) on Nov 21, 2011 at 22:22 UTC
    Please:
    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 (http://www.calamp.com/products/cellular-a-gps/fleet-tracking-units/236-lmu-1200-gprs). 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
        0000035
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 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 http://search.cpan.org 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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://939330]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2014-09-22 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (208 votes), past polls