Bmag incl gps rettelse
Dependencies: mbed WDT MODSERIAL BME280
Diff: NMEA/NMEA.cpp
- Branch:
- MbedBMAGThrRev
- Revision:
- 61:52a6d0ffd8e5
- Parent:
- 34:c6c5e7ec9163
- Child:
- 63:168f5498a3c5
--- a/NMEA/NMEA.cpp Mon Jan 07 14:17:53 2019 +0000 +++ b/NMEA/NMEA.cpp Fri Jul 05 12:55:53 2019 +0000 @@ -203,36 +203,35 @@ will be stored in the format: YYYY/MM/DD */ +int strtoint(string str, int index) { +char value[3]; + value[0]=str[index]; + value[1]=str[index+1]; + value[2]=0; + return atoi(value); +} + void NMEA::ParseCurrentDateFromGPRMC(){ //Getting date from GPRMC string, assigning to tmpStr getXFromNMEAString(9,currentGPRMCString); - + currentDATEFromGPRMC = ""; currentDATEFromGPRMC.resize(20); - + char tmpdate[20]; //if date string is the expected length if(strlen(tmpStr.c_str()) == 6){ - - //Year - currentDATEFromGPRMC[0] = '2'; - currentDATEFromGPRMC[1] = '0'; - currentDATEFromGPRMC[2] = tmpStr[4]; - currentDATEFromGPRMC[3] = tmpStr[5]; - currentDATEFromGPRMC[4] = '/'; - - //Month - currentDATEFromGPRMC[5] = tmpStr[2]; - currentDATEFromGPRMC[6] = tmpStr[3]; - currentDATEFromGPRMC[7] = '/'; - - //Date - currentDATEFromGPRMC[8] = tmpStr[0]; - currentDATEFromGPRMC[9] = tmpStr[1]; + int y=strtoint(tmpStr,4); + int m=strtoint(tmpStr,2); + int d=strtoint(tmpStr,0); + struct tm t = { .tm_year=y, .tm_mon=m-1, .tm_mday=d }; + t.tm_mday += 1024*7; //rollover compentation + mktime(&t); + strftime (tmpdate,20,"%G/%m/%d",&t); + for (int i=0; i<20; i++) currentDATEFromGPRMC[i]=tmpdate[i]; } }; - //! GGAFixVerification, returns gps fix indication. /*! GGAFixVerification verifies gga fix status in current GGA string.