[Gpredict-svn] SF.net SVN: gpredict:[648] trunk
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
|
From: <cs...@us...> - 2010-08-21 08:50:54
|
Revision: 648
http://gpredict.svn.sourceforge.net/gpredict/?rev=648&view=rev
Author: csete
Date: 2010-08-21 08:50:48 +0000 (Sat, 21 Aug 2010)
Log Message:
-----------
Fixed bug 3050068: Unable to update TLE from local files.
Modified Paths:
--------------
trunk/ChangeLog
trunk/NEWS
trunk/src/tle-update.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-08-21 06:55:00 UTC (rev 647)
+++ trunk/ChangeLog 2010-08-21 08:50:48 UTC (rev 648)
@@ -8,6 +8,9 @@
Applied patch 3050047 from Patrick Strasser OE6PSE to include current
pass in the list of future passes.
+ * src/tle-update.c:
+ Fixed bug 3050068: Unable to update TLE from local files.
+
2010-07-12 Alexandru Csete <oz9aec at gmail.com>
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2010-08-21 06:55:00 UTC (rev 647)
+++ trunk/NEWS 2010-08-21 08:50:48 UTC (rev 648)
@@ -16,7 +16,8 @@
- Fixed bug 2918672: Trailing whitespace and newline in satellite names.
- Fixed bug 2914679: Unable to save Future passes.
- Fixed bug 2674626: Process 100% CPU load with one kepler element.
-- Fixed bug 2792349: Segfault on certain satellites (Geo)
+- Fixed bug 2792349: Segfault on certain satellites (Geo).
+- Fixed bug 3050068: Unable to update TLE from local files.
- Applied patch 2876485: Fix a memory leak in the rotator controller (Thanks to Charles Suprin AA1VS).
- Applied patch 2877878: Change Flag to Lock in tle-update (thanks to Charles Suprin AA1VS).
- Applied patch 2877918: Fixes segfault in TLE updater (thanks to Charles Suprin AA1VS).
Modified: trunk/src/tle-update.c
===================================================================
--- trunk/src/tle-update.c 2010-08-21 06:55:00 UTC (rev 647)
+++ trunk/src/tle-update.c 2010-08-21 08:50:48 UTC (rev 648)
@@ -55,7 +55,9 @@
/* private function prototypes */
static size_t my_write_func (void *ptr, size_t size, size_t nmemb, FILE *stream);
static gint read_fresh_tle (const gchar *dir, const gchar *fnam, GHashTable *data);
+static gboolean is_tle_file (const gchar *dir, const gchar *fnam);
+
static void update_tle_in_file (const gchar *ldname,
const gchar *fname,
GHashTable *data,
@@ -159,28 +161,32 @@
}
else {
- /* read fresh tle files into memory */
+ /* scan directory for tle files */
while ((fnam = g_dir_read_name (cache_dir)) != NULL) {
- /* status message */
- if (!silent && (label1 != NULL)) {
- text = g_strdup_printf (_("Reading data from %s"), fnam);
- gtk_label_set_text (GTK_LABEL (label1), text);
- g_free (text);
-
-
- /* Force the drawing queue to be processed otherwise there will
- not be any visual feedback, ie. frozen GUI
- - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602
- */
- while (g_main_context_iteration (NULL, FALSE));
-
- /* give user a chance to follow progress */
- g_usleep (G_USEC_PER_SEC / 100);
+ /* check that we got a TLE file */
+ if (is_tle_file(dir, fnam)) {
+
+ /* status message */
+ if (!silent && (label1 != NULL)) {
+ text = g_strdup_printf (_("Reading data from %s"), fnam);
+ gtk_label_set_text (GTK_LABEL (label1), text);
+ g_free (text);
+
+
+ /* Force the drawing queue to be processed otherwise there will
+ not be any visual feedback, ie. frozen GUI
+ - see Gtk+ FAQ http://www.gtk.org/faq/#AEN602
+ */
+ while (g_main_context_iteration (NULL, FALSE));
+
+ /* give user a chance to follow progress */
+ g_usleep (G_USEC_PER_SEC / 100);
+ }
+
+ /* now, do read the fresh data */
+ num = read_fresh_tle (dir, fnam, data);
}
-
- /* now, do read the fresh data */
- num = read_fresh_tle (dir, fnam, data);
if (num < 1) {
sat_log_log (SAT_LOG_LEVEL_ERROR,
@@ -712,12 +718,44 @@
}
+/** \brief Check whether file is TLE file.
+ * \param dir The directory.
+ * \param fnam The file name.
+ *
+ * This function checks whether the file with path dir/fnam is a potential
+ * TLE file. Checks performed:
+ * - It is a real file
+ * - suffix is .txt or .tle
+ */
+static gboolean is_tle_file (const gchar *dir, const gchar *fnam)
+{
+ gchar *path;
+ gboolean fileIsOk = FALSE;
+
+
+ path = g_strconcat (dir, G_DIR_SEPARATOR_S, fnam, NULL);
+
+ if (g_file_test (path, G_FILE_TEST_IS_REGULAR) &&
+ (g_str_has_suffix(fnam, ".tle") || g_str_has_suffix(fnam, ".txt")))
+ {
+ fileIsOk = TRUE;
+ }
+
+ g_free (path);
+
+ return fileIsOk;
+}
+
/** \brief Read fresh TLE data into hash table.
* \param dir The directory to read from.
* \param fnam The name of the file to read from.
* \param fresh_data Hash table where the data should be stored.
* \return The number of satellites successfully read.
+ *
+ * This function will read fresh TLE data from local files into memory.
+ * If there is a saetllite category (.cat file) with the same name as the
+ * input file it will also update the satellites in that category.
*/
static gint read_fresh_tle (const gchar *dir, const gchar *fnam, GHashTable *data)
{
@@ -736,6 +774,7 @@
gchar *catname, *catpath, *buff, **buffv;
FILE *catfile;
gchar category[80];
+ gboolean catsync = FALSE; /* whether .cat file should be synced */
@@ -757,95 +796,97 @@
if (catfile!=NULL) {
b = fgets (category, 80, catfile);
fclose (catfile);
+ catsync = TRUE;
}
else {
- /* FIXME not sure what goes here AA1VS */
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%s: Failed to open %s"),
- __FILE__, __FUNCTION__, catpath);
- return (retcode);
+ /* There is no category with this name (could be update from custom file) */
+ sat_log_log (SAT_LOG_LEVEL_MSG,
+ _("%s:%s: There is no category called %s"),
+ __FILE__, __FUNCTION__, fnam);
}
/* reopen a new catfile and write category name */
- catfile = g_fopen (catpath, "w");
- if (catfile!=NULL) {
-
- fputs (category, catfile);
-
+ if (catsync) {
+ catfile = g_fopen (catpath, "w");
+ if (catfile != NULL) {
+ fputs (category, catfile);
+ }
+ else {
+ catsync = FALSE;
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%s: Could not reopne .cat file while reading TLE from %s"),
+ __FILE__, __FUNCTION__, fnam);
+ }
+
/* .cat file now contains the category name;
satellite catnums will be added during update in the while loop */
+ }
+
- /* read 3 lines at a time */
- while (fgets (tle_str[0], 80, fp)) {
- /* read second and third lines */
- b = fgets (tle_str[1], 80, fp);
- b = fgets (tle_str[2], 80, fp);
+ /* read 3 lines at a time */
+ while (fgets (tle_str[0], 80, fp)) {
+ /* read second and third lines */
+ b = fgets (tle_str[1], 80, fp);
+ b = fgets (tle_str[2], 80, fp);
- tle_str[1][69] = '\0';
- tle_str[2][69] = '\0';
+ tle_str[1][69] = '\0';
+ tle_str[2][69] = '\0';
- /* copy catnum and convert to integer */
- for (i = 2; i < 7; i++) {
- catstr[i-2] = tle_str[1][i];
- }
- catstr[5] = '\0';
- catnr = (guint) g_ascii_strtod (catstr, NULL);
+ /* copy catnum and convert to integer */
+ for (i = 2; i < 7; i++) {
+ catstr[i-2] = tle_str[1][i];
+ }
+ catstr[5] = '\0';
+ catnr = (guint) g_ascii_strtod (catstr, NULL);
- if (Get_Next_Tle_Set (tle_str, &tle) != 1) {
- /* TLE data not good */
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%s: Invalid data for %d"),
- __FILE__, __FUNCTION__, catnr);
- }
- else {
- /* DATA OK, phew... */
- /* sat_log_log (SAT_LOG_LEVEL_DEBUG, */
- /* _("%s: Good data for %d"), */
- /* __FUNCTION__, */
- /* catnr); */
+ if (Get_Next_Tle_Set (tle_str, &tle) != 1) {
+ /* TLE data not good */
+ sat_log_log (SAT_LOG_LEVEL_ERROR,
+ _("%s:%s: Invalid data for %d"),
+ __FILE__, __FUNCTION__, catnr);
+ }
+ else {
+ if (catsync) {
/* store catalog number in catfile */
buff = g_strdup_printf ("%d\n", catnr);
fputs (buff, catfile);
g_free (buff);
+ }
- /* add data to hash table */
- key = g_try_new0 (guint, 1);
- *key = catnr;
+ /* add data to hash table */
+ key = g_try_new0 (guint, 1);
+ *key = catnr;
- /* check if satellite already in hash table */
- if (g_hash_table_lookup (data, key) == NULL) {
+ /* check if satellite already in hash table */
+ if (g_hash_table_lookup (data, key) == NULL) {
- /* create new_tle structure */
- ntle = g_try_new (new_tle_t, 1);
- ntle->catnum = catnr;
- ntle->epoch = tle.epoch;
- ntle->satname = g_strdup (g_strchomp(tle_str[0]));
- ntle->line1 = g_strdup (tle_str[1]);
- ntle->line2 = g_strdup (tle_str[2]);
- ntle->srcfile = g_strdup (fnam);
- ntle->isnew = TRUE; /* flag will be reset when using data */
+ /* create new_tle structure */
+ ntle = g_try_new (new_tle_t, 1);
+ ntle->catnum = catnr;
+ ntle->epoch = tle.epoch;
+ ntle->satname = g_strdup (g_strchomp(tle_str[0]));
+ ntle->line1 = g_strdup (tle_str[1]);
+ ntle->line2 = g_strdup (tle_str[2]);
+ ntle->srcfile = g_strdup (fnam);
+ ntle->isnew = TRUE; /* flag will be reset when using data */
- g_hash_table_insert (data, key, ntle);
- retcode++;
- }
- else {
- g_free (key);
- }
+ g_hash_table_insert (data, key, ntle);
+ retcode++;
}
-
+ else {
+ g_free (key);
+ }
}
+ }
+
+ if (catsync) {
/* close category file */
fclose (catfile);
}
- else {
- sat_log_log (SAT_LOG_LEVEL_ERROR,
- _("%s:%s: Failed to open %s"),
- __FILE__, __FUNCTION__, catpath);
- }
g_free (catpath);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|