GPS_CANSAT
Dependencies: MODSERIAL mbed-src
Fork of GPS_U-blox_NEO-6M_Test_Code by
main.cpp@1:acd907fbcbae, 2014-08-22 (annotated)
- Committer:
- edodm85
- Date:
- Fri Aug 22 12:43:55 2014 +0000
- Revision:
- 1:acd907fbcbae
- Parent:
- 0:ea14ad6794af
- Child:
- 2:cc1334afbbfd
Added support for LPC4330
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
edodm85 | 0:ea14ad6794af | 1 | /* |
edodm85 | 0:ea14ad6794af | 2 | * Author: Edoardo De Marchi |
edodm85 | 1:acd907fbcbae | 3 | * Date: 22-08-14 |
edodm85 | 0:ea14ad6794af | 4 | * Notes: Firmware for GPS U-Blox NEO-6M |
edodm85 | 0:ea14ad6794af | 5 | */ |
edodm85 | 0:ea14ad6794af | 6 | |
edodm85 | 0:ea14ad6794af | 7 | #include "main.h" |
edodm85 | 0:ea14ad6794af | 8 | |
edodm85 | 0:ea14ad6794af | 9 | |
edodm85 | 0:ea14ad6794af | 10 | void Init() |
edodm85 | 0:ea14ad6794af | 11 | { |
edodm85 | 0:ea14ad6794af | 12 | gps.baud(9600); |
edodm85 | 0:ea14ad6794af | 13 | pc.baud(115200); |
edodm85 | 0:ea14ad6794af | 14 | |
edodm85 | 0:ea14ad6794af | 15 | pc.printf("Init OK\n"); |
edodm85 | 0:ea14ad6794af | 16 | } |
edodm85 | 0:ea14ad6794af | 17 | |
edodm85 | 0:ea14ad6794af | 18 | |
edodm85 | 0:ea14ad6794af | 19 | |
edodm85 | 0:ea14ad6794af | 20 | int main() |
edodm85 | 0:ea14ad6794af | 21 | { |
edodm85 | 0:ea14ad6794af | 22 | Init(); |
edodm85 | 0:ea14ad6794af | 23 | char c; |
edodm85 | 0:ea14ad6794af | 24 | |
edodm85 | 0:ea14ad6794af | 25 | while(true) |
edodm85 | 0:ea14ad6794af | 26 | { |
edodm85 | 0:ea14ad6794af | 27 | if(gps.readable()) |
edodm85 | 0:ea14ad6794af | 28 | { |
edodm85 | 0:ea14ad6794af | 29 | if(gps.getc() == '$'); // wait a $ |
edodm85 | 0:ea14ad6794af | 30 | { |
edodm85 | 0:ea14ad6794af | 31 | for(int i=0; i<sizeof(cDataBuffer); i++) |
edodm85 | 0:ea14ad6794af | 32 | { |
edodm85 | 0:ea14ad6794af | 33 | c = gps.getc(); |
edodm85 | 0:ea14ad6794af | 34 | if( c == '\r' ) |
edodm85 | 0:ea14ad6794af | 35 | { |
edodm85 | 0:ea14ad6794af | 36 | //pc.printf("%s\n", cDataBuffer); |
edodm85 | 0:ea14ad6794af | 37 | parse(cDataBuffer, i); |
edodm85 | 0:ea14ad6794af | 38 | i = sizeof(cDataBuffer); |
edodm85 | 0:ea14ad6794af | 39 | } |
edodm85 | 0:ea14ad6794af | 40 | else |
edodm85 | 0:ea14ad6794af | 41 | { |
edodm85 | 0:ea14ad6794af | 42 | cDataBuffer[i] = c; |
edodm85 | 0:ea14ad6794af | 43 | } |
edodm85 | 0:ea14ad6794af | 44 | } |
edodm85 | 0:ea14ad6794af | 45 | } |
edodm85 | 0:ea14ad6794af | 46 | } |
edodm85 | 0:ea14ad6794af | 47 | } |
edodm85 | 0:ea14ad6794af | 48 | } |
edodm85 | 0:ea14ad6794af | 49 | |
edodm85 | 0:ea14ad6794af | 50 | |
edodm85 | 0:ea14ad6794af | 51 | void parse(char *cmd, int n) |
edodm85 | 0:ea14ad6794af | 52 | { |
edodm85 | 0:ea14ad6794af | 53 | |
edodm85 | 0:ea14ad6794af | 54 | char ns, ew, tf, status; |
edodm85 | 0:ea14ad6794af | 55 | int fq, nst, fix, date; // fix quality, Number of satellites being tracked, 3D fix |
edodm85 | 0:ea14ad6794af | 56 | float latitude, longitude, timefix, speed, altitude; |
edodm85 | 0:ea14ad6794af | 57 | |
edodm85 | 0:ea14ad6794af | 58 | |
edodm85 | 0:ea14ad6794af | 59 | // Global Positioning System Fix Data |
edodm85 | 0:ea14ad6794af | 60 | if(strncmp(cmd,"$GPGGA", 6) == 0) |
edodm85 | 0:ea14ad6794af | 61 | { |
edodm85 | 0:ea14ad6794af | 62 | sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); |
edodm85 | 0:ea14ad6794af | 63 | pc.printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude); |
edodm85 | 0:ea14ad6794af | 64 | } |
edodm85 | 0:ea14ad6794af | 65 | |
edodm85 | 0:ea14ad6794af | 66 | // Satellite status |
edodm85 | 0:ea14ad6794af | 67 | if(strncmp(cmd,"$GPGSA", 6) == 0) |
edodm85 | 0:ea14ad6794af | 68 | { |
edodm85 | 0:ea14ad6794af | 69 | sscanf(cmd, "$GPGSA,%c,%d,%d", &tf, &fix, &nst); |
edodm85 | 0:ea14ad6794af | 70 | pc.printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst); |
edodm85 | 0:ea14ad6794af | 71 | } |
edodm85 | 0:ea14ad6794af | 72 | |
edodm85 | 0:ea14ad6794af | 73 | // Geographic position, Latitude and Longitude |
edodm85 | 0:ea14ad6794af | 74 | if(strncmp(cmd,"$GPGLL", 6) == 0) |
edodm85 | 0:ea14ad6794af | 75 | { |
edodm85 | 0:ea14ad6794af | 76 | sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix); |
edodm85 | 0:ea14ad6794af | 77 | pc.printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n", latitude, ns, longitude, ew, timefix); |
edodm85 | 0:ea14ad6794af | 78 | } |
edodm85 | 0:ea14ad6794af | 79 | |
edodm85 | 0:ea14ad6794af | 80 | // Geographic position, Latitude and Longitude |
edodm85 | 0:ea14ad6794af | 81 | if(strncmp(cmd,"$GPRMC", 6) == 0) |
edodm85 | 0:ea14ad6794af | 82 | { |
edodm85 | 0:ea14ad6794af | 83 | sscanf(cmd, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date); |
edodm85 | 0:ea14ad6794af | 84 | pc.printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, ns, longitude, ew, speed, date); |
edodm85 | 0:ea14ad6794af | 85 | } |
edodm85 | 0:ea14ad6794af | 86 | } |
edodm85 | 0:ea14ad6794af | 87 | |
edodm85 | 0:ea14ad6794af | 88 | |
edodm85 | 0:ea14ad6794af | 89 | |
edodm85 | 0:ea14ad6794af | 90 |