Bmag incl gps rettelse
Dependencies: mbed WDT MODSERIAL BME280
Diff: main.cpp
- Branch:
- MbedBMAGThrRev
- Revision:
- 31:342036402df2
- Parent:
- 30:072e918663b8
- Child:
- 32:a8d74b3c9d6f
--- a/main.cpp Tue Sep 05 12:46:19 2017 +0000 +++ b/main.cpp Wed Sep 06 04:51:05 2017 +0000 @@ -394,65 +394,84 @@ timeDiffStrLen = strlen(tmpTimeDiff); - //ensure correct timestamp - if(tmpTimeDiff[timeDiffStrLen-4] == '1'){ + //ensure correct timestamp, if more than or equal to 1000ms has passed. + if(tmpTimeDiff[0] == '1'){ + + //initialize temporary char arrays memset(tmpChar1, '\0', 5); memset(tmpChar2, '\0', 5); + //first temporary array gets the timestamp section containing seconds. tmpChar1[0] = gpsNMEA.currentUTCFromGPRMC[6]; tmpChar1[1] = gpsNMEA.currentUTCFromGPRMC[7]; + //add one to the temporary seconds counter, and assign it to second temporary char array snprintf(tmpChar2, 5, "%d", ((atoi(tmpChar1) + 1))); - if(atoi(tmpChar2)%60 != 0){ + //if a remainder is present after division by 60 seconds + if((atoi(tmpChar2)%60) != 0){ + //if the seconds counter has one digit if(strlen(tmpChar2) == 1){ gpsNMEA.currentUTCFromGPRMC[6] = '0'; gpsNMEA.currentUTCFromGPRMC[7] = tmpChar2[0]; } - + //if the seconds counter has two digits if(strlen(tmpChar2) == 2){ gpsNMEA.currentUTCFromGPRMC[6] = tmpChar2[0]; gpsNMEA.currentUTCFromGPRMC[7] = tmpChar2[1]; } } + //if a remainder is not present after division by 60 seconds if(atoi(tmpChar2)%60 == 0){ + + //set the seconds counter to 00 gpsNMEA.currentUTCFromGPRMC[6] = '0'; gpsNMEA.currentUTCFromGPRMC[7] = '0'; + //assign the two digits of the minute counter to tmpChar1 tmpChar1[0] = gpsNMEA.currentUTCFromGPRMC[3]; tmpChar1[1] = gpsNMEA.currentUTCFromGPRMC[4]; + //add one to the minute counter and assign it to tmpChar2 array snprintf(tmpChar2, 5, "%d", ((atoi(tmpChar1) + 1))); + //if remainder present after division by 60 if(atoi(tmpChar2)%60 != 0){ - + //if 1 digit is present, assign the new incremented minute counter if(strlen(tmpChar2) == 1){ gpsNMEA.currentUTCFromGPRMC[3] = '0'; gpsNMEA.currentUTCFromGPRMC[4] = tmpChar2[0]; } + //if two digits are present. assign the new incremented minute counter if(strlen(tmpChar2) == 2){ gpsNMEA.currentUTCFromGPRMC[3] = tmpChar2[0]; gpsNMEA.currentUTCFromGPRMC[4] = tmpChar2[1]; } } + //if no remainder is present after division by 60 if(atoi(tmpChar2)%60 == 0){ + //set minute counter digits to 00 gpsNMEA.currentUTCFromGPRMC[3] = '0'; gpsNMEA.currentUTCFromGPRMC[4] = '0'; + //assign hour counter to tmpChar1 array tmpChar1[0] = gpsNMEA.currentUTCFromGPRMC[0]; tmpChar1[1] = gpsNMEA.currentUTCFromGPRMC[1]; + //increment hour counter and assign to tmpChar2 snprintf(tmpChar2, 5, "%d", ((atoi(tmpChar1) + 1))); + //if hour counter is one digit long if(strlen(tmpChar2) == 1){ gpsNMEA.currentUTCFromGPRMC[0] = '0'; gpsNMEA.currentUTCFromGPRMC[1] = tmpChar2[0]; } + //if hour counter is 2 digits long if(strlen(tmpChar2) == 2){ gpsNMEA.currentUTCFromGPRMC[0] = tmpChar2[0]; gpsNMEA.currentUTCFromGPRMC[1] = tmpChar2[1];