-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrigrecv.cxx
64 lines (51 loc) · 1.07 KB
/
trigrecv.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
*
*/
#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>
#include "zmq.hpp"
const char *zport = "tcp://localhost:8888";
int trig_recv()
{
zmq::context_t context(1);
zmq::socket_t subsocket(context, ZMQ_SUB);
subsocket.connect(zport);
subsocket.setsockopt(ZMQ_SUBSCRIBE, "", 0);
while(true) {
zmq::message_t msg;
//bool rc;
try {
subsocket.recv(&msg);
//rc = subsocket.recv(&msg, ZMQ_NOBLOCK);
} catch (zmq::error_t &e) {
std::cerr << "#E recv zmq err. " << e.what() << std::endl;
return -1;
}
#if 0
if (! rc) {
usleep(100);
continue;
}
#endif
unsigned int trig = *(reinterpret_cast<unsigned int *>(msg.data()));
std::cout << "got " << trig << " size: " << msg.size() << std::endl;
}
return 0;
}
int main(int argc, char *argv[])
{
double freq = 100.;
for (int i = 0 ; i < argc ; i++) {
std::string sargv(argv[i]);
if (((sargv == "-f") || (sargv == "--freq"))
&& (argc > i)) {
std::string param(argv[i+1]);
std::istringstream iss(param);
iss >> freq;
}
}
trig_recv();
return 0;
}