Prechádzať zdrojové kódy

Improve module initialization code
(this does not fix any known issue)

k4be 1 rok pred
rodič
commit
db12e2fc8a
2 zmenil súbory, kde vykonal 49 pridanie a 33 odobranie
  1. 6 1
      soft/main.h
  2. 43 32
      soft/nmea.c

+ 6 - 1
soft/main.h

@@ -126,6 +126,11 @@
 #define LOC_VALID	1
 #define LOC_VALID_NEW	2
 
+/* System.gps_initialized values */
+#define GPS_INIT_NOT_INITIALIZED	0
+#define GPS_INIT_QUERY_SENT			1
+#define GPS_INIT_INITIALIZED		2
+
 #define ms(x) (x/10)
 
 struct timers {
@@ -156,7 +161,7 @@ struct system_s {
 	unsigned satellites_used:5;
 	unsigned location_valid:2;
 	unsigned sbas:1;
-	unsigned gps_initialized:1;
+	unsigned gps_initialized:2;
 	unsigned gps_only:1;
 	unsigned tracking_paused:1;
 	unsigned tracking_auto_paused:1;

+ 43 - 32
soft/nmea.c

@@ -319,39 +319,50 @@ void gps_initialize(void) {
 	 * PMTK353: set gnss search mode (GPS/Galileo/Glonass/Beidou)
 	 * PMTK313: enable SBAS
 	 */
-	if (!System.gps_initialized)
-		xfprintf(uart0_put_wrap, PSTR("$PMTK355*31\r\n"));
-	if (get_flag(CONFFLAG_ENABLE_SBAS))
-		xfprintf(uart0_put_wrap, PSTR("$PMTK313,1*2E\r\n"));
-	else
-		xfprintf(uart0_put_wrap, PSTR("$PMTK313,0*2F\r\n"));
-	if (!System.gps_only) {
-		switch (System.conf.gnss_mode) {
-			default:
-			case GNSS_MODE_GPS_GLONASS_GALILEO:
-				xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,1,1,0,0*2A\r\n"));
-				break;
-			case GNSS_MODE_GPS:
-				xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,0,0,0,0*2A\r\n"));
-				break;
-			case GNSS_MODE_GPS_GALILEO:
-				xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,0,1,0,0*2B\r\n"));
-				break;
-			case GNSS_MODE_GALILEO:
-				xfprintf(uart0_put_wrap, PSTR("$PMTK353,0,0,1,0,0*2A\r\n"));
-				break;
-			case GNSS_MODE_GPS_BEIDOU:
-				xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,0,0,0,1*2B\r\n"));
-				break;
-			case GNSS_MODE_BEIDOU:
-				xfprintf(uart0_put_wrap, PSTR("$PMTK353,0,0,0,0,1*2A\r\n"));
-				break;
-		}
-	} else {
-		System.conf.gnss_mode = GNSS_MODE_GPS;
+	switch (System.gps_initialized) {
+		case GPS_INIT_NOT_INITIALIZED:
+			xfprintf(uart0_put_wrap, PSTR("$PMTK355*31\r\n"));
+			xputs_P(PSTR("GNSS mode query sent\r\n"));
+			System.gps_initialized = GPS_INIT_QUERY_SENT;
+			break;
+		case GPS_INIT_QUERY_SENT:
+			if (get_flag(CONFFLAG_ENABLE_SBAS)) {
+				xfprintf(uart0_put_wrap, PSTR("$PMTK313,1*2E\r\n"));
+				xputs_P(PSTR("SBAS enable sent\r\n"));
+			} else {
+				xfprintf(uart0_put_wrap, PSTR("$PMTK313,0*2F\r\n"));
+				xputs_P(PSTR("SBAS disable sent\r\n"));
+			}
+			if (!System.gps_only) {
+				switch (System.conf.gnss_mode) {
+					default:
+					case GNSS_MODE_GPS_GLONASS_GALILEO:
+						xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,1,1,0,0*2A\r\n"));
+						break;
+					case GNSS_MODE_GPS:
+						xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,0,0,0,0*2A\r\n"));
+						break;
+					case GNSS_MODE_GPS_GALILEO:
+						xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,0,1,0,0*2B\r\n"));
+						break;
+					case GNSS_MODE_GALILEO:
+						xfprintf(uart0_put_wrap, PSTR("$PMTK353,0,0,1,0,0*2A\r\n"));
+						break;
+					case GNSS_MODE_GPS_BEIDOU:
+						xfprintf(uart0_put_wrap, PSTR("$PMTK353,1,0,0,0,1*2B\r\n"));
+						break;
+					case GNSS_MODE_BEIDOU:
+						xfprintf(uart0_put_wrap, PSTR("$PMTK353,0,0,0,0,1*2A\r\n"));
+						break;
+				}
+				xputs_P(PSTR("GNSS mode setting sent\r\n"));
+			} else {
+				System.conf.gnss_mode = GNSS_MODE_GPS;
+			}
+			break;
+		default:
+			break;
 	}
-	xputs_P(PSTR("GPS init sent\r\n"));
-	System.gps_initialized = 1;
 }
 
 void check_min_sat_limit(void) {