Jump to content

$GPRMC and NMEA how to extract from report


cr-ispinternet

Recommended Posts

Hi There,

 

Im a little bi lost and not sure where to start with this one, ive got a small gps receiver which im

polling over a serial connection, each time i poll the device i get a load of rubbish back like this...

 

$GPRMC,223450.000,A,5310.5785,N,00226.2042,W,0.0,25.8,291109,,,A*49

$GPGGA,223450.000,5310.5785,N,00226.2042,W,1,06,2.1,22.3,M,59.1,M,,0000*7D

$GPVTG,25.8,T,,M,0.0,N,0.0,K,A*32

$PMST200,00,204*1E

$PMST200,00,204*1E

$PMST200,00,204*1E

$PMST200,??,204*1E

$PMST200,??,204*1E

$PMST200,??,204*1E

$PMST200,??,204*1E

$PMST200,??,204*1E

$PMST200,??,204*1E

$GPGLL,5310.5785,N,00226.2042,W,223450.00,A,A*73

$GPGSA,A,3,02,04,05,07,08,10,,,,,,,4.5,2.1,4.0*39

$PMST200,??,204*1E

$PMST200,??,204*1E

$PMST200,??,204*1E

 

As they are never ever in the same order i cant really use reg_exp to get what i want, basically im

trying to capture the following and then use split to break them down further and insert into a DB

 

$GPRMC,223450.000,A,5310.5785,N,00226.2042,W,0.0,25.8,291109,,,A*49

 

how can i just get it to extract that line and nothing else unless i ask it to????

 

the output from the serial devic come is extract using this

 

$read = $serial->readPort();

 

than i just echo read etc etc and get my text which is further up, any ones help

or suggestions would be brill...

 

thanks in advance

 

Alan

Link to comment
Share on other sites

You could use a basic regular expression to grab only the $GPMRC line (are you familiar at all with regular expressions?) then break that down into an array (or whatever) to work with.

 

Here's a quick example (only lines 1, 2 and 4 are important).

preg_match('/^\$GPRMC,.*$/m', $read, $match);
$line   = $match[0];
$keys   = explode(',', 'command,timestamp,fix,lat,lath,lon,lonh,knots,bearing,date,mag_var,mode,checksum');
$values = explode(',', $line);
$recmin = array_combine($keys, $values);

// Just output the array to test
var_dump($recmin);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.