Mercurial > hg > fxanalyse
changeset 142:fd085d61e4ca
Rework data logging
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 14:45:23 +0100 |
parents | e1dec4f11831 |
children | 09a4548e1436 |
files | DDS4xAD9912.c DDS4xAD9912.h FXAnalyse.c FXAnalyse.h FXAnalyse.uir |
diffstat | 5 files changed, 147 insertions(+), 195 deletions(-) [+] |
line wrap: on
line diff
--- a/DDS4xAD9912.c Wed Jan 22 14:45:22 2014 +0100 +++ b/DDS4xAD9912.c Wed Jan 22 14:45:23 2014 +0100 @@ -1,38 +1,23 @@ +#include <ansi_c.h> #include <utility.h> - -//============================================================================== -// -// Title: DDS4xAD9912.c -// Purpose: -// -// Created on: by Volodimer Laurent, modified by YLC -// Copyright: syrte. All Rights Reserved. -// -//============================================================================== - -//============================================================================== -// Include files - -#include "DDS4xAD9912.h" #include <userint.h> #include <tcpsupp.h> -#include <ansi_c.h> -//============================================================================== -// Global functions +#include "DDS4xAD9912.h" + static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) - { +{ switch(xType) - { - case TCP_DISCONNECT : + { + case TCP_DISCONNECT: break; - case TCP_DATAREADY : - ClientTCPRead (handle, Response, sizeof(Response), 0); + case TCP_DATAREADY: + ClientTCPRead(handle, Response, sizeof(Response), 0); break; - } - return 0; } + return 0; +} //============================================================================== @@ -43,8 +28,6 @@ // PARAM : Buffer contenant la chaîne de caractères à envoyer // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK //============================================================================== - - static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) { int port = 0; @@ -91,42 +74,21 @@ // PARAM : // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK //============================================================================== - int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) - { - int res_1,res_2; + { + int chan, rv; - sprintf(Request,"set;%i;%i",1,17); - res_1 = DDS4xAD9912_SendCmd(1,Request) ; - if(res_1 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_1 Reset failed !") ; - } - else Instance->Frequency1 = 0.0 ; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4xAD9912_SendCmd(2,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_2 Reset failed !") ; + for (chan = 1; chan < 5; chan++) { + sprintf(Request, "set;%i;%i", 1, 17); + rv = DDS4xAD9912_SendCmd(chan, Request); + if (rv < 0) { + MessagePopup("DDS Serveur", "DDS4xAD9912 reset failed"); + return -1; } - else Instance->Frequency2 = 0.0; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4xAD9912_SendCmd(3,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_3 Reset failed !") ; - } - else Instance->Frequency3 = 0.0; - - sprintf(Request,"set;%i;%i",1,17); - res_2 = DDS4xAD9912_SendCmd(4,Request) ; - if(res_2 <0) { - MessagePopup("DDS Serveur", "DDS4xAD9912_4 Reset failed !") ; - } - else Instance->Frequency4 = 0.0; - - - return (res_1+res_2); - } + Instance->frequency[chan - 1] = 0.0; + } + return 0; +} //============================================================================== @@ -141,7 +103,7 @@ double Word=WORD(Freq,Clk) ; double reste ; - int res_0 ; + int rv; unsigned char b5,b4,b3,b2,b1,b0 ; b5=(unsigned char)(Word/E40); @@ -153,25 +115,22 @@ reste = (Word - E40*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); - res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; - if (res_0 <0) { - MessagePopup("DDS Serveur", "SetFrequency function failed !") ; - } - else { - if (DDSNum==1) Instance->Frequency1 = Freq - reste*Clk/E48 ; - if (DDSNum==2) Instance->Frequency2 = Freq - reste*Clk/E48 ; - if (DDSNum==3) Instance->Frequency3 = Freq - reste*Clk/E48 ; - if (DDSNum==4) Instance->Frequency4 = Freq - reste*Clk/E48 ; - } ; - - sprintf(Request,"set;%i;%i",0,18); // IO_Update logiciel - res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; - if (res_0 <0) { - MessagePopup("DDS Serveur", "IO_Update function failed !") ; - } - return(res_0) ; - - } + rv = DDS4xAD9912_SendCmd(DDSNum, Request) ; + if (rv < 0) { + MessagePopup("DDS Serveur", "SetFrequency function failed !"); + return -1; + } + + sprintf(Request,"set;%i;%i",0,18); + rv = DDS4xAD9912_SendCmd(DDSNum, Request) ; + if (rv < 0) { + MessagePopup("DDS Serveur", "IO_Update function failed !"); + return -1; + } + + Instance->frequency[DDSNum - 1] = Freq - reste * Clk / E48; + return 0; +} /* @@ -215,17 +174,6 @@ double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel) { - switch (channel) { - case 1: - return dds->Frequency1; - case 2: - return dds->Frequency2; - case 3: - return dds->Frequency3; - case 4: - return dds->Frequency4; - default: - return 0.0; - } + return dds->frequency[channel - 1]; }
--- a/DDS4xAD9912.h Wed Jan 22 14:45:22 2014 +0100 +++ b/DDS4xAD9912.h Wed Jan 22 14:45:23 2014 +0100 @@ -44,10 +44,7 @@ // DDS4xAD9912_Data : the data of crypto class DDS4xAD9912 typedef struct { - double Frequency1 ; - double Frequency2 ; - double Frequency3 ; - double Frequency4 ; + double frequency[4]; } DDS4xAD9912_Data ; //==============================================================================
--- a/FXAnalyse.c Wed Jan 22 14:45:22 2014 +0100 +++ b/FXAnalyse.c Wed Jan 22 14:45:23 2014 +0100 @@ -42,10 +42,11 @@ int CVICALLBACK FileDataProvider (void *functionData); int CVICALLBACK KKDataProvider (void *functionData); + // select which data provider to use #define DataProvider KKDataProvider - +struct event event; double utc; double Ch1, Ch2, Ch3, Ch4; double Math1, Math2, Math3, Math4, Math5; @@ -285,7 +286,63 @@ }; -char * thousands(char *buffer, int size, char *fmt, double val) +// data loggging +struct datafile { + char *name; + double *data; + int nchan; + int control; + int write; +}; + + +struct datafile datafiles[] = { + { "Raw", event.data, 4, PANEL_SAVE_RAW, FALSE }, + { "DDS", DDS4xAD9912.frequency, 4, PANEL_SAVE_DDS, FALSE }, + { "Lo", &Math2, 1, PANEL_SAVE_LO, FALSE }, + { "Hg", &Math3, 1, PANEL_SAVE_HG, FALSE }, + { "Sr", &Math4, 1, PANEL_SAVE_SR, FALSE }, + { "Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE }, + { NULL, } +}; + + +static void write_data(const char *folder, const char *name, const char *id, + const char *timestr, double utc, double *v, int nchan) +{ + char line[1024]; + char filename[FILENAME_MAX]; + + // construct filename in the form folder\\id-name.txt + snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name); + + int fd = OpenFile(filename, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); + switch (nchan) + { + case 1: + Fmt(line, "%s\t%f[p3]\t%f[p3]", + timestr, utc, v[0]); + break; + case 4: + Fmt(line, "%s\t%f[p3]\t%f[p3]\t%f[p3]\t%f[p3]\t%f[p3]", + timestr, utc, v[0], v[1], v[2], v[3]); + break; + default: + strcpy(line, "?"); + } + WriteLine(fd, line, -1); + CloseFile(fd); +} + + +static inline void datafile_append(struct datafile *d, char *id, char *timestr) +{ + if (d->write) + write_data(DATAFOLDER, d->name, id, timestr, utc, d->data, d->nchan); +} + + +static const char * thousands(char *buffer, int size, char *fmt, double val) { // compute how many separators we need #pragma DisableFunctionRuntimeChecking log10 @@ -346,8 +403,12 @@ SetCtrlVal(LoggingPanel, LOGGING_LOGGING, msg); } + +int Sr_datalogger_enabled = FALSE; + + // Sr data logger -int sendLogger(const char* id, double utc, double data) +int Sr_datalogger_send(const char* id, double utc, double data) { static unsigned int handle = 0; char buffer[1024]; @@ -365,12 +426,13 @@ if (ClientTCPWrite(handle, buffer, strlen(buffer) + 1, 0) < 0) { // try to reconnect and resend handle = 0; - sendLogger(id, utc, data); + Sr_datalogger_send(id, utc, data); } return 0; } + muParserHandle_t initMathParser() { muParserHandle_t parser = mupCreate(); @@ -382,10 +444,10 @@ mupDefineVar(parser, "Ch2", &Ch2); mupDefineVar(parser, "Ch3", &Ch3); mupDefineVar(parser, "Ch4", &Ch4); - mupDefineVar(parser, "DDS1", &(DDS4xAD9912.Frequency1)); - mupDefineVar(parser, "DDS2", &(DDS4xAD9912.Frequency2)); - mupDefineVar(parser, "DDS3", &(DDS4xAD9912.Frequency3)); - mupDefineVar(parser, "DDS4", &(DDS4xAD9912.Frequency4)); + mupDefineVar(parser, "DDS1", &(DDS4xAD9912.frequency[0])); + mupDefineVar(parser, "DDS2", &(DDS4xAD9912.frequency[1])); + mupDefineVar(parser, "DDS3", &(DDS4xAD9912.frequency[2])); + mupDefineVar(parser, "DDS4", &(DDS4xAD9912.frequency[3])); mupDefineVar(parser, "N1", &N1); mupDefineVar(parser, "N2", &N2); mupDefineVar(parser, "N3", &N3); @@ -412,36 +474,6 @@ } -void writeData(const char *folder, const char *name, const char *id, - const char *timestr, double utc, double value) -{ - char line[1024]; - char filename[FILENAME_MAX]; - - // construct filename in the form folder\\id-name.txt - snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name); - - int fd = OpenFile(filename, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); - Fmt(line, "%s\t%f[p3]\t%f[p3]", timestr, utc, value); - WriteLine(fd, line, -1); - CloseFile(fd); -} - -void writeData4(const char *folder, const char *name, const char *id, - const char *timestr, double utc, double v1, double v2, double v3, double v4) -{ - char line[1024]; - char filename[FILENAME_MAX]; - - // construct filename in the form folder\\id-name.txt - snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name); - - int fd = OpenFile(filename, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); - Fmt(line, "%s\t%f[p3]\t%f[p3]\t%f[p3]\t%f[p3]\t%f[p3]", timestr, utc, v1, v2, v3, v4); - WriteLine(fd, line, -1); - CloseFile(fd); -} - void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, int value, void *callbackData); @@ -489,14 +521,14 @@ MathParser2 = initMathParser(); mupDefineVar(MathParser2, "Math1", &Math1); - mupDefineVar(MathParser2, "DDS", &(DDS4xAD9912.Frequency1)); + mupDefineVar(MathParser2, "DDS", &(DDS4xAD9912.frequency[0])); GetCtrlVal(MainPanel, PANEL_MATHSTRING2, expr); mupSetExpr(MathParser2, expr); MathParser3 = initMathParser(); mupDefineVar(MathParser3, "Math1", &Math1); mupDefineVar(MathParser3, "Math2", &Math2); - mupDefineVar(MathParser3, "DDS", &(DDS4xAD9912.Frequency2)); + mupDefineVar(MathParser3, "DDS", &(DDS4xAD9912.frequency[1])); GetCtrlVal(MainPanel, PANEL_MATHSTRING3, expr); mupSetExpr(MathParser3, expr); @@ -703,7 +735,6 @@ void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int ev, int value, void *callbackData) { - struct event event; int read; switch (ev) { @@ -944,7 +975,7 @@ // adjust DDS3 to keep beatnote within the bandpass filter. prediction double fDDS3 = FrequencyDDS3Init - DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2); - DeltaDDS3 = fDDS3 - DDS4xAD9912.Frequency3; + DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); printf("deltaDDS3 = %g\n", DeltaDDS3); SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); @@ -966,11 +997,11 @@ break; } - double fDDS2 = DDS4xAD9912.Frequency2 + 275000 - Ch4; + double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); - double fDDS3 = DDS4xAD9912.Frequency3 + 10000 - Ch2; + double fDDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; DeltaDDS3 = DeltaDDS3 + 10000 - Ch2; SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); @@ -1010,7 +1041,7 @@ // adjust DDS3 to keep beatnote within the bandpass filter. prediction double fDDS3 = FrequencyDDS3Init + DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1); - DeltaDDS3 = fDDS3 - DDS4xAD9912.Frequency3; + DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); @@ -1088,8 +1119,8 @@ f_beat_Sr_plus = f_beat_Sr_minus = 0.0; // record current DDS frequencies - FrequencyDDSBesInit = DDS4xAD9912.Frequency2; - FrequencyDDS3Init = DDS4xAD9912.Frequency3; + FrequencyDDSBesInit = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); + FrequencyDDS3Init = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); // next step Measuring_3 += 1; @@ -1137,7 +1168,7 @@ } // adjust DDS frequency to keep 55 MHz tracker oscillator locked - double fDDS2 = DDS4xAD9912.Frequency2 + 275000 - Ch4; + double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); @@ -1414,53 +1445,13 @@ char id[7]; strftime(id, sizeof(id), "%y%m%d", ltime); - int save; - - // write counter data to disk - GetCtrlVal(MainPanel, PANEL_SAVE_RAW_DATA, &save); - if (save) { - writeData4(DATAFOLDER, "Raw", id, timestr, utc, Ch1, Ch2, Ch3, Ch4); - } - - // write Lo frequency (Math2) to disk - GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &save); - if (save) { - writeData(DATAFOLDER, "Lo", id, timestr, utc, Math2); - } - - // write Hg frequency (Math3) to disk - GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save); - if (save) { - writeData(DATAFOLDER, "Hg", id, timestr, utc, Math3); - writeData("C:\\Femto\\Results", "Hg", id, timestr, utc, Math3); - } - - // write Sr frequency (Math4) to disk - GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4SAVE, &save); - if (save) { - writeData(DATAFOLDER, "Sr", id, timestr, utc, Math4); - } + // write datafiles + for (struct datafile *d = datafiles; d->data; d++) + datafile_append(d, id, timestr); // send Sr frequency (Math4) to Sr data logger - GetCtrlVal(MainPanel, PANEL_SR_LOGGER, &save); - if (save) { - sendLogger("FEMTO2", utc, Math4); - } - - - // write ExtraMath (Math5) to disk - GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save); - if (save) { - writeData(DATAFOLDER, "Ex", id, timestr, utc, Math5); - } - - // write DDS freqs to disk - GetCtrlVal(MainPanel, PANEL_SAVE_DDS_FREQS, &save); - if (save) { - writeData4(DATAFOLDER, "DDS", id, timestr, utc, - DDS4xAD9912.Frequency1, DDS4xAD9912.Frequency2, - DDS4xAD9912.Frequency3, DDS4xAD9912.Frequency4); - } + if (Sr_datalogger_enabled) + Sr_datalogger_send("FEMTO2", utc, Math4); } break; @@ -2236,6 +2227,22 @@ return 0; } +int CVICALLBACK CB_SaveData (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_COMMIT: + for (struct datafile *d = datafiles; d->data; d++) { + if (d->control == control) + GetCtrlVal(panel, control, &(d->write)); + } + break; + } + return 0; +} + + int CVICALLBACK CB_RecenterInterval (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
--- a/FXAnalyse.h Wed Jan 22 14:45:22 2014 +0100 +++ b/FXAnalyse.h Wed Jan 22 14:45:23 2014 +0100 @@ -79,14 +79,14 @@ #define PANEL_TEXTMSG_15 42 /* control type: textMsg, callback function: (none) */ #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_CHECKBOX_MATH5SAVE 45 /* control type: radioButton, callback function: (none) */ +#define PANEL_SAVE_EXTRA 45 /* control type: radioButton, callback function: (none) */ #define PANEL_SR_LOGGER 46 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_MATH4SAVE 47 /* control type: radioButton, callback function: (none) */ +#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 */ #define PANEL_PLOT_Math2 50 /* control type: radioButton, callback function: CB_OnFreqPlot */ -#define PANEL_CHECKBOX_MATH3SAVE 51 /* control type: radioButton, callback function: (none) */ -#define PANEL_CHECKBOX_MATH2SAVE 52 /* control type: radioButton, callback function: (none) */ +#define PANEL_SAVE_HG 51 /* control type: radioButton, callback function: (none) */ +#define PANEL_SAVE_LO 52 /* control type: radioButton, callback function: (none) */ #define PANEL_ADEV_Math2 53 /* control type: radioButton, callback function: CB_OnAllanPlot */ #define PANEL_MATHSTRING3 54 /* control type: string, callback function: CB_ChangeMath */ #define PANEL_MATHSTRING1 55 /* control type: string, callback function: CB_ChangeMath */ @@ -125,10 +125,10 @@ #define PANEL_MEASURE_SLOPE 88 /* control type: LED, callback function: CB_MeasureSlope */ #define PANEL_SLOPE_MEASURED 89 /* control type: numeric, callback function: (none) */ #define PANEL_RESET_DEDRIFT_DDS 90 /* control type: command, callback function: CB_ResetDedriftDDS */ -#define PANEL_SAVE_RAW_DATA 91 /* control type: radioButton, callback function: (none) */ +#define PANEL_SAVE_RAW 91 /* control type: radioButton, callback function: (none) */ #define PANEL_SHOWLOG 92 /* control type: radioButton, callback function: CB_ShowLog */ #define PANEL_SLOPEX2 93 /* control type: radioButton, callback function: CB_SlopeX2 */ -#define PANEL_SAVE_DDS_FREQS 94 /* control type: radioButton, callback function: (none) */ +#define PANEL_SAVE_DDS 94 /* control type: radioButton, callback function: (none) */ #define PANEL_DECORATION_2 95 /* control type: deco, callback function: (none) */ #define PANEL_DECORATION_8 96 /* control type: deco, callback function: (none) */ #define PANEL_DECORATION 97 /* control type: deco, callback function: (none) */