Test software for SatChat prototype hardware Platform - MAX32630FTHR

Dependencies:   USBDevice max32630fthr

Revision:
9:b8a60ade343e
Parent:
8:b4a6c632c809
Child:
10:349d4fa9037f
--- a/main.cpp	Sat Jul 01 06:33:58 2017 +0000
+++ b/main.cpp	Sat Jul 01 07:57:16 2017 +0000
@@ -13,6 +13,18 @@
 DigitalOut green_led(LED2,1);
 DigitalOut blue_led(LED3,1);
 
+char gpsfix_last_utc_time[11] = {0};
+char gpsfix_last_utc_date[7] = {0};
+char gpsfix_longtitude[12] = {0};
+char gpsfix_latitude[12] = {0};
+char gpsfix_speed[8] = {0};     //Set but not used
+char gpsfix_course[7] = {0};    //Set but not used
+char gpsfix_variation[7] = {0}; //Set but not used
+char gpsfix_mag_var_ew[1] = {0};//Set but not used
+char gpsfix_ns[1] = {0};
+char gpsfix_ew[1] = {0};
+
+
 void gps_power(bool state)
 {
     char    data[2];
@@ -21,13 +33,13 @@
     if (state == on) {
         data[1] = 0xE2; //Enable LDO3
     }
-    i2c.write( 0x50, data, 2 ); 
+    i2c.write( 0x50, data, 2 );
 }
 
 void gps_update(void)
 {
     gps_power(on);
-    
+
     while (1) {
         int checksum = 0;
         char nmea_sentence[82] = {0};   //Fill with NULL terminators to save doing it later
@@ -36,7 +48,7 @@
         nmea_sentence[nmea_index] = '$';    //Manually insert the '$' because we don't want it included in the checksum loop
         char nmea_char = gps.getc();        //get sentence first char from GPS
         while (nmea_char != '*') {          //Loop building sentence and calc'ing CS until *
-             checksum ^= nmea_char;         //Calc checksum as we read sentence
+            checksum ^= nmea_char;         //Calc checksum as we read sentence
             if ((nmea_sentence[nmea_index] == ',')&&(nmea_char == ',')) {
                 nmea_sentence[++nmea_index] = ' ';  //Pad consecutive comma with a space to make it possible to use strtok with empty values
             }
@@ -50,24 +62,33 @@
         char hex_checksum[3] = {0};
         hex_checksum[0] = gps.getc();
         hex_checksum[1] = gps.getc();
-        if (checksum == (int)strtol(hex_checksum, NULL, 16) ){
-            pc.printf("Match\n\r");
+        if (checksum == (int)strtol(hex_checksum, NULL, 16) ) {
+            //Valid sentence so check if it's a GPRMC
+            //pc.printf("Match\n\r");
+            const char gprmc[7] = "$GPRMC";
+            char *token;
+            token = strtok(nmea_sentence, ",");
+            if (strcmp(token,gprmc) == 0) {     //GPRMC ?
+               // gps_power(off);                 //Yes - No need for GPS now
+               // while (gps.readable()){
+               //     char dummy = gps.getc();    //Empty serial buffer because overflows reveal MBED bugs :-(
+               // }  
+                pc.printf( " %s\n\r", token );  //Get the time
+                if (token != NULL) {
+                    token = strtok(NULL, ",");
+                    pc.printf("Time: %s\n\r",token);
+                }
+                if (token != NULL) {
+                    token = strtok(NULL, ",");
+                    pc.printf("Valid: %s\n\r",token);
+                }
+                //If valid, get the rest of the tokens and pass to static variable.
+                
+            }
         }
 
-        //     const char s[2] = ",";
-        const char gprmc[7] = "$GPRMC";
-        char *token;
-        token = strtok(nmea_sentence, ",");
-        if (strcmp(token,gprmc) == 0) {
-            pc.printf( " %s\n\r", token );
-            while (token != NULL) {
-                token = strtok(NULL, ",");
-       //         pc.printf( " %s\n\r", token );
-            }
-     //               pc.printf("GPS CS:");
+ 
 
-        pc.printf("%d \n\r",checksum);
-        }
 
         while (gps.readable()) {
             char dummy = gps.getc();