ArmNN
 22.08
CommandFileParser Class Reference

This class parses a command file for the GatordMockService. More...

#include <CommandFileParser.hpp>

Public Member Functions

void ParseFile (std::string CommandFile, GatordMockService &mockService)
 

Detailed Description

This class parses a command file for the GatordMockService.

The file contains one command per line. Valid commands are: SET and WAIT.

SET: Will construct and send a PeriodicCounterSelection packet to enable a set of counters. WAIT: Will pause for a set period of time to allow for data to be received.

Definition at line 22 of file CommandFileParser.hpp.

Member Function Documentation

◆ ParseFile()

void ParseFile ( std::string  CommandFile,
GatordMockService mockService 
)

Definition at line 19 of file CommandFileParser.cpp.

References GatordMockService::ReceiveThreadRunning(), GatordMockService::SendActivateTimelinePacket(), GatordMockService::SendDeactivateTimelinePacket(), GatordMockService::SendPeriodicCounterSelectionList(), GatordMockService::SendRequestCounterDir(), and GatordMockService::WaitCommand().

Referenced by CreateMockService().

20 {
21  std::ifstream infile(CommandFile);
22  std::string line;
23 
24  std::cout << "Parsing command file: " << CommandFile << std::endl;
25 
26  while (mockService.ReceiveThreadRunning() && std::getline(infile, line))
27  {
28  std::istringstream iss(line);
29  std::vector<std::string> tokens;
30 
31  std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
32  std::back_inserter(tokens));
33  if (tokens.size() > 0)
34  {
35  std::string command = tokens[0];
36  if (command == "DISABLE")
37  {
38  // Send a deactivate timeline packet
39  // Expected format for the ENABLE command
40  //
41  // DISABLE
42  //
43  mockService.SendDeactivateTimelinePacket();
44  }
45  else if (command == "ENABLE")
46  {
47  // Send aa activate timeline packet
48  // Expected format for the ENABLE command
49  //
50  // ENABLE
51  //
52  mockService.SendActivateTimelinePacket();
53  }
54  else if (command == "LIST")
55  {
56  // Request the Counter Directory
57  // Expected format for the LIST command
58  //
59  // LIST
60  //
61 
62  mockService.SendRequestCounterDir();
63  }
64  if (command == "SET")
65  {
66  // Send a periodic counter selection packet
67  // Expected format for the SET command
68  //
69  // SET 500000 1 2 5 10
70  //
71  // This breaks down to:
72  // SET command
73  // 500000 polling period in micro seconds
74  // 1 2 5 10 counter list
75 
76  if (tokens.size() > 2) // minimum of 3 tokens.
77  {
78  uint32_t period = static_cast<uint32_t>(std::stoul(tokens[1]));
79 
80  std::vector<uint16_t> counters;
81 
82  std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
83  [](const std::string& str)
84  { return static_cast<uint16_t>(std::stoul(str)); });
85 
86  mockService.SendPeriodicCounterSelectionList(period, counters);
87  }
88  else
89  {
90  std::cerr << "Invalid SET command. Format is: SET <polling period> <id list>" << std::endl;
91  }
92  }
93  else if (command == "WAIT")
94  {
95  // Wait for an interval of time in microseconds
96  // Expected format for the WAIT command
97  //
98  // WAIT 11000000
99  //
100  // This breaks down to:
101  // WAIT command
102  // 11000000 timeout period in microseconds
103  if (tokens.size() > 1) // minimum of 2 tokens.
104  {
105  uint32_t timeout = static_cast<uint32_t>(std::stoul(tokens[1]));
106  mockService.WaitCommand(timeout);
107  }
108  else
109  {
110  std::cerr << "Invalid WAIT command. Format is: WAIT <interval>" << std::endl;
111  }
112  }
113  }
114  }
115 }

The documentation for this class was generated from the following files: