Browse Source

Fixed RTC time get from GPS

tags/v1.2.0
Bertrand Lemasle 7 years ago
parent
commit
7e112df110
2 changed files with 22 additions and 10 deletions
  1. +19
    -10
      GpsTracker/Gps.cpp
  2. +3
    -0
      GpsTracker/Rtc.cpp

+ 19
- 10
GpsTracker/Gps.cpp View File

@@ -13,10 +13,15 @@
#define TIME_MINUTE_OFFSET 10 #define TIME_MINUTE_OFFSET 10
#define TIME_SECOND_OFFSET 12 #define TIME_SECOND_OFFSET 12


#define STRTOUL_SUBSTRING(dst, src, size) strtoul(strncpy(dst, src , size), NULL, 2);

namespace gps { namespace gps {


namespace details {
uint8_t getTmCompoment(char *buffer, char *start, uint8_t size) {
strlcpy(buffer, start, size + 1);
return static_cast<uint8_t>(strtoul(buffer, NULL, 10));
}

}
char lastPosition[GPS_POSITION_SIZE]; char lastPosition[GPS_POSITION_SIZE];
SIM808_GPS_STATUS lastStatus; SIM808_GPS_STATUS lastStatus;


@@ -45,15 +50,19 @@ namespace gps {


void getTime(tmElements_t &time) { void getTime(tmElements_t &time) {
char *timeStr; char *timeStr;
char buffer[4];
char buffer[5];
char* end;
hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::UTC, &timeStr);

VERBOSE_FORMAT("getTime", "%s", timeStr);


hardware::sim808::device.getGpsField(lastPosition, SIM808_GPS_FIELD::UTC, timeStr);
time.Year = CalendarYrToTm(details::getTmCompoment(buffer, timeStr + TIME_YEAR_OFFSET, 4));
time.Month = details::getTmCompoment(buffer, timeStr + TIME_MONTH_OFFSET, 2);
time.Day = details::getTmCompoment(buffer, timeStr + TIME_DAY_OFFSET, 2);
time.Hour = details::getTmCompoment(buffer, timeStr + TIME_HOUR_OFFSET, 2);
time.Minute = details::getTmCompoment(buffer, timeStr + TIME_MINUTE_OFFSET, 2);
time.Second = details::getTmCompoment(buffer, timeStr + TIME_SECOND_OFFSET, 2);


time.Year = STRTOUL_SUBSTRING(buffer, timeStr + TIME_YEAR_OFFSET, 4);
time.Month = STRTOUL_SUBSTRING(buffer, timeStr + TIME_MONTH_OFFSET, 2);
time.Day = STRTOUL_SUBSTRING(buffer, timeStr + TIME_DAY_OFFSET, 2);
time.Hour = STRTOUL_SUBSTRING(buffer, timeStr + TIME_HOUR_OFFSET, 2);
time.Minute = STRTOUL_SUBSTRING(buffer, timeStr + TIME_MINUTE_OFFSET, 2);
time.Second = STRTOUL_SUBSTRING(buffer, timeStr + TIME_SECOND_OFFSET, 2);
VERBOSE_FORMAT("getTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second);
} }
} }

+ 3
- 0
GpsTracker/Rtc.cpp View File

@@ -1,3 +1,5 @@
#include "Debug.h"

#include "Rtc.h" #include "Rtc.h"
#include "Pins.h" #include "Pins.h"


@@ -43,6 +45,7 @@ namespace rtc {
} }


void setTime(tmElements_t &time) { void setTime(tmElements_t &time) {
VERBOSE_FORMAT("setTime", "%d/%d/%d %d:%d:%d", tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second);
details::writeTimeToRegisters(time); details::writeTimeToRegisters(time);
RTC.writeTime(); RTC.writeTime();
} }


Loading…
Cancel
Save