[Gpredict-svn] SF.net SVN: gpredict:[410] trunk/src
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
From: <cs...@us...> - 2009-08-09 00:45:10
|
Revision: 410 http://gpredict.svn.sourceforge.net/gpredict/?rev=410&view=rev Author: csete Date: 2009-08-09 00:45:01 +0000 (Sun, 09 Aug 2009) Log Message: ----------- Updated to new .sat and .cat files. Buggy (both cat and sat). Modified Paths: -------------- trunk/src/tle-update.c trunk/src/tle-update.h Modified: trunk/src/tle-update.c =================================================================== --- trunk/src/tle-update.c 2009-08-09 00:37:09 UTC (rev 409) +++ trunk/src/tle-update.c 2009-08-09 00:45:01 UTC (rev 410) @@ -11,17 +11,17 @@ More details can be found at the project home page: http://gpredict.oz9aec.net/ - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, visit http://www.fsf.org/ */ @@ -36,7 +36,7 @@ #include "sgpsdp/sgp4sdp4.h" #include "sat-log.h" #include "sat-cfg.h" -#include "tle-lookup.h" +#include "compat.h" #include "tle-update.h" @@ -60,12 +60,12 @@ static gint read_fresh_tle (const gchar *dir, const gchar *fnam, GHashTable *data); static void update_tle_in_file (const gchar *ldname, - const gchar *fname, - GHashTable *data, - guint *sat_upd, - guint *sat_ski, - guint *sat_nod, - guint *sat_tot); + const gchar *fname, + GHashTable *data, + guint *sat_upd, + guint *sat_ski, + guint *sat_nod, + guint *sat_tot); static guint add_new_sats (GHashTable *data); @@ -81,6 +81,7 @@ g_free (tle->satname); g_free (tle->line1); g_free (tle->line2); + g_free (tle->srcfile); g_free (tle); } @@ -103,10 +104,9 @@ * Functional description: TBD * */ -void -tle_update_from_files (const gchar *dir, const gchar *filter, - gboolean silent, GtkWidget *progress, - GtkWidget *label1, GtkWidget *label2) +void tle_update_from_files (const gchar *dir, const gchar *filter, + gboolean silent, GtkWidget *progress, + GtkWidget *label1, GtkWidget *label2) { GHashTable *data; /* hash table with fresh TLE data */ GDir *cache_dir; /* directory to scan fresh TLE */ @@ -114,6 +114,7 @@ GError *err = NULL; gchar *text; gchar *ldname; + gchar *userconfdir; const gchar *fnam; guint num = 0; guint updated,updated_tmp; @@ -137,14 +138,14 @@ /* send an error message */ sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Error opening directory %s (%s)"), - __FUNCTION__, dir, err->message); + _("%s: Error opening directory %s (%s)"), + __FUNCTION__, dir, err->message); /* insert error message into the status string, too */ if (!silent && (label1 != NULL)) { text = g_strdup_printf (_("<b>ERROR</b> opening directory %s\n%s"), dir, err->message); - + gtk_label_set_markup (GTK_LABEL (label1), text); g_free (text); @@ -163,14 +164,14 @@ 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 / 10); } @@ -180,29 +181,24 @@ if (num < 1) { sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: No valid TLE data found in %s"), - __FUNCTION__, fnam); + _("%s: No valid TLE data found in %s"), + __FUNCTION__, fnam); } else { sat_log_log (SAT_LOG_LEVEL_MSG, - _("%s: Read %d sats from %s into memory"), - __FUNCTION__, num, fnam); + _("%s: Read %d sats from %s into memory"), + __FUNCTION__, num, fnam); } } /* close directory since we don't need it anymore */ g_dir_close (cache_dir); - /* store number of available sats */ - num = tle_lookup_count (); - - /* now it is time to read gpredict-tle into memory, too */ - ldname = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, - ".gpredict2", G_DIR_SEPARATOR_S, - "tle", NULL); + userconfdir = get_user_conf_dir (); + ldname = g_strconcat (userconfdir, G_DIR_SEPARATOR_S, "satdata", NULL); + g_free (userconfdir); - /* open directory and read files one by one */ loc_dir = g_dir_open (ldname, 0, &err); @@ -210,14 +206,14 @@ /* send an error message */ sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Error opening directory %s (%s)"), - __FUNCTION__, dir, err->message); + _("%s: Error opening directory %s (%s)"), + __FUNCTION__, dir, err->message); /* insert error message into the status string, too */ if (!silent && (label1 != NULL)) { text = g_strdup_printf (_("<b>ERROR</b> opening directory %s\n%s"), dir, err->message); - + gtk_label_set_markup (GTK_LABEL (label1), text); g_free (text); } @@ -236,12 +232,20 @@ if (progress != NULL) start = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress)); + /* This is insane but I don't know how else to count the number of sats */ + num = 0; + while ((fnam = g_dir_read_name (loc_dir)) != NULL) { + /* only consider .sat files */ + if (g_strrstr (fnam, ".sat")) { + num++; + } + } + /* update TLE files one by one */ while ((fnam = g_dir_read_name (loc_dir)) != NULL) { + /* only consider .sat files */ + if (g_strrstr (fnam, ".sat")) { - /* skip 'cache' directory */ - if (g_ascii_strcasecmp (fnam, "cache")) { - /* clear stat bufs */ updated_tmp = 0; skipped_tmp = 0; @@ -271,8 +275,8 @@ if (label2 != NULL) { text = g_strdup_printf (_("Satellites updated:\t %d\n"\ - "Satellites skipped:\t %d\n"\ - "Missing Satellites:\t %d\n"), + "Satellites skipped:\t %d\n"\ + "Missing Satellites:\t %d\n"), updated, skipped, nodata); gtk_label_set_text (GTK_LABEL (label2), text); g_free (text); @@ -289,7 +293,7 @@ fraction = 0.98; gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), - fraction); + fraction); } @@ -303,7 +307,7 @@ g_usleep (G_USEC_PER_SEC / 10); } } - + } /* close directory handle */ @@ -319,7 +323,7 @@ "Satellites skipped:\t %d\n"\ "Missing Satellites:\t %d\n"\ "New Satellites:\t\t %d"), - updated, skipped, nodata, newsats); + updated, skipped, nodata, newsats); gtk_label_set_text (GTK_LABEL (label2), text); g_free (text); @@ -327,7 +331,7 @@ sat_log_log (SAT_LOG_LEVEL_MSG, _("%s: Added %d new satellites to local database"), - __FUNCTION__, newsats); + __FUNCTION__, newsats); } /* store time of update if we have updated something */ @@ -343,8 +347,8 @@ g_free (ldname); sat_log_log (SAT_LOG_LEVEL_MSG, - _("%s: TLE elements updated."), - __FUNCTION__); + _("%s: TLE elements updated."), + __FUNCTION__); } /* destroy hash tables */ @@ -356,34 +360,113 @@ /** \brief Check if satellite is new, if so, add it to local database */ static void check_and_add_sat (gpointer key, gpointer value, gpointer user_data) { - gchar *ofn; - FILE *fp; - new_tle_t *ntle = (new_tle_t *) value; - guint *num = user_data; + new_tle_t *ntle = (new_tle_t *) value; + guint *num = user_data; + GKeyFile *satdata; + GIOChannel *satfile; + gchar *cfgstr, *cfgfile; + gsize length, written; + guint catnum = GPOINTER_TO_UINT (key); + GError *err = NULL; + /* check if sat is new */ if (ntle->isnew) { - - /* Open $HOME/.gpredict2/tle/new.tle */ - ofn = g_strconcat (g_get_home_dir(), G_DIR_SEPARATOR_S, - ".gpredict2", G_DIR_SEPARATOR_S, - "tle", G_DIR_SEPARATOR_S, - "new.tle", NULL); - fp = g_fopen (ofn, "a"); - g_free (ofn); - - /* store tle data to file */ - if (fp) { - fputs (ntle->satname, fp); - fputs (ntle->line1, fp); - fputs (ntle->line2, fp); - - /* close file */ - fclose (fp); - - /* update data */ - *num += 1; + + /* create config data */ + satdata = g_key_file_new (); + + /* store data */ + g_key_file_set_string (satdata, "Satellite", "VERSION", "1.1"); + g_key_file_set_string (satdata, "Satellite", "NAME", ntle->satname); + g_key_file_set_string (satdata, "Satellite", "NICKNAME", ntle->satname); + g_key_file_set_string (satdata, "Satellite", "TLE1", ntle->line1); + g_key_file_set_string (satdata, "Satellite", "TLE2", ntle->line2); + + /* convert data to text */ + cfgstr = g_key_file_to_data (satdata, &length, NULL); + + /* create an I/O channel and store data */ + cfgfile = sat_file_name_from_catnum (catnum); + satfile = g_io_channel_new_file (cfgfile, "w", &err); + + if (err != NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Could not create satellite file (%s)."), + __FUNCTION__, err->message); + g_clear_error (&err); } + else { + g_io_channel_write_chars (satfile, cfgstr, length, &written, &err); + g_io_channel_shutdown (satfile, TRUE, NULL); + g_io_channel_unref (satfile); + + if (err != NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Error writing satellite data for %d (%s)."), + __FUNCTION__, catnum, err->message); + g_clear_error (&err); + } + else if (length != written) { + sat_log_log (SAT_LOG_LEVEL_WARN, + _("%s: Wrote only %d out of %d chars for satellite data %d."), + __FUNCTION__, written, length, catnum); + } + else { + sat_log_log (SAT_LOG_LEVEL_MSG, + _("%s: Satellite data written for %d."), + __FUNCTION__, catnum); + *num += 1; + } + } + + /* clean up memory */ + g_free (cfgstr); + g_free (cfgfile); + g_key_file_free (satdata); + + + /**** FIXME: NEED TO CREATE COPY of cache */ + /* finally, new satellite must be added to proper category */ + gchar *catfile; + gchar **buff; + + buff = g_strsplit (ntle->srcfile, ".", 0); + cfgfile = g_strconcat (buff[0], ".cat", NULL); + catfile = sat_file_name (cfgfile); + + /* g_io_channel */ + satfile = g_io_channel_new_file (catfile, "a", &err); + + if (err != NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Could not open category file file %s (%s)."), + __FUNCTION__, cfgfile, err->message); + g_clear_error (&err); + } + else { + cfgstr = g_strdup_printf ("%d\n", catnum); + g_io_channel_write_chars (satfile, cfgstr, -1, NULL, &err); + g_io_channel_shutdown (satfile, TRUE, NULL); + g_io_channel_unref (satfile); + g_free (cfgstr); + + if (err != NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Error adding %d to %s (%s)."), + __FUNCTION__, catnum, cfgfile, err->message); + g_clear_error (&err); + } + else { + sat_log_log (SAT_LOG_LEVEL_MSG, + _("%s: Added satellite %d to %s."), + __FUNCTION__, catnum, cfgfile); + } + } + + g_free (catfile); + g_free (cfgfile); + g_strfreev (buff); } } @@ -406,12 +489,11 @@ * \param label1 GtkLabel for activity string. * \param label2 GtkLabel for statistics string. */ -void -tle_update_from_network (gboolean silent, - GtkWidget *progress, - GtkWidget *label1, - GtkWidget *label2) - { +void tle_update_from_network (gboolean silent, + GtkWidget *progress, + GtkWidget *label1, + GtkWidget *label2) +{ gchar *server; gchar *proxy = NULL; gchar *files_tmp; @@ -419,6 +501,7 @@ guint numfiles,i; gchar *curfile; gchar *locfile; + gchar *userconfdir; CURL *curl; CURLcode res; gboolean error = FALSE; @@ -448,8 +531,8 @@ if (numfiles < 1) { sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: No files to fetch from network."), - __FUNCTION__); + _("%s: No files to fetch from network."), + __FUNCTION__); /* set activity string, so user knows why nothing happens */ if (!silent && (label1 != NULL)) { @@ -492,12 +575,12 @@ while (g_main_context_iteration (NULL, FALSE)); } - /* create local file */ - locfile = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, - ".gpredict2", G_DIR_SEPARATOR_S, - "tle", G_DIR_SEPARATOR_S, - "cache", G_DIR_SEPARATOR_S, - files[i], NULL); + /* creae local cache file */ + userconfdir = get_user_conf_dir (); + locfile = g_strconcat (userconfdir, G_DIR_SEPARATOR_S, + "satdata", G_DIR_SEPARATOR_S, + "cache", G_DIR_SEPARATOR_S, + files[i], NULL); outfile = g_fopen (locfile, "wb"); curl_easy_setopt (curl, CURLOPT_WRITEDATA, outfile); curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, my_write_func); @@ -507,14 +590,14 @@ if (res != CURLE_OK) { sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Error fetching %s (%s)"), - __FUNCTION__, curfile, curl_easy_strerror (res)); + _("%s: Error fetching %s (%s)"), + __FUNCTION__, curfile, curl_easy_strerror (res)); error = TRUE; } else { sat_log_log (SAT_LOG_LEVEL_MSG, - _("%s: Successfully fetched %s"), - __FUNCTION__, curfile); + _("%s: Successfully fetched %s"), + __FUNCTION__, curfile); success++; } @@ -533,6 +616,7 @@ } + g_free (userconfdir); g_free (curfile); g_free (locfile); fclose (outfile); @@ -543,14 +627,11 @@ /* continue update if we have fetched at least one file */ if (success > 0) { /* call update_from_files */ - cache = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, - ".gpredict2", G_DIR_SEPARATOR_S, - "tle", G_DIR_SEPARATOR_S, - "cache", NULL); + cache = sat_file_name ("cache"); tle_update_from_files (cache, NULL, silent, progress, label1, label2); g_free (cache); } - + } /* clear cache and memory */ @@ -561,17 +642,14 @@ g_free (proxy); /* open cache */ - cache = g_strconcat (g_get_home_dir (), G_DIR_SEPARATOR_S, - ".gpredict2", G_DIR_SEPARATOR_S, - "tle", G_DIR_SEPARATOR_S, - "cache", NULL); + cache = sat_file_name ("cache"); dir = g_dir_open (cache, 0, &err); if (err != NULL) { /* send an error message */ sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Error opening %s (%s)"), - __FUNCTION__, dir, err->message); + _("%s: Error opening %s (%s)"), + __FUNCTION__, dir, err->message); g_clear_error (&err); } else { @@ -579,7 +657,7 @@ while ((fname = g_dir_read_name (dir)) != NULL) { locfile = g_strconcat (cache, G_DIR_SEPARATOR_S, - fname, NULL); + fname, NULL); g_remove (locfile); g_free (locfile); @@ -606,8 +684,7 @@ * This function writes the received data to the file pointed to by stream. * It is used as write callback by to curl exec function. */ -static size_t -my_write_func (void *ptr, size_t size, size_t nmemb, FILE *stream) +static size_t my_write_func (void *ptr, size_t size, size_t nmemb, FILE *stream) { /*** FIXME: TBC whether this works in wintendo */ return fwrite (ptr, size, nmemb, stream); @@ -621,8 +698,7 @@ * \param fresh_data Hash table where the data should be stored. * \return The number of satellites successfully read. */ -static gint -read_fresh_tle (const gchar *dir, const gchar *fnam, GHashTable *data) +static gint read_fresh_tle (const gchar *dir, const gchar *fnam, GHashTable *data) { new_tle_t *ntle; tle_t tle; @@ -659,21 +735,21 @@ 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); + _("%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); */ + /* sat_log_log (SAT_LOG_LEVEL_DEBUG, */ + /* _("%s: Good data for %d"), */ + /* __FUNCTION__, */ + /* 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) { /* create new_tle structure */ @@ -682,6 +758,7 @@ ntle->satname = g_strdup (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 */ @@ -702,8 +779,8 @@ else { sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s:%s: Failed to open %s"), - __FILE__, __FUNCTION__, path); + _("%s:%s: Failed to open %s"), + __FILE__, __FUNCTION__, path); } g_free (path); @@ -730,180 +807,139 @@ * When all sats have been copied ldname/fnam is deleted and temp_file * is renamed to ldname/fnam. */ -static void -update_tle_in_file (const gchar *ldname, - const gchar *fname, - GHashTable *data, - guint *sat_upd, - guint *sat_ski, - guint *sat_nod, - guint *sat_tot) +static void update_tle_in_file (const gchar *ldname, + const gchar *fname, + GHashTable *data, + guint *sat_upd, + guint *sat_ski, + guint *sat_nod, + guint *sat_tot) { gchar *path; - gchar *tmp_path; guint updated = 0; /* number of updated sats */ guint nodata = 0; /* no sats for which no fresh data available */ guint skipped = 0; /* no. sats where fresh data is older */ guint total = 0; /* total no. of sats in gpredict tle file */ - gchar tle_str[3][80]; - gchar catstr[6]; - gchar *b; - FILE *fp; - FILE *tmp; - guint catnr,i; + gchar **catstr; + guint catnr; guint *key = NULL; tle_t tle; new_tle_t *ntle; - gint retcode = 0; + GError *error = NULL; + GKeyFile *satdata; + gchar *tlestr1, *tlestr2, *rawtle; + gchar *cfgstr; + GIOChannel *cfgfile; + gsize length, written; /* open input file (file containing old tle) */ path = g_strconcat (ldname, G_DIR_SEPARATOR_S, fname, NULL); - fp = g_fopen (path, "r"); + satdata = g_key_file_new (); + if (!g_key_file_load_from_file (satdata, path, G_KEY_FILE_KEEP_COMMENTS, &error)) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Error loading %s (%s)"), + __FUNCTION__, path, error->message); + g_clear_error (&error); - if (fp != NULL) { + skipped++; - /* open output temp file */ - tmp_path = g_strconcat (ldname, G_DIR_SEPARATOR_S, "TLEUPDATE.tmp", NULL); - tmp = g_fopen (tmp_path, "w"); + } - if (tmp != NULL) { + else { - /* 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); + /* get catalog number for this satellite */ + catstr = g_strsplit (fname, ".sat", 0); + catnr = (guint) g_ascii_strtod (catstr[0], NULL); - /* stats */ - total++; + /* see if we have new data for this satellite */ + key = g_try_new0 (guint, 1); + *key = catnr; + ntle = (new_tle_t *) g_hash_table_lookup (data, key); + g_free (key); - /* 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 (ntle == NULL) { + /* no new data found for this sat => obsolete */ + nodata++; + /* check if obsolete sats should be deleted */ + /**** FIXME: This is dangereous, so we omit it */ + sat_log_log (SAT_LOG_LEVEL_MSG, + _("%s: No new TLE data found for %d. Satellite might be obsolete."), + __FUNCTION__, catnr); + } + else { + /* get TLE data */ + tlestr1 = g_key_file_get_string (satdata, "Satellite", "TLE1", NULL); + tlestr2 = g_key_file_get_string (satdata, "Satellite", "TLE2", NULL); + rawtle = g_strconcat (tlestr1, tlestr2, NULL); - if (Get_Next_Tle_Set (tle_str, &tle) != 1) { - /* TLE data not good */ - sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s:%s: Original data for %d seems to be bad"), - __FILE__, __FUNCTION__, catnr); - } - - /* get data from hash table */ - key = g_try_new0 (guint, 1); - *key = catnr; - ntle = (new_tle_t *) g_hash_table_lookup (data, key); - g_free (key); + if (!Good_Elements (rawtle)) { + sat_log_log (SAT_LOG_LEVEL_WARN, + _("%s: Current TLE data for %d appears to be bad"), + __FUNCTION__, catnr); + } + Convert_Satellite_Data (rawtle, &tle); - if (ntle == NULL) { + g_free (tlestr1); + g_free (tlestr2); + g_free (rawtle); - /* no new data found for this sat => obsolete */ - nodata++; - - /* check if obsolete sats should be deleted */ - /**** FIXME: This is dangereous, so we omit it */ + if (tle.epoch < ntle->epoch) { + /* new data is newer than what we already have */ + /* store new data */ + g_key_file_set_string (satdata, "Satellite", "TLE1", ntle->line1); + g_key_file_set_string (satdata, "Satellite", "TLE2", ntle->line2); + /* convert configuration data struct to charachter string */ + cfgstr = g_key_file_to_data (satdata, &length, NULL); /* this function never reports error */ + + /* create and open a file for writing */ + cfgfile = g_io_channel_new_file (path, "w", &error); + + if (error != NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Could not create satellite data file (%s)."), + __FUNCTION__, error->message); + g_clear_error (&error); + skipped++; } else { + g_io_channel_write_chars (cfgfile, cfgstr, length, &written, &error); - /* new data is available for this sat */ - if (tle.epoch < ntle->epoch) { - /* fresh data is newer than original - => update - */ - updated++; + g_io_channel_shutdown (cfgfile, TRUE, NULL); + g_io_channel_unref (cfgfile); - /* write new data to file */ - fputs (ntle->satname, tmp); - fputs (ntle->line1, tmp); - fputs (ntle->line2, tmp); - + if (error != NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Error writing satellite data (%s)."), + __FUNCTION__, error->message); + g_clear_error (&error); + skipped++; } - else { - /* fresh data is older than original - => don't update - */ + else if (length != written) { + sat_log_log (SAT_LOG_LEVEL_WARN, + _("%s: Wrote only %d out of %d chars for satellite data."), + __FUNCTION__, written, length); skipped++; - - /* write current data back to tle file */ - fputs (tle_str[0], tmp); - fputs (tle_str[1], tmp); - fputs (tle_str[2], tmp); } - - /* clear isnew flag */ - ntle->isnew = FALSE; - + else { + sat_log_log (SAT_LOG_LEVEL_MSG, + _("%s: Satellite data written for %d."), + __FUNCTION__, catnr); + updated++; + } } - } + g_free (cfgstr); - fclose (tmp); - fclose (fp); - - /* if there is at least one updated sat */ - if (updated > 0) { - - /* remove old tle file fp */ - retcode = g_remove (path); - - if (retcode != 0) { - /* could not remove file */ - sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Could not remove %s (file open?)"), - __FUNCTION__, path); - } - - /* rename temp file tmp to old tle file */ - retcode = g_rename (tmp_path, path); - - if (retcode != 0) { - /* could not rename file */ - sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Could not rename %s to %s"), - __FUNCTION__, tmp_path, path); - } - + /* mark this satellite as not new */ + ntle->isnew = FALSE; } - else { - /* we have to remove the temp file */ - g_remove (tmp_path); - } - } - else { - sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Failed to open temp file %s"), - __FUNCTION__, tmp_path); - - /* close input TLE file */ - fclose (fp); - } - - /* close input TLE file */ - //fclose (fp); - - /* free path to tmp file */ - g_free (tmp_path); - - /* print stats */ - sat_log_log (SAT_LOG_LEVEL_MSG, - _("%s: Update statistics for %s (U/O/N/T): %d/%d/%d/%d"), - __FUNCTION__, fname, - updated, skipped, nodata, total); - + g_strfreev (catstr); } - - else { - sat_log_log (SAT_LOG_LEVEL_ERROR, - _("%s: Failed to open %s"), - __FUNCTION__, path); - } - + g_key_file_free (satdata); g_free (path); /* update out parameters */ @@ -923,32 +959,32 @@ * */ static void -copy_tle (tle_t *source, tle_t *target) + copy_tle (tle_t *source, tle_t *target) { - target->epoch = source->epoch; - target->epoch_year = source->epoch_year; - target->epoch_day = source->epoch_day; - target->epoch_fod = source->epoch_fod; - target->xndt2o = source->xndt2o; - target->xndd6o = source->xndd6o; - target->bstar = source->bstar; - target->xincl = source->xincl; - target->xnodeo = source->xnodeo; - target->eo = source->eo; - target->omegao = source->omegao; - target->xmo = source->xmo; - target->xno = source->xno; - /*target->catnr = source->catnr;*/ - target->elset = source->elset; - target->revnum = source->revnum; - target->status = source->status; + target->epoch = source->epoch; + target->epoch_year = source->epoch_year; + target->epoch_day = source->epoch_day; + target->epoch_fod = source->epoch_fod; + target->xndt2o = source->xndt2o; + target->xndd6o = source->xndd6o; + target->bstar = source->bstar; + target->xincl = source->xincl; + target->xnodeo = source->xnodeo; + target->eo = source->eo; + target->omegao = source->omegao; + target->xmo = source->xmo; + target->xno = source->xno; + /*target->catnr = source->catnr;*/ + target->elset = source->elset; + target->revnum = source->revnum; + target->status = source->status; - /* - target->xincl1 = source->xincl1; - target->xnodeo1 = source->xnodeo1; - target->omegao1 = source->omegao1; - */ + /* + target->xincl1 = source->xincl1; + target->xnodeo1 = source->xnodeo1; + target->omegao1 = source->omegao1; + */ } @@ -959,32 +995,32 @@ * +1 if tle1->epoch > tle2->epoch. */ static gint -compare_epoch (tle_t *tle1, tle_t *tle2) + compare_epoch (tle_t *tle1, tle_t *tle2) { - gint retval = 0; + gint retval = 0; - if (tle1->epoch > tle2->epoch) - retval = 1; - else if (tle1->epoch < tle2->epoch) - retval = -1; - else - retval = 0; + if (tle1->epoch > tle2->epoch) + retval = 1; + else if (tle1->epoch < tle2->epoch) + retval = -1; + else + retval = 0; - return retval; + return retval; } static tle_t * -gchar_to_tle (tle_type_t type, const gchar *lines) + gchar_to_tle (tle_type_t type, const gchar *lines) { - return NULL; + return NULL; } static gchar * -tle_to_gchar (tle_type_t type, tle_t *tle) + tle_to_gchar (tle_type_t type, tle_t *tle) { return NULL; } @@ -1002,7 +1038,7 @@ }; const gchar * -tle_update_freq_to_str (tle_auto_upd_freq_t freq) + tle_update_freq_to_str (tle_auto_upd_freq_t freq) { if ((freq < TLE_AUTO_UPDATE_NEVER) || (freq >= TLE_AUTO_UPDATE_NUM)) { Modified: trunk/src/tle-update.h =================================================================== --- trunk/src/tle-update.h 2009-08-09 00:37:09 UTC (rev 409) +++ trunk/src/tle-update.h 2009-08-09 00:45:01 UTC (rev 410) @@ -11,7 +11,7 @@ More details can be found at the project home page: http://gpredict.oz9aec.net/ - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -34,56 +34,57 @@ /** \brief TLE format type flags. */ typedef enum { - TLE_TYPE_NASA = 0 /*!< NASA two-line format (3 lines with name). */ -} tle_type_t; + TLE_TYPE_NASA = 0 /*!< NASA two-line format (3 lines with name). */ + } tle_type_t; /** \brief TLE auto update frequency. */ typedef enum { - TLE_AUTO_UPDATE_NEVER = 0, /*!< No auto-update, just warn after one week. */ - TLE_AUTO_UPDATE_MONTHLY = 1, - TLE_AUTO_UPDATE_WEEKLY = 2, - TLE_AUTO_UPDATE_DAILY = 3, - TLE_AUTO_UPDATE_NUM + TLE_AUTO_UPDATE_NEVER = 0, /*!< No auto-update, just warn after one week. */ + TLE_AUTO_UPDATE_MONTHLY = 1, + TLE_AUTO_UPDATE_WEEKLY = 2, + TLE_AUTO_UPDATE_DAILY = 3, + TLE_AUTO_UPDATE_NUM } tle_auto_upd_freq_t; /** \brief Action to perform when it's time to update TLE. */ typedef enum { - TLE_AUTO_UPDATE_NOACT = 0, /*!< No action (not a valid option). */ - TLE_AUTO_UPDATE_NOTIFY = 1, /*!< Notify user. */ - TLE_AUTO_UPDATE_GOAHEAD = 2 /*!< Perform unattended update. */ + TLE_AUTO_UPDATE_NOACT = 0, /*!< No action (not a valid option). */ + TLE_AUTO_UPDATE_NOTIFY = 1, /*!< Notify user. */ + TLE_AUTO_UPDATE_GOAHEAD = 2 /*!< Perform unattended update. */ } tle_auto_upd_action_t; /** \brief Data structure to hold a TLE set. */ typedef struct { - gdouble epoch; /*!< Epoch. */ - gchar *satname; /*!< Satellite name. */ - gchar *line1; /*!< Line 1. */ - gchar *line2; /*!< Line 2. */ + gdouble epoch; /*!< Epoch. */ + gchar *satname; /*!< Satellite name. */ + gchar *line1; /*!< Line 1. */ + gchar *line2; /*!< Line 2. */ + gchar *srcfile; /*!< The file where TLE comes from (needed for cat) */ gboolean isnew; /*!< Flag indicating whether sat is new. */ } new_tle_t; /** \brief Data structure to hold local TLE data. */ typedef struct { - tle_t tle; /*!< TLE data. */ - gchar *filename; /*!< File name where the TLE data is from */ + tle_t tle; /*!< TLE data. */ + gchar *filename; /*!< File name where the TLE data is from */ } loc_tle_t; void tle_update_from_files (const gchar *dir, - const gchar *filter, - gboolean silent, - GtkWidget *progress, - GtkWidget *label1, - GtkWidget *label2); + const gchar *filter, + gboolean silent, + GtkWidget *progress, + GtkWidget *label1, + GtkWidget *label2); void tle_update_from_network (gboolean silent, - GtkWidget *progress, - GtkWidget *label1, - GtkWidget *label2); + GtkWidget *progress, + GtkWidget *label1, + GtkWidget *label2); const gchar *tle_update_freq_to_str (tle_auto_upd_freq_t freq); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |