Test software for SatChat prototype hardware Platform - MAX32630FTHR

Dependencies:   USBDevice max32630fthr

Revision:
16:c5634210628d
Parent:
15:7d75ecaeabdb
--- a/main.cpp	Tue Jul 04 17:24:55 2017 +0000
+++ b/main.cpp	Thu Sep 21 01:24:44 2017 +0000
@@ -48,10 +48,12 @@
 {
     char    data[2];
     data[0] = 0x16;     //MAX14690 LDO3cfg register
+    printf("GPS Power:");
     if (state == ON) {
         data[1] = 0xE2; //Enable LDO3
         i2c.write( 0x50, data, 2 );
         gps_led=ON;
+        printf("ON\n\r");
     } else {
         data[1] = 0xE0; //Disable LDO3
         i2c.write( 0x50, data, 2 );
@@ -59,6 +61,7 @@
         while (gps.readable()) {
                 char dummy = gps.getc();    //Empty serial buffer because overflows reveal MBED bugs :-(
         }
+        printf("OFF\n\r");
     }
 }
 
@@ -149,8 +152,8 @@
             const char gprmc[7] = "$GPRMC";
             char *token;
             token = strtok(nmea_sentence, ",");
-            if (strcmp(token,gprmc) == 0) {     //GPRMC ?
-                //pc.printf( " %s\n\r", token );  //Get the time
+            if (strcmp(token,gprmc) == 0) {     //GPRMC
+pc.printf( " %s\n\r", token );  //Get the time
                 if (token != NULL) {
                     token = strtok(NULL, ",");
                     if (*token != 32) {         //If there is a time present (anything but a space), record it.
@@ -161,9 +164,9 @@
                 }
                 if (token != NULL) {
                     token = strtok(NULL, ",");
-                /*    if (*token == 'V') {
-                        pc.printf("VOID");
-                    } */
+if (*token == 'V') {
+       pc.printf("VOID");
+} 
                 } 
                 if (*token == 'A') {                //Is this an 'A'ctive (valid) fix?
                     pc.printf("Got a fix\n\r");
@@ -171,22 +174,22 @@
                     wait_for_fix = false;           //Stop looping now we have a fix.
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("Latitude: %s\n\r",token);
+pc.printf("Latitude: %s\n\r",token);
                         memcpy(gpsfix_latitude, token, sizeof gpsfix_latitude - 1);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("North/South: %s\n\r",token);
+pc.printf("North/South: %s\n\r",token);
                         gpsfix_ns = *token;
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("Longitude: %s\n\r",token);
+pc.printf("Longitude: %s\n\r",token);
                         memcpy(gpsfix_longtitude, token, sizeof gpsfix_longtitude - 1);
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("East/West: %s\n\r",token);
+pc.printf("East/West: %s\n\r",token);
                         gpsfix_ew = *token;
                     }
                     if (token != NULL) {
@@ -199,7 +202,7 @@
                     }
                     if (token != NULL) {
                         token = strtok(NULL, ",");
-                        //pc.printf("Date: %s\n\r",token);
+pc.printf("Date: %s\n\r",token);
                         memcpy(gpsfix_last_utc_date, token, sizeof gpsfix_last_utc_date - 1);
                     }
                     if (token != NULL) {
@@ -219,75 +222,41 @@
 }
 
 main()
-/*  Start of BLACK CODE region.  This area provides minimal SOS and position
-    updating. It needs to be robust and well tested. Put all the fancy stuff 
-    outside this area.  Changes here should be limited to fixing bugs and
-    simplifying the code.
-*/
-{   //Set the power button behaviour.
-    char    data[2];
-    data[0] = 0x1A;     //MAX14690 BootCfg register
-    data[1] = 0x30;     //Always-On Mode, off state via PWR_OFF_CMD
-    i2c.write( 0x50, data, 2 );
+{   /*Set the power button behaviour.
+      char    data[2];
+      data[0] = 0x1A;     //MAX14690 BootCfg register
+      data[1] = 0x30;     //Always-On Mode, off state via PWR_OFF_CMD
+      i2c.write( 0x50, data, 2 );
+    */
+    
     //Set the voltage to 3v3 for the GPS.
+    char data[2];
     data[0] = 0x17;     //MAX14690 LDO3Vset register
     data[1] = 0x19;     //3.3V
     i2c.write( 0x50, data, 2 );
     gps_power(OFF);
 
-    pc.printf("\n\n\rOpen EPIRB - Simple mode\n\r");
-    pc.printf("Press and hold both side buttons to signal rescue needed\n\r");
-    pc.printf("Full functionality will start in:");
-    for (int i=9; i > 0; i--) {
-        time_t seconds = time(NULL);    //get current epoch
-        pc.printf("%d",i);
-        while(time(NULL) - seconds < 1) {
-            if (false/*button_combination()==SOS_PRESSED*/) {
-                //do the emergency code
-                if (gps_update()==EXIT_SUCCESS) {
-                    gps_data_present = true;
-                    int gps_epoch = get_epoch_from_last_gps_time();
-                    set_time(gps_epoch);
-                    pc.printf("Got a GPS fix and time.\n\r");
-                    pc.printf("Sending SOS in 10 seconds");
-                    green_led=ON;
-                } else {
-                    pc.printf("\n\rGPS timed out and we have no existing fix.\n\r");
-                    pc.printf("We can send an Iridium packet but coordinates are rough.\n\r");
-                    pc.printf("Sending SOS in 10 seconds");
-                    red_led=ON;
-                }
-                while(true) {}; //STOP HERE
-            }
+    while (1) {
+        if (gps_update()==EXIT_SUCCESS) {
+            gps_data_present = true;
+            int gps_epoch = get_epoch_from_last_gps_time();
+            set_time(gps_epoch);
+            pc.printf("Got a GPS fix and time.\n\r");
+        } else {
+            pc.printf("GPS timed out and we have no existing fix.\n\r");
+            pc.printf("We can send an Iridium packet but coordinates are rough.\n\r");
         }
-        pc.printf("\b");            //Backspace
-    }
-/*  END OF BLACK CODE REGION - Put all the fancy stuff down here
-*/
-    pc.printf("\n\rStarting normal operation\n\r");
-/*
-    if (true) {         //Temp simulation
-        while (1) {
-            if (gps_update()==EXIT_SUCCESS) {
-                gps_data_present = true;
-                int gps_epoch = get_epoch_from_last_gps_time();
-                set_time(gps_epoch);
-                pc.printf("Got a GPS fix and time.\n\r");
-            } else {
-                pc.printf("GPS timed out and we have no existing fix.\n\r");
-                pc.printf("We can send an Iridium packet but coordinates are rough.\n\r");
-            }
-            time_t seconds = time(NULL);
-            //printf("Time as a basic string = %s", ctime(&seconds));
-            wait(60);
-            seconds = time(NULL);
+        time_t seconds = time(NULL);
+        //printf("Time as a basic string = %s", ctime(&seconds));
+        wait(60);
+        seconds = time(NULL);
 
-            wait(33);
-            seconds = time(NULL);
-            printf("Time as a basic string = %s", ctime(&seconds));
-            wait(60);
-        } */
-    }
+        wait(33);
+        seconds = time(NULL);
+        printf("Time as a basic string = %s", ctime(&seconds));
+        wait(60);
+    } 
+}