14 if (!xml_content.empty())
27 get_command_and_params_from_input(line, command, params);
31 for (
auto b : raw_data)
33 cout << hex << fixed << setfill(
'0') << setw(2) << (int)
b <<
" ";
41 const std::vector<uint8_t>& response)
const 46 get_command_and_params_from_input(line, command, params);
48 unsigned returned_opcode = *response.data();
50 if (command.
op_code != returned_opcode)
53 msg <<
"OpCodes do not match! Sent 0x" << hex << command.
op_code <<
" but received 0x" << hex << (returned_opcode) <<
"!";
54 throw runtime_error(msg.str());
61 vector<uint8_t> data_vec;
62 data_vec.insert(data_vec.begin(), data.begin(), data.end());
74 throw runtime_error(
"Input string was not in a correct format!");
76 vector<parameter> vec_parameters;
77 for (
auto param_index = 0; param_index < params.size(); ++param_index)
79 auto is_there_write_data = param_index >= int(command.
parameters.size());
80 auto name = (is_there_write_data) ?
"" : command.
parameters[param_index].name;
81 auto is_reverse_bytes = (is_there_write_data) ?
false : command.
parameters[param_index].is_reverse_bytes;
82 auto is_decimal = (is_there_write_data) ?
false : command.
parameters[param_index].is_decimal;
83 auto format_length = (is_there_write_data) ? -1 : command.
parameters[param_index].format_length;
84 vec_parameters.push_back(
parameter(name, params[param_index], is_decimal, is_reverse_bytes, format_length));
87 vector<uint8_t> raw_data;
93 vector<string>&
params)
const 95 vector<string> tokens;
96 stringstream ss(line);
100 stringstream converter;
101 converter << hex << word;
102 tokens.push_back(word);
106 throw runtime_error(
"Wrong input!");
108 auto command_str = tokens.front();
109 auto it = _cmd_xml.commands.find(command_str);
110 if (
it == _cmd_xml.commands.end())
111 throw runtime_error(
"Command not found!");
113 command =
it->second;
114 for (
auto i = 1;
i < tokens.size(); ++
i)
115 params.push_back(tokens[
i]);
void get_command_and_params_from_input(const std::string &line, command_from_xml &command, std::vector< std::string > ¶ms) const
GLboolean GLboolean GLboolean b
GLuint const GLchar * name
std::vector< uint8_t > parse_command(const std::string &command) const
void decode_string_from_raw_data(const command_from_xml &command, const std::map< std::string, custom_formatter > &custom_formatters, const uint8_t *raw_data_offset, size_t data_size, std::string &output, const std::map< std::string, xml_parser_function > &format_type_to_lambda)
GLsizei const GLchar *const * string
vector< uint8_t > build_raw_command_data(const command &command, const vector< string > ¶ms)
void parse_xml_from_memory(const char *content, commands_xml &cmd_xml)
std::vector< parameter > parameters
void update_format_type_to_lambda(std::map< std::string, xml_parser_function > &format_type_to_lambda)
GLenum const GLfloat * params
terminal_parser(const std::string &xml_content)
std::vector< uint8_t > parse_response(const std::string &command, const std::vector< uint8_t > &response) const
std::vector< uint8_t > build_raw_command_data(const command_from_xml &command, const std::vector< std::string > ¶ms) const
void encode_raw_data_command(const command_from_xml &xml_cmd_info, const std::vector< parameter > ¶ms, std::vector< uint8_t > &raw_data)