您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

main.cpp 3.2KB

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