# HG changeset patch # User Daniele Nicolodi # Date 1423766814 -3600 # Node ID 7fd5cb857d077908fa035a26b662a29dd1cc5008 # Parent ec81395bf08d5810964a11a61b749ad1d3774a4b Add data pubblication through ZMQ socket diff -r ec81395bf08d -r 7fd5cb857d07 FXAnalyse.c --- a/FXAnalyse.c Thu Feb 12 19:13:55 2015 +0100 +++ b/FXAnalyse.c Thu Feb 12 19:46:54 2015 +0100 @@ -1,3 +1,4 @@ +#include #include #include #include @@ -49,6 +50,28 @@ // data provider thread CmtThreadFunctionID dataProviderThread; +// ZMQ +void *zmqcontext; +void *zmqsocket; + +// utility function to send data through ZMQ socket framed by an envelope +// see "Pub-Sub Message Envelopes" in chapter 2 "Sockets and Patterns" +// of "ZMQ The Guide" http://zguide.zeromq.org/page:all#toc49 +int zmq_xpub(void *socket, char *envelope, void *data, size_t len) +{ + int r; + + r = zmq_send(socket, envelope, strlen(envelope), ZMQ_SNDMORE); + if (r < 0) + return zmq_errno(); + + r = zmq_send(socket, data, len, 0); + if (r < 0) + return zmq_errno(); + + return 0; +} + struct event ev; double utc; @@ -641,6 +664,19 @@ ad9912_set_frequency_w(&ad9912, 2, frequency); GetCtrlVal(MainPanel, PANEL_DDS4, &frequency); ad9912_set_frequency_w(&ad9912, 3, frequency); + + // setup ZMQ pub socket + char *socket; + rv = Ini_GetStringCopy(configuration, "ZMQ", "socket", &socket); + if (! rv) + socket = strdup("tcp://127.0.0.1:3456"); + logmessage(INFO, "data sent to ZMQ socket '%s'", socket); + zmqcontext = zmq_ctx_new(); + zmqsocket = zmq_socket(zmqcontext, ZMQ_PUB); + rv = zmq_bind(zmqsocket, socket); + if (rv) + logmessage(ERROR, "cannot bind ZMQ socket '%s': %s", socket, zmq_strerror(zmq_errno())); + free(socket); // dispose configuration Ini_Dispose(configuration); @@ -1451,6 +1487,11 @@ // send Sr frequency (Math4) to Sr data logger sr_datalogger_send(&datalogger, utc, Math4); + + // publish data through ZMQ + int r = zmq_xpub(zmqsocket, "RAW", &ev, sizeof(ev)); + if (r) + logmessage(ERROR, "cannot send data through ZMQ socket: %s", zmq_strerror(r)); } break; } diff -r ec81395bf08d -r 7fd5cb857d07 FXAnalyse.ini --- a/FXAnalyse.ini Thu Feb 12 19:13:55 2015 +0100 +++ b/FXAnalyse.ini Thu Feb 12 19:46:54 2015 +0100 @@ -7,14 +7,17 @@ host = 145.238.205.58 [data] -folder = "C:\\\\data\\test" +folder = C:\\\\data\\test [KK] port = COM1:115200 nchan = 4 +[ZMQ] +socket = tcp://127.0.0.1:3456 + [Sr data logger] host = 145.238.204.91 -id = "FEMTO2" +id = FEMTO2 port = 3491 diff -r ec81395bf08d -r 7fd5cb857d07 future.h --- a/future.h Thu Feb 12 19:13:55 2015 +0100 +++ b/future.h Thu Feb 12 19:46:54 2015 +0100 @@ -1,6 +1,8 @@ #ifndef __FUTURE_H__ #define __FUTURE_H__ +#define strdup(s) StrDup(s) + /* required for time_t definition */ #include