Colm Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 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 | |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 26 | while (mockService.ReceiveThreadRunning() && std::getline(infile, line)) |
Colm Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 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 | |
Finn Williams | 15db745 | 2019-10-15 14:22:13 +0100 | [diff] [blame] | 37 | if (command == "LIST") |
| 38 | { |
| 39 | // Expected format for the SET command |
| 40 | // |
| 41 | // LIST |
| 42 | // |
| 43 | |
| 44 | mockService.SendRequestCounterDir(); |
| 45 | } |
Colm Donelan | a21620d | 2019-10-11 13:09:49 +0100 | [diff] [blame] | 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 | uint period = static_cast<uint>(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 | uint timeout = static_cast<uint>(std::stoul(tokens[1])); |
| 77 | |
| 78 | mockService.WaitCommand(timeout); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | } // namespace gatordmock |
| 84 | |
| 85 | } // namespace armnn |