CQ出版 Interface 2014年10月号のC027(MAX7-Q)GPSテスト記事のプログラム。 CQ publishing Interface 2014.10 issue, C027 GPS(MAX-7Q) test program.

Dependencies:   C027 C027_Support mbed

Revision:
2:bc413454a83e
Parent:
1:cecf9bdf045b
Child:
3:002503ab7199
--- a/main.cpp	Tue Jun 10 00:25:59 2014 +0000
+++ b/main.cpp	Mon Jul 28 15:45:16 2014 +0000
@@ -5,38 +5,32 @@
 #include "C027.h"
 C027 c027;
 
-#define DOTRACE ((USBRX!=MDMRXD)&&(USBTX!=MDMTXD))
-#define TRACE     (!DOTRACE)?:printf
+#define TRACE     printf
 
 int main(void)
 {
     int ret;
     char buf[2048] = "";
 
-    if (DOTRACE) {
-        Serial pc(USBTX,USBRX);
-        pc.baud(115200);
-    }
+    // USB debug output
+    Serial pc(USBTX,USBRX);
+    pc.baud(115200);
     
     wait_ms(1000);
-    
-    // turn on the supplies of the Modem and the GPS
+    // 3G modem power off
     c027.mdmPower(false);
+    // GPS power on
     c027.gpsPower(true);
     wait(2);
-    
-    // Create the GPS object
+    // Create gps object    
     GPSI2C gps(GPSSDA,GPSSCL,GPSADR); 
-    
-    // open the PC serial port and (use the same baudrate)
+
+    // Serial out for Logomatic    
     Serial pc2(P4_28, P4_29);
     pc2.baud(9600);
     
     const int wait = 100;
     bool abort = false;
-    double hdop=99.99;
-    double hgeo=99.99;
-    double hsea=99.99;
     while (!abort) {
         while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
         {
@@ -45,31 +39,26 @@
 //            pc2.printf("NMEA: %.*s\r\n", len-2, buf); 
             if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6))
             {
-                if (!strncmp("$GPGLL", buf, 6))
+                if (!strncmp("$GPGGA", buf, 6))
                 {
-                    double la = 0, lo = 0;
+                    double lat = 0, lon = 0;
                     double  utc;
-                    char ch;
+                    char qual;
+                    double hdop = 99.99;
+                    double hsea = 99.99;
                     char    outbuf[256];
-                    if (gps.getNmeaAngle(1,buf,len,la) && 
-                        gps.getNmeaAngle(3,buf,len,lo) && 
-                        gps.getNmeaItem(5,buf,len,utc) && 
-                        gps.getNmeaItem(6,buf,len,ch) && ch == 'A')
+                    if (gps.getNmeaItem(1,buf,len,utc) && 
+                        gps.getNmeaAngle(2,buf,len,lat) && 
+                        gps.getNmeaAngle(4,buf,len,lon) && 
+                        gps.getNmeaItem(8,buf,len,hdop) &&
+                        gps.getNmeaItem(9,buf,len,hsea) &&
+                        gps.getNmeaItem(6,buf,len,qual) && qual != 0)
                     {
-                        sprintf(outbuf, "%06d,%.6f,%.6f,%.2f,%.1f,%.1f\r\n", (long)utc, la, lo, hdop, hsea, hgeo); 
+                        sprintf(outbuf, "%06d,%.6f,%.6f,%.2f,%.1f\r\n", (long)utc, lat, lon, hdop, hsea); 
                         TRACE(outbuf);
                         pc2.printf(outbuf);
                     }
                 }
-                else if (!strncmp("$GPGSA", buf, 6))
-                {
-                    gps.getNmeaItem(16,buf,len,hdop);
-                }
-                else if (!strncmp("$GPGGA", buf, 6))
-                {
-                    gps.getNmeaItem(9,buf,len,hsea);
-                    gps.getNmeaItem(11,buf,len,hgeo);
-                }
             }
         }
         wait_ms(wait);
@@ -79,4 +68,3 @@
     c027.gpsPower(false);
     return 0;
 }
-