GPS Latitude/Longitude Buffer Verification

Dependencies:   mbed

main.cpp

Committer:
Rbinas
Date:
2019-02-24
Revision:
2:68f47ba7fe0a
Parent:
0:8508616aa661

File content as of revision 2:68f47ba7fe0a:

#include "mbed.h"
//Board:mbed LPC1768
//Veriy GPS Lat/Long buffer Data from GNRMC sentence.If using Nema 0183 GPS, Change GNRMC to GPRMC
//GPS Receiver: HolyBro
//Wait until you get a good fix
Serial gps(p9, p10);       // TX, RX
Serial pc(USBTX, USBRX);    // TX, RX
DigitalOut led1(LED1);

char s[82];
char y1,y2,y3,y4,y5,y6,y7,y8,y9;
char x1,x2,x3,x4,x5,x6,x7,x8,x9,x10;
char NS,WE;
char GPSBuffer[1024];

int main() {
    pc.baud(9600);
    
    while (1) {
        GPSBuffer[0] = '\0';
        while (1) {
            char c = gps.getc();
           // char s[2];
            s[0] = c;
            s[1] = '\0';
            strcat(GPSBuffer, s);
            if (c == '\n') {
                break;
            }
            
if ((GPSBuffer[1] == 'G') && (GPSBuffer[2] == 'N') && (GPSBuffer[3] == 'R') && (GPSBuffer[4] == 'M') && (GPSBuffer[5] == 'C'))//GNRMC Sentence
  {
    //Latitude
    y1= GPSBuffer[19]; y2 = GPSBuffer[20]; //Degrees
    y3= GPSBuffer[21]; y4 = GPSBuffer[22];y5= GPSBuffer[24]; y6 = GPSBuffer[25];y7= GPSBuffer[26]; y8 = GPSBuffer[27];y9= GPSBuffer[28]; //DEGMIN
    NS = GPSBuffer[30];
    //Longitude 
    x1= GPSBuffer[32]; x2= GPSBuffer[33]; x3= GPSBuffer[34];//Degrees
    x4=GPSBuffer[35]; x5=GPSBuffer[36]; x6=GPSBuffer[38]; x7=GPSBuffer[39]; x8=GPSBuffer[40]; x9=GPSBuffer[41];x10=GPSBuffer[42];//DEGMIN
    WE=GPSBuffer[44];
  }
        }
        
     pc.printf("Latitude:%c%c:%c%c.%c%c%c%c%c %c",y1,y2,y3,y4,y5,y6,y7,y8,y9,NS); //Print latitude buffer data
     pc.printf(" Longitude:%c%c%c:%c%c.%c%c%c%c%c %c\r\n",x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,WE); //Print Longitude buffer data
   
    led1 = !led1;
    }
}