comparison FXAnalyse.c @ 134:bd28161e5ac2

Major code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 12:29:28 +0100
parents 7540703b8473
children 77539f2597b1
comparison
equal deleted inserted replaced
133:7540703b8473 134:bd28161e5ac2
49 double utc; 49 double utc;
50 double Ch1, Ch2, Ch3, Ch4; 50 double Ch1, Ch2, Ch3, Ch4;
51 double Math1, Math2, Math3, Math4, Math5; 51 double Math1, Math2, Math3, Math4, Math5;
52 double N1, N2, N3, N4; 52 double N1, N2, N3, N4;
53 53
54 Plot_Data PlotCh1, PlotCh2, PlotCh3, PlotCh4, PlotMath1, PlotMath2, PlotMath3, PlotMath4, PlotMath5 ; 54
55 Allan_Data AllanCh1, AllanCh2, AllanCh3, AllanCh4, AllanMath1, AllanMath2, AllanMath3, AllanMath4, AllanMath5 ; 55 // panels
56 static int MainPanel;
57 static int CalcNPanel;
58 static int EstimateN3Panel;
59 static int LoggingPanel;
60
61
62 struct adev {
63 Allan_Data allan;
64 double *data;
65 const char *title;
66 double normalization;
67 int control;
68 };
69
70
71 #define ADEV_INIT(__channel, __normalization) \
72 { \
73 .data = & ## __channel, \
74 .title = #__channel, \
75 .normalization = __normalization, \
76 .control = PANEL_ADEV_ ## __channel \
77 }
78
79
80 int adev_toggle(struct adev *adev)
81 {
82 if (adev->allan.active)
83 Allan_ClosePanel(&(adev->allan));
84 else
85 Allan_InitPanel(&(adev->allan), adev->title,
86 adev->normalization, MainPanel, adev->control);
87 return adev->allan.active;
88 }
89
90
91 void adev_update(struct adev *adev)
92 {
93 if (adev->allan.active)
94 Allan_AddFrequency(&(adev->allan), *(adev->data));
95 }
96
97
98 struct adev adevs[] = {
99 ADEV_INIT(Ch1, 1.84e12),
100 ADEV_INIT(Ch2, 10.0e3),
101 ADEV_INIT(Ch3, 429.228e12),
102 ADEV_INIT(Ch4, 275.0e3),
103 ADEV_INIT(Math1, 250.0e6),
104 ADEV_INIT(Math2, 194.395e12),
105 ADEV_INIT(Math3, 282.143e12),
106 ADEV_INIT(Math4, 429.228e12),
107 ADEV_INIT(Math5, 1.0),
108 { NULL }
109 };
110
111
112 struct plot {
113 Plot_Data plot;
114 double *data;
115 const char *title;
116 double min;
117 double max;
118 int control;
119 };
120
121
122 #define PLOT_INIT(__channel, __min, __max) \
123 { \
124 .data = & ## __channel, \
125 .title = #__channel, \
126 .min = __min, \
127 .max = __max, \
128 .control = PANEL_PLOT_ ## __channel \
129 }
130
131
132 int plot_toggle(struct plot *plot)
133 {
134 if (plot->plot.active)
135 Plot_ClosePanel(&(plot->plot));
136 else
137 Plot_InitPanel(&(plot->plot), plot->title,
138 plot->min, plot->max, MainPanel, plot->control);
139 return plot->plot.active;
140 }
141
142
143 void plot_update(struct plot *plot)
144 {
145 if (plot->plot.active)
146 Plot_AddFrequency(&(plot->plot), *(plot->data));
147 }
148
149 struct plot plots[] = {
150 PLOT_INIT(Ch1, 54.999e6, 55.001e6),
151 PLOT_INIT(Ch2, 0.0, 0.0),
152 PLOT_INIT(Ch3, 0.0, 0.0),
153 PLOT_INIT(Ch4, 0.0, 0.0),
154 PLOT_INIT(Math1, 0.0, 0.0),
155 PLOT_INIT(Math2, 0.0, 0.0),
156 PLOT_INIT(Math3, 0.0, 0.0),
157 PLOT_INIT(Math4, 0.0, 0.0),
158 PLOT_INIT(Math5, 0.0, 0.0),
159 { NULL }
160 };
161
56 162
57 // 1xAD9956 DDS box 163 // 1xAD9956 DDS box
58 DDSParameter DDS1xAD9956; 164 DDSParameter DDS1xAD9956;
59 // 4xAD9912 DDS box 165 // 4xAD9912 DDS box
60 DDS4xAD9912_Data DDS4xAD9912; 166 DDS4xAD9912_Data DDS4xAD9912;
177 .interval = 1800.0, 283 .interval = 1800.0,
178 .t0 = 0.0 284 .t0 = 0.0
179 }; 285 };
180 286
181 287
182 // panels
183 static int MainPanel;
184 static int CalcNPanel;
185 static int EstimateN3Panel;
186 static int LoggingPanel;
187
188
189 char * thousands(char *buffer, int size, char *fmt, double val) 288 char * thousands(char *buffer, int size, char *fmt, double val)
190 { 289 {
191 // compute how many separators we need 290 // compute how many separators we need
192 #pragma DisableFunctionRuntimeChecking log10 291 #pragma DisableFunctionRuntimeChecking log10
193 int nsep = log10(fabs(val)) / 3; 292 int nsep = log10(fabs(val));
293 nsep = (nsep > 0 ? nsep / 3 : 0);
194 // format value 294 // format value
195 int len = snprintf(buffer, size, fmt, val); 295 int len = snprintf(buffer, size, fmt, val);
196 char *src = buffer + len; 296 char *src = buffer + len;
197 char *dst = src + nsep; 297 char *dst = src + nsep;
198 // copy till decimal separator 298 // copy till decimal separator
428 528
429 DiscardPanel(MainPanel); 529 DiscardPanel(MainPanel);
430 return 0; 530 return 0;
431 } 531 }
432 532
433
434 void OnCloseViewPanel(int panel){
435
436 if (panel==PlotCh1.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ1PLOT, FALSE) ; } ;
437 if (panel==PlotCh2.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ2PLOT, FALSE) ; } ;
438 if (panel==PlotCh3.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ3PLOT, FALSE) ; } ;
439 if (panel==PlotCh4.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ4PLOT, FALSE) ; } ;
440 if (panel==PlotMath1.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH1PLOT, FALSE) ; } ;
441 if (panel==PlotMath2.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH2PLOT, FALSE) ; } ;
442 if (panel==PlotMath3.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH3PLOT, FALSE) ; } ;
443 if (panel==PlotMath4.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH4PLOT, FALSE) ; } ;
444 if (panel==PlotMath5.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH5PLOT, FALSE) ; } ;
445
446 if (panel==AllanCh1.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ1ALLAN, FALSE) ; } ;
447 if (panel==AllanCh2.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ2ALLAN, FALSE) ; } ;
448 if (panel==AllanCh3.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ3ALLAN, FALSE) ; } ;
449 if (panel==AllanCh4.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ4ALLAN, FALSE) ; } ;
450 if (panel==AllanMath1.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH1ALLAN, FALSE) ; } ;
451 if (panel==AllanMath2.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH2ALLAN, FALSE) ; } ;
452 if (panel==AllanMath3.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH3ALLAN, FALSE) ; } ;
453 if (panel==AllanMath4.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH4ALLAN, FALSE) ; } ;
454 if (panel==AllanMath5.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH5ALLAN, FALSE) ; } ;
455
456 return ;
457 }
458 533
459 int CVICALLBACK QuitCallback (int panel, int control, int event, 534 int CVICALLBACK QuitCallback (int panel, int control, int event,
460 void *callbackData, int eventData1, int eventData2) 535 void *callbackData, int eventData1, int eventData2)
461 { 536 {
462 switch (event) 537 switch (event)
633 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int ev, 708 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int ev,
634 int value, void *callbackData) 709 int value, void *callbackData)
635 { 710 {
636 struct event event; 711 struct event event;
637 int read; 712 int read;
638 int BoxChecked = FALSE;
639 713
640 switch (ev) { 714 switch (ev) {
641 case EVENT_TSQ_ITEMS_IN_QUEUE: 715 case EVENT_TSQ_ITEMS_IN_QUEUE:
642 // read data from the data queue 716 // read data from the data queue
643 while (value > 0) { 717 while (value > 0) {
675 SetCtrlVal(MainPanel,PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2)); 749 SetCtrlVal(MainPanel,PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2));
676 SetCtrlVal(MainPanel,PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3)); 750 SetCtrlVal(MainPanel,PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3));
677 SetCtrlVal(MainPanel,PANEL_MATH4, thousands(buffer, sizeof(buffer), "%.3f", Math4)); 751 SetCtrlVal(MainPanel,PANEL_MATH4, thousands(buffer, sizeof(buffer), "%.3f", Math4));
678 SetCtrlVal(MainPanel,PANEL_MATH5, thousands(buffer, sizeof(buffer), "%.3f", Math5)); 752 SetCtrlVal(MainPanel,PANEL_MATH5, thousands(buffer, sizeof(buffer), "%.3f", Math5));
679 753
680 // plot 754 // update timeseries plots
681 755 for (struct plot *plot = plots; plot->data; plot++)
682 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1PLOT, &BoxChecked); 756 plot_update(plot);
683 if (BoxChecked) { 757
684 Plot_AddFrequency(&PlotCh1, Ch1); 758 // update allan deviation plots
685 } 759 for (struct adev *adev = adevs; adev->data; adev++)
686 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1ALLAN, &BoxChecked); 760 adev_update(adev);
687 if (BoxChecked) {
688 Allan_AddFrequency(&AllanCh1, Ch1);
689 }
690
691 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2PLOT, &BoxChecked);
692 if (BoxChecked) {
693 Plot_AddFrequency(&PlotCh2, Ch2);
694 }
695 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2ALLAN, &BoxChecked);
696 if (BoxChecked) {
697 Allan_AddFrequency(&AllanCh2, Ch2);
698 }
699
700 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3PLOT, &BoxChecked);
701 if (BoxChecked) {
702 Plot_AddFrequency(&PlotCh3, Ch3);
703 }
704 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3ALLAN, &BoxChecked);
705 if (BoxChecked) {
706 Allan_AddFrequency(&AllanCh3, Ch3);
707 }
708
709 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4PLOT, &BoxChecked);
710 if (BoxChecked) {
711 Plot_AddFrequency(&PlotCh4, Ch4);
712 }
713 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4ALLAN, &BoxChecked);
714 if (BoxChecked) {
715 Allan_AddFrequency(&AllanCh4, Ch4);
716 }
717
718 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1PLOT, &BoxChecked);
719 if (BoxChecked) {
720 Plot_AddFrequency(&PlotMath1, Math1);
721 }
722 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1ALLAN, &BoxChecked);
723 if (BoxChecked) {
724 Allan_AddFrequency(&AllanMath1, Math1);
725 }
726
727 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2PLOT, &BoxChecked);
728 if (BoxChecked) {
729 Plot_AddFrequency(&PlotMath2, Math2);
730 }
731 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2ALLAN, &BoxChecked);
732 if (BoxChecked) {
733 Allan_AddFrequency(&AllanMath2, Math2);
734 }
735
736 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3PLOT, &BoxChecked);
737 if (BoxChecked) {
738 Plot_AddFrequency(&PlotMath3, Math3);
739 }
740 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3ALLAN, &BoxChecked);
741 if (BoxChecked) {
742 Allan_AddFrequency(&AllanMath3, Math3);
743 }
744
745 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4PLOT, &BoxChecked);
746 if (BoxChecked) {
747 Plot_AddFrequency(&PlotMath4, Math4);
748 }
749 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4ALLAN, &BoxChecked);
750 if (BoxChecked) {
751 Allan_AddFrequency(&AllanMath4, Math4);
752 }
753
754 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5PLOT, &BoxChecked);
755 if (BoxChecked) {
756 Plot_AddFrequency(&PlotMath5, Math5);
757 }
758 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5ALLAN, &BoxChecked);
759 if (BoxChecked) {
760 Allan_AddFrequency(&AllanMath5, Math5);
761 }
762 761
763 // Calcul de N 762 // Calcul de N
764 763
765 switch (Measuring_1) { 764 switch (Measuring_1) {
766 765
1476 1475
1477 1476
1478 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event, 1477 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event,
1479 void *callbackData, int eventData1, int eventData2) 1478 void *callbackData, int eventData1, int eventData2)
1480 { 1479 {
1481 int BoxChecked ; 1480 switch (event)
1482 Plot_Data * pPlot = NULL; 1481 {
1483 char PlotTitle[] = "Ch? Frequency Plot" ; 1482 case EVENT_COMMIT:
1484 double PlotMin = 10e6 ; 1483 for (struct plot *plot = plots; plot->data; plot++) {
1485 double PlotMax = 65e6 ; 1484 if (plot->control == control)
1486 1485 plot_toggle(plot);
1487 switch (event) {
1488 case EVENT_COMMIT:
1489
1490 GetCtrlVal(MainPanel, control, &BoxChecked);
1491 switch (control) {
1492 case PANEL_CHECKBOX_FREQ1PLOT :
1493 pPlot = &PlotCh1 ;
1494 Fmt(PlotTitle, "Ch1 Frequency Plot") ;
1495 PlotMin = 54.999e6 ; PlotMax = 55.001e6 ;
1496 break ;
1497 case PANEL_CHECKBOX_FREQ2PLOT :
1498 pPlot = &PlotCh2 ;
1499 Fmt(PlotTitle, "Ch2 Frequency Plot") ;
1500 PlotMin = 8.0e3 ; PlotMax = 12.0e3 ;
1501 break ;
1502 case PANEL_CHECKBOX_FREQ3PLOT :
1503 pPlot = &PlotCh3 ;
1504 Fmt(PlotTitle, "Ch3 Frequency Plot") ;
1505 PlotMin = 8.0e3 ; PlotMax = 12.0e3 ;
1506 break ;
1507 case PANEL_CHECKBOX_FREQ4PLOT :
1508 pPlot = &PlotCh4 ;
1509 Fmt(PlotTitle, "Ch4 Frequency Plot") ;
1510 break ;
1511 case PANEL_CHECKBOX_MATH1PLOT :
1512 pPlot = &PlotMath1 ;
1513 Fmt(PlotTitle, "Math1 Plot") ;
1514 PlotMin = 765.0e6 ; PlotMax = 775.0e6 ;
1515 break ;
1516 case PANEL_CHECKBOX_MATH2PLOT :
1517 pPlot = &PlotMath2 ;
1518 Fmt(PlotTitle, "Math2 Plot") ;
1519 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1520 break ;
1521 case PANEL_CHECKBOX_MATH3PLOT :
1522 pPlot = &PlotMath3 ;
1523 Fmt(PlotTitle, "Math3 Plot") ;
1524 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1525 break ;
1526 case PANEL_CHECKBOX_MATH4PLOT :
1527 pPlot = &PlotMath4 ;
1528 Fmt(PlotTitle, "Math4 Plot") ;
1529 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1530 break ;
1531 case PANEL_CHECKBOX_MATH5PLOT :
1532 pPlot = &PlotMath5 ;
1533 Fmt(PlotTitle, "Math5 Plot") ;
1534 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1535 break ;
1536 } 1486 }
1537
1538 if (BoxChecked)
1539 Plot_InitPanel(pPlot, PlotTitle, PlotMin, PlotMax, &OnCloseViewPanel);
1540 else
1541 Plot_ClosePanel(pPlot);
1542 break; 1487 break;
1543 } 1488 }
1544 return 0; 1489 return 0;
1545 } 1490 }
1546 1491
1547 1492
1548 int CVICALLBACK CB_OnAllanPlot (int panel, int control, int event, 1493 int CVICALLBACK CB_OnAllanPlot (int panel, int control, int event,
1549 void *callbackData, int eventData1, int eventData2) 1494 void *callbackData, int eventData1, int eventData2)
1550 { 1495 {
1551 int BoxChecked ; 1496 switch (event)
1552 Allan_Data * pAllan = NULL; 1497 {
1553 char AllanTitle[] = "Ch? Allan Deviation " ; 1498 case EVENT_COMMIT:
1554 double Normalizer = 300e12 ; 1499 for (struct adev *adev = adevs; adev->data; adev++) {
1555 1500 if (adev->control == control)
1556 switch (event) 1501 adev_toggle(adev);
1557 { 1502 }
1558 case EVENT_COMMIT: 1503 break;
1559 1504 }
1560 GetCtrlVal(MainPanel, control, &BoxChecked);
1561 switch (control) {
1562 case PANEL_CHECKBOX_FREQ1ALLAN :
1563 pAllan = &AllanCh1 ;
1564 Fmt(AllanTitle, "Ch1 Allan Deviation") ;
1565 Normalizer = 1.84e12 ;
1566 break ;
1567 case PANEL_CHECKBOX_FREQ2ALLAN :
1568 pAllan = &AllanCh2 ;
1569 Fmt(AllanTitle, "Ch2 Allan Deviation") ;
1570 Normalizer = 10.e3 ;
1571 break ;
1572 case PANEL_CHECKBOX_FREQ3ALLAN :
1573 pAllan = &AllanCh3 ;
1574 Fmt(AllanTitle, "Ch3 Allan Deviation") ;
1575 Normalizer = 429.228e12 ;
1576 break ;
1577 case PANEL_CHECKBOX_FREQ4ALLAN :
1578 pAllan = &AllanCh4 ;
1579 Fmt(AllanTitle, "Ch4 Allan Deviation") ;
1580 Normalizer = 275.0e3 ;
1581 break ;
1582 case PANEL_CHECKBOX_MATH1ALLAN :
1583 pAllan = &AllanMath1 ;
1584 Fmt(AllanTitle, "Math1 Allan Deviation") ;
1585 Normalizer = 250.0e6 ;
1586 break ;
1587 case PANEL_CHECKBOX_MATH2ALLAN :
1588 pAllan = &AllanMath2 ;
1589 Fmt(AllanTitle, "Math2 Allan Deviation") ;
1590 Normalizer = 194.395e12 ;
1591 break ;
1592 case PANEL_CHECKBOX_MATH3ALLAN :
1593 pAllan = &AllanMath3 ;
1594 Fmt(AllanTitle, "Math3 Allan Deviation") ;
1595 Normalizer = 282.143e12 ;
1596 break ;
1597 case PANEL_CHECKBOX_MATH4ALLAN :
1598 pAllan = &AllanMath4 ;
1599 Fmt(AllanTitle, "Math4 Allan Deviation") ;
1600 Normalizer = 429.228e12 ;
1601 break ;
1602 case PANEL_CHECKBOX_MATH5ALLAN :
1603 pAllan = &AllanMath5 ;
1604 Fmt(AllanTitle, "Math5 Allan Deviation") ;
1605 Normalizer = 429.228e12 ;
1606 break ;
1607 }
1608
1609 if (BoxChecked) {
1610 Allan_InitPanel(pAllan, AllanTitle, Normalizer, &OnCloseViewPanel) ;
1611 }
1612 else {
1613 Allan_ClosePanel(pAllan) ;
1614 } ;
1615 break;
1616
1617 case EVENT_RIGHT_CLICK:
1618
1619 break;
1620
1621 }
1622 return 0; 1505 return 0;
1623 } 1506 }
1624 1507
1625 int CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event, 1508 int CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event,
1626 void *callbackData, int eventData1, int eventData2) 1509 void *callbackData, int eventData1, int eventData2)