Procházet zdrojové kódy

Parse speed information

k4be před 1 rokem
rodič
revize
9dfe711c9e
2 změnil soubory, kde provedl 19 přidání a 0 odebrání
  1. 1 0
      soft/main.h
  2. 18 0
      soft/nmea.c

+ 1 - 0
soft/main.h

@@ -140,6 +140,7 @@ struct system_s {
 	unsigned char keypress;
 	unsigned char working_mode;
 	unsigned long int distance; // cm
+	unsigned char speed; // km/h
 	time_t time_start;
 	unsigned temperature_ok:1;
 	unsigned satellites_used:5;

+ 18 - 0
soft/nmea.c

@@ -204,6 +204,20 @@ static void gp_gga_parse(const char *str) {
 
 	location.time = utc; /* parsed from RMC */
 }
+
+static void gp_vtg_parse(const char *str) {
+	const char *p;
+	double speed;
+	
+	p = gp_col(str, 9);
+	if (*p == 'N') /* Not valid */
+		return;
+	
+	p = gp_col(str, 7); /* speed in km/h */
+	xatof(&p, &speed);
+	System.speed = speed+0.5;
+}
+
 /*$PMTK355*31<CR><LF>
 Return $PMTK001,355,3,1,0,0*2E “$PMTK001,355,3,GLON_Enable,BEIDOU_Enable,GALILEO_Enable”
 The GLONASS search mode is enabled. */
@@ -280,6 +294,10 @@ time_t gps_parse(const char *str) {	/* Get all required data from NMEA sentences
 		gp_gga_parse(str);
 		return 0;
 	}
+	if (!gp_comp(str, PSTR("GPVTG")) || !gp_comp(str, PSTR("GNVTG"))) {
+		gp_vtg_parse(str);
+		return 0;
+	}
 	if (!System.gps_initialized && !gp_comp(str, PSTR("PMTK011"))) {
 		gps_initialize();
 		return 0;