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

main.cpp

Committer:
ntaka206
Date:
2014-06-10
Revision:
1:cecf9bdf045b
Parent:
0:1ababa0d0c42
Child:
2:bc413454a83e

File content as of revision 1:cecf9bdf045b:

#include "mbed.h"
#include "GPS.h"

#define C027_USEONBOARD
#include "C027.h"
C027 c027;

#define DOTRACE ((USBRX!=MDMRXD)&&(USBTX!=MDMTXD))
#define TRACE     (!DOTRACE)?:printf

int main(void)
{
    int ret;
    char buf[2048] = "";

    if (DOTRACE) {
        Serial pc(USBTX,USBRX);
        pc.baud(115200);
    }
    
    wait_ms(1000);
    
    // turn on the supplies of the Modem and the GPS
    c027.mdmPower(false);
    c027.gpsPower(true);
    wait(2);
    
    // Create the GPS object
    GPSI2C gps(GPSSDA,GPSSCL,GPSADR); 
    
    // open the PC serial port and (use the same baudrate)
    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)
        {
            int len = LENGTH(ret);
//            TRACE("NMEA: %.*s\r\n", len-2, buf); 
//            pc2.printf("NMEA: %.*s\r\n", len-2, buf); 
            if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6))
            {
                if (!strncmp("$GPGLL", buf, 6))
                {
                    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')
                    {
                        sprintf(outbuf, "%06d,%.6f,%.6f,%.2f,%.1f,%.1f\r\n", (long)utc, la, lo, hdop, hsea, hgeo); 
                        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);
    }
    gps.powerOff();
    TRACE("Shutdown\r\n");
    c027.gpsPower(false);
    return 0;
}