ArmNN  NotReleased
CommandFileParser Class Reference

#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::SendPeriodicCounterSelectionList(), GatordMockService::SendRequestCounterDir(), and GatordMockService::WaitCommand().

Referenced by main().

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 
30  std::vector<std::string> tokens;
31 
32  std::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
33  std::back_inserter(tokens));
34 
35  std::string command = tokens[0];
36 
37  if (command == "LIST")
38  {
39  // Expected format for the SET command
40  //
41  // LIST
42  //
43 
44  mockService.SendRequestCounterDir();
45  }
46  if (command == "SET")
47  {
48  // Expected format for the SET command
49  //
50  // SET 500000 1 2 5 10
51  //
52  // This breaks down to:
53  // SET command
54  // 500000 polling period in micro seconds
55  // 1 2 5 10 counter list
56 
57  uint32_t period = static_cast<uint32_t>(std::stoul(tokens[1]));
58 
59  std::vector<uint16_t> counters;
60 
61  std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
62  [](const std::string& str) { return static_cast<uint16_t>(std::stoul(str)); });
63 
64  mockService.SendPeriodicCounterSelectionList(period, counters);
65  }
66  else if (command == "WAIT")
67  {
68  // Expected format for the SET command
69  //
70  // WAIT 11000000
71  //
72  // This breaks down to:
73  // WAIT command
74  // 11000000 timeout period in micro seconds
75 
76  uint32_t timeout = static_cast<uint32_t>(std::stoul(tokens[1]));
77 
78  mockService.WaitCommand(timeout);
79  }
80  }
81 }

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