Mercurial > hg > fxanalyse
diff FXAnalyse.c @ 169:97112b45b838
Get Sr data logger parameters from configuration file. Code reorganization.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 14 Feb 2014 16:58:19 +0100 |
parents | 4de7f2c9f328 |
children | a4fcebb5941b |
line wrap: on
line diff
--- a/FXAnalyse.c Fri Feb 14 16:58:08 2014 +0100 +++ b/FXAnalyse.c Fri Feb 14 16:58:19 2014 +0100 @@ -17,10 +17,11 @@ #include "stat.h" #include "future.h" #include "data-provider.h" +#include "sr-data-logger.h" +#include "config.h" +#include "logging.h" -#define CONFIGFILE "FXAnalyse.ini" -#define SR_LOGGER_IP "145.238.204.91" #define DATAFOLDER "Z:\\Measures-2014" #define FREP_STEP_SIZE 50000.0 @@ -51,14 +52,11 @@ double N1, N2, N3; double Ndiv = 8.0; double Sign1 = 1.0, Sign2 = 1.0, Sign3 = 0.0; - - void *MathParser1, *MathParser2, *MathParser3, *MathParser4, *MathParser5; // panels static int MainPanel; -static int LoggingPanel; static int CalcNPanel; static int EstimateNPanel; @@ -334,60 +332,7 @@ } -void logmsg(const char *frmt, ...) -{ - char msg[1024]; - int len = 0; - - // timestamp - len += sprintf(msg, "%014.3f ", utc); - time_t now = time(NULL); - struct tm *t = localtime(&now); - len += strftime(msg + len, sizeof(msg) - len, "%d-%m-%Y %H:%M:%S ", t); - - // message - va_list args; - va_start(args, frmt); - len += vsnprintf(msg + len, sizeof(msg) - len, frmt, args); - va_end(args); - - // add newline - len = MIN(len, sizeof(msg) - 2); - msg[len] = '\n'; - msg[len + 1] = '\0'; - - // display message - SetCtrlVal(LoggingPanel, LOGGING_LOGGING, msg); -} - - -int Sr_datalogger_enabled = FALSE; - - -// Sr data logger -int Sr_datalogger_send(const char* id, double utc, double data) -{ - static unsigned int handle = 0; - char buffer[1024]; - - // try to connect and quit if unsuccessfull - if (handle == 0) { - if (ConnectToTCPServer(&handle, 3491, SR_LOGGER_IP, NULL, NULL, 1) < 0) { - logmsg("Sr data logger connection error"); - return -1; - } - logmsg("connected to Sr data logger"); - } - - snprintf(buffer, sizeof(buffer), "%s %.7f %.8f", id, utc2mjd(utc), data); - if (ClientTCPWrite(handle, buffer, strlen(buffer) + 1, 0) < 0) { - // try to reconnect and resend - handle = 0; - Sr_datalogger_send(id, utc, data); - } - - return 0; -} +static struct datalogger datalogger; void * muParserNew() @@ -441,22 +386,19 @@ if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0) return -1; - if ((LoggingPanel = LoadPanel (0, "FXAnalyse.uir", LOGGING)) < 0) - return -1; if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0) return -1; if ((EstimateNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN)) < 0) return -1; - // construct configuration file path - char pathname[MAX_PATHNAME_LEN]; - char project[MAX_PATHNAME_LEN]; - GetProjectDir(project); - MakePathname(project, CONFIGFILE, pathname); - + // logging + logger_init(); + // load configuration file + char path[MAX_PATHNAME_LEN]; + GetIniFilePath(path); IniText configuration = Ini_New(TRUE); - Ini_ReadFromFile(configuration, pathname); + Ini_ReadFromFile(configuration, path); // get AD9956 configuration parameters char host[256]; @@ -475,6 +417,9 @@ // dispose configuration Ini_Dispose(configuration); + // Sr data logger + sr_datalogger_init(&datalogger); + // dedrift DDS DDSFox_Initialize(&DDS1xAD9956, host, port, dedrift.freq0); @@ -619,7 +564,7 @@ case EVENT_COMMIT: if (acquiring) break; - + logmsg("start"); SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); acquiring = 1; @@ -1324,8 +1269,7 @@ datafile_append(d, id, timestr); // send Sr frequency (Math4) to Sr data logger - if (Sr_datalogger_enabled) - Sr_datalogger_send("FEMTO2", utc, Math4); + sr_datalogger_send(&datalogger, utc, Math4); } break; } @@ -2055,7 +1999,7 @@ { case EVENT_COMMIT: GetCtrlVal(panel, PANEL_SHOWLOG, &visible); - SetPanelAttribute(LoggingPanel, ATTR_VISIBLE, visible); + logger_panel_visible(visible); break; } return 0; @@ -2067,7 +2011,7 @@ switch (event) { case EVENT_CLOSE: - SetPanelAttribute(LoggingPanel, ATTR_VISIBLE, 0); + logger_panel_visible(0); SetCtrlVal(MainPanel, PANEL_SHOWLOG, 0); break; } @@ -2155,7 +2099,7 @@ switch (event) { case EVENT_COMMIT: - GetCtrlVal(panel, control, &Sr_datalogger_enabled); + GetCtrlVal(panel, control, &datalogger.enabled); break; } return 0;