Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 119:f9fb17fb64cc
Add Sr frequency logging to disk and to Sr data logger
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Thu, 12 Sep 2013 18:01:49 +0200 |
parents | 43b35f4aae78 |
children | f48e8ff21f0f |
comparison
equal
deleted
inserted
replaced
118:43b35f4aae78 | 119:f9fb17fb64cc |
---|---|
1 #include <tcpsupp.h> | |
1 #include <utility.h> | 2 #include <utility.h> |
2 #include <ansi_c.h> | 3 #include <ansi_c.h> |
3 #include <cvirte.h> | 4 #include <cvirte.h> |
4 #include <userint.h> | 5 #include <userint.h> |
5 #include <formatio.h> | 6 #include <formatio.h> |
185 | 186 |
186 struct stat stat_math1, stat_ch2, stat_ch4, stat_ch3, freq; | 187 struct stat stat_math1, stat_ch2, stat_ch4, stat_ch3, freq; |
187 | 188 |
188 #define MIN(x, y) (x) < (y) ? (x) : (y) | 189 #define MIN(x, y) (x) < (y) ? (x) : (y) |
189 | 190 |
191 // MJD functiom used by the Sr programs | |
192 static inline double utc2mjd(double utc) | |
193 { | |
194 return 15020.0 + utc / 86400.0; | |
195 } | |
196 | |
190 void logmsg(const char *frmt, ...) | 197 void logmsg(const char *frmt, ...) |
191 { | 198 { |
192 char msg[1024]; | 199 char msg[1024]; |
193 int len = 0; | 200 int len = 0; |
194 | 201 |
211 | 218 |
212 // display message | 219 // display message |
213 SetCtrlVal(LoggingPanel, LOGGING_LOGGING, msg); | 220 SetCtrlVal(LoggingPanel, LOGGING_LOGGING, msg); |
214 } | 221 } |
215 | 222 |
223 // Sr data logger | |
224 int sendLogger(const char* id, double utc, double data) | |
225 { | |
226 static unsigned int handle = 0; | |
227 char buffer[1024]; | |
228 | |
229 // try to connect and quit if unsuccessfull | |
230 if (handle == 0) { | |
231 if (ConnectToTCPServer(&handle, 3491, "145.238.204.146", NULL, NULL, 1) < 0) { | |
232 logmsg("Sr data logger connection error"); | |
233 return -1; | |
234 } | |
235 logmsg("connected to Sr data logger"); | |
236 } | |
237 | |
238 snprintf(buffer, sizeof(buffer), "%s %.7f %.8f", id, utc2mjd(utc), data); | |
239 if (ClientTCPWrite(handle, buffer, strlen(buffer) + 1, 0) < 0) { | |
240 // try to reconnect and resend | |
241 handle = 0; | |
242 sendLogger(id, utc, data); | |
243 } | |
244 | |
245 return 0; | |
246 } | |
216 | 247 |
217 muParserHandle_t initMathParser() | 248 muParserHandle_t initMathParser() |
218 { | 249 { |
219 muParserHandle_t parser = mupCreate(); | 250 muParserHandle_t parser = mupCreate(); |
220 mupDefineOprtChars(parser, "abcdefghijklmnopqrstuvwxyzµ" | 251 mupDefineOprtChars(parser, "abcdefghijklmnopqrstuvwxyzµ" |
1372 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save); | 1403 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &save); |
1373 if (save) { | 1404 if (save) { |
1374 writeData(DATAFOLDER, "Hg", id, timestr, utc, Math3); | 1405 writeData(DATAFOLDER, "Hg", id, timestr, utc, Math3); |
1375 writeData("C:\\Femto\\Results", "Hg", id, timestr, utc, Math3); | 1406 writeData("C:\\Femto\\Results", "Hg", id, timestr, utc, Math3); |
1376 } | 1407 } |
1408 | |
1409 // write Sr frequency (Math4) to disk | |
1410 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4SAVE, &save); | |
1411 if (save) { | |
1412 writeData(DATAFOLDER, "Sr", id, timestr, utc, Math4); | |
1413 } | |
1414 | |
1415 // send Sr frequency (Math4) to Sr data logger | |
1416 GetCtrlVal(MainPanel, PANEL_SR_LOGGER, &save); | |
1417 if (save) { | |
1418 sendLogger("FEMTO2", utc, Math4); | |
1419 } | |
1420 | |
1377 | 1421 |
1378 // write ExtraMath (Math5) to disk | 1422 // write ExtraMath (Math5) to disk |
1379 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save); | 1423 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save); |
1380 if (save) { | 1424 if (save) { |
1381 writeData(DATAFOLDER, "Ex", id, timestr, utc, Math5); | 1425 writeData(DATAFOLDER, "Ex", id, timestr, utc, Math5); |