PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/oneshot_timer_tests/src/ArgumentParser.cpp

https://gitlab.com/F34140r/ros_realtime_tests
C++ | 73 lines | 61 code | 5 blank | 7 comment | 24 complexity | ac5e87c6c7ef2c848338bb294d815835 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. ArgumentParser::ArgumentParser()
  11. {
  12. }
  13. bool ArgumentParser::parseArgs(int argc, char* argv[])
  14. {
  15. Config* config = Config::getConfig();
  16. config->loops = 1000;
  17. config->timeout_us = 1000;
  18. config->testnodeRT = false;
  19. bool error = false;
  20. for(int i = 1; i < argc; i++)
  21. {
  22. std::string arg(argv[i]);
  23. if(arg.compare("-s") == 0)
  24. {
  25. std::string val(argv[i+1]);
  26. if(val.compare("0") == 0)
  27. {
  28. config->testnodeRT = false;
  29. } else if(val.compare("RR") == 0)
  30. {
  31. config->testnodeRT = true;
  32. config->fifoScheduling = false;
  33. } else if(val.compare("FIFO") == 0)
  34. {
  35. config->testnodeRT = true;
  36. config->fifoScheduling = true;
  37. } else {
  38. error = true;
  39. continue;
  40. }
  41. i++;
  42. } else if(arg.compare("-r") == 0)
  43. {
  44. config->loops = atoi(argv[i+1]);
  45. i++;
  46. } else if(arg.compare("-t") == 0)
  47. {
  48. config->timeout_us = atoi(argv[i+1]);
  49. i++;
  50. } else if(arg.compare("-p") == 0)
  51. {
  52. config->namePrefix = std::string(argv[i+1]);
  53. i++;
  54. } else if(arg.compare("-b") == 0)
  55. {
  56. config->busyMode = atoi(argv[i+1]);
  57. i++;
  58. }
  59. }
  60. return !error;
  61. }
  62. std::string ArgumentParser::getUsage()
  63. {
  64. return "Args: [-t <timeout(microseconds)>] [-r <repetitions>] [-s <0/RR/FIFO>] [-p <file/name_prefix>] [-b <(busy_mode)0/1>]";
  65. }
  66. ArgumentParser::~ArgumentParser()
  67. {
  68. }