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
Diff: main.cpp
- Revision:
- 0:1ababa0d0c42
- Child:
- 1:cecf9bdf045b
diff -r 000000000000 -r 1ababa0d0c42 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jun 04 02:37:42 2014 +0000 @@ -0,0 +1,134 @@ +#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 + +#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 + +int main(void) +{ + 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); + } + + 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; + 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)) + { + double la = 0, lo = 0; + double utc; + char ch; + 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); + } + } + 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') + { +// 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); + } + } +#endif + } + wait_ms(wait); + } + gps.powerOff(); + TRACE("Shutdown\r\n"); + // now it is safe to switch LDOs off + c027.gpsPower(false); + return 0; +} +