Bmag incl gps rettelse
Dependencies: mbed WDT MODSERIAL BME280
Diff: main.cpp
- Branch:
- MbedBMAGThrRev
- Revision:
- 35:ccc79f4147f2
- Parent:
- 34:c6c5e7ec9163
- Child:
- 36:4d7a41f97ff5
--- a/main.cpp Mon Sep 25 10:36:34 2017 +0000 +++ b/main.cpp Mon Sep 25 12:55:37 2017 +0000 @@ -159,9 +159,10 @@ checkStateFlag = true; } -//timer reset +//timer reset // clock update void resetTimer(void){ - t.reset(); + t.reset(); + clk.pps_Tick(); } int main(void){ @@ -497,25 +498,30 @@ //dbg.printf("Timer: %d\r\n", tmpTime); //dbg.printf("ms timer val = %s\r\n", timer_ms); + if(RTC_set){ - t_of_day = time(NULL); - char buffer[15]; - strftime(buffer, 15, "%T", localtime(&t_of_day)); - dbg.printf("Time: %s\r\n", buffer); + //t_of_day = time(NULL); + //char buffer[15]; + //strftime(buffer, 15, "%T", localtime(&t_of_day)); + //dbg.printf("Time: %s\r\n", buffer); + + string tmpTime = clk.getTime(); + //HH - gpsNMEA.currentUTCFromGPRMC[0] = buffer[0]; - gpsNMEA.currentUTCFromGPRMC[1] = buffer[1]; + gpsNMEA.currentUTCFromGPRMC[0] = tmpTime[0]; + gpsNMEA.currentUTCFromGPRMC[1] = tmpTime[1]; //MM - gpsNMEA.currentUTCFromGPRMC[3] = buffer[3]; - gpsNMEA.currentUTCFromGPRMC[4] = buffer[4]; + gpsNMEA.currentUTCFromGPRMC[3] = tmpTime[3]; + gpsNMEA.currentUTCFromGPRMC[4] = tmpTime[4]; //SS - gpsNMEA.currentUTCFromGPRMC[6] = buffer[6]; - gpsNMEA.currentUTCFromGPRMC[7] = buffer[7]; + gpsNMEA.currentUTCFromGPRMC[6] = tmpTime[6]; + gpsNMEA.currentUTCFromGPRMC[7] = tmpTime[7]; } + if(strlen(timer_ms) == 1){ gpsNMEA.currentUTCFromGPRMC[9] = '0'; gpsNMEA.currentUTCFromGPRMC[10] = '0'; @@ -734,7 +740,25 @@ if(GGA_Fix_Present && !RTC_set && (strlen(gpsNMEA.currentDATEFromGPRMC.c_str()) > 5)){ setMbedTime(gpsNMEA.currentDATEFromGPRMC, gpsNMEA.currentUTCFromGPRMC, &dbg); - RTC_set = true; + RTC_set = true; + + char tmpHour[5]; + char tmpMinute[5]; + char tmpSecond[5]; + + memset(tmpHour, '/0', 5); + memset(tmpMinute, '/0', 5); + memset(tmpSecond, '/0', 5); + + snprintf(tmpHour, 5, "%s", gpsNMEA.currentUTCFromGPRMC.substr(0, 2)); + snprintf(tmpMinute, 5, "%s", gpsNMEA.currentUTCFromGPRMC.substr(3, 2)); + snprintf(tmpSecond, 5, "%s", gpsNMEA.currentUTCFromGPRMC.substr(6, 2)); + + int hours = atoi(tmpHour); + int minutes = atoi(tmpMinute); + int seconds = atoi(tmpSecond); + + clk.setTime(seconds, minutes, hours); } }