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.
This commit is contained in:
Niccolò Izzo 2021-02-13 11:20:06 +01:00
parent ec06b14618
commit c7e8a258f3
3 changed files with 32 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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};