| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*
- radangeldump -- a simple shell that displays data distributed by a radageld
- Copyright (C) 2020 Matthias Janke <matthias.janke@physi.uni-heidelberg.de>
-
- This program is free software: you can redistribute it and/or modify it under
- the terms of the GNU Affero General Public License as published by the Free
- Software Foundation, version 3.
-
- This program is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along
- with this program. If not, see <https://www.gnu.org/licenses/>
- */
- // SPDX-License-Identifier: AGPL-3.0-only
-
- #include <iostream>
-
- // program option parser
- #include <boost/program_options.hpp>
-
- // thread/ipc/tcp communications
- #include <zmqpp/zmqpp.hpp>
-
- int main(int argc, char *argv[])
- {
- int64_t timestamp{0};
- uint16_t event{0};
- double countrate{0.0};
-
- bool events;
- bool cpm;
-
- std::string socket;
-
- zmqpp::context zmqc;
-
- boost::program_options::options_description desc ("Available options:");
- desc.add_options()
- ("help,?", "Prints this list of available options.")
- ("events,e", boost::program_options::value<bool> (&events)->implicit_value (true)->default_value (true), "Socket publishes events.")
- ("cpm,c", boost::program_options::value<bool> (&cpm)->implicit_value (true)->default_value (false), "Socket publishes counts per minute.")
- ("socket,s", boost::program_options::value<std::string> (&socket)->default_value("ipc://radangel.events"), "Socket to connect to.")
- ;
-
- boost::program_options::positional_options_description p;
- p.add ("socket", -1);
-
- boost::program_options::variables_map vm;
- boost::program_options::store (boost::program_options::command_line_parser (argc, argv).options (desc).positional (p).run(), vm);
- boost::program_options::notify (vm);
-
- if (vm.count ("help") )
- {
- std::cout << "Usage: " << argv[0] << " [options] [socket]\n";
- std::cout << desc;
- return 0;
- }
-
- if (vm["events"].defaulted() && !vm["cpm"].defaulted())
- events = false;
-
- if (events == cpm)
- {
- std::cerr << "Please decide if you either want events or counts per minute displayed! Only one of both options is valid." << std::endl;
- return -1;
- }
-
- if (cpm && vm["socket"].defaulted())
- socket = "ipc://radangel.cpm";
-
- zmqpp::socket radangelsocket (zmqc, zmqpp::socket_type::subscribe);
- radangelsocket.connect (socket);
- radangelsocket.subscribe ("");
- zmqpp::message messages;
-
- if(events)
- std::cout << "Energy [Ch]\trelative timestamp[µs]\n";
- else if (cpm)
- std::cout << "relative timestamp[µs]\tCoutrate [1/min]\n";
-
- do
- {
- radangelsocket.receive(messages);
-
- if(events)
- {
- messages >> event
- >> timestamp;
- std::cout << event << "\t"
- << timestamp << "\n";
- }
- else if(cpm)
- {
- messages >> timestamp
- >> countrate;
- std::cout << timestamp << "\t"
- << countrate << "\n";
- }
- else
- break;
- }
- while(true);
-
- return 0;
- }
|