|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+/*
|
|
|
2
|
+radangeldump -- a simple shell that displays data distributed by a radageld
|
|
|
3
|
+Copyright (C) 2020 Matthias Janke <matthias.janke@physi.uni-heidelberg.de>
|
|
|
4
|
+
|
|
|
5
|
+This program is free software: you can redistribute it and/or modify it under
|
|
|
6
|
+the terms of the GNU Affero General Public License as published by the Free
|
|
|
7
|
+Software Foundation, version 3.
|
|
|
8
|
+
|
|
|
9
|
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
10
|
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
11
|
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
|
12
|
+
|
|
|
13
|
+You should have received a copy of the GNU Affero General Public License along
|
|
|
14
|
+with this program. If not, see <https://www.gnu.org/licenses/>
|
|
|
15
|
+*/
|
|
|
16
|
+// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
17
|
+
|
|
|
18
|
+#include <iostream>
|
|
|
19
|
+
|
|
|
20
|
+// program option parser
|
|
|
21
|
+#include <boost/program_options.hpp>
|
|
|
22
|
+
|
|
|
23
|
+// thread/ipc/tcp communications
|
|
|
24
|
+#include <zmqpp/zmqpp.hpp>
|
|
|
25
|
+
|
|
|
26
|
+int main(int argc, char *argv[])
|
|
|
27
|
+{
|
|
|
28
|
+ int64_t timestamp{0};
|
|
|
29
|
+ uint16_t event{0};
|
|
|
30
|
+ double countrate{0.0};
|
|
|
31
|
+
|
|
|
32
|
+ bool events;
|
|
|
33
|
+ bool cpm;
|
|
|
34
|
+
|
|
|
35
|
+ std::string socket;
|
|
|
36
|
+
|
|
|
37
|
+ zmqpp::context zmqc;
|
|
|
38
|
+
|
|
|
39
|
+ boost::program_options::options_description desc ("Available options:");
|
|
|
40
|
+ desc.add_options()
|
|
|
41
|
+ ("help,?", "Prints this list of available options.")
|
|
|
42
|
+ ("events,e", boost::program_options::value<bool> (&events)->implicit_value (true)->default_value (true), "Socket publishes events.")
|
|
|
43
|
+ ("cpm,c", boost::program_options::value<bool> (&cpm)->implicit_value (true)->default_value (false), "Socket publishes counts per minute.")
|
|
|
44
|
+ ("socket,s", boost::program_options::value<std::string> (&socket)->default_value("ipc://radangel.events"), "Socket to connect to.")
|
|
|
45
|
+ ;
|
|
|
46
|
+
|
|
|
47
|
+ boost::program_options::positional_options_description p;
|
|
|
48
|
+ p.add ("socket", -1);
|
|
|
49
|
+
|
|
|
50
|
+ boost::program_options::variables_map vm;
|
|
|
51
|
+ boost::program_options::store (boost::program_options::command_line_parser (argc, argv).options (desc).positional (p).run(), vm);
|
|
|
52
|
+ boost::program_options::notify (vm);
|
|
|
53
|
+
|
|
|
54
|
+ if (vm.count ("help") )
|
|
|
55
|
+ {
|
|
|
56
|
+ std::cout << "Usage: " << argv[0] << " [options] [socket]\n";
|
|
|
57
|
+ std::cout << desc;
|
|
|
58
|
+ return 0;
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ if (vm["events"].defaulted() && !vm["cpm"].defaulted())
|
|
|
62
|
+ events = false;
|
|
|
63
|
+
|
|
|
64
|
+ if (events == cpm)
|
|
|
65
|
+ {
|
|
|
66
|
+ std::cerr << "Please decide if you either want events or counts per minute displayed! Only one of both options is valid." << std::endl;
|
|
|
67
|
+ return -1;
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ if (cpm && vm["socket"].defaulted())
|
|
|
71
|
+ socket = "ipc://radangel.cpm";
|
|
|
72
|
+
|
|
|
73
|
+ zmqpp::socket radangelsocket (zmqc, zmqpp::socket_type::subscribe);
|
|
|
74
|
+ radangelsocket.connect (socket);
|
|
|
75
|
+ radangelsocket.subscribe ("");
|
|
|
76
|
+ zmqpp::message messages;
|
|
|
77
|
+
|
|
|
78
|
+ if(events)
|
|
|
79
|
+ std::cout << "Energy [Ch]\trelative timestamp[µs]\n";
|
|
|
80
|
+ else if (cpm)
|
|
|
81
|
+ std::cout << "relative timestamp[µs]\tCoutrate [1/min]\n";
|
|
|
82
|
+
|
|
|
83
|
+ do
|
|
|
84
|
+ {
|
|
|
85
|
+ radangelsocket.receive(messages);
|
|
|
86
|
+
|
|
|
87
|
+ if(events)
|
|
|
88
|
+ {
|
|
|
89
|
+ messages >> event
|
|
|
90
|
+ >> timestamp;
|
|
|
91
|
+ std::cout << event << "\t"
|
|
|
92
|
+ << timestamp << "\n";
|
|
|
93
|
+ }
|
|
|
94
|
+ else if(cpm)
|
|
|
95
|
+ {
|
|
|
96
|
+ messages >> timestamp
|
|
|
97
|
+ >> countrate;
|
|
|
98
|
+ std::cout << timestamp << "\t"
|
|
|
99
|
+ << countrate << "\n";
|
|
|
100
|
+ }
|
|
|
101
|
+ else
|
|
|
102
|
+ break;
|
|
|
103
|
+ }
|
|
|
104
|
+ while(true);
|
|
|
105
|
+
|
|
|
106
|
+ return 0;
|
|
|
107
|
+}
|