comparison FXAnalyse.c @ 209:11a88d389705

Adapt to new AD9956 interface
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 31 Mar 2014 17:03:38 +0200
parents 31093786d41d
children 72fafb670eaf
comparison
equal deleted inserted replaced
208:b955e35c07ae 209:11a88d389705
10 10
11 #include "FXAnalyse.h" 11 #include "FXAnalyse.h"
12 #include "Plot.h" 12 #include "Plot.h"
13 #include "Allan.h" 13 #include "Allan.h"
14 #include "ad9912.h" 14 #include "ad9912.h"
15 #include "DDS_Fox.h" 15 #include "ad9956.h"
16 #include "muParserDLL.h" 16 #include "muParserDLL.h"
17 #include "utils.h" 17 #include "utils.h"
18 #include "stat.h" 18 #include "stat.h"
19 #include "future.h" 19 #include "future.h"
20 #include "data-provider.h" 20 #include "data-provider.h"
179 { 179 {
180 int r = ad9912_ramp_frequency(d, c, f, s); 180 int r = ad9912_ramp_frequency(d, c, f, s);
181 if (r) 181 if (r)
182 logmessage(ERROR, "ad9912 ramp frequency channel=%d error=%d", c, -r); 182 logmessage(ERROR, "ad9912 ramp frequency channel=%d error=%d", c, -r);
183 return r; 183 return r;
184 }
185
186
187 static inline int ad9956_set_sweep_rate_w(struct ad9956 *d, double s)
188 {
189 int r = ad9956_set_sweep_rate(d, s);
190 if (r)
191 logmessage(ERROR, "ad9956 set sweep rate error=%d", -r);
192 return r;
193 }
194
195
196 static int ad9956_set_w(struct ad9956 *d, double f, double s)
197 {
198 int r;
199
200 r = ad9956_sweep_stop(d);
201 if (r) {
202 logmessage(ERROR, "ad9956 sweep stop error=%d", -r);
203 return r;
204 }
205
206 r = ad9956_set_frequency(d, f);
207 if (r) {
208 logmessage(ERROR, "ad9956 set frequency error=%d", -r);
209 return r;
210 }
211
212 r = ad9956_set_sweep_rate(d, s);
213 if (r) {
214 logmessage(ERROR, "ad9956 set sweep rate error=%d", -r);
215 return r;
216 }
217
218 r = ad9956_sweep_start(d);
219 if (r) {
220 logmessage(ERROR, "ad9956 sweep start error=%d", -r);
221 return r;
222 }
223
224 return 0;
184 } 225 }
185 226
186 227
187 enum { 228 enum {
188 LO = 1, 229 LO = 1,
413 { 454 {
414 int rv; 455 int rv;
415 double frequency; 456 double frequency;
416 char expr[1024]; 457 char expr[1024];
417 char host[256]; 458 char host[256];
418 int port;
419 double clock; 459 double clock;
420 460
421 if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0) 461 if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0)
422 return -1; 462 return -1;
423 if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0) 463 if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0)
446 486
447 // ad9956 configuration parameters 487 // ad9956 configuration parameters
448 rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host)); 488 rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host));
449 if (! rv) 489 if (! rv)
450 return -1; 490 return -1;
451 rv = Ini_GetInt(configuration, "AD9956", "port", &port);
452 if (! rv)
453 return -1;
454 rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock); 491 rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock);
455 if (! rv) 492 if (! rv)
456 return -1; 493 return -1;
457 494
458 // dedrift DDS 495 // initialize AD9956 dedrift DDS
459 DDSFox_Init(&ad9956, host, port); 496 rv = ad9956_init(&ad9956, host, clock);
497 if (rv)
498 logmessage(ERROR, "ad9956 init erorr=%d", -rv);
460 499
461 // ad9912 configuration parameters 500 // ad9912 configuration parameters
462 rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host)); 501 rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host));
463 if (! rv) 502 if (! rv)
464 return -1; 503 return -1;
1226 & (freq.previous != 0.0) 1265 & (freq.previous != 0.0)
1227 & (fabs(f - freq.previous) > dedrift.threshold)) { 1266 & (fabs(f - freq.previous) > dedrift.threshold)) {
1228 1267
1229 if (! dedrift.keep_slope) { 1268 if (! dedrift.keep_slope) {
1230 dedrift.applied = 0.0; 1269 dedrift.applied = 0.0;
1231 DDSFox_SetSweepRate(&ad9956, dedrift.applied); 1270 ad9956_set_sweep_rate_w(&ad9956, dedrift.applied);
1232 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); 1271 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
1233 } 1272 }
1234 if (! dedrift.keep_freq) { 1273 if (! dedrift.keep_freq) {
1235 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied); 1274 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied);
1236 } 1275 }
1237 1276
1238 stat_zero(&freq); 1277 stat_zero(&freq);
1239 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); 1278 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope);
1240 dedrift.enabled = FALSE; 1279 dedrift.enabled = FALSE;
1259 dedrift.applied += freq.slope; 1298 dedrift.applied += freq.slope;
1260 1299
1261 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); 1300 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
1262 1301
1263 if (dedrift.doubleslope) 1302 if (dedrift.doubleslope)
1264 DDSFox_SetSweepRate(&ad9956, dedrift.applied * 2.0); 1303 ad9956_set_sweep_rate_w(&ad9956, 2 * dedrift.applied);
1265 else 1304 else
1266 DDSFox_SetSweepRate(&ad9956, dedrift.applied); 1305 ad9956_set_sweep_rate_w(&ad9956, dedrift.applied);
1267 1306
1268 logmsg("dedrift update: adjustment=%+3e slope=%+3e", freq.slope, dedrift.applied); 1307 logmsg("dedrift update: adjustment=%+3e slope=%+3e", freq.slope, dedrift.applied);
1269 1308
1270 stat_zero(&freq); 1309 stat_zero(&freq);
1271 dedrift.t0 = utc; 1310 dedrift.t0 = utc;
1741 stat_zero(&freq); 1780 stat_zero(&freq);
1742 logmsg("dedrift start"); 1781 logmsg("dedrift start");
1743 } else { 1782 } else {
1744 if (! dedrift.keep_slope) { 1783 if (! dedrift.keep_slope) {
1745 dedrift.applied = 0.0; 1784 dedrift.applied = 0.0;
1746 DDSFox_SetSweepRate(&ad9956, dedrift.applied); 1785 ad9956_set_sweep_rate_w(&ad9956, dedrift.applied);
1747 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); 1786 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
1748 } 1787 }
1749 if (! dedrift.keep_freq) { 1788 if (! dedrift.keep_freq) {
1750 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied); 1789 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied);
1751 } 1790 }
1752 stat_zero(&freq); 1791 stat_zero(&freq);
1753 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope); 1792 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope);
1754 logmsg("dedrift stop"); 1793 logmsg("dedrift stop");
1755 } 1794 }
1764 switch (event) 1803 switch (event)
1765 { 1804 {
1766 case EVENT_COMMIT: 1805 case EVENT_COMMIT:
1767 dedrift.applied = 0.0; 1806 dedrift.applied = 0.0;
1768 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); 1807 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied);
1769 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied); 1808 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied);
1770 logmsg("dedrift reset"); 1809 logmsg("dedrift reset");
1771 break; 1810 break;
1772 } 1811 }
1773 return 0; 1812 return 0;
1774 } 1813 }
1943 { 1982 {
1944 switch (event) 1983 switch (event)
1945 { 1984 {
1946 case EVENT_COMMIT: 1985 case EVENT_COMMIT:
1947 GetCtrlVal(panel, control, &dedrift.applied); 1986 GetCtrlVal(panel, control, &dedrift.applied);
1948 DDSFox_SetSweepRate(&ad9956, dedrift.applied); 1987 ad9956_set_sweep_rate_w(&ad9956, dedrift.applied);
1949 break; 1988 break;
1950 } 1989 }
1951 return 0; 1990 return 0;
1952 } 1991 }
1953 1992
1973 dedrift.enabled = FALSE; 2012 dedrift.enabled = FALSE;
1974 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0); 2013 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0);
1975 dedrift.applied = 0.0; 2014 dedrift.applied = 0.0;
1976 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); 2015 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied);
1977 // reset DDS 2016 // reset DDS
1978 DDSFox_Reset(&ad9956, dedrift.freq0); 2017 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied);
1979 break; 2018 break;
1980 } 2019 }
1981 return 0; 2020 return 0;
1982 } 2021 }
1983 2022
2123 { 2162 {
2124 switch (event) 2163 switch (event)
2125 { 2164 {
2126 case EVENT_COMMIT: 2165 case EVENT_COMMIT:
2127 GetCtrlVal(panel, control, &dedrift.freq0); 2166 GetCtrlVal(panel, control, &dedrift.freq0);
2128 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied); 2167 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied);
2129 break; 2168 break;
2130 } 2169 }
2131 return 0; 2170 return 0;
2132 } 2171 }