Преглед на файлове

add radangeldump, a utility to dump the messages from radangeld via its sockets

master
Matthias Janke преди 5 години
родител
ревизия
0cb834ee92
променени са 4 файла, в които са добавени 111 реда и са изтрити 2 реда
  1. 3
    0
      meson.build
  2. 0
    2
      radangeld/meson.build
  3. 107
    0
      radangeldump/main.cpp
  4. 1
    0
      radangeldump/meson.build

+ 3
- 0
meson.build Целия файл

@@ -1,6 +1,8 @@
1 1
 project('RadAngel', 'cpp', default_options : ['cpp_std=c++17'], license : ['AGPL3','GPL3'], version : '0.1')
2 2
 
3 3
 thread_dep = dependency('threads')
4
+boost_dep = dependency('boost', modules : 'program_options')
5
+zmqpp_dep = dependency('libzmqpp')
4 6
 
5 7
 udev_dir = get_option('udev-dir')
6 8
 install_udev_dir = (udev_dir != 'no')
@@ -17,6 +19,7 @@ if install_systemd_unit_dir and systemd_unit_dir == ''
17 19
 endif
18 20
 
19 21
 subdir('radangeld')
22
+subdir('radangeldump')
20 23
 #subdir('radangel-webmon')
21 24
 #subdir('src')
22 25
 

+ 0
- 2
radangeld/meson.build Целия файл

@@ -2,9 +2,7 @@ subdir('resources')
2 2
 
3 3
 tz_dep = dependency('tz', fallback : ['hinnant-date', 'tz_dep'], default_options : ['use_system_tzdb=true'])
4 4
 hidapi_usb_dep = dependency('hidapi-libusb')
5
-boost_dep = dependency('boost', modules : 'program_options')
6 5
 libconfigpp_dep = dependency('libconfig++')
7
-zmqpp_dep = dependency('libzmqpp')
8 6
 libsystemd_dep = dependency('libsystemd')
9 7
 
10 8
 executable('radangeld', 'main.cpp', dependencies : [hidapi_usb_dep, boost_dep, libconfigpp_dep, libsystemd_dep, thread_dep, zmqpp_dep, tz_dep], install : true)

+ 107
- 0
radangeldump/main.cpp Целия файл

@@ -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
+}

+ 1
- 0
radangeldump/meson.build Целия файл

@@ -0,0 +1 @@
1
+executable('radangeldump', 'main.cpp', dependencies: [boost_dep, zmqpp_dep])

Loading…
Отказ
Запис