diff --git a/radio/src/debug.h b/radio/src/debug.h index 31662e69a..b04e2f55c 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -54,9 +54,8 @@ uint8_t serial2TracesEnabled(); } #endif -#define TRACE_PING(...) do { debugPrintf(__VA_ARGS__); } while(0) +#define TRACE_NOCRLF(...) do { debugPrintf(__VA_ARGS__); } while(0) #define TRACE(...) do { debugPrintf(__VA_ARGS__); debugPrintf("\r\n"); } while(0) -#define TRACE_WP(...) debugPrintf(__VA_ARGS__) #define DUMP(data, size) dump(data, size) #define TRACE_DEBUG(...) debugPrintf("-D- " __VA_ARGS__) #define TRACE_DEBUG_WP(...) debugPrintf(__VA_ARGS__) diff --git a/radio/src/gps.cpp b/radio/src/gps.cpp index 380bb1f07..97091a7af 100644 --- a/radio/src/gps.cpp +++ b/radio/src/gps.cpp @@ -159,10 +159,24 @@ bool gpsNewFrameNMEA(char c) if (param == 0) { // Frame identification (accept all GPS talkers (GP: GPS, GL:Glonass, GN:combination, etc...)) gps_frame = NO_FRAME; - if (string[0] == 'G' && string[2] == 'G' && string[3] == 'G' && string[4] == 'A') + if (string[0] == 'G' && string[2] == 'G' && string[3] == 'G' && string[4] == 'A') { gps_frame = FRAME_GGA; - if (string[0] == 'G' && string[2] == 'R' && string[3] == 'M' && string[4] == 'C') + } + else if (string[0] == 'G' && string[2] == 'R' && string[3] == 'M' && string[4] == 'C') { gps_frame = FRAME_RMC; + } + else { + // turn off this frame (do this only once a second) + static gtime_t lastGpsCmdSent = 0; + if (string[0] == 'G' && g_rtcTime != lastGpsCmdSent) { + lastGpsCmdSent = g_rtcTime; + char cmd[] = "$PUBX,40,GSV,0,0,0,0"; + cmd[9] = string[2]; + cmd[10] = string[3]; + cmd[11] = string[4]; + gpsSendFrame(cmd); + } + } } switch (gps_frame) { @@ -203,6 +217,14 @@ bool gpsNewFrameNMEA(char c) case 1: gps_Msg.time = grab_fields(string, 0); break; + case 2: + if (string[0] == 'A') { + gps_Msg.fix = 1; + } + else { + gps_Msg.fix = 0; + } + break; case 7: gps_Msg.speed = ((grab_fields(string, 1) * 5144L) / 1000L); // speed in cm/s added by Mis break; @@ -309,6 +331,7 @@ void gpsSendFrame(const char * frame) { // send given frame, add checksum and CRLF uint8_t parity = 0; + TRACE_NOCRLF("gps> %s", frame); while (*frame) { if (*frame != '$') parity ^= *frame; gpsSendByte(*frame); @@ -319,7 +342,7 @@ void gpsSendFrame(const char * frame) gpsSendByte(hex(parity & 0x0F)); gpsSendByte('\r'); gpsSendByte('\n'); - TRACE("parity %02x", parity); + TRACE("*%02x", parity); } #endif // #if defined(DEBUG) diff --git a/radio/src/rtc.cpp b/radio/src/rtc.cpp index 9601dd070..d8da110e0 100644 --- a/radio/src/rtc.cpp +++ b/radio/src/rtc.cpp @@ -446,6 +446,7 @@ void gettime(struct gtm * tm) filltm(&g_rtcTime, tm); // create a struct tm date/time structure from global unix time stamp } +void rtcGetTime(struct gtm * t); #define RTC_ADJUST_PERIOD 60 // how often RTC is checked for accuracy [seconds] #define RTC_ADJUST_TRESHOLD 20 // how much clock must differ before adjustment is made [seconds] @@ -473,7 +474,14 @@ uint8_t rtcAdjust(uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t t.tm_sec = sec; gtime_t newTime = gmktime(&t) + g_eeGeneral.timezone * 3600; gtime_t diff = (g_rtcTime > newTime) ? (g_rtcTime - newTime) : (newTime - g_rtcTime); - TRACE("rtc: %d, new: %d, diff: %d", g_rtcTime, newTime, diff); + +#if defined(DEBUG) + struct gtm utm; + rtcGetTime(&utm); + gtime_t rtcTime = gmktime(&utm); + TRACE("rtc: %d, grtc: %d, gps: %d, diff: %d, ", rtcTime, g_rtcTime, newTime, diff); +#endif + if (diff > RTC_ADJUST_TRESHOLD) { // convert newTime to struct gtm and set RTC clock filltm(&newTime, &t);