Test software for SatChat prototype hardware Platform - MAX32630FTHR
Dependencies: USBDevice max32630fthr
Diff: main.cpp
- Revision:
- 12:a895e3581542
- Parent:
- 11:a9c16968e7f6
- Child:
- 13:ff0b39177386
--- a/main.cpp Sat Jul 01 16:48:47 2017 +0000 +++ b/main.cpp Sun Jul 02 13:37:27 2017 +0000 @@ -36,11 +36,33 @@ i2c.write( 0x50, data, 2 ); } +void set_epoch_from_last_gps_time(void) +{ + struct tm t; + time_t t_of_day; + char two_char_str[3] = {0}; + memcpy(two_char_str, gpsfix_last_utc_date+4, 2); + t.tm_year = atoi(two_char_str)+100; //Years since 1900 + memcpy(two_char_str, gpsfix_last_utc_date+2, 2); + t.tm_mon = atoi(two_char_str)-1; // Month, 0 - jan gpsfix_last_utc_date + memcpy(two_char_str, gpsfix_last_utc_date, 2); + t.tm_mday = atoi(two_char_str); // Day of the month gpsfix_last_utc_date + memcpy(two_char_str, gpsfix_last_utc_time, 2); + t.tm_hour = atoi(two_char_str); + memcpy(two_char_str, gpsfix_last_utc_time+2, 2); + t.tm_min = atoi(two_char_str); + memcpy(two_char_str, gpsfix_last_utc_time+4, 2); + t.tm_sec = atoi(two_char_str); + t.tm_isdst = 0; // Is DST on? 1 = yes, 0 = no, -1 = unknown + t_of_day = mktime(&t); + printf("seconds since the Epoch: %ld\n", (long) t_of_day); +} + void gps_update(void) { gps_power(on); - - while (1) { + bool wait_for_fix = true; + while (wait_for_fix) { int checksum = 0; char nmea_sentence[82] = {0}; //Fill with NULL terminators to save doing it later while (gps.getc()!='$'); //wait for start of sentence @@ -72,7 +94,7 @@ pc.printf( " %s\n\r", token ); //Get the time if (token != NULL) { token = strtok(NULL, ","); - if (*token != 32){ //If there is a time present, record it. + if (*token != 32) { //If there is a time present, record it. pc.printf("Time: %s\n\r",token); memcpy(gpsfix_last_utc_time, token, sizeof gpsfix_last_utc_time - 1); } @@ -83,9 +105,10 @@ pc.printf("VOID"); } } - if (*token == 'A') { + if (*token == 'A') { //Is this an 'A'ctive (valid) fix? pc.printf("Got a fix\n\r"); gps_power(off); //Yes - No need for GPS now + wait_for_fix = false; //Stop looping now we have a fix. while (gps.readable()) { char dummy = gps.getc(); //Empty serial buffer because overflows reveal MBED bugs :-( } @@ -101,12 +124,12 @@ } 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) { @@ -131,22 +154,16 @@ //pc.printf("Variation East/West: %s\n\r",token); } } - } } - - - - while (gps.readable()) { char dummy = gps.getc(); } } +} -} int main() { -// char data[2]; data[0] = 0x1A; //MAX14690 BootCfg register data[1] = 0x30; //Always-On Mode, off state via PWR_OFF_CMD @@ -159,8 +176,8 @@ wait(2); while (1) { gps_update(); - - + set_epoch_from_last_gps_time(); + wait(600); } }