From 68f5de4eedfee0c2fae1dfbcdf925f7be8484640 Mon Sep 17 00:00:00 2001 From: Alexandru Csete Date: Sat, 19 Jan 2019 14:57:07 +0100 Subject: [PATCH] Add cycle time and threshold to rotator conf Issue #52 --- src/rotor-conf.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++- src/rotor-conf.h | 5 +++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/rotor-conf.c b/src/rotor-conf.c index c821110..f066966 100644 --- a/src/rotor-conf.c +++ b/src/rotor-conf.c @@ -2,7 +2,7 @@ /* Gpredict: Real-time satellite tracking and orbit prediction program - Copyright (C) 2001-2009 Alexandru Csete. + Copyright (C) 2001-2019 Alexandru Csete. Authors: Alexandru Csete @@ -37,13 +37,17 @@ #define GROUP "Rotator" #define KEY_HOST "Host" #define KEY_PORT "Port" +#define KEY_CYCLE "Cycle" #define KEY_AZTYPE "AzType" #define KEY_MINAZ "MinAz" #define KEY_MAXAZ "MaxAz" #define KEY_MINEL "MinEl" #define KEY_MAXEL "MaxEl" #define KEY_AZSTOPPOS "AzStopPos" +#define KEY_THLD "Threshold" +#define DEFAULT_CYCLE_MS 1000 +#define DEFAULT_THLD_DEG 5.0 /** * \brief Read rotator configuration. @@ -110,6 +114,47 @@ gboolean rotor_conf_read(rotor_conf_t * conf) return FALSE; } + /* cycle period and threshold are only saved if not default */ + if (g_key_file_has_key(cfg, GROUP, KEY_CYCLE, NULL)) + { + conf->cycle = g_key_file_get_integer(cfg, GROUP, KEY_CYCLE, &error); + if (error != NULL) + { + sat_log_log(SAT_LOG_LEVEL_ERROR, + _("%s: Error reading rotor conf from %s (%s)."), + __func__, conf->name, error->message); + g_clear_error(&error); + g_key_file_free(cfg); + return FALSE; + } + if (conf->cycle < 10) + conf->cycle = 10; + } + else + { + conf->cycle = DEFAULT_CYCLE_MS; + } + + if (g_key_file_has_key(cfg, GROUP, KEY_THLD, NULL)) + { + conf->threshold = g_key_file_get_double(cfg, GROUP, KEY_THLD, &error); + if (error != NULL) + { + sat_log_log(SAT_LOG_LEVEL_ERROR, + _("%s: Error reading rotor conf from %s (%s)."), + __func__, conf->name, error->message); + g_clear_error(&error); + g_key_file_free(cfg); + return FALSE; + } + if (conf->threshold < 0.1) + conf->threshold = 0.1; + } + else + { + conf->threshold = DEFAULT_THLD_DEG; + } + conf->aztype = g_key_file_get_integer(cfg, GROUP, KEY_AZTYPE, &error); if (error != NULL) { @@ -205,6 +250,16 @@ void rotor_conf_save(rotor_conf_t * conf) g_key_file_set_double(cfg, GROUP, KEY_MAXEL, conf->maxel); g_key_file_set_double(cfg, GROUP, KEY_AZSTOPPOS, conf->azstoppos); + if (conf->cycle == DEFAULT_CYCLE_MS) + g_key_file_remove_key(cfg, GROUP, KEY_CYCLE, NULL); + else + g_key_file_set_integer(cfg, GROUP, KEY_CYCLE, conf->cycle); + + if (conf->threshold == DEFAULT_THLD_DEG) + g_key_file_remove_key(cfg, GROUP, KEY_THLD, NULL); + else + g_key_file_set_double(cfg, GROUP, KEY_THLD, conf->threshold); + /* build filename */ confdir = get_hwconf_dir(); fname = g_strconcat(confdir, G_DIR_SEPARATOR_S, conf->name, ".rot", NULL); diff --git a/src/rotor-conf.h b/src/rotor-conf.h index 7533121..516d128 100644 --- a/src/rotor-conf.h +++ b/src/rotor-conf.h @@ -43,13 +43,14 @@ typedef struct { gchar *name; /*!< Configuration file name, less .rot */ gchar *host; /*!< hostname */ gint port; /*!< port number */ + gint cycle; /*!< cycle period in msec */ rot_az_type_t aztype; /*!< Az type */ gdouble minaz; /*!< Lower azimuth limit */ gdouble maxaz; /*!< Upper azimuth limit */ gdouble minel; /*!< Lower elevation limit */ gdouble maxel; /*!< Upper elevation limit */ - gdouble azstoppos; /*!< absolute position of rotation stops; - * will normally be equal to minaz */ + gdouble azstoppos; /*!< absolute position of rotation stops; normally = minaz */ + gdouble threshold; /*!< Angle difference that triggers new motion command */ } rotor_conf_t;