PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/communication_tests/src/ArgumentParser.cpp

https://gitlab.com/F34140r/ros_realtime_tests
C++ | 79 lines | 67 code | 5 blank | 7 comment | 27 complexity | b565b112fc00938df3f30d25efea7664 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. /**
  2. * Copyright (C) 2014, BMW Car IT GmbH
  3. * Author: Jonas Sticha (Jonas.Sticha@bmw-carit.de)
  4. *
  5. * This software is licensed under BSD 3-clause License
  6. * (see http://spdx.org/licenses/BSD-3-Clause).
  7. **/
  8. #include "Config.h"
  9. #include "ArgumentParser.h"
  10. #include <rt_tests_support/Logger.h>
  11. ArgumentParser::ArgumentParser()
  12. {
  13. }
  14. bool ArgumentParser::parseArgs(int argc, char* argv[])
  15. {
  16. Config* config = Config::getConfig();
  17. config->rtPrio = false;
  18. config->fifoScheduling = false;
  19. config->amountMessages = 1000;
  20. config->pubFrequency = 1000;
  21. config->payloadLength = 0;
  22. config->startDelay = 0;
  23. for(int i = 1; i < argc; i++)
  24. {
  25. std::string arg(argv[i]);
  26. if(arg.compare("-s") == 0)
  27. {
  28. std::string val(argv[i+1]);
  29. if(val.compare("0") == 0)
  30. {
  31. config->rtPrio = false;
  32. } else if(val.compare("RR") == 0)
  33. {
  34. config->rtPrio = true;
  35. config->fifoScheduling = false;
  36. } else if(val.compare("FIFO") == 0)
  37. {
  38. config->rtPrio = true;
  39. config->fifoScheduling = true;
  40. } else {
  41. return false;
  42. }
  43. i++;
  44. } else if(arg.compare("-r") == 0)
  45. {
  46. config->amountMessages = atoi(argv[i+1]);
  47. i++;
  48. } else if(arg.compare("-f") == 0)
  49. {
  50. config->pubFrequency = atoi(argv[i+1]);
  51. i++;
  52. } else if(arg.compare("-l") == 0)
  53. {
  54. config->payloadLength = atoi(argv[i+1]);
  55. i++;
  56. } else if(arg.compare("-p") == 0)
  57. {
  58. config->namePrefix = std::string(argv[i+1]);
  59. i++;
  60. } else if(arg.compare("-d") == 0)
  61. {
  62. config->startDelay = atoi(argv[i+1]);
  63. i++;
  64. }
  65. }
  66. return true;
  67. }
  68. void ArgumentParser::printUsage()
  69. {
  70. Logger::ERROR("Args: [-f <frequency>] [-r <repetitions>] [-s <0/RR/FIFO>] [-l <payload_length>] [-p <file_prefix>] [-d <start_delay(seconds)>]");
  71. }
  72. ArgumentParser::~ArgumentParser()
  73. {
  74. }