From 491578e176316bb262b857c9866113125e31f305 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Wed, 31 Aug 2011 22:43:39 +0100 Subject: [PATCH] leo: updated to libgps 2.1 NMEA (thanks to tytung) --- libgps/leo-gps-rpc.c | 43 ++++++++++++++++++++++++++++++++++--------- libgps/leo-gps.c | 25 ++++++++++++++++++------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/libgps/leo-gps-rpc.c b/libgps/leo-gps-rpc.c index 3cd1c9d..100dd5b 100644 --- a/libgps/leo-gps-rpc.c +++ b/libgps/leo-gps-rpc.c @@ -40,7 +40,6 @@ #define ENABLE_NMEA 1 -#define MEASUREMENT_PRECISION 10.0f // in meters #define DUMP_DATA 0 #define GPS_DEBUG 0 @@ -96,6 +95,13 @@ static struct CLIENT *_clnt; static struct timeval timeout; static SVCXPRT *_svc; +static uint8_t CHECKED[4] = {0}; +static uint8_t XTRA_AUTO_DOWNLOAD_ENABLED = 0; +static uint8_t XTRA_DOWNLOAD_INTERVAL = 24; // hours +static uint8_t CLEANUP_ENABLED = 1; +static uint8_t SESSION_TIMEOUT = 2; // seconds +static uint8_t MEASUREMENT_PRECISION = 10; // meters + struct params { uint32_t *data; int length; @@ -691,7 +697,7 @@ void dispatch_pdsm_pd(uint32_t *data) { if (ntohl(data[75])) { fix.flags |= GPS_LOCATION_HAS_ACCURACY; float hdop = (float)ntohl(data[75]) / 10.0f / 2.0f; - fix.accuracy = hdop * MEASUREMENT_PRECISION; + fix.accuracy = hdop * (float)MEASUREMENT_PRECISION; } union { @@ -752,7 +758,6 @@ void dispatch_pdsm_ext(uint32_t *data) { no_fix++; if (no_fix < 2) return; - if (no_fix == UINT32_MAX) no_fix = 2; // avoid overflow ret.num_svs=ntohl(data[8]); D("%s() is called. num_svs=%d", __FUNCTION__, ret.num_svs); @@ -838,17 +843,16 @@ void dispatch(struct svc_req* a, registered_server* svc) { svc_sendreply(svc, xdr_int, &result); } -static uint8_t CHECKED[4] = {0}; -static uint8_t XTRA_AUTO_DOWNLOAD_ENABLED = 0; -static uint8_t XTRA_DOWNLOAD_INTERVAL = 24; // hours -static uint8_t CLEANUP_ENABLED = 1; -static uint8_t SESSION_TIMEOUT = 2; // seconds - uint8_t get_cleanup_value() { D("%s() is called: %d", __FUNCTION__, CLEANUP_ENABLED); return CLEANUP_ENABLED; } +uint8_t get_precision_value() { + D("%s() is called: %d", __FUNCTION__, MEASUREMENT_PRECISION); + return MEASUREMENT_PRECISION; +} + int parse_gps_conf() { FILE *file = fopen("/system/etc/gps.conf", "r"); if (!file) { @@ -860,6 +864,7 @@ int parse_gps_conf() { char *check_interval = "GPS1_XTRA_DOWNLOAD_INTERVAL"; char *check_cleanup = "GPS1_CLEANUP_ENABLED"; char *check_timeout = "GPS1_SESSION_TIMEOUT"; + char *check_precision = "GPS1_MEASUREMENT_PRECISION"; char *result; char str[256]; int i = -1; @@ -905,8 +910,23 @@ int parse_gps_conf() { CHECKED[3] = 1; } } + if (!CHECKED[4]) { + result = strstr(str, check_precision); + if (result != NULL) { + result = result+strlen(check_precision)+1; + i = atoi(result); + if (i>0 && i<16) + MEASUREMENT_PRECISION = i; + CHECKED[4] = 1; + } + } } fclose(file); + LOGD("%s() is called: GPS1_XTRA_AUTO_DOWNLOAD_ENABLED = %d", __FUNCTION__, XTRA_AUTO_DOWNLOAD_ENABLED); + LOGD("%s() is called: GPS1_XTRA_DOWNLOAD_INTERVAL = %d", __FUNCTION__, XTRA_DOWNLOAD_INTERVAL); + LOGD("%s() is called: GPS1_CLEANUP_ENABLED = %d", __FUNCTION__, CLEANUP_ENABLED); + LOGD("%s() is called: GPS1_SESSION_TIMEOUT = %d", __FUNCTION__, SESSION_TIMEOUT); + LOGD("%s() is called: GPS1_MEASUREMENT_PRECISION = %d", __FUNCTION__, MEASUREMENT_PRECISION); return 0; } @@ -952,6 +972,11 @@ int init_leo() pdsm_client_act(clnt, 4); if (!CHECKED[0]) { + if (use_nmea) + LOGD("%s() is called: %s version", __FUNCTION__, "NMEA"); + else + LOGD("%s() is called: %s version", __FUNCTION__, "RPC"); + parse_gps_conf(); if (XTRA_AUTO_DOWNLOAD_ENABLED) gps_xtra_set_auto_params(); diff --git a/libgps/leo-gps.c b/libgps/leo-gps.c index 12005ff..0dc191b 100644 --- a/libgps/leo-gps.c +++ b/libgps/leo-gps.c @@ -40,7 +40,6 @@ #define XTRA_BLOCK_SIZE 400 #define ENABLE_NMEA 1 -#define MEASUREMENT_PRECISION 10.0f // in meters #define DUMP_DATA 0 #define GPS_DEBUG 1 @@ -83,6 +82,7 @@ void update_gps_svstatus(GpsSvStatus *svstatus); void update_gps_nmea(GpsUtcTime timestamp, const char* nmea, int length); extern uint8_t get_cleanup_value(); +extern uint8_t get_precision_value(); /*****************************************************************/ /*****************************************************************/ @@ -445,7 +445,8 @@ nmea_reader_update_accuracy( NmeaReader* r, return -1; r->fix.flags |= GPS_LOCATION_HAS_ACCURACY; - r->fix.accuracy = (float)str2float(tok.p, tok.end) * MEASUREMENT_PRECISION; + float precision = (float)get_precision_value(); + r->fix.accuracy = (float)str2float(tok.p, tok.end) * precision; return 0; } @@ -835,7 +836,9 @@ void update_gps_status(GpsStatusValue value) { } void update_gps_svstatus(GpsSvStatus *svstatus) { +#if DUMP_DATA D("%s(): GpsSvStatus.num_svs=%d", __FUNCTION__, svstatus->num_svs); +#endif GpsState* state = _gps_state; //Should be made thread safe... if(state->callbacks.sv_status_cb) @@ -1125,8 +1128,16 @@ static int gps_xtra_inject_xtra_data(char* data, int length) { total_parts += 1; } + uint8_t part_no = total_parts % 10; + if (part_no > 0) + part_no = total_parts - part_no; + else + part_no = total_parts - 5; + len_injected = 0; // O bytes injected // XTRA injection starts with part 1 + D("gps_xtra_inject_xtra_data: inject part = %d/%d, len = %d\n", 1, total_parts, XTRA_BLOCK_SIZE); + D("gps_xtra_inject_xtra_data: ......"); for (part = 1; part <= total_parts; part++) { part_len = XTRA_BLOCK_SIZE; @@ -1136,7 +1147,8 @@ static int gps_xtra_inject_xtra_data(char* data, int length) { } xtra_data_ptr = data + len_injected; - D("gps_xtra_inject_xtra_data: inject part = %d/%d, len = %d\n", part, total_parts, part_len); + if (part > part_no) // reduce the number of the xtra debugging info + D("gps_xtra_inject_xtra_data: inject part = %d/%d, len = %d\n", part, total_parts, part_len); if (part < total_parts) { @@ -1306,11 +1318,10 @@ static int gps_set_position_mode(GpsPositionMode mode, int fix_frequency) { //We don't handle single shot requests atm... //So one every 1 seconds will it be. fix_frequency = 1; - } else if (fix_frequency > 8) { - //Ok, A9 will timeout with so high value. - //Set it to 8. - fix_frequency = 8; + } else if (fix_frequency > 1800) { //30mins + fix_frequency = 1800; } + // fix_frequency is only used by NMEA version s->fix_freq = fix_frequency; return 0; }