Skip to content

Commit 6e452c2

Browse files
robbie-spsbkueng
authored andcommitted
move NO_MKTIME compilation flags
- removes dependency on tm struct being defined without MKTIME - removes unnecessary operations
1 parent b443b79 commit 6e452c2

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

src/ashtech.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ int GPSDriverAshtech::handleMessage(int len)
8585
int ret = 0;
8686

8787
if ((memcmp(_rx_buffer + 3, "ZDA,", 3) == 0) && (uiCalcComma == 6)) {
88+
#ifndef NO_MKTIME
8889
/*
8990
UTC day, month, and year, and local time zone offset
9091
An example of the ZDA message string is:
@@ -120,7 +121,6 @@ int GPSDriverAshtech::handleMessage(int len)
120121

121122
if (bufptr && *(++bufptr) != ',') { local_time_off_min = strtol(bufptr, &endp, 10); bufptr = endp; }
122123

123-
124124
int ashtech_hour = static_cast<int>(ashtech_time / 10000);
125125
int ashtech_minute = static_cast<int>((ashtech_time - ashtech_hour * 10000) / 100);
126126
double ashtech_sec = static_cast<double>(ashtech_time - ashtech_hour * 10000 - ashtech_minute * 100);
@@ -137,7 +137,6 @@ int GPSDriverAshtech::handleMessage(int len)
137137
timeinfo.tm_sec = int(ashtech_sec);
138138
timeinfo.tm_isdst = 0;
139139

140-
#ifndef NO_MKTIME
141140
time_t epoch = mktime(&timeinfo);
142141

143142
if (epoch > GPS_EPOCH_SECS) {

src/mtk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ GPSDriverMTK::handleMessage(gps_mtk_packet_t &packet)
246246
_gps_position->cog_rad = ((float)packet.heading) * M_DEG_TO_RAD_F * 1e-2f; //from deg *100 to rad
247247
_gps_position->satellites_used = packet.satellites;
248248

249+
#ifndef NO_MKTIME
249250
/* convert time and date information to unix timestamp */
250251
struct tm timeinfo = {};
251252
uint32_t timeinfo_conversion_temp;
@@ -264,7 +265,6 @@ GPSDriverMTK::handleMessage(gps_mtk_packet_t &packet)
264265

265266
timeinfo.tm_isdst = 0;
266267

267-
#ifndef NO_MKTIME
268268

269269
time_t epoch = mktime(&timeinfo);
270270

src/nmea.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int GPSDriverNMEA::handleMessage(int len)
102102
int ret = 0;
103103

104104
if ((memcmp(_rx_buffer + 3, "ZDA,", 4) == 0) && (uiCalcComma == 6)) {
105-
105+
#ifndef NO_MKTIME
106106
/*
107107
UTC day, month, and year, and local time zone offset
108108
An example of the ZDA message string is:
@@ -142,6 +142,7 @@ int GPSDriverNMEA::handleMessage(int len)
142142
int utc_minute = static_cast<int>((utc_time - utc_hour * 10000) / 100);
143143
double utc_sec = static_cast<double>(utc_time - utc_hour * 10000 - utc_minute * 100);
144144

145+
145146
/*
146147
* convert to unix timestamp
147148
*/
@@ -154,7 +155,7 @@ int GPSDriverNMEA::handleMessage(int len)
154155
timeinfo.tm_sec = int(utc_sec);
155156
timeinfo.tm_isdst = 0;
156157

157-
#ifndef NO_MKTIME
158+
158159
time_t epoch = mktime(&timeinfo);
159160

160161
if (epoch > GPS_EPOCH_SECS) {
@@ -481,12 +482,7 @@ int GPSDriverNMEA::handleMessage(int len)
481482
float velocity_ms = ground_speed_K / 1.9438445f;
482483
float velocity_north = velocity_ms * cosf(track_rad);
483484
float velocity_east = velocity_ms * sinf(track_rad);
484-
int utc_hour = static_cast<int>(utc_time / 10000);
485-
int utc_minute = static_cast<int>((utc_time - utc_hour * 10000) / 100);
486-
double utc_sec = static_cast<double>(utc_time - utc_hour * 10000 - utc_minute * 100);
487-
int nmea_day = static_cast<int>(nmea_date / 10000);
488-
int nmea_mth = static_cast<int>((nmea_date - nmea_day * 10000) / 100);
489-
int nmea_year = static_cast<int>(nmea_date - nmea_day * 10000 - nmea_mth * 100);
485+
490486
/* convert from degrees, minutes and seconds to degrees */
491487
_gps_position->latitude_deg = int(lat * 0.01) + (lat * 0.01 - int(lat * 0.01)) * 100.0 / 60.0;
492488
_gps_position->longitude_deg = int(lon * 0.01) + (lon * 0.01 - int(lon * 0.01)) * 100.0 / 60.0;
@@ -500,7 +496,14 @@ int GPSDriverNMEA::handleMessage(int len)
500496
_gps_position->s_variance_m_s = 0;
501497
_gps_position->timestamp = gps_absolute_time();
502498
_last_timestamp_time = gps_absolute_time();
503-
499+
500+
#ifndef NO_MKTIME
501+
int utc_hour = static_cast<int>(utc_time / 10000);
502+
int utc_minute = static_cast<int>((utc_time - utc_hour * 10000) / 100);
503+
double utc_sec = static_cast<double>(utc_time - utc_hour * 10000 - utc_minute * 100);
504+
int nmea_day = static_cast<int>(nmea_date / 10000);
505+
int nmea_mth = static_cast<int>((nmea_date - nmea_day * 10000) / 100);
506+
int nmea_year = static_cast<int>(nmea_date - nmea_day * 10000 - nmea_mth * 100);
504507
/*
505508
* convert to unix timestamp
506509
*/
@@ -513,7 +516,6 @@ int GPSDriverNMEA::handleMessage(int len)
513516
timeinfo.tm_sec = int(utc_sec);
514517
timeinfo.tm_isdst = 0;
515518

516-
#ifndef NO_MKTIME
517519
time_t epoch = mktime(&timeinfo);
518520

519521
if (epoch > GPS_EPOCH_SECS) {
@@ -539,6 +541,8 @@ int GPSDriverNMEA::handleMessage(int len)
539541
}
540542

541543
#else
544+
NMEA_UNUSED(utc_time);
545+
NMEA_UNUSED(nmea_date);
542546
_gps_position->time_utc_usec = 0;
543547
#endif
544548

src/ubx.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,7 @@ GPSDriverUBX::payloadRxDone()
19221922
if ((_buf.payload_rx_nav_pvt.valid & UBX_RX_NAV_PVT_VALID_VALIDDATE)
19231923
&& (_buf.payload_rx_nav_pvt.valid & UBX_RX_NAV_PVT_VALID_VALIDTIME)
19241924
&& (_buf.payload_rx_nav_pvt.valid & UBX_RX_NAV_PVT_VALID_FULLYRESOLVED)) {
1925+
#ifndef NO_MKTIME
19251926
/* convert to unix timestamp */
19261927
tm timeinfo{};
19271928
timeinfo.tm_year = _buf.payload_rx_nav_pvt.year - 1900;
@@ -1931,7 +1932,7 @@ GPSDriverUBX::payloadRxDone()
19311932
timeinfo.tm_min = _buf.payload_rx_nav_pvt.min;
19321933
timeinfo.tm_sec = _buf.payload_rx_nav_pvt.sec;
19331934

1934-
#ifndef NO_MKTIME
1935+
19351936
time_t epoch = mktime(&timeinfo);
19361937

19371938
if (epoch > GPS_EPOCH_SECS) {
@@ -2057,6 +2058,7 @@ GPSDriverUBX::payloadRxDone()
20572058
UBX_TRACE_RXMSG("Rx NAV-TIMEUTC");
20582059

20592060
if (_buf.payload_rx_nav_timeutc.valid & UBX_RX_NAV_TIMEUTC_VALID_VALIDUTC) {
2061+
#ifndef NO_MKTIME
20602062
// convert to unix timestamp
20612063
tm timeinfo {};
20622064
timeinfo.tm_year = _buf.payload_rx_nav_timeutc.year - 1900;
@@ -2066,7 +2068,7 @@ GPSDriverUBX::payloadRxDone()
20662068
timeinfo.tm_min = _buf.payload_rx_nav_timeutc.min;
20672069
timeinfo.tm_sec = _buf.payload_rx_nav_timeutc.sec;
20682070
timeinfo.tm_isdst = 0;
2069-
#ifndef NO_MKTIME
2071+
20702072
time_t epoch = mktime(&timeinfo);
20712073

20722074
// only set the time if it makes sense

0 commit comments

Comments
 (0)