-static __xdata uint8_t ao_log_mutex;
-static __xdata struct ao_log_gps log;
-
-__code uint8_t ao_log_format = AO_LOG_FORMAT_TELEGPS;
-
-static uint8_t
-ao_log_csum(__xdata uint8_t *b) __reentrant
-{
- uint8_t sum = 0x5a;
- uint8_t i;
-
- for (i = 0; i < sizeof (struct ao_log_gps); i++)
- sum += *b++;
- return -sum;
-}
-
-uint8_t
-ao_log_gps(__xdata struct ao_log_gps *log) __reentrant
-{
- uint8_t wrote = 0;
- /* set checksum */
- log->csum = 0;
- log->csum = ao_log_csum((__xdata uint8_t *) log);
- ao_mutex_get(&ao_log_mutex); {
- if (ao_log_current_pos >= ao_log_end_pos && ao_log_running)
- ao_log_stop();
- if (ao_log_running) {
- wrote = 1;
- ao_storage_write(ao_log_current_pos,
- log,
- sizeof (struct ao_log_gps));
- ao_log_current_pos += sizeof (struct ao_log_gps);
- }
- } ao_mutex_put(&ao_log_mutex);
- return wrote;
-}
-
-
-static int32_t prev_lat, prev_lon;
-static int16_t prev_alt;
-static uint8_t has_prev, unmoving;
-
-#define GPS_SPARSE_UNMOVING_REPORTS 10
-#define GPS_SPARSE_UNMOVING_GROUND 10
-#define GPS_SPARSE_UNMOVING_AIR 10
-
-uint8_t
-ao_log_gps_should_log(int32_t lat, int32_t lon, int16_t alt)
-{
- if (has_prev && ao_log_running) {
- uint32_t h = ao_distance(prev_lat, prev_lon, lat, lon);
- uint16_t v = alt > prev_alt ? (alt - prev_alt) : (prev_alt - alt);
-
- if (h < GPS_SPARSE_UNMOVING_GROUND && v < GPS_SPARSE_UNMOVING_AIR) {
- if (unmoving < GPS_SPARSE_UNMOVING_REPORTS)
- ++unmoving;
- } else
- unmoving = 0;
- } else
- unmoving = 0;
-
- prev_lat = lat;
- prev_lon = lon;
- prev_alt = alt;
- has_prev = 1;
- return unmoving >= GPS_SPARSE_UNMOVING_REPORTS;
-}
-