NmeaGga *gga = (NmeaGga *)sentence->data;
ASSERT(gga);
+ ASSERT(context->tokens >= 12);
- /*
- * if there is a data element, extract data from the tokens
- */
gga->latitude = nmea_latitude(context->token[2],context->token[3]);
gga->longitude = nmea_longitude(context->token[4],context->token[5]);
gga->altitude = nmea_altitude(context->token[9],context->token[10]);
*/
NmeaRmc *rmc = (NmeaRmc *)sentence->data;
+ ASSERT(rmc);
+ ASSERT(context->tokens >= 10);
+
/*
- * if there is a data element, use it
+ * extract data from the tokens
*/
- if (rmc != 0)
- {
- /*
- * extract data from the tokens
- */
- rmc->time = timestampToSec(tokenToInt(context->token[1], 3), atoi(context->token[9]));
- rmc->warn = *context->token[2];
- rmc->latitude = nmea_latitude(context->token[3],context->token[4]);
- rmc->longitude = nmea_longitude(context->token[5],context->token[6]);
- rmc->speed = atoi(context->token[7]);
- rmc->course = atoi(context->token[8]);
- rmc->mag_var = atoi(context->token[10]);
- }
+ rmc->time = timestampToSec(tokenToInt(context->token[1], 3), atoi(context->token[9]));
+ rmc->warn = *context->token[2];
+ rmc->latitude = nmea_latitude(context->token[3],context->token[4]);
+ rmc->longitude = nmea_longitude(context->token[5],context->token[6]);
+ rmc->speed = atoi(context->token[7]);
+ rmc->course = atoi(context->token[8]);
+ rmc->mag_var = atoi(context->token[10]);
- /*
- * if the sentence has a callout, call it
- */
if (sentence->callout != 0)
(*sentence->callout)(context, rmc, context->user_data);
*/
NmeaVtg *vtg = (NmeaVtg *)sentence->data;
+ ASSERT(vtg);
+ ASSERT(context->tokens >= 7);
+
/*
- * if there is a data element, use it
+ * extract data from the tokens
*/
- if (vtg != 0)
- {
- /*
- * extract data from the tokens
- */
- vtg->track_good = atoi(context->token[1]);
- vtg->knot_speed = atoi(context->token[5]);
- vtg->km_speed = atoi(context->token[7]);
- }
+ vtg->track_good = atoi(context->token[1]);
+ vtg->knot_speed = atoi(context->token[5]);
+ vtg->km_speed = atoi(context->token[7]);
/*
* if the sentence has a callout, call it
*/
NmeaGsv *gsv = (NmeaGsv *)sentence->data;
+
/*
- * if there is a data element, use it
+ * extract data from the tokens
*/
- if (gsv != 0)
+ gsv->tot_message = atoi(context->token[1]);
+ gsv->message_num = atoi(context->token[2]);
+ gsv->tot_svv = atoi(context->token[3]);
+
+ // Fill remaning member until we have token
+ int j = 0;
+ for (int i = 4; i < context->tokens - 3; i += 4, j++)
{
- /*
- * extract data from the tokens
- */
- gsv->tot_message = atoi(context->token[1]);
- gsv->message_num = atoi(context->token[2]);
- gsv->tot_svv = atoi(context->token[3]);
- gsv->sv_prn = atoi(context->token[4]);
- gsv->elevation = atoi(context->token[5]);
- gsv->azimut = atoi(context->token[6]);
- gsv->snr = atoi(context->token[7]);
- gsv->sv_prn2 = atoi(context->token[8]);
- gsv->elevation2 = atoi(context->token[9]);
- gsv->azimut2 = atoi(context->token[10]);
- gsv->snr2 = atoi(context->token[11]);
- gsv->sv_prn3 = atoi(context->token[12]);
- gsv->elevation3 = atoi(context->token[13]);
- gsv->azimut3 = atoi(context->token[14]);
- gsv->snr3 = atoi(context->token[15]);
- gsv->sv_prn4 = atoi(context->token[16]);
- gsv->elevation4 = atoi(context->token[17]);
- gsv->azimut4 = atoi(context->token[18]);
- gsv->snr4 = atoi(context->token[19]);
- }
+ gsv->info[j].sv_prn = atoi(context->token[i]);
+ gsv->info[j].elevation = atoi(context->token[i + 1]);
+ gsv->info[j].azimut = atoi(context->token[i + 2]);
+ gsv->info[j].snr = atoi(context->token[i + 3]);
+ }
/*
* if the sentence has a callout, call it
/**
* Extracted data from an gsv message
*/
-typedef struct NmeaGsv
+struct SvInfo
{
- uint16_t tot_message; /* Total number of messages of this type in this cycle */
- uint16_t message_num; /* Message number */
- uint16_t tot_svv; /* Total number of SVs in view */
uint16_t sv_prn; /* SV PRN number */
degree_t elevation; /* Elevation in degrees, 90 maximum */
degree_t azimut; /* Azimuth, degrees from true north, 000 to 359 */
uint16_t snr; /* SNR, 00-99 dB (null when not tracking) */
- uint16_t sv_prn2; /* Information about second SV PRN number */
- degree_t elevation2; /* Information about second SV elevation in degrees, 90 maximum */
- degree_t azimut2; /* Information about second SV azimuth, degrees from true north, 000 to 359 */
- uint16_t snr2; /* Information about second SV SNR, 00-99 dB (null when not tracking) */
- uint16_t sv_prn3; /* Information about third SV PRN number */
- degree_t elevation3; /* Information about third SV elevation in degrees, 90 maximum */
- degree_t azimut3; /* Information about third SV azimuth, degrees from true north, 000 to 359 */
- uint16_t snr3; /* Information about third SV SNR, 00-99 dB (null when not tracking) */
- uint16_t sv_prn4; /* Information about fourth SV PRN number */
- degree_t elevation4; /* Information about fourth SV elevation in degrees, 90 maximum */
- degree_t azimut4; /* Information about fourth SV azimuth, degrees from true north, 000 to 359 */
- uint16_t snr4; /* Information about fourth SV SNR, 00-99 dB (null when not tracking) */
+};
+
+typedef struct NmeaGsv
+{
+ uint16_t tot_message; /* Total number of messages of this type in this cycle */
+ uint16_t message_num; /* Message number */
+ uint16_t tot_svv; /* Total number of SVs in view */
+ struct SvInfo info[4]; /* Stanrd gsv nmea report up to 4 sv info */
} NmeaGsv;
void nmea_poll(nmeap_context_t *context, KFile *channel);
.geoid = 45,
};
+#include <net/nmea_log.c>
+
#define TOT_GOOD_SENTENCE_NUM 12
#define MAX_SENTENCE_POLL 20
tot_sentence_parsed++;
- LOG_INFO("[%d]found GPGSV message %d %d %d %d %d %d %d\n",tot_sentence_parsed,
+ LOG_INFO("[%d]found GPGSV message %d %d %d\n",tot_sentence_parsed,
gsv->tot_message,
gsv->message_num,
- gsv->tot_svv,
- gsv->sv_prn,
- gsv->elevation,
- gsv->azimut,
- gsv->snr
- );
+ gsv->tot_svv);
+
+ for (int i = 0; i < 4; i++)
+ LOG_INFO("[%d]%d %d %d %d\n", i, gsv->info[i].sv_prn, gsv->info[i].elevation, gsv->info[i].azimut, gsv->info[i].snr);
}
/**
{
kdbg_init();
- kfilemem_init(&mem, nmea_test_vector, sizeof(nmea_test_vector));
+ kfilemem_init(&mem, test, sizeof(test));
LOG_INFO("Init test buffer..done.\n");
nmeap_init(&nmea, NULL);
- LOG_INFO("Init NMEA context..done.\n");
nmeap_addParser(&nmea, "GPGGA", nmea_gpgga, gpgga_callout, &gga);
- LOG_INFO("Init NMEA GPGGA parser..done.\n");
nmeap_addParser(&nmea, "GPRMC", nmea_gprmc, gprmc_callout, &rmc);
- LOG_INFO("Init NMEA GPRMC parser..done.\n");
nmeap_addParser(&nmea, "GPGSV", nmea_gpgsv, gpgsv_callout, &gsv);
- LOG_INFO("Init NMEA GPGSV parser..done.\n");
nmeap_addParser(&nmea, "GPVTG", nmea_gpvtg, gpvtg_callout, &vtg);
- LOG_INFO("Init NMEA GPVTG parser..done.\n");
return 0;
}