-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriggen.cxx
56 lines (44 loc) · 1006 Bytes
/
triggen.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
/*
*
*/
#include <iostream>
#include <string>
#include <sstream>
#include <unistd.h>
#include "zmq.hpp"
const char *zport = "tcp://*:8888";
int trig_gen(double freq)
{
static unsigned int trig_num = 0;
zmq::context_t context(1);
zmq::socket_t pubsocket(context, ZMQ_PUB);
pubsocket.bind(zport);
while(true) {
usleep(static_cast<int>(1000000 / freq));
zmq::message_t msg(sizeof(unsigned int));
*(reinterpret_cast<unsigned int *>(msg.data())) = trig_num++;
try {
pubsocket.send(msg);
} catch (zmq::error_t &e) {
std::cerr << "#E send zmq err. " << e.what() << std::endl;
return -1;
}
std::cout << "\r" << trig_num << " " << std::flush;
}
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_gen(freq);
return 0;
}