blob: 7c746f16e9fcae9e7ac234ee925d328d43742e6a [file] [log] [blame]
Colm Donelana21620d2019-10-11 13:09:49 +01001//
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
13namespace armnn
14{
15
16namespace gatordmock
17{
18
19void 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
Colm Donelan02705242019-11-14 14:19:07 +000026 while (mockService.ReceiveThreadRunning() && std::getline(infile, line))
Colm Donelana21620d2019-10-11 13:09:49 +010027 {
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
Finn Williams15db7452019-10-15 14:22:13 +010037 if (command == "LIST")
38 {
39 // Expected format for the SET command
40 //
41 // LIST
42 //
43
44 mockService.SendRequestCounterDir();
45 }
Colm Donelana21620d2019-10-11 13:09:49 +010046 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
Rob Hughes25b74362020-01-13 11:14:59 +000057 uint32_t period = static_cast<uint32_t>(std::stoul(tokens[1]));
Colm Donelana21620d2019-10-11 13:09:49 +010058
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
Rob Hughes25b74362020-01-13 11:14:59 +000076 uint32_t timeout = static_cast<uint32_t>(std::stoul(tokens[1]));
Colm Donelana21620d2019-10-11 13:09:49 +010077
78 mockService.WaitCommand(timeout);
79 }
80 }
81}
82
83} // namespace gatordmock
84
85} // namespace armnn