Browse Source

Add minimum satellite number option
Fix NMEA file write

k4be 2 years ago
parent
commit
3c3209f640
7 changed files with 52 additions and 16 deletions
  1. 8 3
      soft/display.c
  2. 2 2
      soft/main.c
  3. 1 0
      soft/main.h
  4. 25 9
      soft/nmea.c
  5. 2 1
      soft/nmea.h
  6. 11 0
      soft/settings.c
  7. 3 1
      soft/settings.h

+ 8 - 3
soft/display.c

@@ -119,6 +119,7 @@ __flash const char _tracking_resumed[] =	"Wznowiono!";
 __flash const char _point_saved[] =		"Zapisano!";
 __flash const char _point_not_saved[] =	"Nie zapisano!";
 __flash const char _logging_auto_paused[] = "Autom. wstrzym.";
+__flash const char _sat_count_low[] = "Za malo satelit";
 
 void display_event(unsigned char event) { /* overrides display with current messages */
 	switch (event) {
@@ -181,10 +182,14 @@ void disp_func_main_default(void) {
 	} else
 		strcpy_P(disp.line1, _card_ok);
 
-	if (FLAGS & F_GPSOK)
-		strcpy_P(disp.line2, _gps_ok);
-	else
+	if (FLAGS & F_GPSOK) {
+		if (System.sat_count_low)
+			strcpy_P(disp.line2, _sat_count_low);
+		else
+			strcpy_P(disp.line2, _gps_ok);
+	} else {
 		strcpy_P(disp.line2, _gps_wait);
+	}
 }
 
 void disp_func_coord(void) {

+ 2 - 2
soft/main.c

@@ -404,8 +404,8 @@ int main (void)
 			}
 
 			if (FLAGS & F_FILEOPEN) {
-				f_write(&gps_log, Line, len, &bw);
-				if (bw != len) {
+				f_write(&gps_log, Line, len-1, &bw);
+				if (bw != len-1) {
 					System.status = STATUS_FILE_WRITE_ERROR;
 					break;
 				}

+ 1 - 0
soft/main.h

@@ -150,6 +150,7 @@ struct system_s {
 	unsigned tracking_paused:1;
 	unsigned tracking_auto_paused:1;
 	unsigned open_new_file:1;
+	unsigned sat_count_low:1;
 };
 
 struct location_s {

+ 25 - 9
soft/nmea.c

@@ -2,6 +2,7 @@
 #include <stddef.h>
 #include <string.h>
 #include <stdlib.h>
+#include <ctype.h>
 #include <avr/sleep.h>
 #include "nmea.h"
 #include "main.h"
@@ -40,12 +41,14 @@ uint16_t get_line (		/* 0:line incomplete or timed out, >0: Number of bytes rece
 		if (i == 0 && c != '$' )
 			continue;	/* Find start of line */
 		if (c == '\n' || c == '\r') {
+			buff[i++] = '\r';
+			buff[i++] = '\n';
 			buff[i++] = '\0'; /* add null termination for string */
 			break;	/* EOL */
 		}
 		buff[i++] = c;
 		uart1_put(c);
-		if (i >= sz_buf - 1) /* keep one byte for terminating character */
+		if (i >= sz_buf - 3) /* keep 3 bytes for terminating character */
 			i = 0;	/* Buffer overflow (abort this line) */
 	}
 	ret_len = i;
@@ -150,6 +153,12 @@ static void gp_gga_parse(const char *str) {
 	p = gp_col(str, 7); /* satellites used */
 	System.satellites_used = atoi(p);
 
+	if (System.satellites_used >= System.conf.min_sats) {
+		System.sat_count_low = 0;
+	} else {
+		System.sat_count_low = 1;
+	}
+
 	/* check validity */
 	p = gp_col(str, 6);
 	if (*p == '0') {
@@ -157,7 +166,8 @@ static void gp_gga_parse(const char *str) {
 		return;
 	}
 	
-	System.location_valid = LOC_VALID_NEW;
+	if (!System.sat_count_low)
+		System.location_valid = LOC_VALID_NEW; /* don't accept the coordinates otherwise, even if reported valid */
 
 	/* parse location */
 	p = gp_col(str, 2);		/* latitude */
@@ -218,17 +228,17 @@ static void pmtk001_parse(const char *str) {
 
 unsigned char nmea_checksum(const char *str) {
 	unsigned char cs = 0;
-	while (*str) {
+	while (*str && *str != '*') {
 		cs ^= *str++; /* NMEA checksum is quite primitive, but still should catch simple bitstream errors or truncated lines */
 	}
 	return cs;
 }
 
-time_t gps_parse(char *str) {	/* Get all required data from NMEA sentences */
-	unsigned int len = strlen(str);
+time_t gps_parse(const char *str) {	/* Get all required data from NMEA sentences */
+	signed int len = strlen(str)-2; /* remove final \r\n */
 	const char *checksum;
 	unsigned char calc_checksum, inc_checksum;
-	unsigned int i;
+	signed int i;
 	char c;
 
 	if (len < 4)
@@ -240,7 +250,7 @@ time_t gps_parse(char *str) {	/* Get all required data from NMEA sentences */
 	}
 	checksum = str+i+1; /* skip * character */
 	inc_checksum = 0; /* parse hex string */
-	while (*checksum) {
+	while (*checksum && isalnum(*checksum)) {
 		inc_checksum *= 16;
 		c = *checksum++;
 		if (c >= '0' && c <= '9') {
@@ -255,8 +265,7 @@ time_t gps_parse(char *str) {	/* Get all required data from NMEA sentences */
 		}
 	}
 	
-	str[i] = '\0'; /* drop checksum (*xx) and initial $ */
-	str++;
+	str++; /* drop initial $ */
 
 	calc_checksum = nmea_checksum(str);
 	if (inc_checksum != calc_checksum) {
@@ -327,3 +336,10 @@ void gps_initialize(void) {
 	System.gps_initialized = 1;
 }
 
+void check_min_sat_limit(void) {
+	if (System.conf.min_sats > 6 && (System.conf.gnss_mode == GNSS_MODE_GPS || System.conf.gnss_mode == GNSS_MODE_GALILEO || System.conf.gnss_mode == GNSS_MODE_BEIDOU)) {
+		 /* by geometry, max visible number is 6..12 */
+		 System.conf.min_sats = 6;
+	}
+}
+

+ 2 - 1
soft/nmea.h

@@ -2,7 +2,8 @@
 #include "main.h"
 #include "ff.h"
 
-time_t gps_parse(char *str);
+time_t gps_parse(const char *str);
 UINT get_line(char *buff, UINT sz_buf);
 void gps_initialize(void);
+void check_min_sat_limit(void);
 

+ 11 - 0
soft/settings.c

@@ -15,6 +15,7 @@ const __flash unsigned char limits_max_u8[] = {
 	[CONF_U8_SKIP_POINTS] = 120,
 	[CONF_U8_AUTO_PAUSE_TIME] = 120,
 	[CONF_U8_AUTO_PAUSE_DIST] = 100,
+	[CONF_U8_MIN_SATS] = 12,
 };
 
 const __flash unsigned char limits_min_u8[] = {
@@ -22,6 +23,7 @@ const __flash unsigned char limits_min_u8[] = {
 	[CONF_U8_SKIP_POINTS] = 0,
 	[CONF_U8_AUTO_PAUSE_TIME] = 10,
 	[CONF_U8_AUTO_PAUSE_DIST] = 2,
+	[CONF_U8_MIN_SATS] = 4,
 };
 
 const __flash unsigned char defaults_u8[] = {
@@ -29,6 +31,7 @@ const __flash unsigned char defaults_u8[] = {
 	[CONF_U8_SKIP_POINTS] = 15,
 	[CONF_U8_AUTO_PAUSE_TIME] = 30,
 	[CONF_U8_AUTO_PAUSE_DIST] = 10,
+	[CONF_U8_MIN_SATS] = 5,
 };
 
 unsigned char settings_load(void) { /* 0 - ok, 1 - error */
@@ -61,6 +64,7 @@ unsigned char check_config_data(void) { /* 0 - ok, 1 - error */
 			System.conf.conf_u8[i] = defaults_u8[i];
 		}
 	}
+	check_min_sat_limit();
 	return ret;
 }
 
@@ -110,6 +114,7 @@ __flash const char _msg_back[] = "< Powrot";
 __flash const char _msg_auto_pause[] = "Autopauza";
 __flash const char _msg_auto_pause_time[] = "Autopauza czas";
 __flash const char _msg_auto_pause_dist[] = "Autopauza odleg";
+__flash const char _msg_min_sats[] = "Minimum satelit";
 
 __flash const struct menu_pos settings_menu_list[] = {
 	{
@@ -150,6 +155,12 @@ __flash const struct menu_pos settings_menu_list[] = {
 		.index = CONFFLAG_ENABLE_SBAS,
 		.changed = gps_initialize,
 	},
+	{
+		.type = MENU_TYPE_SETTING_U8,
+		.name = _msg_min_sats,
+		.index = CONF_U8_MIN_SATS,
+		.changed = check_min_sat_limit,
+	},
 	{
 		.type = MENU_TYPE_SETTING_U8,
 		.display_type = MENU_DISPLAY_TYPE_NAME_FUNCTION,

+ 3 - 1
soft/settings.h

@@ -7,8 +7,9 @@
 #define CONF_U8_SKIP_POINTS	1
 #define CONF_U8_AUTO_PAUSE_TIME	2
 #define CONF_U8_AUTO_PAUSE_DIST	3
+#define CONF_U8_MIN_SATS	4
 
-#define CONF_U8_LAST		3
+#define CONF_U8_LAST		4
 
 /* flags list - max 31 */
 #define CONFFLAG_DISABLE_FILTERS	0
@@ -34,6 +35,7 @@ struct config_s {
 			unsigned char skip_points;	// 1
 			unsigned char auto_pause_time;	// 2
 			unsigned char auto_pause_dist;	// 3
+			unsigned char min_sats;		// 4
 		};
 	};
 	unsigned char flags[4];