summaryrefslogtreecommitdiff
path: root/ao-tools/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ao-tools/lib')
-rw-r--r--ao-tools/lib/cc-logfile.c66
-rw-r--r--ao-tools/lib/cc.h25
2 files changed, 88 insertions, 3 deletions
diff --git a/ao-tools/lib/cc-logfile.c b/ao-tools/lib/cc-logfile.c
index 4abf7eb6..2136eec4 100644
--- a/ao-tools/lib/cc-logfile.c
+++ b/ao-tools/lib/cc-logfile.c
@@ -80,6 +80,44 @@ gpsdata_add(struct cc_gpsdata *data, struct cc_gpselt *elt)
return 1;
}
+static int
+gpssat_add(struct cc_gpsdata *data, struct cc_gpssat *sat)
+{
+ int i, j;
+ int reuse = 0;
+ int newsizesats;
+ struct cc_gpssats *newsats;
+
+ for (i = data->numsats; --i >= 0;) {
+ if (data->sats[i].sat[0].time == sat->time) {
+ reuse = 1;
+ break;
+ }
+ if (data->sats[i].sat[0].time < sat->time)
+ break;
+ }
+ if (!reuse) {
+ if (data->numsats == data->sizesats) {
+ if (data->sizesats == 0)
+ newsats = malloc((newsizesats = 256) * sizeof (struct cc_gpssats));
+ else
+ newsats = realloc (data->data, (newsizesats = data->sizesats * 2)
+ * sizeof (struct cc_gpssats));
+ if (!newsats)
+ return 0;
+ data->sats = newsats;
+ }
+ i = data->numsats++;
+ data->sats[i].nsat = 0;
+ }
+ j = data->sats[i].nsat;
+ if (j < 12) {
+ data->sats[i].sat[j] = *sat;
+ data->sats[i].nsat = j + 1;
+ }
+ return 1;
+}
+
static void
gpsdata_free(struct cc_gpsdata *data)
{
@@ -100,13 +138,20 @@ gpsdata_free(struct cc_gpsdata *data)
#define AO_LOG_POS_NONE (~0UL)
+#define GPS_TIME 1
+#define GPS_LAT 2
+#define GPS_LON 4
+#define GPS_ALT 8
+
static int
read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int *ground_pres_count)
{
char type;
int tick;
int a, b;
- struct cc_gpselt gps;
+ static struct cc_gpselt gps;
+ static int gps_valid;
+ struct cc_gpssat sat;
int serial;
if (sscanf(line, "serial-number %u", &serial) == 1) {
@@ -145,23 +190,38 @@ read_eeprom(const char *line, struct cc_flightraw *f, double *ground_pres, int *
timedata_add(&f->state, tick, a);
break;
case AO_LOG_GPS_TIME:
+ /* the flight computer writes TIME first, so reset
+ * any stale data before adding this record
+ */
gps.time = tick;
+ gps_valid = GPS_TIME;
break;
case AO_LOG_GPS_LAT:
gps.lat = ((int32_t) (a + (b << 16))) / 10000000.0;
+ gps_valid |= GPS_LAT;
break;
case AO_LOG_GPS_LON:
gps.lon = ((int32_t) (a + (b << 16))) / 10000000.0;
+ gps_valid |= GPS_LON;
break;
case AO_LOG_GPS_ALT:
- gps.alt = ((int32_t) (a + (b << 16)));
- gpsdata_add(&f->gps, &gps);
+ gps.alt = (int16_t) a;
+ gps_valid |= GPS_ALT;
break;
case AO_LOG_GPS_SAT:
+ sat.time = tick;
+ sat.svid = a;
+ sat.state = (b & 0xff);
+ sat.c_n = (b >> 8) & 0xff;
+ gpssat_add(&f->gps, &sat);
break;
default:
return 0;
}
+ if (gps_valid == 0xf) {
+ gps_valid = 0;
+ gpsdata_add(&f->gps, &gps);
+ }
return 1;
}
diff --git a/ao-tools/lib/cc.h b/ao-tools/lib/cc.h
index 01226958..b5f1132f 100644
--- a/ao-tools/lib/cc.h
+++ b/ao-tools/lib/cc.h
@@ -19,6 +19,7 @@
#define _CC_H_
#include <stdio.h>
+#include <stdint.h>
char *
cc_fullname (char *dir, char *file);
@@ -90,11 +91,35 @@ struct cc_gpselt {
double alt;
};
+#define SIRF_SAT_STATE_ACQUIRED (1 << 0)
+#define SIRF_SAT_STATE_CARRIER_PHASE_VALID (1 << 1)
+#define SIRF_SAT_BIT_SYNC_COMPLETE (1 << 2)
+#define SIRF_SAT_SUBFRAME_SYNC_COMPLETE (1 << 3)
+#define SIRF_SAT_CARRIER_PULLIN_COMPLETE (1 << 4)
+#define SIRF_SAT_CODE_LOCKED (1 << 5)
+#define SIRF_SAT_ACQUISITION_FAILED (1 << 6)
+#define SIRF_SAT_EPHEMERIS_AVAILABLE (1 << 7)
+
+struct cc_gpssat {
+ double time;
+ uint16_t svid;
+ uint8_t state;
+ uint8_t c_n;
+};
+
+struct cc_gpssats {
+ int nsat;
+ struct cc_gpssat sat[12];
+};
+
struct cc_gpsdata {
int num;
int size;
struct cc_gpselt *data;
double time_offset;
+ int numsats;
+ int sizesats;
+ struct cc_gpssats *sats;
};
/*