5 Commits

Author SHA1 Message Date
  Matthias Janke 0cb834ee92 add radangeldump, a utility to dump the messages from radangeld via its sockets 5 years ago
  Matthias Janke 58b369b2bf fix cpm calculation.\nNote: while calculation is correct now the wrong method is used to determine cpm. a fixed time interval should be used. 5 years ago
  Matthias Janke d8bc04b134 build: documet how to disable unit file instalation 5 years ago
  Matthias Janke 683e55ad7b meson: install radangeld 5 years ago
  Matthias Janke 22022b663c clean up sockets after shutdown 5 years ago
6 changed files with 121 additions and 5 deletions
  1. 3
    0
      meson.build
  2. 1
    1
      meson_options.txt
  3. 8
    1
      radangeld/main.cpp
  4. 1
    3
      radangeld/meson.build
  5. 107
    0
      radangeldump/main.cpp
  6. 1
    0
      radangeldump/meson.build

+ 3
- 0
meson.build View File

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

+ 1
- 1
meson_options.txt View File

@@ -1,2 +1,2 @@
1 1
 option('udev-dir', type: 'string', value: '', description: 'Absolute path of the udev base directory. Set to \'no\' not to install the udev rule')
2
-option('systemd-unit-dir', type: 'string', value: '', description: 'systemd service directory')
2
+option('systemd-unit-dir', type: 'string', value: '', description: 'Absolute path of the systemd service directory. Set to \'no\' not to install the radangeld service file.')

+ 8
- 1
radangeld/main.cpp View File

@@ -25,6 +25,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
25 25
 #include <thread>
26 26
 #include <atomic>
27 27
 #include <csignal>
28
+#include <cstdio>
28 29
 
29 30
 #include <wchar.h>
30 31
 
@@ -539,6 +540,9 @@ void publish_events (zmqpp::context &zmqc)
539 540
 		}
540 541
 	}
541 542
 	while (true);
543
+
544
+	eventpublisher.close();
545
+	std::remove("radangel.events");
542 546
 }
543 547
 
544 548
 void publish_cpm (zmqpp::context &zmqc)
@@ -575,7 +579,7 @@ void publish_cpm (zmqpp::context &zmqc)
575 579
 			if (validevents > 0)
576 580
 			{
577 581
 				cpm << timestamp
578
-				    << static_cast<double> (validevents / (timestamp - oldtimestamp) * 1000 * 60);
582
+				    << static_cast<double> (validevents / ((timestamp - oldtimestamp) / 1000.0 / 1000.0 ) * 60.0);
579 583
 
580 584
 				cpmsocket.send (cpm);
581 585
 
@@ -591,6 +595,9 @@ void publish_cpm (zmqpp::context &zmqc)
591 595
 		}
592 596
 	}
593 597
 	while (true);
598
+
599
+	cpmsocket.close();
600
+	std::remove("radangel.cpm");
594 601
 }
595 602
 
596 603
 int main (int argc, char *argv[])

+ 1
- 3
radangeld/meson.build View File

@@ -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
-executable('radangeld', 'main.cpp', dependencies : [hidapi_usb_dep, boost_dep, libconfigpp_dep, libsystemd_dep, thread_dep, zmqpp_dep, tz_dep])
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 View File

@@ -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 View File

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

Loading…
Cancel
Save