From c7e8a258f39389fca45803dca2107b0be614b4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Izzo?= Date: Sat, 13 Feb 2021 11:20:06 +0100 Subject: [PATCH] Add active satellite field in GPS data Now for each satellite in view we are keeping track if it's part of a fix or not. This information is represented by a yellow color in the bar graph screen. --- openrtx/include/state.h | 1 + openrtx/src/gps.c | 31 +++++++++++++++++++++++++++---- openrtx/src/graphics.c | 7 ++++--- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/openrtx/include/state.h b/openrtx/include/state.h index a570a856..806afb49 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -35,6 +35,7 @@ typedef struct uint8_t elevation; // Elevation in degrees uint16_t azimuth; // Azimuth in degrees uint8_t snr; // Quality of the signal in range 0-99 + bool active; // True if this satellite is part of the fix } sat_t; diff --git a/openrtx/src/gps.c b/openrtx/src/gps.c index bfd3e8e2..654de64e 100644 --- a/openrtx/src/gps.c +++ b/openrtx/src/gps.c @@ -48,7 +48,8 @@ void gps_taskFunc(char *line, int len, gps_t *state) case MINMEA_SENTENCE_GGA: { struct minmea_sentence_gga frame; - if (minmea_parse_gga(&frame, line)) { + if (minmea_parse_gga(&frame, line)) + { state->fix_quality = frame.fix_quality; state->satellites_tracked = frame.satellites_tracked; state->altitude = minmea_tofloat(&frame.altitude); @@ -58,23 +59,45 @@ void gps_taskFunc(char *line, int len, gps_t *state) case MINMEA_SENTENCE_GSA: { struct minmea_sentence_gsa frame; - if (minmea_parse_gsa(&frame, line)) { + if (minmea_parse_gsa(&frame, line)) + { state->fix_type = frame.fix_type; + for (int i = 0; i < 12; i++) + { + if (frame.sats[i] != 0) + { + for (int j = 0; j < 12; j++) + { + if (state->satellites[j].id == frame.sats[i]) + { + state->satellites[j].active = true; + break; + } + } + } + } } } break; case MINMEA_SENTENCE_GSV: { struct minmea_sentence_gsv frame; - if (minmea_parse_gsv(&frame, line)) { + if (minmea_parse_gsv(&frame, line)) + { state->satellites_in_view = frame.total_sats; - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 4; i++) + { int index = 4 * (frame.msg_nr - 1) + i; state->satellites[index].id = frame.sats[i].nr; state->satellites[index].elevation = frame.sats[i].elevation; state->satellites[index].azimuth = frame.sats[i].azimuth; state->satellites[index].snr = frame.sats[i].snr; + state->satellites[index].active = false; } + // Zero out unused satellite slots + if (frame.msg_nr == frame.total_msgs && frame.total_msgs < 3) + bzero(&state->satellites[4 * frame.msg_nr], + sizeof(sat_t) * 12 - frame.total_msgs * 4); } } break; diff --git a/openrtx/src/graphics.c b/openrtx/src/graphics.c index e1a6e9cc..807682ca 100644 --- a/openrtx/src/graphics.c +++ b/openrtx/src/graphics.c @@ -555,10 +555,11 @@ void gfx_drawGPSgraph(point_t start, bar_height = (height - 8) * sats[i].snr / 100 + 1; point_t bar_pos = {start.x + 2 + i * (bar_width + 2), start.y + (height - 8) - bar_height}; - gfx_drawRect(bar_pos, bar_width, bar_height, white, true); + color_t bar_color = (sats[i].active) ? yellow : white; + gfx_drawRect(bar_pos, bar_width, bar_height, bar_color, true); snprintf(id_buf, 5, "%2d ", sats[i].id); - point_t id_start = {bar_pos.x, start.y + height}; - gfx_print(id_start, id_buf, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, white); + point_t id_pos = {bar_pos.x, start.y + height}; + gfx_print(id_pos, id_buf, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, white); } uint8_t bars_width = 9 + 11 * (bar_width + 2); point_t left_line_end = {start.x, start.y + height - 9};