diff --git a/libgps/leo-gps-rpc.c b/libgps/leo-gps-rpc.c index 7052a1b..3cd1c9d 100644 --- a/libgps/leo-gps-rpc.c +++ b/libgps/leo-gps-rpc.c @@ -86,7 +86,7 @@ struct SVCXPRT { } while(0); static uint32_t client_IDs[16];//highest known value is 0xb -static uint32_t has_fix=0; +static uint32_t no_fix=1; #if ENABLE_NMEA static uint32_t use_nmea=1; #else @@ -646,7 +646,7 @@ void dispatch_pdsm_pd(uint32_t *data) { } if(event&PDSM_PD_EVENT_GPS_DONE) { D("PDSM_PD_EVENT_GPS_DONE"); - has_fix = 0; + no_fix = 1; } GpsLocation fix; fix.flags = 0; @@ -686,7 +686,7 @@ void dispatch_pdsm_pd(uint32_t *data) { fix.timestamp *= 1000; //ms fix.flags |= GPS_LOCATION_HAS_LAT_LONG; - has_fix = 1; + no_fix = 0; if (ntohl(data[75])) { fix.flags |= GPS_LOCATION_HAS_ACCURACY; @@ -749,7 +749,10 @@ void dispatch_pdsm_ext(uint32_t *data) { int i; if (use_nmea) return; - if (has_fix) return; + + 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); @@ -771,9 +774,7 @@ void dispatch_pdsm_ext(uint32_t *data) { } //ret.used_in_fix_mask=ntohl(data[9]); ret.used_in_fix_mask=0; - if (ret.num_svs) { - update_gps_svstatus(&ret); - } + update_gps_svstatus(&ret); } void dispatch_pdsm_xtra_req(uint8_t *data) { @@ -837,10 +838,11 @@ void dispatch(struct svc_req* a, registered_server* svc) { svc_sendreply(svc, xdr_int, &result); } -static uint8_t CHECKED[3] = {0}; +static uint8_t CHECKED[4] = {0}; static uint8_t XTRA_AUTO_DOWNLOAD_ENABLED = 0; -static uint8_t XTRA_DOWNLOAD_INTERVAL = 24; +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); @@ -857,12 +859,13 @@ int parse_gps_conf() { char *check_auto_download = "GPS1_XTRA_AUTO_DOWNLOAD_ENABLED"; char *check_interval = "GPS1_XTRA_DOWNLOAD_INTERVAL"; char *check_cleanup = "GPS1_CLEANUP_ENABLED"; + char *check_timeout = "GPS1_SESSION_TIMEOUT"; char *result; char str[256]; int i = -1; while (fscanf(file, "%s", str) != EOF) { - //printf("%s (%d)\n", str, strlen(str)); + //D("%s (%d)\n", str, strlen(str)); if (!CHECKED[1]) { result = strstr(str, check_auto_download); if (result != NULL) { @@ -892,6 +895,16 @@ int parse_gps_conf() { CHECKED[2] = 1; } } + if (!CHECKED[3]) { + result = strstr(str, check_timeout); + if (result != NULL) { + result = result+strlen(check_timeout)+1; + i = atoi(result); + if (i>1 && i<121) + SESSION_TIMEOUT = i; + CHECKED[3] = 1; + } + } } fclose(file); return 0; @@ -994,9 +1007,15 @@ int gps_xtra_inject_time_info(GpsUtcTime time, int64_t timeReference, int uncert return res; } -void gps_get_position(int timeout) +void gps_get_position() { - D("%s() is called", __FUNCTION__); +#if GPS_DEBUG + struct tm tm; + time_t now = time(NULL); + gmtime_r( &now, &tm ); + long time = mktime(&tm); + D("%s() is called: %ld", __FUNCTION__, time); +#endif pdsm_get_position(_clnt, 0, 0, 1, @@ -1008,7 +1027,7 @@ void gps_get_position(int timeout) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 50, timeout, + 1, 50, SESSION_TIMEOUT, client_IDs[2]); } diff --git a/libgps/leo-gps.c b/libgps/leo-gps.c index b47894d..12005ff 100644 --- a/libgps/leo-gps.c +++ b/libgps/leo-gps.c @@ -967,12 +967,6 @@ Exit: return NULL; } -uint64_t get_usleep_time(int fix_freq) { - uint64_t microseconds; - microseconds = (fix_freq * 1000000) - 500000; - return microseconds; -} - #if ENABLE_NMEA static void* gps_timer_thread( void* arg ) { D("%s() running", __FUNCTION__); @@ -1008,7 +1002,7 @@ static void* gps_timer_thread( void* arg ) { GPS_STATE_UNLOCK_FIX(state); - uint64_t microseconds = get_usleep_time(state->fix_freq); + uint64_t microseconds = (state->fix_freq * 1000000) - 500000; usleep(microseconds); //D("%s() usleep(%ld)", __FUNCTION__, microseconds); @@ -1020,13 +1014,6 @@ static void* gps_timer_thread( void* arg ) { #endif void pdsm_pd_callback() { -#if DUMP_DATA - struct tm tm; - time_t now = time(NULL); - gmtime_r( &now, &tm ); - long time = mktime(&tm); - D("%s() is called: %ld", __FUNCTION__, time); -#endif pthread_cond_signal(&get_pos_ready_cond); } @@ -1037,7 +1024,7 @@ static void* gps_get_position_thread( void* arg ) { { while(started) { - gps_get_position(s->fix_freq); + gps_get_position(); pthread_mutex_lock(&get_pos_ready_mutex); pthread_cond_wait(&get_pos_ready_cond, &get_pos_ready_mutex); pthread_mutex_unlock(&get_pos_ready_mutex);