Mercurial > hg > fxanalyse
comparison 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 |
comparison
equal
deleted
inserted
replaced
90:c9aec93005a4 | 91:4102fe614df2 |
---|---|
16 | 16 |
17 #define DATAFOLDER "Z:\\Measures-2013" | 17 #define DATAFOLDER "Z:\\Measures-2013" |
18 | 18 |
19 #define DEDRIFT_DDS_FREQUENCY 70000000 | 19 #define DEDRIFT_DDS_FREQUENCY 70000000 |
20 | 20 |
21 // panels | 21 // number of channels read |
22 static int MainPanel; | 22 #define NCHAN 4 |
23 static int CalcNPanel; | 23 |
24 static int EstimateN3Panel; | 24 // data acquisition event |
25 static int LoggingPanel; | 25 struct event { |
26 struct timeval time; | |
27 double data[NCHAN]; | |
28 }; | |
26 | 29 |
27 // data acquisition status | 30 // data acquisition status |
28 int acquiring; | 31 int acquiring; |
29 // data queue | 32 // data queue |
30 CmtTSQHandle dataQueue; | 33 CmtTSQHandle dataQueue; |
141 int KeepCentering = FALSE; | 144 int KeepCentering = FALSE; |
142 double Timetorecenter275K = 3600.0 * 10; | 145 double Timetorecenter275K = 3600.0 * 10; |
143 double Timetorecenter10K = 3600.0 * 3; | 146 double Timetorecenter10K = 3600.0 * 3; |
144 double CenteringTimeBegin275K = 0.0; | 147 double CenteringTimeBegin275K = 0.0; |
145 double CenteringTimeBegin10K = 0.0; | 148 double CenteringTimeBegin10K = 0.0; |
149 | |
150 | |
151 // panels | |
152 static int MainPanel; | |
153 static int CalcNPanel; | |
154 static int EstimateN3Panel; | |
155 static int LoggingPanel; | |
146 | 156 |
147 | 157 |
148 struct stat { | 158 struct stat { |
149 int samples; | 159 int samples; |
150 double mean; | 160 double mean; |
257 WriteLine(fd, line, -1); | 267 WriteLine(fd, line, -1); |
258 CloseFile(fd); | 268 CloseFile(fd); |
259 } | 269 } |
260 | 270 |
261 | 271 |
262 #define NCHAN 4 | |
263 #define DATA_EVENT_SIZE (NCHAN + 1) | |
264 #define DATA_QUEUE_SIZE (128 * DATA_EVENT_SIZE) | |
265 | |
266 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, | 272 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, |
267 int value, void *callbackData); | 273 int value, void *callbackData); |
268 | 274 |
269 | 275 |
270 int main (int argc, char *argv[]) | 276 int main (int argc, char *argv[]) |
335 mupDefineVar(MathParser5, "Math4", &Math4); | 341 mupDefineVar(MathParser5, "Math4", &Math4); |
336 GetCtrlVal(MainPanel, PANEL_MATHSTRING5, expr); | 342 GetCtrlVal(MainPanel, PANEL_MATHSTRING5, expr); |
337 mupSetExpr(MathParser5, expr); | 343 mupSetExpr(MathParser5, expr); |
338 | 344 |
339 // data queue | 345 // data queue |
340 CmtNewTSQ(DATA_QUEUE_SIZE, sizeof(double), 0, &dataQueue); | 346 CmtNewTSQ(128, sizeof(struct event), 0, &dataQueue); |
341 | 347 |
342 // register callback to execute when data will be in the data queue | 348 // register callback to execute when data will be in the data queue |
343 CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, DATA_EVENT_SIZE, | 349 CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, 1, |
344 DataAvailableCB, NULL, CmtGetCurrentThreadID(), NULL); | 350 DataAvailableCB, NULL, CmtGetCurrentThreadID(), NULL); |
345 | 351 |
346 DisplayPanel(MainPanel); | 352 DisplayPanel(MainPanel); |
347 | 353 |
348 RunUserInterface(); | 354 RunUserInterface(); |
546 if (msg != NULL) | 552 if (msg != NULL) |
547 logmsg(msg); | 553 logmsg(msg); |
548 } | 554 } |
549 | 555 |
550 | 556 |
551 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, | 557 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int ev, |
552 int value, void *callbackData) | 558 int value, void *callbackData) |
553 { | 559 { |
554 double data[DATA_EVENT_SIZE]; | 560 struct event event; |
561 int read; | |
555 int BoxChecked = FALSE; | 562 int BoxChecked = FALSE; |
556 int read; | 563 |
557 | 564 switch (ev) { |
558 switch (event) { | |
559 case EVENT_TSQ_ITEMS_IN_QUEUE: | 565 case EVENT_TSQ_ITEMS_IN_QUEUE: |
560 /* read data from the data queue */ | 566 /* read data from the data queue */ |
561 while (value >= DATA_EVENT_SIZE) { | 567 while (value > 0) { |
562 | 568 |
563 read = CmtReadTSQData(queueHandle, data, DATA_EVENT_SIZE, TSQ_INFINITE_TIMEOUT, 0); | 569 read = CmtReadTSQData(queueHandle, &event, 1, TSQ_INFINITE_TIMEOUT, 0); |
564 if (read != DATA_EVENT_SIZE) | 570 if (read != 1) |
565 logmsg("Error!"); | 571 logmsg("Error!"); |
566 value = value - read; | 572 value = value - read; |
567 | 573 |
568 utc = data[0]; | 574 utc = event.time.tv_sec + event.time.tv_usec * 1e-6; |
569 Ch1 = data[1]; | 575 Ch1 = event.data[0]; |
570 Ch2 = data[2]; | 576 Ch2 = event.data[1]; |
571 Ch3 = data[3]; | 577 Ch3 = event.data[2]; |
572 Ch4 = data[4]; | 578 Ch4 = event.data[3]; |
573 | 579 |
574 SetCtrlVal(MainPanel, PANEL_UTC, utc); | 580 SetCtrlVal(MainPanel, PANEL_UTC, utc); |
575 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1); | 581 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1); |
576 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2); | 582 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2); |
577 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3); | 583 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3); |
1280 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); | 1286 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); |
1281 CenteringTimeBegin10K = utc; | 1287 CenteringTimeBegin10K = utc; |
1282 } | 1288 } |
1283 } | 1289 } |
1284 | 1290 |
1291 // local time | |
1292 struct tm *ltime = localtime(&event.time.tv_sec); | |
1293 // round to milliseconds | |
1294 int msec = round(event.time.tv_usec / 1000.0); | |
1295 while (msec >= 1000) { | |
1296 ltime->tm_sec += 1; | |
1297 msec -= 1000; | |
1298 } | |
1299 // format local time | |
1300 char timestr[24]; | |
1301 int len = strftime(timestr, sizeof(timestr), "%d/%m/%Y %H:%M:%S", ltime); | |
1302 snprintf(timestr + len, sizeof(timestr) - len, ".%03d", msec); | |
1303 // display local time | |
1304 SetCtrlVal(MainPanel, PANEL_TIME, timestr); | |
1305 | |
1306 // run id derived from current local date in the form YYMMDD | |
1307 char id[7]; | |
1308 strftime(id, sizeof(id), "%y%m%d", ltime); | |
1309 | |
1285 int save; | 1310 int save; |
1286 | |
1287 // run id derived from current date in the form YYMMDD | |
1288 char id[7]; | |
1289 FormatDateTimeString(utc, "%y%m%d", id, sizeof(id)); | |
1290 | |
1291 // time | |
1292 char timestr[24]; | |
1293 FormatDateTimeString(utc, "%d/%m/%Y %H:%M:%S.%3f", timestr, sizeof(timestr)); | |
1294 SetCtrlVal(MainPanel, PANEL_TIME, timestr); | |
1295 | 1311 |
1296 // write LO frequency (Math2) to disk | 1312 // write LO frequency (Math2) to disk |
1297 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &save); | 1313 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &save); |
1298 if (save) { | 1314 if (save) { |
1299 writeData(DATAFOLDER, "Lo", id, timestr, utc, Math2); | 1315 writeData(DATAFOLDER, "Lo", id, timestr, utc, Math2); |
1300 writeData("C:\\Femto\\Results", "OptCavity", id, timestr, utc, Math2); | 1316 writeData("C:\\Femto\\Results", "Lo", id, timestr, utc, Math2); |
1301 } | 1317 } |
1302 | 1318 |
1303 // write Hg frequency (Math3) to disk | 1319 // write Hg frequency (Math3) to disk |
1304 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save); | 1320 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save); |
1305 if (save) { | 1321 if (save) { |
1306 writeData(DATAFOLDER, "Hg", id, timestr, utc, Math3); | 1322 writeData(DATAFOLDER, "Hg", id, timestr, utc, Math3); |
1307 writeData("C:\\Femto\\Results", "HgCavity", id, timestr, utc, Math3); | 1323 writeData("C:\\Femto\\Results", "Hg", id, timestr, utc, Math3); |
1308 } | 1324 } |
1309 | 1325 |
1310 // write ExtraMath (Math5) to disk | 1326 // write ExtraMath (Math5) to disk |
1311 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save); | 1327 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save); |
1312 if (save) { | 1328 if (save) { |