Mercurial > hg > fxanalyse
changeset 144:be87c8e78266
Code cleanup
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 14:45:24 +0100 |
parents | 09a4548e1436 |
children | ceac0c01661f |
files | Allan.c FXAnalyse.c FXAnalyse.h FXAnalyse.uir Plot.c YLCStuff.c YLCStuff.h YLCTypes.h data-provider.c data-provider.h stat.c utils.c utils.h |
diffstat | 13 files changed, 195 insertions(+), 256 deletions(-) [+] |
line wrap: on
line diff
--- a/Allan.c Wed Jan 22 14:45:23 2014 +0100 +++ b/Allan.c Wed Jan 22 14:45:24 2014 +0100 @@ -1,7 +1,7 @@ #include <ansi_c.h> #include <userint.h> -#include "YLCStuff.h" +#include "utils.h" #include "FXAllan.h" #include "Allan.h"
--- a/FXAnalyse.c Wed Jan 22 14:45:23 2014 +0100 +++ b/FXAnalyse.c Wed Jan 22 14:45:24 2014 +0100 @@ -7,29 +7,21 @@ #include <string.h> #include <future.h> -#include "YLCStuff.h" #include "FXAnalyse.h" #include "Plot.h" #include "Allan.h" #include "DDS4xAD9912.h" #include "DDS_Fox.h" #include "muParserDLL.h" +#include "utils.h" #include "stat.h" +#include "data-provider.h" #define SR_LOGGER_IP "145.238.204.91" #define DATAFOLDER "Z:\\Measures-2013" #define FREP_STEP_SIZE 50000.0 -// number of channels read -#define NCHAN 4 - -// data acquisition event -struct event { - struct timeval time; - double data[NCHAN]; -}; - // data acquisition status int acquiring; // data queue @@ -37,14 +29,12 @@ // data provider thread CmtThreadFunctionID dataProviderThread; -// data providers -int CVICALLBACK FakeDataProvider (void *functionData); -int CVICALLBACK FileDataProvider (void *functionData); -int CVICALLBACK KKDataProvider (void *functionData); - - // select which data provider to use +#ifdef NDEBUG #define DataProvider KKDataProvider +#else +#define DataProvider FakeDataProvider +#endif struct event event; double utc; @@ -52,7 +42,6 @@ double Math1, Math2, Math3, Math4, Math5; double N1, N2, N3; - // panels static int MainPanel; static int CalcNPanel; @@ -223,7 +212,7 @@ double Frequencystep2=10.0, tbegin2=0.0, Frepbefore2=0.0, Ch2before=0.0, Frequency2=0.0; double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; -volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; +int Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; double Sign1=1.0, Sign2=1.0, Sign3=0.0; @@ -269,18 +258,18 @@ // recenter struct recenter { int enabled; // recenter enabled - int Lo; // recenter microwave beatnote - int Sr; // recenter Sr beatnote - int Hg; // recenter Hg beatnote + int lo; // recenter microwave beatnote + int sr; // recenter Sr beatnote + int hg; // recenter Hg beatnote double interval; // interval double t0; // beginning of current interval }; struct recenter recenter = { .enabled = FALSE, - .Lo = FALSE, - .Sr = FALSE, - .Hg = FALSE, + .lo = FALSE, + .sr = FALSE, + .hg = FALSE, .interval = 1800.0, .t0 = 0.0 }; @@ -342,41 +331,6 @@ } -static const char * thousands(char *buffer, int size, char *fmt, double val) -{ - // compute how many separators we need - #pragma DisableFunctionRuntimeChecking log10 - int nsep = log10(fabs(val)); - nsep = (nsep > 0 ? nsep / 3 : 0); - // format value - int len = snprintf(buffer, size, fmt, val); - char *src = buffer + len; - char *dst = src + nsep; - // copy till decimal separator - while (*src != '.') - *dst-- = *src--; - // the next char is the decimal separator - int n = -1; - // copy till src and dst point to the same location - while (src != dst) { - *dst-- = *src--; - // insert separator - if (isdigit(*src) && (++n) && ((n % 3) == 0)) - *dst-- = ' '; - } - return buffer; -} - - -#define MIN(x, y) (x) < (y) ? (x) : (y) - -// MJD functiom used by the Sr programs -static inline double utc2mjd(double utc) -{ - return 15020.0 + utc / 86400.0; -} - - void logmsg(const char *frmt, ...) { char msg[1024]; @@ -669,7 +623,6 @@ return 0; } - int CVICALLBACK CB_OnStart (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -718,14 +671,6 @@ return 0; } - -void CVICALLBACK MessageCB (void *msg) -{ - if (msg != NULL) - logmsg(msg); -} - - void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int ev, int value, void *callbackData) { @@ -1383,7 +1328,7 @@ if ((utc - recenter.t0) > recenter.interval) { - if (recenter.Lo) { + if (recenter.lo) { // adjust DDS2 frequency to keep Ch4 reading at 275 kHz double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); double adj = 275000.0 - rollmean_ch4.mean; @@ -1393,7 +1338,7 @@ logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); } - if (recenter.Hg) { + if (recenter.hg) { // adjust DDS3 frequency to keep Ch2 reading at 10 kHz double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); double adj = 10000 - rollmean_ch2.mean; @@ -1403,7 +1348,7 @@ logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); } - if (recenter.Sr) { + if (recenter.sr) { // adjust DDS3 frequency to keep Ch3 reading at 10 kHz double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); double adj = 10000 - rollmean_ch3.mean; @@ -1452,7 +1397,6 @@ } } - int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1468,7 +1412,6 @@ return 0; } - int CVICALLBACK CB_OnAllanPlot (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1637,7 +1580,6 @@ return 0; } - int CVICALLBACK CB_OnMinus10k (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1678,7 +1620,6 @@ return 0; } - int CVICALLBACK CB_OnAcceptN (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1703,7 +1644,6 @@ return 0; } - int CVICALLBACK CB_OnNCalculus (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1758,7 +1698,6 @@ return 0; } - int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1789,8 +1728,6 @@ return 0; } - - int CVICALLBACK CB_OnNStop (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1829,7 +1766,6 @@ return 0; } - int CVICALLBACK CB_OnFindSign (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1870,7 +1806,6 @@ return 0; } - int CVICALLBACK CB_OnFind275K (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1900,8 +1835,7 @@ return 0; } - - int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, +int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) @@ -1916,8 +1850,7 @@ return 0; } - - int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, +int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) @@ -1946,7 +1879,6 @@ return 0; } - int CVICALLBACK CB_OnResetSlope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1963,7 +1895,6 @@ return 0; } - int CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1977,7 +1908,6 @@ return 0; } - int CVICALLBACK CB_OnCROX (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -1999,8 +1929,6 @@ return 0; } - - int CVICALLBACK CB_RecenterEnable (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -2017,7 +1945,6 @@ return 0; } - int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -2044,7 +1971,6 @@ return 0; } - int CVICALLBACK CB_OnEstimateN (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -2258,19 +2184,31 @@ switch (control) { case PANEL_RECENTER_LO: - GetCtrlVal(panel, control, &recenter.Lo); + GetCtrlVal(panel, control, &recenter.lo); break; case PANEL_RECENTER_HG: - GetCtrlVal(panel, control, &recenter.Hg); + GetCtrlVal(panel, control, &recenter.hg); break; case PANEL_RECENTER_SR: - GetCtrlVal(panel, control, &recenter.Sr); + GetCtrlVal(panel, control, &recenter.sr); break; } break; } return 0; } + +int CVICALLBACK CB_SrDatalogger (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_COMMIT: + GetCtrlVal(panel, control, &Sr_datalogger_enabled); + break; + } + return 0; +} int CVICALLBACK CB_DedriftDDSFreq (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
--- a/FXAnalyse.h Wed Jan 22 14:45:23 2014 +0100 +++ b/FXAnalyse.h Wed Jan 22 14:45:24 2014 +0100 @@ -80,7 +80,7 @@ #define PANEL_ADEV_Math5 43 /* control type: radioButton, callback function: CB_OnAllanPlot */ #define PANEL_PLOT_Math3 44 /* control type: radioButton, callback function: CB_OnFreqPlot */ #define PANEL_SAVE_EXTRA 45 /* control type: radioButton, callback function: (none) */ -#define PANEL_SR_LOGGER 46 /* control type: radioButton, callback function: (none) */ +#define PANEL_SR_LOGGER 46 /* control type: radioButton, callback function: CB_SrDatalogger */ #define PANEL_SAVE_SR 47 /* control type: radioButton, callback function: (none) */ #define PANEL_ADEV_Math3 48 /* control type: radioButton, callback function: CB_OnAllanPlot */ #define PANEL_MATHSTRING4 49 /* control type: string, callback function: CB_ChangeMath */ @@ -204,6 +204,7 @@ int CVICALLBACK CB_ShowLog(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_Sign3(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_SlopeX2(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); +int CVICALLBACK CB_SrDatalogger(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK QuitCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
--- a/Plot.c Wed Jan 22 14:45:23 2014 +0100 +++ b/Plot.c Wed Jan 22 14:45:24 2014 +0100 @@ -1,7 +1,7 @@ #include <ansi_c.h> #include <userint.h> -#include "YLCStuff.h" +#include "utils.h" #include "FXPlot.h" #include "Plot.h"
--- a/YLCStuff.c Wed Jan 22 14:45:23 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -//============================================================================== -// -// Title: YLCStuff.c -// Purpose: Various stuff used by femtosoftYLC, like math parser callbacks -// and personnal types -// -// Created on: 19/08/2008 at 10:06:43 by Yann Le Coq. -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -//============================================================================== -// Include files - -//#include "YLCStuff.h" - -//============================================================================== -// Constants - -//============================================================================== -// Types - -//============================================================================== -// Static global variables - -//============================================================================== -// Static functions - -//============================================================================== -// Global variables - -//============================================================================== -// Global functions - -/// HIFN What does your function do? -/// HIPAR x/What inputs does your function expect? -/// HIRET What does your function return? -double Peta (double x) { - return 1.0e15*x ; -}; - -double Tera (double x) { - return 1.0e12*x ; -}; - -double Giga (double x) { - return 1.0e9*x ; -}; - -double Mega (double x) { - return 1.0e6*x ; -}; - -double kilo (double x) { - return 1.0e3*x ; -}; - -double milli(double x) { - return 1.0e-3*x ; -}; - -double micro(double x){ - return 1.0e-6*x ; -}; - -double nano (double x){ - return 1.0e-9*x ; -}; - -double pico (double x){ - return 1.e-12*x ; -}; - -double femto(double x){ - return 1.0e-15*x ; -}; -
--- a/YLCStuff.h Wed Jan 22 14:45:23 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -//============================================================================== -// -// Title: YLCStuff.h -// Purpose: A short description of the interface. -// -// Created on: 19/08/2008 at 10:06:43 by pascal blonde. -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -#ifndef __YLCStuff_H__ -#define __YLCStuff_H__ - -#ifdef __cplusplus - extern "C" { -#endif - -//============================================================================== -// Include files - -#include "cvidef.h" - -//============================================================================== -// Constants - -//============================================================================== -// Types - -typedef int bool; - -#define FALSE 0 -#define TRUE 1 - -typedef int PanelHandle ; - - -//============================================================================== -// External variables - -//============================================================================== -// Global functions - -double Peta (double x); -double Tera (double x); -double Giga (double x); -double Mega (double x); -double kilo (double x); -double milli(double x); -double micro(double x); -double nano (double x); -double pico (double x); -double femto(double x); -double atto (double x); - -#ifdef __cplusplus - } -#endif - -#endif /* ndef __YLCStuff_H__ */
--- a/YLCTypes.h Wed Jan 22 14:45:23 2014 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -typedef int bool; - -#define FALSE 0 -#define TRUE 1 - -typedef int PanelHandle ; -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data-provider.c Wed Jan 22 14:45:24 2014 +0100 @@ -0,0 +1,34 @@ +#include <ansi_c.h> +#include <userint.h> + +/* message buffer */ +#define DATA_PROVIDER_MSGLEN 256 +#define DATA_PROVIDER_MSGNUM 16 +static char messages[DATA_PROVIDER_MSGLEN][DATA_PROVIDER_MSGNUM]; +static unsigned int messageid = 0; + +/* logging function defined in main program */ +extern void logmsg(const char *frmt, ...); + +/* message callback */ +void CVICALLBACK MessageCB (void *msg) +{ + if (msg != NULL) + logmsg(msg); +} + +void SendMessage(int threadId, const char *frmt, ...) +{ + /* message buffer */ + char *message = messages[messageid++ % DATA_PROVIDER_MSGNUM]; + + /* format message */ + va_list args; + va_start(args, frmt); + vsnprintf(message, DATA_PROVIDER_MSGLEN - 1, frmt, args); + va_end(args); + + /* signal main thread */ + PostDeferredCallToThread(MessageCB, message, threadId); +} +
--- a/data-provider.h Wed Jan 22 14:45:23 2014 +0100 +++ b/data-provider.h Wed Jan 22 14:45:24 2014 +0100 @@ -12,23 +12,21 @@ /* callback receiving messages in the main thread */ void CVICALLBACK MessageCB (void *callbackData); +/* number of data channels */ +#define NCHAN 4 + /* data acquisition event */ struct event { struct timeval time; - double data[4]; + double data[NCHAN]; }; -/* message buffer */ -#define DATA_PROVIDER_MSGLEN 256 -#define DATA_PROVIDER_MSGNUM 16 -static char messages[DATA_PROVIDER_MSGLEN][DATA_PROVIDER_MSGNUM]; -static unsigned int messageid = 0; +/* send messages to the main thread */ +void SendMessage(int threadId, const char *frmt, ...); -#define SendMessage(threadId, ...) \ - do { \ - char *message = messages[messageid++ % DATA_PROVIDER_MSGNUM]; \ - snprintf(message, DATA_PROVIDER_MSGLEN - 1, ##__VA_ARGS__); \ - PostDeferredCallToThread(MessageCB, message, threadId); \ - } while (0) +/* data providers */ +int CVICALLBACK FakeDataProvider (void *functionData); +int CVICALLBACK FileDataProvider (void *functionData); +int CVICALLBACK KKDataProvider (void *functionData); #endif
--- a/stat.c Wed Jan 22 14:45:23 2014 +0100 +++ b/stat.c Wed Jan 22 14:45:24 2014 +0100 @@ -13,12 +13,9 @@ void stat_accumulate(struct stat *s, double value) { s->samples += 1; - if (s->samples > 1) s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); - s->mean = ((s->samples - 1) * s->mean + value) / s->samples; - s->previous = value; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils.c Wed Jan 22 14:45:24 2014 +0100 @@ -0,0 +1,78 @@ +#include <ansi_c.h> + +const char * thousands(char *buffer, int size, char *fmt, double val) +{ + /* compute how many separators we need */ + #pragma DisableFunctionRuntimeChecking log10 + int nsep = log10(fabs(val)); + nsep = (nsep > 0 ? nsep / 3 : 0); + /* format value */ + int len = snprintf(buffer, size, fmt, val); + char *src = buffer + len; + char *dst = src + nsep; + /* copy till decimal separator */ + while (*src != '.') + *dst-- = *src--; + /* the next char is the decimal separator */ + int n = -1; + /* copy till src and dst point to the same location */ + while (src != dst) { + *dst-- = *src--; + /* insert separator */ + if (isdigit(*src) && (++n) && ((n % 3) == 0)) + *dst-- = ' '; + } + return buffer; +} + + +double Peta(double x) +{ + return 1.0e15 * x; +} + +double Tera(double x) +{ + return 1.0e12 * x; +} + +double Giga(double x) +{ + return 1.0e9 * x; +} + +double Mega(double x) +{ + return 1.0e6 * x; +} + +double kilo(double x) +{ + return 1.0e3 * x; +} + +double milli(double x) +{ + return 1.0e-3 * x; +} + +double micro(double x) +{ + return 1.0e-6 * x; +} + +double nano(double x) +{ + return 1.0e-9 * x; +} + +double pico(double x) +{ + return 1.e-12 * x; +} + +double femto(double x) +{ + return 1.0e-15 * x; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils.h Wed Jan 22 14:45:24 2014 +0100 @@ -0,0 +1,36 @@ +#ifndef __FXANALISE_UTILS_H__ +#define __FXANALISE_UTILS_H__ + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef MIN +#define MIN(x, y) (x) < (y) ? (x) : (y) +#endif + +/* format floating points numbers accordingly to fmt and asdd thousands separator */ +const char * thousands(char *buffer, int size, char *fmt, double val); + +/* MJD functiom used by the Sr programs */ +static inline double utc2mjd(double utc) +{ + return 15020.0 + utc / 86400.0; +} + +double Peta(double x); +double Tera(double x); +double Giga(double x); +double Mega(double x); +double kilo(double x); +double milli(double x); +double micro(double x); +double nano(double x); +double pico(double x); +double femto(double x); +double atto(double x); + +#endif