mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-23 21:45:07 +00:00
tryfix: use UTC on Phone API (#3576)
This commit is contained in:
parent
b14ac777f1
commit
ea61808fd9
@ -1379,7 +1379,7 @@ bool GPS::lookForLocation()
|
|||||||
t.tm_mon = reader.date.month() - 1;
|
t.tm_mon = reader.date.month() - 1;
|
||||||
t.tm_year = reader.date.year() - 1900;
|
t.tm_year = reader.date.year() - 1900;
|
||||||
t.tm_isdst = false;
|
t.tm_isdst = false;
|
||||||
p.timestamp = mktime(&t);
|
p.timestamp = gm_mktime(&t);
|
||||||
|
|
||||||
// Nice to have, if available
|
// Nice to have, if available
|
||||||
if (reader.satellites.isUpdated()) {
|
if (reader.satellites.isUpdated()) {
|
||||||
|
@ -75,10 +75,10 @@ uint32_t printWPL(char *buf, size_t bufsz, const meshtastic_Position &pos, const
|
|||||||
uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos)
|
uint32_t printGGA(char *buf, size_t bufsz, const meshtastic_Position &pos)
|
||||||
{
|
{
|
||||||
GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude);
|
GeoCoord geoCoord(pos.latitude_i, pos.longitude_i, pos.altitude);
|
||||||
tm *t = localtime((time_t *)&pos.timestamp);
|
tm *t = gmtime((time_t *)&pos.timestamp);
|
||||||
if (getRTCQuality() > 0) { // use the device clock if we got time from somewhere. If not, use the GPS timestamp.
|
if (getRTCQuality() > 0) { // use the device clock if we got time from somewhere. If not, use the GPS timestamp.
|
||||||
uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice);
|
uint32_t rtc_sec = getValidTime(RTCQuality::RTCQualityDevice);
|
||||||
t = localtime((time_t *)&rtc_sec);
|
t = gmtime((time_t *)&rtc_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t len = snprintf(
|
uint32_t len = snprintf(
|
||||||
|
@ -40,7 +40,7 @@ void readFromRTC()
|
|||||||
t.tm_hour = rtc.getHour();
|
t.tm_hour = rtc.getHour();
|
||||||
t.tm_min = rtc.getMinute();
|
t.tm_min = rtc.getMinute();
|
||||||
t.tm_sec = rtc.getSecond();
|
t.tm_sec = rtc.getSecond();
|
||||||
tv.tv_sec = mktime(&t);
|
tv.tv_sec = gm_mktime(&t);
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
LOG_DEBUG("Read RTC time from RV3028 as %ld\n", tv.tv_sec);
|
LOG_DEBUG("Read RTC time from RV3028 as %ld\n", tv.tv_sec);
|
||||||
timeStartMsec = now;
|
timeStartMsec = now;
|
||||||
@ -68,7 +68,7 @@ void readFromRTC()
|
|||||||
t.tm_hour = tc.hour;
|
t.tm_hour = tc.hour;
|
||||||
t.tm_min = tc.minute;
|
t.tm_min = tc.minute;
|
||||||
t.tm_sec = tc.second;
|
t.tm_sec = tc.second;
|
||||||
tv.tv_sec = mktime(&t);
|
tv.tv_sec = gm_mktime(&t);
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
LOG_DEBUG("Read RTC time from PCF8563 as %ld\n", tv.tv_sec);
|
LOG_DEBUG("Read RTC time from PCF8563 as %ld\n", tv.tv_sec);
|
||||||
timeStartMsec = now;
|
timeStartMsec = now;
|
||||||
@ -177,13 +177,7 @@ bool perhapsSetRTC(RTCQuality q, struct tm &t)
|
|||||||
*/
|
*/
|
||||||
// horrible hack to make mktime TZ agnostic - best practise according to
|
// horrible hack to make mktime TZ agnostic - best practise according to
|
||||||
// https://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html
|
// https://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html
|
||||||
setenv("TZ", "GMT0", 1);
|
time_t res = gm_mktime(&t);
|
||||||
time_t res = mktime(&t);
|
|
||||||
if (*config.device.tzdef) {
|
|
||||||
setenv("TZ", config.device.tzdef, 1);
|
|
||||||
} else {
|
|
||||||
setenv("TZ", "UTC0", 1);
|
|
||||||
}
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = res;
|
tv.tv_sec = res;
|
||||||
tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
|
tv.tv_usec = 0; // time.centisecond() * (10 / 1000);
|
||||||
@ -236,3 +230,15 @@ uint32_t getValidTime(RTCQuality minQuality, bool local)
|
|||||||
{
|
{
|
||||||
return (currentQuality >= minQuality) ? getTime(local) : 0;
|
return (currentQuality >= minQuality) ? getTime(local) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t gm_mktime(struct tm *tm)
|
||||||
|
{
|
||||||
|
setenv("TZ", "GMT0", 1);
|
||||||
|
time_t res = mktime(tm);
|
||||||
|
if (*config.device.tzdef) {
|
||||||
|
setenv("TZ", config.device.tzdef, 1);
|
||||||
|
} else {
|
||||||
|
setenv("TZ", "UTC0", 1);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
@ -36,6 +36,8 @@ uint32_t getValidTime(RTCQuality minQuality, bool local = false);
|
|||||||
|
|
||||||
void readFromRTC();
|
void readFromRTC();
|
||||||
|
|
||||||
|
time_t gm_mktime(struct tm *tm);
|
||||||
|
|
||||||
#define SEC_PER_DAY 86400
|
#define SEC_PER_DAY 86400
|
||||||
#define SEC_PER_HOUR 3600
|
#define SEC_PER_HOUR 3600
|
||||||
#define SEC_PER_MIN 60
|
#define SEC_PER_MIN 60
|
Loading…
Reference in New Issue
Block a user