[Gpredict-svn] SF.net SVN: gpredict:[732] branches/gpsd_testing/src
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
From: <aa...@us...> - 2011-01-08 18:26:30
|
Revision: 732 http://gpredict.svn.sourceforge.net/gpredict/?rev=732&view=rev Author: aa1vs Date: 2011-01-08 18:26:24 +0000 (Sat, 08 Jan 2011) Log Message: ----------- Make gpsd code safer for multiple modules. Add position comparison for event updates. Modified Paths: -------------- branches/gpsd_testing/src/gtk-sat-map.c branches/gpsd_testing/src/gtk-sat-module.c branches/gpsd_testing/src/gtk-sat-module.h branches/gpsd_testing/src/qth-data.c branches/gpsd_testing/src/qth-data.h Modified: branches/gpsd_testing/src/gtk-sat-map.c =================================================================== --- branches/gpsd_testing/src/gtk-sat-map.c 2011-01-05 23:47:41 UTC (rev 731) +++ branches/gpsd_testing/src/gtk-sat-map.c 2011-01-08 18:26:24 UTC (rev 732) @@ -609,12 +609,41 @@ guint h, m, s; gchar *ch, *cm, *cs; gfloat x,y; + gdouble oldx,oldy; + /* check whether there are any pending resize requests */ if (satmap->resize) update_map_size (satmap); - /* check refresh rate and refresh sats if time */ + /* check if qth has moved significantly if so move it*/ + lonlat_to_xy (satmap, satmap->qth->lon, satmap->qth->lat, &x, &y); + g_object_get (satmap->qthmark, + "x", &oldx, + "y", &oldy, + NULL); + + if ((fabs (oldx-x) >= 2*MARKER_SIZE_HALF) || + (fabs (oldy-y) >= 2*MARKER_SIZE_HALF)) { + + /* update qth mark */ + g_object_set (satmap->qthmark, + "x", x - MARKER_SIZE_HALF, + "y", y - MARKER_SIZE_HALF, + NULL); + g_object_set (satmap->qthlabel, + "x", x, + "y", y+2, + NULL); + + /* QTH info */ + g_object_set (satmap->locnam, + "x", (gdouble) satmap->x0 + 2, + "y", (gdouble) satmap->y0 + 1, + NULL); + } + + /* check refresh rate and refresh sats/qth if time */ if (satmap->counter < satmap->refresh) { satmap->counter++; } @@ -622,7 +651,9 @@ /* reset data */ satmap->counter = 1; satmap->naos = 2458849.5; + /* QTH */ + /*update for accuracy*/ lonlat_to_xy (satmap, satmap->qth->lon, satmap->qth->lat, &x, &y); g_object_set (satmap->qthmark, "x", x - MARKER_SIZE_HALF, Modified: branches/gpsd_testing/src/gtk-sat-module.c =================================================================== --- branches/gpsd_testing/src/gtk-sat-module.c 2011-01-05 23:47:41 UTC (rev 731) +++ branches/gpsd_testing/src/gtk-sat-module.c 2011-01-08 18:26:24 UTC (rev 732) @@ -293,7 +293,7 @@ return NULL; } - /*initialize the qth engine*/ + /*initialize the qth engine and get position*/ qth_data_update_init(GTK_SAT_MODULE(widget)->qth); /* module state */ @@ -816,17 +816,22 @@ mod->event_count = 0; } /*update the qth position*/ - /*if new position update stuff*/ - /*should probably have window around qth to reduce distance*/ if(qth_data_update(mod->qth,mod->tmgCdnum)) { - /* reset counter, this will make gtk_sat_module_update_sat - recalculate events - */ - mod->event_count = 0; + /*only trigger an update if adequate movement has occurred*/ + /*FIXME position threshhold should be configurable*/ + if (qth_small_dist(mod->qth,mod->qth_event)>1.0) { + /* reset counter, this will make gtk_sat_module_update_sat + recalculate events + */ + mod->event_count = 0; + } } - + /*if the events are going to be recalculated store the position*/ + if (mod->event_count == 0){ + qth_small_save(mod->qth,&(mod->qth_event)); + } /* update satellite data */ g_hash_table_foreach (mod->satellites, gtk_sat_module_update_sat, @@ -977,7 +982,7 @@ } - /*** FIXME: we don't need to do this every time! */ + /*data may have been updated by gpsd*/ obs_geodetic.lon = module->qth->lon * de2ra; obs_geodetic.lat = module->qth->lat * de2ra; obs_geodetic.alt = module->qth->alt / 1000.0; Modified: branches/gpsd_testing/src/gtk-sat-module.h =================================================================== --- branches/gpsd_testing/src/gtk-sat-module.h 2011-01-05 23:47:41 UTC (rev 731) +++ branches/gpsd_testing/src/gtk-sat-module.h 2011-01-08 18:26:24 UTC (rev 732) @@ -117,7 +117,7 @@ GKeyFile *cfgdata; /*!< Configuration data. */ qth_t *qth; /*!< QTH information. */ - + qth_small_t qth_event; /*!< QTH information for last AOS/LOS update. */ GHashTable *satellites; /*!< Satellites. */ guint32 timeout; /*!< Timeout value [msec] */ Modified: branches/gpsd_testing/src/qth-data.c =================================================================== --- branches/gpsd_testing/src/qth-data.c 2011-01-05 23:47:41 UTC (rev 731) +++ branches/gpsd_testing/src/qth-data.c 2011-01-08 18:26:24 UTC (rev 732) @@ -38,6 +38,7 @@ #include "config-keys.h" #include "orbit-tools.h" #include "time-tools.h" +#include "locator.h" #if HAS_LIBGPS #include <gps.h> #endif @@ -412,40 +413,47 @@ * \param qth the time at which the qth is to be computed. this may be ignored by gps updates. */ gboolean qth_data_update(qth_t * qth, gdouble t) { + gboolean retval = FALSE; switch (qth->type) { case QTH_STATIC_TYPE: - return FALSE; + /*never changes*/ break; case QTH_GPSD_TYPE: - if (qth->gps_data==NULL) { - return FALSE; - } else { + if (qth->gps_data!=NULL) { #if HAS_LIBGPS if(gps_waiting(qth->gps_data) == 1) { - if(gps_poll(qth->gps_data)==0){ - if (qth->gps_data->fix.mode>=2) { - qth->lat = qth->gps_data->fix.latitude; - qth->lon = qth->gps_data->fix.longitude; + if(gps_poll(qth->gps_data) == 0){ + if (qth->gps_data->fix.mode >= MODE_2D) { + if (qth->lat != qth->gps_data->fix.latitude) { + qth->lat = qth->gps_data->fix.latitude; + retval = TRUE; + } + if (qth->lon!=qth->gps_data->fix.longitude) { + qth->lon = qth->gps_data->fix.longitude; + retval = TRUE; + } } - if (qth->gps_data->fix.mode==3) { - qth->alt=qth->gps_data->fix.altitude; + if (qth->gps_data->fix.mode == MODE_3D) { + if (qth->alt != qth->gps_data->fix.altitude) { + qth->alt = qth->gps_data->fix.altitude; + retval = TRUE; + } + } else { + if (qth->alt != 0) { + qth->alt = 0; + retval = TRUE; + } } } - return (TRUE); - } else { - return FALSE; - } - -#else - return FALSE; + } #endif } - break; default: break; } + return retval; } /** \brief Initialize whatever structures inside the qth_t stucture for later updates. @@ -465,8 +473,10 @@ case QTH_GPSD_TYPE: #if HAS_LIBGPS /* open the connection to gpsd and start the stream */ - qth->gps_data=gps_open(server,port); - if (qth->gps_data==NULL) { + //qth->gps_data=gps_open(server,port); + qth->gps_data=g_try_new0(struct gps_data_t,1); + + if (gps_open_r(server,port,qth->gps_data)==-1) { printf("Could not open gps\n"); return FALSE; } else { @@ -491,8 +501,9 @@ */ void qth_data_update_stop (qth_t *qth) { switch (qth->type) { - //case QTH_STATIC_TYPE: - // break; + case QTH_STATIC_TYPE: + /*nothing to do. the data never updates*/ + break; case QTH_GPSD_TYPE: /* close gpsd socket */ @@ -537,3 +548,26 @@ qth->gps_data=NULL; } +/** \brief Copy values from qth structure to qth_small structure + * \param qth the qth data structure to backup + * \param qth_small the data structure to store values + * This is intended for copying only the minimal qth data to a structure for tagging and later comparison. + */ +void qth_small_save(qth_t*qth,qth_small_t *qth_small){ + qth_small->lat=qth->lat; + qth_small->lon=qth->lon; + qth_small->alt=qth->alt; +} + +/** \brief Compute the distance between a location in a qth_t structure and qth_small_t structure. + * \param qth the qth data structure + * \param qth_small the data structure + * This is intended for measuring distance between the current qth and the position that tagged some data in qth_small. + */ +double qth_small_dist(qth_t *qth,qth_small_t qth_small){ + double distance,azimuth; + /* FIXME Is this the right coordinate system to use? */ + /* a 3d coordinate system might make more sense long term */ + qrb(qth->lon,qth->lat,qth_small.lon,qth_small.lat,&distance,&azimuth); + return(distance); +} Modified: branches/gpsd_testing/src/qth-data.h =================================================================== --- branches/gpsd_testing/src/qth-data.h 2011-01-05 23:47:41 UTC (rev 731) +++ branches/gpsd_testing/src/qth-data.h 2011-01-08 18:26:24 UTC (rev 732) @@ -48,6 +48,15 @@ GKeyFile *data; /*!< Raw data from cfg file. */ } qth_t; +/** \brief Compact QTH data structure for tagging data and comparing. */ +typedef struct { + gdouble lat; /*!< Latitude in dec. deg. North. */ + gdouble lon; /*!< Longitude in dec. deg. East. */ + gint alt; /*!< Altitude above sea level in meters. */ +} qth_small_t; + + + enum { QTH_STATIC_TYPE=0, QTH_GPSD_TYPE @@ -60,5 +69,8 @@ gboolean qth_data_update(qth_t *qth, gdouble t); gboolean qth_data_update_init(qth_t *qth); void qth_data_update_stop(qth_t *qth); - +double qth_small_dist(qth_t *qth,qth_small_t qth_small); +void qth_small_save(qth_t *qth,qth_small_t *qth_small); +void qth_init(qth_t* qth); +void qth_safe(qth_t* qth); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |