Mercurial > hg > fxanalyse
diff FXAnalyse.c @ 91:4102fe614df2
Fix timestamping. Cleanup data providers
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 22 Mar 2013 16:32:15 +0100 |
parents | c9e4f63c2033 |
children | 675cb8d5e8a7 |
line wrap: on
line diff
--- a/FXAnalyse.c Fri Mar 22 18:49:58 2013 +0100 +++ b/FXAnalyse.c Fri Mar 22 16:32:15 2013 +0100 @@ -18,11 +18,14 @@ #define DEDRIFT_DDS_FREQUENCY 70000000 -// panels -static int MainPanel; -static int CalcNPanel; -static int EstimateN3Panel; -static int LoggingPanel; +// number of channels read +#define NCHAN 4 + +// data acquisition event +struct event { + struct timeval time; + double data[NCHAN]; +}; // data acquisition status int acquiring; @@ -145,6 +148,13 @@ double CenteringTimeBegin10K = 0.0; +// panels +static int MainPanel; +static int CalcNPanel; +static int EstimateN3Panel; +static int LoggingPanel; + + struct stat { int samples; double mean; @@ -259,10 +269,6 @@ } -#define NCHAN 4 -#define DATA_EVENT_SIZE (NCHAN + 1) -#define DATA_QUEUE_SIZE (128 * DATA_EVENT_SIZE) - void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, int value, void *callbackData); @@ -337,10 +343,10 @@ mupSetExpr(MathParser5, expr); // data queue - CmtNewTSQ(DATA_QUEUE_SIZE, sizeof(double), 0, &dataQueue); + CmtNewTSQ(128, sizeof(struct event), 0, &dataQueue); // register callback to execute when data will be in the data queue - CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, DATA_EVENT_SIZE, + CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, 1, DataAvailableCB, NULL, CmtGetCurrentThreadID(), NULL); DisplayPanel(MainPanel); @@ -548,28 +554,28 @@ } -void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, +void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int ev, int value, void *callbackData) { - double data[DATA_EVENT_SIZE]; - int BoxChecked = FALSE; + struct event event; int read; + int BoxChecked = FALSE; - switch (event) { + switch (ev) { case EVENT_TSQ_ITEMS_IN_QUEUE: /* read data from the data queue */ - while (value >= DATA_EVENT_SIZE) { + while (value > 0) { - read = CmtReadTSQData(queueHandle, data, DATA_EVENT_SIZE, TSQ_INFINITE_TIMEOUT, 0); - if (read != DATA_EVENT_SIZE) + read = CmtReadTSQData(queueHandle, &event, 1, TSQ_INFINITE_TIMEOUT, 0); + if (read != 1) logmsg("Error!"); value = value - read; - utc = data[0]; - Ch1 = data[1]; - Ch2 = data[2]; - Ch3 = data[3]; - Ch4 = data[4]; + utc = event.time.tv_sec + event.time.tv_usec * 1e-6; + Ch1 = event.data[0]; + Ch2 = event.data[1]; + Ch3 = event.data[2]; + Ch4 = event.data[3]; SetCtrlVal(MainPanel, PANEL_UTC, utc); SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1); @@ -1282,29 +1288,39 @@ } } - int save; + // local time + struct tm *ltime = localtime(&event.time.tv_sec); + // round to milliseconds + int msec = round(event.time.tv_usec / 1000.0); + while (msec >= 1000) { + ltime->tm_sec += 1; + msec -= 1000; + } + // format local time + char timestr[24]; + int len = strftime(timestr, sizeof(timestr), "%d/%m/%Y %H:%M:%S", ltime); + snprintf(timestr + len, sizeof(timestr) - len, ".%03d", msec); + // display local time + SetCtrlVal(MainPanel, PANEL_TIME, timestr); - // run id derived from current date in the form YYMMDD + // run id derived from current local date in the form YYMMDD char id[7]; - FormatDateTimeString(utc, "%y%m%d", id, sizeof(id)); + strftime(id, sizeof(id), "%y%m%d", ltime); - // time - char timestr[24]; - FormatDateTimeString(utc, "%d/%m/%Y %H:%M:%S.%3f", timestr, sizeof(timestr)); - SetCtrlVal(MainPanel, PANEL_TIME, timestr); + int save; // write LO frequency (Math2) to disk GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &save); if (save) { writeData(DATAFOLDER, "Lo", id, timestr, utc, Math2); - writeData("C:\\Femto\\Results", "OptCavity", id, timestr, utc, Math2); + writeData("C:\\Femto\\Results", "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", "HgCavity", id, timestr, utc, Math3); + writeData("C:\\Femto\\Results", "Hg", id, timestr, utc, Math3); } // write ExtraMath (Math5) to disk