[Gpredict-svn] SF.net SVN: gpredict: [19] trunk/src
Real time satellite tracking and orbit prediction
Status: Beta
Brought to you by:
csete
From: <cs...@us...> - 2008-01-24 21:39:31
|
Revision: 19 http://gpredict.svn.sourceforge.net/gpredict/?rev=19&view=rev Author: csete Date: 2008-01-24 13:39:25 -0800 (Thu, 24 Jan 2008) Log Message: ----------- Added files with functions to read and save rotator configuration. Added Paths: ----------- trunk/src/rotor-conf.c trunk/src/rotor-conf.h Added: trunk/src/rotor-conf.c =================================================================== --- trunk/src/rotor-conf.c (rev 0) +++ trunk/src/rotor-conf.c 2008-01-24 21:39:25 UTC (rev 19) @@ -0,0 +1,138 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.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/ + +*/ + +#include <gtk/gtk.h> +#include <glib/gi18n.h> +#include "sat-log.h" +#include "compat.h" + +#include "rotor-conf.h" + +#define GROUP "Rotator" +#define KEY_MODEL "Model" +#define KEY_ID "ID" +#define KEY_TYPE "Type" +#define KEY_PORT "Port" +#define KEY_SPEED "Speed" + + +/** \brief Read rotator configuration. + * \param conf Pointer to a rotor_conf_t structure where the data will be + * stored. + * + * This function reads a rotoator configuration from a .rot file into conf. + * conf->name must contain the file name of the configuration (no path, just + * file name and without the .rot extension). + */ +gboolean rotor_conf_read (rotor_conf_t *conf) +{ + GKeyFile *cfg = NULL; + gchar *confdir; + gchar *fname; + + + if (conf->name == NULL) + return FALSE; + + confdir = get_conf_dir(); + fname = g_strconcat (confdir, G_DIR_SEPARATOR_S, + "hwconf", G_DIR_SEPARATOR_S, + conf->name, ".rot", NULL); + g_free (confdir); + + /* open .grc file */ + cfg = g_key_file_new (); + g_key_file_load_from_file(cfg, fname, 0, NULL); + + if (cfg == NULL) { + sat_log_log (SAT_LOG_LEVEL_ERROR, + _("%s: Could not load file %s\n"), + __FUNCTION__, fname); + g_free (fname); + + return FALSE; + } + + g_free (fname); + + /* read parameters */ + conf->model = g_key_file_get_string (cfg, GROUP, KEY_MODEL, NULL); + conf->id = g_key_file_get_integer (cfg, GROUP, KEY_ID, NULL); + conf->type = g_key_file_get_integer (cfg, GROUP, KEY_TYPE, NULL); + conf->port = g_key_file_get_string (cfg, GROUP, KEY_PORT, NULL); + conf->speed = g_key_file_get_integer (cfg, GROUP, KEY_SPEED, NULL); + + g_key_file_free (cfg); + + return TRUE; +} + + +/** \brief Save rotator configuration. + * \param conf Pointer to the rotator configuration. + * + * This function saves the rotator configuration stored in conf to a + * .rig file. conf->name must contain the file name of the configuration + * (no path, just file name and without the .rot extension). + */ +void rotor_conf_save (radio_conf_t *conf) +{ + GKeyFile *cfg = NULL; + gchar *confdir; + gchar *fname; + gchar *data; + gsize len; + + if (conf->name == NULL) + return; + + /* create a config structure */ + cfg = g_key_file_new(); + + g_key_file_set_string (cfg, GROUP, KEY_MODEL, conf->model); + g_key_file_set_integer (cfg, GROUP, KEY_ID, conf->id); + g_key_file_set_integer (cfg, GROUP, KEY_TYPE, conf->type); + g_key_file_set_string (cfg, GROUP, KEY_PORT, conf->port); + g_key_file_set_integer (cfg, GROUP, KEY_SPEED, conf->speed); + + /* convert to text sdata */ + data = g_key_file_to_data (cfg, &len, NULL); + + confdir = get_conf_dir(); + fname = g_strconcat (confdir, G_DIR_SEPARATOR_S, + "hwconf", G_DIR_SEPARATOR_S, + conf->name, ".rot", NULL); + g_free (confdir); + + g_file_set_contents (fname, data, len, NULL); + + g_free (fname); + g_free (data); + g_key_file_free (cfg); +} Added: trunk/src/rotor-conf.h =================================================================== --- trunk/src/rotor-conf.h (rev 0) +++ trunk/src/rotor-conf.h 2008-01-24 21:39:25 UTC (rev 19) @@ -0,0 +1,60 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + Gpredict: Real-time satellite tracking and orbit prediction program + + Copyright (C) 2001-2007 Alexandru Csete. + + Authors: Alexandru Csete <oz...@gm...> + + Comments, questions and bugreports should be submitted via + http://sourceforge.net/projects/groundstation/ + More details can be found at the project home page: + + http://groundstation.sourceforge.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/ + + +*/ +#ifndef ROTOR_CONF_H +#define ROTOR_CONF_H 1 + +#include <glib.h> + + + + +/** \brief Rotator type definitions. */ +typedef enum { + ROTOR_TYPE_AZ = 1, /*!< Azimuth rotator. */ + ROTOR_TYPE_EL = 2, /*!< Elevation rotator. */ + ROTOR_TYPE_AZEL = 3 /*!< Both azimuth and elevation rotator. */ +} rotor_type_t; + + +/** \brief Rotator configuration. */ +typedef struct { + gchar *name; /*!< Configuration file name, less .rot */ + gchar *model; /*!< Rotator model. */ + guint id; /*!< Hamlib ID. */ + rotor_type_t type; /*!< Rotator type. */ + gchar *port; /*!< Device name, e.g. /dev/ttyS0. */ + guint speed; /*!< Serial speed. */ +} rotor_conf_t; + + +gboolean rotor_conf_read (rotor_conf_t *conf); +void rotor_conf_save (rtor_conf_t *conf); + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |