ArmNN
 20.02
CommandFileParser.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "CommandFileParser.hpp"
7 
8 #include <algorithm>
9 #include <fstream>
10 #include <iostream>
11 #include <iterator>
12 
13 namespace armnn
14 {
15 
16 namespace gatordmock
17 {
18 
19 void CommandFileParser::ParseFile(std::string CommandFile, GatordMockService& mockService)
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 == "LIST")
37  {
38  // Expected format for the SET command
39  //
40  // LIST
41  //
42 
43  mockService.SendRequestCounterDir();
44  }
45  if (command == "SET")
46  {
47  // Expected format for the SET command
48  //
49  // SET 500000 1 2 5 10
50  //
51  // This breaks down to:
52  // SET command
53  // 500000 polling period in micro seconds
54  // 1 2 5 10 counter list
55 
56  if (tokens.size() > 2) // minimum of 3 tokens.
57  {
58  uint32_t period = static_cast<uint32_t>(std::stoul(tokens[1]));
59 
60  std::vector<uint16_t> counters;
61 
62  std::transform(tokens.begin() + 2, tokens.end(), std::back_inserter(counters),
63  [](const std::string& str)
64  { return static_cast<uint16_t>(std::stoul(str)); });
65 
66  mockService.SendPeriodicCounterSelectionList(period, counters);
67  }
68  else
69  {
70  std::cerr << "Invalid SET command. Format is: SET <polling period> <id list>" << std::endl;
71  }
72  }
73  else if (command == "WAIT")
74  {
75  // Expected format for the SET command
76  //
77  // WAIT 11000000
78  //
79  // This breaks down to:
80  // WAIT command
81  // 11000000 timeout period in micro seconds
82  if (tokens.size() > 1) // minimum of 2 tokens.
83  {
84  uint32_t timeout = static_cast<uint32_t>(std::stoul(tokens[1]));
85  mockService.WaitCommand(timeout);
86  }
87  else
88  {
89  std::cerr << "Invalid WAIT command. Format is: WAIT <interval>" << std::endl;
90  }
91  }
92  }
93  }
94 }
95 
96 } // namespace gatordmock
97 
98 } // namespace armnn
void ParseFile(std::string CommandFile, GatordMockService &mockService)
Copyright (c) 2020 ARM Limited.
void SendRequestCounterDir()
Send a request counter directory packet back to the client.
A class that implements a Mock Gatord server.
void WaitCommand(uint32_t timeout)
Execute the WAIT command from the comamnd file.
void SendPeriodicCounterSelectionList(uint32_t period, std::vector< uint16_t > counters)
Send the counter list to ArmNN.