Browse Source

Fix nmea code after test.

Add DML types
master
Jeroen Vreeken 4 years ago
parent
commit
fb86bb53e0
3 changed files with 32 additions and 24 deletions
  1. +6
    -4
      eth_ar/fprs.h
  2. +10
    -4
      fprs_test.c
  3. +16
    -16
      nmea.c

+ 6
- 4
eth_ar/fprs.h View File

@ -80,10 +80,12 @@ enum fprs_type {
/* length limited to 255 */
FPRS_OBJECTNAME = 16, /* Object name (variable length) */
FPRS_COMMENT = 17, /* Generic comment (do not use it for objects, altitude etc) */
FPRS_DMLSTREAM = 18, /* DML stream name (variable length) */
FPRS_REQUEST = 19, /* Request elements about a station */
FPRS_DESTINATION = 20, /* Reply target */
FPRS_TIMESTAMP = 21, /* variable length timestamp */
FPRS_REQUEST = 18, /* Request elements about a station */
FPRS_DESTINATION = 19, /* Reply target */
FPRS_TIMESTAMP = 20, /* variable length timestamp */
FPRS_DMLSTREAM = 21, /* DML stream name (variable length) */
FPRS_DMLASSOC = 22, /* DML stream name (variable length) */
};
char *fprs_type2str(enum fprs_type);


+ 10
- 4
fprs_test.c View File

@ -559,8 +559,14 @@ static int test_fprs2aprs(void)
static bool fp_check(double val, double checkval, double prec)
{
bool r;
double diff = fabs(val - checkval);
return diff <= prec;
r = diff <= prec;
if (!r) {
printf("%f != %f (within %f)\n", val, checkval, prec);
}
return r;
}
static int test_nmea_line(void)
@ -581,7 +587,7 @@ static int test_nmea_line(void)
if (!state->position_valid || !state->altitude_valid)
return -1;
if (!fp_check(state->latitude, 48.117300, 0.000001)) {
if (!fp_check(state->latitude, 48.117301, 0.000001)) {
return -1;
}
if (!fp_check(state->longitude, 11.516667, 0.000001)) {
@ -613,7 +619,7 @@ static int test_nmea_line(void)
if (!state->position_valid)
return -1;
if (!fp_check(state->latitude, 48.117300, 0.000001)) {
if (!fp_check(state->latitude, 48.117301, 0.000001)) {
return -1;
}
if (!fp_check(state->longitude, 11.516667, 0.000001)) {
@ -691,7 +697,7 @@ static int test_nmea(void)
if (!state->position_valid)
return -1;
if (!fp_check(state->latitude, 48.117300, 0.000001)) {
if (!fp_check(state->latitude, 48.117301, 0.000001)) {
return -1;
}
if (!fp_check(state->longitude, 11.516667, 0.000001)) {


+ 16
- 16
nmea.c View File

@ -71,8 +71,8 @@ int nmea_parse_line(struct nmea_state *state, char *line)
return -1;
if (!strncmp(line + 1, "GPGGA", 5)) {
int t;
int lat, latd, lon, lond;
float t;
float lat, lon;
char ns, ew;
int fix;
int nrsat;
@ -80,48 +80,48 @@ int nmea_parse_line(struct nmea_state *state, char *line)
float alt;
char at;
sscanf(line, "$GPGGA,%d,%d.%d,%c,%d.%d,%c,%d,%d,%g,%g,%c",
&t, &lat, &latd, &ns, &lon, &lond, &ew, &fix, &nrsat, &dilution,
sscanf(line, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%g,%g,%c",
&t, &lat, &ns, &lon, &ew, &fix, &nrsat, &dilution,
&alt, &at);
state->position_valid = fix;
state->altitude_valid = fix;
state->longitude = lon / 100;
state->longitude += ((lon % 100) + lond * 0.001) / 60.0;
state->longitude = (int)lon / 100;
state->longitude += (lon - state->longitude * 100) / 60.0;
if (ew == 'W')
state->longitude *= -1;
state->latitude = lat / 100;
state->latitude += ((lat % 100) + latd * 0.001) / 60.0;
state->latitude = (int)lat / 100;
state->latitude += (lat - state->latitude * 100) / 60.0;
if (ns == 'S')
state->latitude *= -1;
state->altitude = alt;
}
if (!strncmp(line + 1, "GPRMC", 5)) {
int t;
float t;
char status;
int lat, latd, lon, lond;
float lat, lon;
char ns, ew;
float sknot;
float tt;
sscanf(line, "$GPRMC,%d,%c,%d.%d,%c,%d.%d,%c,%f,%f",
&t, &status, &lat, &latd, &ns, &lon, &lond, &ew,
sscanf(line, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,%f",
&t, &status, &lat, &ns, &lon, &ew,
&sknot, &tt);
state->position_valid = status == 'A';
state->course_valid = status == 'A';
state->speed_valid = status == 'A';
state->longitude = lon / 100;
state->longitude += ((lon % 100) + lond * 0.001) / 60.0;
state->longitude = (int)lon / 100;
state->longitude += (lon - state->longitude * 100) / 60.0;
if (ew == 'W')
state->longitude *= -1;
state->latitude = lat / 100;
state->latitude += ((lat % 100) + latd * 0.001) / 60.0;
state->latitude = (int)lat / 100;
state->latitude += (lat - state->latitude * 100) / 60.0;
if (ns == 'S')
state->latitude *= -1;


Loading…
Cancel
Save