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