![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
K64F based data logger for GPS (ublox MAX M8Q) & 6 Axis Sensor (FXOS8700Q) - Outputs to SD + UDP - Uses FRDM K64F + ublox "Cellular and positioning shield" (3G version)
Dependencies: MAX_M8Q_Capture EthernetInterface FXOS8700Q SDFileSystem eCompass_FPU_Lib mbed-rtos mbed
MAX_M8Q.cpp@3:6085916c9d74, 2015-05-20 (annotated)
- Committer:
- rlinnmoran
- Date:
- Wed May 20 07:14:22 2015 +0000
- Revision:
- 3:6085916c9d74
- Parent:
- 2:bcd60a69583f
First release V1_0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rlinnmoran | 0:77857a36b4ff | 1 | #include "mbed.h" |
rlinnmoran | 0:77857a36b4ff | 2 | #include "MAX_M8Q.h" |
rlinnmoran | 0:77857a36b4ff | 3 | #include "GPS.h" |
rlinnmoran | 2:bcd60a69583f | 4 | #include "debug.h" |
rlinnmoran | 0:77857a36b4ff | 5 | |
rlinnmoran | 0:77857a36b4ff | 6 | //------------------------------------------------------------------------------------ |
rlinnmoran | 0:77857a36b4ff | 7 | /* This example was tested on C027-U20 and C027-G35 with the on board modem. |
rlinnmoran | 0:77857a36b4ff | 8 | |
rlinnmoran | 0:77857a36b4ff | 9 | Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON |
rlinnmoran | 0:77857a36b4ff | 10 | is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this |
rlinnmoran | 0:77857a36b4ff | 11 | configuration the following platforms were tested (it is likely that others |
rlinnmoran | 0:77857a36b4ff | 12 | will work as well) |
rlinnmoran | 0:77857a36b4ff | 13 | - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD) |
rlinnmoran | 0:77857a36b4ff | 14 | - NXP: LPC1549v2, LPC4088qsb |
rlinnmoran | 0:77857a36b4ff | 15 | - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F |
rlinnmoran | 0:77857a36b4ff | 16 | - STM: NUCLEO-F401RE, NUCLEO-F030R8 |
rlinnmoran | 0:77857a36b4ff | 17 | mount resistors SB13/14 1k, SB62/63 0R |
rlinnmoran | 0:77857a36b4ff | 18 | |
rlinnmoran | 0:77857a36b4ff | 19 | ### RLM - MODIFIED TO REMOVE MODEM FUNCTIONALITY |
rlinnmoran | 0:77857a36b4ff | 20 | */ |
rlinnmoran | 0:77857a36b4ff | 21 | |
rlinnmoran | 0:77857a36b4ff | 22 | gpsinfo_t gpsinfo; // Structure to store GPS data |
rlinnmoran | 0:77857a36b4ff | 23 | int captureMAX_M8Q(void); // Prototype |
rlinnmoran | 0:77857a36b4ff | 24 | |
rlinnmoran | 0:77857a36b4ff | 25 | int captureMAX_M8Q(void) |
rlinnmoran | 0:77857a36b4ff | 26 | { |
rlinnmoran | 0:77857a36b4ff | 27 | int ret; |
rlinnmoran | 0:77857a36b4ff | 28 | #ifdef LARGE_DATA |
rlinnmoran | 0:77857a36b4ff | 29 | char buf[2048] = ""; |
rlinnmoran | 0:77857a36b4ff | 30 | #else |
rlinnmoran | 0:77857a36b4ff | 31 | char buf[512] = ""; |
rlinnmoran | 0:77857a36b4ff | 32 | #endif |
rlinnmoran | 0:77857a36b4ff | 33 | |
rlinnmoran | 0:77857a36b4ff | 34 | // Create the GPS object |
rlinnmoran | 0:77857a36b4ff | 35 | GPSI2C gps; |
rlinnmoran | 0:77857a36b4ff | 36 | |
rlinnmoran | 0:77857a36b4ff | 37 | |
rlinnmoran | 2:bcd60a69583f | 38 | D(printf("GPS Loop\r\n")); |
rlinnmoran | 0:77857a36b4ff | 39 | |
rlinnmoran | 0:77857a36b4ff | 40 | |
rlinnmoran | 0:77857a36b4ff | 41 | bool GGA_done = false; |
rlinnmoran | 0:77857a36b4ff | 42 | bool RMC_done = false; |
rlinnmoran | 0:77857a36b4ff | 43 | bool VTG_done = false; |
rlinnmoran | 0:77857a36b4ff | 44 | |
rlinnmoran | 0:77857a36b4ff | 45 | // While required messages are not yet processed |
rlinnmoran | 0:77857a36b4ff | 46 | while(!(GGA_done & RMC_done & VTG_done)) |
rlinnmoran | 0:77857a36b4ff | 47 | { |
rlinnmoran | 0:77857a36b4ff | 48 | // Debug - comment normally |
rlinnmoran | 0:77857a36b4ff | 49 | //printf("GGA/RMC/VTG_done:%d\r\n", !(GGA_done & RMC_done & VTG_done)); |
rlinnmoran | 0:77857a36b4ff | 50 | |
rlinnmoran | 0:77857a36b4ff | 51 | // Test for valid message from GPS |
rlinnmoran | 0:77857a36b4ff | 52 | if ((ret = gps.getMessage(buf, sizeof(buf))) > 0) |
rlinnmoran | 0:77857a36b4ff | 53 | { |
rlinnmoran | 0:77857a36b4ff | 54 | int len = LENGTH(ret); //message length |
rlinnmoran | 0:77857a36b4ff | 55 | |
rlinnmoran | 0:77857a36b4ff | 56 | //### Debug - comment normally |
rlinnmoran | 0:77857a36b4ff | 57 | //printf("NMEA: %.*s\r\n", len-2, buf); |
rlinnmoran | 0:77857a36b4ff | 58 | |
rlinnmoran | 0:77857a36b4ff | 59 | // Test is valid NMEA message |
rlinnmoran | 0:77857a36b4ff | 60 | if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) |
rlinnmoran | 0:77857a36b4ff | 61 | { |
rlinnmoran | 0:77857a36b4ff | 62 | // Test if this is a valid GPS talker |
rlinnmoran | 0:77857a36b4ff | 63 | // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS |
rlinnmoran | 0:77857a36b4ff | 64 | if ((buf[0] == '$') || buf[1] == 'G') { |
rlinnmoran | 0:77857a36b4ff | 65 | |
rlinnmoran | 0:77857a36b4ff | 66 | // Assign the 3 letter NMEA message acronym to 's' |
rlinnmoran | 0:77857a36b4ff | 67 | #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) |
rlinnmoran | 0:77857a36b4ff | 68 | |
rlinnmoran | 0:77857a36b4ff | 69 | // Test for GGA NMEA Message |
rlinnmoran | 0:77857a36b4ff | 70 | if (_CHECK_TALKER("GGA")) { |
rlinnmoran | 0:77857a36b4ff | 71 | // GGA Message Detected |
rlinnmoran | 2:bcd60a69583f | 72 | D(printf("GGA NMEA Message Detected:%.*s\r\n",len-2, buf)); |
rlinnmoran | 0:77857a36b4ff | 73 | |
rlinnmoran | 0:77857a36b4ff | 74 | // Extract NS (GGA, field 3) |
rlinnmoran | 0:77857a36b4ff | 75 | if(gps.getNmeaItem(3,buf,len,gpsinfo.NS)) |
rlinnmoran | 2:bcd60a69583f | 76 | D(printf("NS: %c\r\n", gpsinfo.NS)); |
rlinnmoran | 0:77857a36b4ff | 77 | |
rlinnmoran | 0:77857a36b4ff | 78 | // Extract EW (GGA, field 5) |
rlinnmoran | 0:77857a36b4ff | 79 | if(gps.getNmeaItem(5,buf,len,gpsinfo.EW)) |
rlinnmoran | 2:bcd60a69583f | 80 | D(printf("EW: %c\r\n", gpsinfo.EW)); |
rlinnmoran | 0:77857a36b4ff | 81 | |
rlinnmoran | 0:77857a36b4ff | 82 | // Extract Altitude (GGA, field 9) |
rlinnmoran | 0:77857a36b4ff | 83 | if(gps.getNmeaItem(9,buf,len,gpsinfo.alt)) |
rlinnmoran | 2:bcd60a69583f | 84 | D(printf("Altitude: %.1f\r\n", gpsinfo.alt)); |
rlinnmoran | 0:77857a36b4ff | 85 | |
rlinnmoran | 0:77857a36b4ff | 86 | // Set flag indicating GGA processing complete |
rlinnmoran | 0:77857a36b4ff | 87 | GGA_done = true; |
rlinnmoran | 0:77857a36b4ff | 88 | |
rlinnmoran | 0:77857a36b4ff | 89 | } // end GGA NMEA Test |
rlinnmoran | 0:77857a36b4ff | 90 | |
rlinnmoran | 0:77857a36b4ff | 91 | // Test for RMC NMEA Message |
rlinnmoran | 0:77857a36b4ff | 92 | if (_CHECK_TALKER("RMC")) { |
rlinnmoran | 0:77857a36b4ff | 93 | // RMC Message Detected |
rlinnmoran | 2:bcd60a69583f | 94 | D(printf("RMC NMEA Message Detected:%.*s\r\n",len-2, buf)); |
rlinnmoran | 0:77857a36b4ff | 95 | |
rlinnmoran | 0:77857a36b4ff | 96 | // Extract Time (RMC, field 1) |
rlinnmoran | 0:77857a36b4ff | 97 | if(gps.getNmeaItem(1,buf,len,gpsinfo.utc)) |
rlinnmoran | 2:bcd60a69583f | 98 | D(printf("Time: %.2f\r\n", gpsinfo.utc)); |
rlinnmoran | 0:77857a36b4ff | 99 | |
rlinnmoran | 0:77857a36b4ff | 100 | // Extract Latitude (RMC, field 3) |
rlinnmoran | 0:77857a36b4ff | 101 | if(gps.getNmeaAngle(3,buf,len,gpsinfo.lat)) |
rlinnmoran | 2:bcd60a69583f | 102 | D(printf("Latitude: %.5f\r\n", gpsinfo.lat)); |
rlinnmoran | 0:77857a36b4ff | 103 | |
rlinnmoran | 0:77857a36b4ff | 104 | // Extract Longtitude (RMC, field 5) |
rlinnmoran | 0:77857a36b4ff | 105 | if(gps.getNmeaAngle(5,buf,len,gpsinfo.lng)) |
rlinnmoran | 2:bcd60a69583f | 106 | D(printf("Longtitude: %.5f\r\n", gpsinfo.lng)); |
rlinnmoran | 0:77857a36b4ff | 107 | |
rlinnmoran | 0:77857a36b4ff | 108 | // Extract Date (RMC, field 9) |
rlinnmoran | 0:77857a36b4ff | 109 | if(gps.getNmeaItem(9,buf,len,gpsinfo.dte,10)) |
rlinnmoran | 2:bcd60a69583f | 110 | D(printf("Date: %d\r\n", gpsinfo.dte)); |
rlinnmoran | 0:77857a36b4ff | 111 | |
rlinnmoran | 0:77857a36b4ff | 112 | // Set flag indicating RMC processing complete |
rlinnmoran | 0:77857a36b4ff | 113 | RMC_done = true; |
rlinnmoran | 0:77857a36b4ff | 114 | |
rlinnmoran | 0:77857a36b4ff | 115 | } // end RMC NMEA Test |
rlinnmoran | 0:77857a36b4ff | 116 | |
rlinnmoran | 0:77857a36b4ff | 117 | // Test for VTG NMEA Message |
rlinnmoran | 0:77857a36b4ff | 118 | if (_CHECK_TALKER("VTG")) { |
rlinnmoran | 0:77857a36b4ff | 119 | // VTG Message Detected |
rlinnmoran | 2:bcd60a69583f | 120 | D(printf("VTG NMEA Message Detected:%.*s\r\n",len-2, buf)); |
rlinnmoran | 0:77857a36b4ff | 121 | |
rlinnmoran | 0:77857a36b4ff | 122 | // Extract Speed_kmph (VTG, field 7) |
rlinnmoran | 0:77857a36b4ff | 123 | if(gps.getNmeaItem(7,buf,len,gpsinfo.spd)) |
rlinnmoran | 2:bcd60a69583f | 124 | D(printf("Speed: %.3f\r\n", gpsinfo.spd)); |
rlinnmoran | 0:77857a36b4ff | 125 | |
rlinnmoran | 0:77857a36b4ff | 126 | // Set flag indicating VTG processing complete |
rlinnmoran | 0:77857a36b4ff | 127 | VTG_done = true; |
rlinnmoran | 0:77857a36b4ff | 128 | |
rlinnmoran | 0:77857a36b4ff | 129 | } // end VTG NMEA Test |
rlinnmoran | 0:77857a36b4ff | 130 | } // end GPS Talker Test |
rlinnmoran | 0:77857a36b4ff | 131 | } // end NMEA Test |
rlinnmoran | 0:77857a36b4ff | 132 | } // end Message Test |
rlinnmoran | 0:77857a36b4ff | 133 | } // restart while loop |
rlinnmoran | 0:77857a36b4ff | 134 | |
rlinnmoran | 0:77857a36b4ff | 135 | // All GPS Data has been collected, power off receiver |
rlinnmoran | 2:bcd60a69583f | 136 | D(printf("GPS Data Collected\r\n")); |
rlinnmoran | 0:77857a36b4ff | 137 | |
rlinnmoran | 0:77857a36b4ff | 138 | return(0); |
rlinnmoran | 0:77857a36b4ff | 139 | } |