Mark x / Mbed 2 deprecated GPS_Test

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gps.h Source File

gps.h

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "data.h"
00004 // Green wire to pin13
00005 // White wire to pin14
00006 
00007 DigitalOut led1(LED1);
00008 DigitalOut led2(LED2);
00009 DigitalOut led3(LED3);
00010 DigitalOut led4(LED4);
00011 Serial pc(USBTX, USBRX);
00012 Serial gps(p13, p14);
00013 TextLCD lcd(p21, p22, p23, p24, p25, p27, p28);
00014 
00015 
00016 int parseGSV() {
00017                     gsv2 = strtok(gsv1, ",");
00018                     while (gsv2 != NULL) {
00019                         sep++;
00020                         switch (sep) {
00021                             case 1:
00022                                 // # of sentences
00023                                 lcd.printf("#:%s\n",gsv2);
00024                             break;
00025                             case 2 :
00026                                 // Sentence # of #
00027                                 lcd.printf("S#:%s",gsv2);
00028                             break;
00029                             case 3 :
00030                                 // Number of Satellites in view (Should give a hint as to how many cases to expect here...
00031                                 lcd.printf("#:%s\n",gsv2);
00032                             break;
00033                             case 4 :
00034                                 // Satellite PRN Number
00035                                 lcd.printf("PRN#:%s\n",gsv2);
00036                             break;
00037                             case 5 :
00038                                 // Elevation in Degrees
00039                             break;
00040                             case 6:
00041                                 // Azimuth in Degrees 
00042                             break;
00043                             case 7:
00044                                 // SNR - up to 4 satellites per sentence
00045                             break;
00046                         }
00047                         gsv2 = strtok(NULL, ",");
00048                     }
00049                     sep = 0;
00050     return *gsv2;
00051 }
00052 
00053 int parseRMC() {
00054 
00055     return 0;
00056 }
00057 
00058 int parseGGA() {
00059                     gga2 = strtok(gga1, ",");
00060                     while (gga2 != NULL) {
00061                         sep++;
00062                         switch (sep) {
00063                             case 1:
00064                                 if (mode == 1) {
00065                                     lcd.cls();
00066                                     lcd.printf("Time:%s\n",gga2);
00067                                 }
00068                             break;
00069                             case 2 :
00070                                 if (mode == 2) {
00071                                     lcd.cls();
00072                                     lcd.printf("Lat:%s",gga2);
00073                                 }
00074                             break;
00075                             case 3 :
00076                                 if (mode == 2) {
00077                                     lcd.printf("%s\n",gga2);
00078                                     wait(0.25);
00079                                 }
00080                             break;
00081                             case 4 :
00082                                 if (mode == 2) {
00083                                     lcd.cls();
00084                                     lcd.printf("Lon:%s",gga2);
00085                                 }
00086                             break;
00087                             case 5 :
00088                                 if (mode == 2) {
00089                                     lcd.printf("%s\n",gga2);
00090                                     wait(0.25);
00091                                 }
00092                             break;
00093                             case 6:
00094                                 if (mode == 1) {
00095                                     if (gga2 == "0") {
00096                                         fix = "Invalid";
00097                                     }
00098                                     if (gga2 == "1") {
00099                                         fix = "GPS Fix (SPS)";
00100                                     }
00101                                     if (gga2 == "2") {
00102                                         fix = "DGPS Fix";
00103                                     }
00104                                     if (gga2 == "3") {
00105                                         fix = "PPS Fix";
00106                                     }
00107                                     if (gga2 == "4") {
00108                                         fix = "Real Time Kinematic";
00109                                     }
00110                                     if (gga2 == "5") {
00111                                         fix = "Float RTK";
00112                                     }
00113                                     if (gga2 == "6") {
00114                                         fix = "Estimated (Dead Reckoning)";
00115                                     }
00116                                     if (gga2 == "7") {
00117                                         fix = "Manual Input Mode";
00118                                     }
00119                                     if (gga2 == "8") {
00120                                         fix = "Simulation Mode";
00121                                     }
00122                                     lcd.printf("FIX: %s_%s",gga2,fix);
00123                                 }
00124                             break;
00125                         }
00126                         gga2 = strtok(NULL, ",");
00127                     }
00128                     sep = 0;
00129     return *gga2;
00130 }
00131 
00132 int getGPSstring(int str) {
00133     if (gps.scanf("%s", &gpsString) ==1) {
00134         if (str == 1) {
00135             if (sscanf(gpsString, "$GPGSV,%s",gsv1) >= 1) {
00136                 sep = 0;
00137                 parseGSV();
00138             }
00139         return *gsv2;
00140         }
00141         if (str == 2) {
00142             if (sscanf(gpsString, "$GPRMC,%s",rmc1) >= 1) {
00143                 sep = 0;
00144                 parseRMC();
00145             }
00146         return *rmc2;
00147         }
00148         if (str == 3) {
00149             if (sscanf(gpsString, "$GPGGA,%s",gga1) >=1) {
00150                 sep = 0;
00151                 parseGGA();
00152             }
00153         return *gga2;
00154         }
00155     }
00156     return 0;
00157 }