GPS_CANSAT

Dependencies:   MODSERIAL mbed-src

Fork of GPS_U-blox_NEO-6M_Test_Code by Edoardo De Marchi

Committer:
edodm85
Date:
Sat Apr 12 11:53:35 2014 +0000
Revision:
0:ea14ad6794af
Child:
1:acd907fbcbae
First Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:ea14ad6794af 1 /*
edodm85 0:ea14ad6794af 2 * Author: Edoardo De Marchi
edodm85 0:ea14ad6794af 3 * Date: 12-04-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 pc.printf("\n");
edodm85 0:ea14ad6794af 65 }
edodm85 0:ea14ad6794af 66
edodm85 0:ea14ad6794af 67 // Satellite status
edodm85 0:ea14ad6794af 68 if(strncmp(cmd,"$GPGSA", 6) == 0)
edodm85 0:ea14ad6794af 69 {
edodm85 0:ea14ad6794af 70 sscanf(cmd, "$GPGSA,%c,%d,%d", &tf, &fix, &nst);
edodm85 0:ea14ad6794af 71 pc.printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst);
edodm85 0:ea14ad6794af 72 pc.printf("\n");
edodm85 0:ea14ad6794af 73 }
edodm85 0:ea14ad6794af 74
edodm85 0:ea14ad6794af 75 // Geographic position, Latitude and Longitude
edodm85 0:ea14ad6794af 76 if(strncmp(cmd,"$GPGLL", 6) == 0)
edodm85 0:ea14ad6794af 77 {
edodm85 0:ea14ad6794af 78 sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix);
edodm85 0:ea14ad6794af 79 pc.printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n", latitude, ns, longitude, ew, timefix);
edodm85 0:ea14ad6794af 80 pc.printf("\n");
edodm85 0:ea14ad6794af 81 }
edodm85 0:ea14ad6794af 82
edodm85 0:ea14ad6794af 83 // Geographic position, Latitude and Longitude
edodm85 0:ea14ad6794af 84 if(strncmp(cmd,"$GPRMC", 6) == 0)
edodm85 0:ea14ad6794af 85 {
edodm85 0:ea14ad6794af 86 sscanf(cmd, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date);
edodm85 0:ea14ad6794af 87 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 88 pc.printf("\n");
edodm85 0:ea14ad6794af 89 }
edodm85 0:ea14ad6794af 90 }
edodm85 0:ea14ad6794af 91
edodm85 0:ea14ad6794af 92
edodm85 0:ea14ad6794af 93
edodm85 0:ea14ad6794af 94