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:
1:cecf9bdf045b
Parent:
0:1ababa0d0c42
Child:
2:bc413454a83e
--- a/main.cpp	Wed Jun 04 02:37:42 2014 +0000
+++ b/main.cpp	Tue Jun 10 00:25:59 2014 +0000
@@ -1,30 +1,10 @@
 #include "mbed.h"
 #include "GPS.h"
-#include "MDM.h"
-
 
-//----------------------------------------------------------------------
-/* This example was tested on C027-U20 and C027-G35 with the on board modem. 
-   
-   Additionally it was tested with a shield where the SARA-G350 RX/TX/PWRON 
-   is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this 
-   configuration the following platforms were tested (it is likely that others 
-   will work as well)
-   - U-BLOX:    C027-XX.
-   - NXP:       LPC1549v2 
-   - Freescale: FRDM-KL25Z, FRDM-KL46Z
-   - STM:       NUCLEO-F401RE, NUCLEO-F030R8
-*/
-#if defined(TARGET_UBLOX_C027)
-  #define C027_USEONBOARD // remove this if you have the GSM/GPS shield mounted
-#endif
+#define C027_USEONBOARD
+#include "C027.h"
+C027 c027;
 
-#ifdef C027_USEONBOARD
-  #include "C027.h"
-  C027 c027;
-#endif
-
-// no tracing if serial is shared with the VCP
 #define DOTRACE ((USBRX!=MDMRXD)&&(USBTX!=MDMTXD))
 #define TRACE     (!DOTRACE)?:printf
 
@@ -33,7 +13,6 @@
     int ret;
     char buf[2048] = "";
 
-    // only trace if the serial is different from our modem port
     if (DOTRACE) {
         Serial pc(USBTX,USBRX);
         pc.baud(115200);
@@ -41,41 +20,29 @@
     
     wait_ms(1000);
     
-    TRACE("GSM/GPS Support Example\r\n");
-    
     // turn on the supplies of the Modem and the GPS
     c027.mdmPower(false);
     c027.gpsPower(true);
     wait(2);
     
     // Create the GPS object
-#if GPSADR    // use GPSI2C class
     GPSI2C gps(GPSSDA,GPSSCL,GPSADR); 
-#elif GPSBAUD // or GPSSerial class 
-    GPSSerial gps(GPSTXD,GPSRXD,GPSBAUD); 
-#else
-    #warning "please define the pins for the GPS"
-#endif
     
     // open the PC serial port and (use the same baudrate)
     Serial pc2(P4_28, P4_29);
     pc2.baud(9600);
     
-    TRACE("Checking GPS\r\n");
-//    char link[128] = "";
-//    unsigned int i = 0xFFFFFFFF;
     const int wait = 100;
     bool abort = false;
-    //DigitalOut led(LED1);
     double hdop=99.99;
+    double hgeo=99.99;
+    double hsea=99.99;
     while (!abort) {
-    //    led = !led;        
         while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
         {
             int len = LENGTH(ret);
 //            TRACE("NMEA: %.*s\r\n", len-2, buf); 
 //            pc2.printf("NMEA: %.*s\r\n", len-2, buf); 
-#if 1
             if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6))
             {
                 if (!strncmp("$GPGLL", buf, 6))
@@ -83,51 +50,32 @@
                     double la = 0, lo = 0;
                     double  utc;
                     char ch;
+                    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')
                     {
-    //                    TRACE("GPS Location: %.5f %.5f\r\n", la, lo); 
-                        TRACE("%06d,%.6f,%.6f\r\n", (long)utc, la, lo); 
-                        pc2.printf("%06d,%.6f,%.6f,%.2f\r\n", (long)utc, la, lo, hdop); 
-    //                    sprintf(link, "I am here!\n"
-    //                                  "https://maps.google.com/?q=%.5f,%.5f", la, lo); 
+                        sprintf(outbuf, "%06d,%.6f,%.6f,%.2f,%.1f,%.1f\r\n", (long)utc, la, lo, hdop, hsea, hgeo); 
+                        TRACE(outbuf);
+                        pc2.printf(outbuf);
                     }
                 }
-                if (!strncmp("$GPGSA", buf, 6))
+                else if (!strncmp("$GPGSA", buf, 6))
                 {
                     gps.getNmeaItem(16,buf,len,hdop);
                 }
-            }
-
-#endif
-#if 0
-            if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6) && !strncmp("$GPGGA", buf, 6))
-            {
-                double la = 0, lo = 0;
-                double  utc, alt;
-                char ch;
-                if (gps.getNmeaAngle(2,buf,len,la) && 
-                    gps.getNmeaAngle(4,buf,len,lo) && 
-                    gps.getNmeaItem(11,buf,len,alt) && 
-                    gps.getNmeaItem(1,buf,len,utc) && 
-                    gps.getNmeaItem(6,buf,len,ch) && ch == 'A')
+                else if (!strncmp("$GPGGA", buf, 6))
                 {
-//                    TRACE("GPS Location: %.5f %.5f\r\n", la, lo); 
-                    TRACE("%06d,%.6f,%.6f,%.2f\r\n", (long)utc, la, lo, alt); 
-                    pc2.printf("%06d,%.6f,%.6f,%.2f\r\n", (long)utc, la, lo, alt); 
-//                    sprintf(link, "I am here!\n"
-//                                  "https://maps.google.com/?q=%.5f,%.5f", la, lo); 
+                    gps.getNmeaItem(9,buf,len,hsea);
+                    gps.getNmeaItem(11,buf,len,hgeo);
                 }
             }
-#endif
         }
         wait_ms(wait);
     }
     gps.powerOff();
     TRACE("Shutdown\r\n");
-    // now it is safe to switch LDOs off
     c027.gpsPower(false);
     return 0;
 }