Extracting ID from data packet GPS

1.7k Views Asked by At

I am trying to configure a GPS device to my systems. The GPS device send the data packet to my IP in the following format :

$$�W��¬ÿÿÿÿ™U042903.000,A,2839.6408,N,07717.0905,E,0.00,,230111,,,A*7C|1.2|203|0000÷ 

I am able to extract the latitude, longitude and other information but I am not able to extract the Tracker ID out of the string.

According to the manual the ID is in hex format.And the format of the packet is

$$<L(2 bytes)><ID(7 bytes)><command (2 bytes)><data><checksum (2 bytes)>\r\n

I don't know what to do with it, I have tried converting this to hex..but it didn't work.

Any help will be greatly appreciated.

1

There are 1 best solutions below

3
On

How about more information? What GPS? What interface (USB, serial)? What language are you working in?

Your data certainly looks odd. In my experience with GPS data, it's generally alphanumeric and separators, but it looks like you have either a corrupt string or non-alphanumeric values.


Update based upon additional information you provided:

The GPRS manual you supplied explains the format:

$$ - 2 bytes - in ASCII code (Hex code: 0x24) 
L - 2 bytes - in hex code
ID  7 bytes - in the format of hex code.
    For example, if ID is 13612345678, then it will be shown as follows: 
    0x13, 0x61, 0x23, 0x45, 0x67, 0x8f, 0xff.  
command - 2 bytes - hex code

If I understand correctly, the gibberish characters after $$ and before the data field are not printable ASCII characters. They're actual numeric values, provided one byte at a time. If you convert each byte to a hexadecimal-formatted string and display it, you should see what I mean.

I don't remember my PHP well, but I think the ID could be formed into a hexadecimal-formatted string by something like this:

$s = GetYourGPRSStringFromWherever()
$sID = sprintf("0x%02x%02x%02x%02x%02x%02x%02x", $s[4],  $s[5],  $s[6],  
               $s[7],  $s[8],  $s[9],  $s[10]);

(also, strip out or ignore any 0xFF values, as per the documentation's example)