16 using namespace TCLAP;
22 throw runtime_error(
"Input string was not in a correct format!");
24 vector<parameter> vec_parameters;
25 for (
auto param_index = 0; param_index < params.size(); ++param_index)
27 auto is_there_write_data = param_index >= int(command.
parameters.size());
28 auto name = (is_there_write_data) ?
"" : command.
parameters[param_index].name;
29 auto is_reverse_bytes = (is_there_write_data) ?
false : command.
parameters[param_index].is_reverse_bytes;
30 auto is_decimal = (is_there_write_data) ?
false : command.
parameters[param_index].is_decimal;
31 auto format_length = (is_there_write_data) ? -1 : command.
parameters[param_index].format_length;
32 vec_parameters.push_back(
parameter(name, params[param_index], is_decimal, is_reverse_bytes, format_length));
35 vector<uint8_t> raw_data;
42 vector<string> tokens;
43 stringstream ss(line);
47 stringstream converter;
48 converter << hex << word;
49 tokens.push_back(word);
53 throw runtime_error(
"Wrong input!");
55 auto command_str = tokens.front();
58 throw runtime_error(
"Command not found!");
62 for (
auto i = 1;
i < tokens.size(); ++
i)
63 params.push_back(tokens[
i]);
67 for (
auto b : raw_data)
69 cout << hex << fixed << setfill(
'0') << setw(2) << (int)
b <<
" ";
75 unsigned returned_opcode = *
result.data();
80 msg <<
"OpCodes do not match! Sent 0x" << hex <<
command.
op_code <<
" but received 0x" << hex << (returned_opcode) <<
"!";
81 throw runtime_error(msg.str());
88 cout << endl << data << endl;
92 cout << endl <<
"Done!" << endl;
98 vector<uint8_t> raw_data;
99 stringstream ss(line);
103 stringstream converter;
105 converter << hex << word;
107 raw_data.push_back(temp);
109 if (raw_data.empty())
110 throw runtime_error(
"Wrong input!");
116 cout << setfill('0') << setw(2) << hex << static_cast<int>(elem) <<
" ";
122 if (!is_application_in_hex_mode)
124 for (
auto& elem : commands_map)
125 commands.insert(elem.first);
132 ifstream myfile(full_file_path);
133 if (myfile.is_open())
136 while (getline(myfile, line))
137 hex_lines.push_back(line);
142 throw runtime_error(
"Script file not found!");
148 cout <<
"\nWaiting for RealSense device to connect...\n";
153 cout <<
"RealSense device has connected...\n";
158 int main(
int argc,
char** argv)
161 ValueArg<string> xml_arg(
"l",
"load",
"Full file path of commands XML file",
false,
"",
"Load commands XML file");
162 ValueArg<int> device_id_arg(
"d",
"deviceId",
"Device ID could be obtain from rs-enumerate-devices example",
false, 0,
"Select a device to work with");
163 ValueArg<string> specific_SN_arg(
"n",
"serialNum",
"Serial Number can be obtain from rs-enumerate-devices example",
false,
"",
"Select a device serial number to work with");
164 SwitchArg all_devices_arg(
"a",
"allDevices",
"Do this command to all attached Realsense Devices",
false);
165 ValueArg<string> hex_cmd_arg(
"s",
"send",
"Hexadecimal raw data",
false,
"",
"Send hexadecimal raw data to device");
166 ValueArg<string> hex_script_arg(
"r",
"raw",
"Full file path of hexadecimal raw data script",
false,
"",
"Send raw data line by line from script file");
167 ValueArg<string> commands_script_arg(
"c",
"cmd",
"Full file path of commands script",
false,
"",
"Send commands line by line from script file");
169 cmd.
add(device_id_arg);
170 cmd.
add(specific_SN_arg);
171 cmd.
add(all_devices_arg);
172 cmd.
add(hex_cmd_arg);
173 cmd.
add(hex_script_arg);
174 cmd.
add(commands_script_arg);
175 cmd.
parse(argc, argv);
183 if (all_device_list.
size() == 0) {
184 std::cout <<
"\nLibrealsense is not detecting any devices" << std::endl;
188 std::vector<rs2::device> rs_device_list;
190 for (
size_t i = 0;
i < all_device_list.
size();
i++) {
193 rs_device_list.push_back(all_device_list[
i]);
200 auto num_rs_devices = rs_device_list.
size();
201 if (rs_device_list.size() == 0) {
202 std::cout <<
"\nLibrealsense is not detecting any Realsense cameras" << std::endl;
206 auto xml_full_file_path = xml_arg.
getValue();
207 map<string, xml_parser_function> format_type_to_lambda;
209 auto is_application_in_hex_mode =
true;
211 if (!xml_full_file_path.empty())
216 cout <<
"Provided XML not found!\n";
221 is_application_in_hex_mode =
false;
222 cout <<
"Commands XML file - " << xml_full_file_path <<
" was loaded successfully. Type commands by name (e.g.'gvd'`).\n";
226 cout <<
"Commands XML file not provided.\nyou still can send raw data to device in hexadecimal\nseparated by spaces.\n";
227 cout <<
"Example GVD command for the SR300:\n14 00 ab cd 3b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n";
228 cout <<
"Example GVD command for the RS4xx:\n14 00 ab cd 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\n";
233 std::vector<rs2::device> selected_rs_devices;
236 if (all_devices_arg.
isSet()) {
237 for (
size_t i = 0;
i < num_rs_devices;
i++) {
239 selected_rs_devices.push_back(rs_device_list[
i]);
243 else if (specific_SN_arg.
isSet()) {
244 auto desired_sn = specific_SN_arg.
getValue();
245 bool device_not_found =
true;
246 for (
size_t i = 0;
i < num_rs_devices;
i++) {
248 if (device_sn.compare(desired_sn) == 0) {
249 selected_rs_devices.push_back(rs_device_list[
i]);
250 device_not_found =
false;
251 std::cout <<
"\nDevice with SN: " << device_sn <<
" has loaded.\n";
255 if (device_not_found) {
256 std::cout <<
"\nGiven device serial number doesn't exist! desired serial number=" << desired_sn << std::endl;
261 else if (device_id_arg.
isSet())
263 auto dev_id = device_id_arg.
getValue();
264 if (num_rs_devices < (dev_id + 1))
266 std::cout <<
"\nGiven device_id doesn't exist! device_id=" <<
267 dev_id <<
" ; connected devices=" << num_rs_devices << std::endl;
271 for (
int i = 0;
i < (num_rs_devices - 1); ++
i)
275 selected_rs_devices.push_back(rs_device_list[dev_id]);
276 std::cout <<
"\nDevice ID " << dev_id <<
" has loaded.\n";
278 else if (rs_device_list.size() == 1)
280 selected_rs_devices.push_back(rs_device_list[0]);
284 std::cout <<
"\nEnter a command line option:" << std::endl;
285 std::cout <<
"-d to choose by device number" << std::endl;
286 std::cout <<
"-n to choose by serial number" << std::endl;
287 std::cout <<
"-a to send to all devices" << std::endl;
291 if (selected_rs_devices.empty()) {
292 std::cout <<
"\nNo devices were selected. Recheck input arguments" << std::endl;
296 if (hex_cmd_arg.
isSet())
298 for (
auto dev : selected_rs_devices) {
304 catch (
const exception& ex)
306 cout << endl << ex.what() << endl;
315 vector<string> script_lines;
316 if (hex_script_arg.
isSet())
318 script_file = hex_script_arg.
getValue();
320 else if (commands_script_arg.
isSet())
322 script_file = commands_script_arg.
getValue();
325 if (!script_file.empty())
328 if (hex_script_arg.
isSet())
330 for (
auto dev : selected_rs_devices) {
333 for (
auto& elem : script_lines)
336 catch (
const exception& ex)
338 cout << endl << ex.what() << endl;
348 if (commands_script_arg.
isSet())
350 for (
auto dev : selected_rs_devices) {
353 for (
auto& elem : script_lines)
354 xml_mode(elem, cmd_xml,
dev, format_type_to_lambda);
356 catch (
const exception& ex)
358 cout << endl << ex.what() << endl;
365 auto dev = selected_rs_devices[0];
388 for (
auto&&
dev : selected_rs_devices)
393 if (is_application_in_hex_mode)
399 xml_mode(line, cmd_xml,
dev, format_type_to_lambda);
408 catch (
const exception & e)
410 cerr << e.what() << endl;
GLboolean GLboolean GLboolean b
void read_script_file(const string &full_file_path, vector< string > &hex_lines)
bool is_connected(const device &dev) const
GLuint const GLchar * name
bool parse_xml_from_file(const std::string &xml_full_file_path, commands_xml &cmd_xml)
void hex_mode(const string &line, rs2::device &dev)
device_list query_devices() const
rs2::device wait_for_device(const rs2::device_hub &hub, bool print_info=true)
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)
auto_complete get_auto_complete_obj(bool is_application_in_hex_mode, const map< string, command > &commands_map)
GLsizei const GLchar *const * string
int main(int argc, char **argv)
GLsizei const GLubyte * commands
vector< uint8_t > build_raw_command_data(const command &command, const vector< string > ¶ms)
const std::string & get_failed_args() const
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
std::map< std::string, command_from_xml > commands
void log_to_file(rs2_log_severity min_severity, const char *file_path=nullptr)
void parse(int argc, const char *const *argv)
#define RS2_API_VERSION_STR
device wait_for_device() const
std::map< std::string, custom_formatter > custom_formatters
void xml_mode(const string &line, const commands_xml &cmd_xml, rs2::device &dev, map< string, xml_parser_function > &format_type_to_lambda)
const std::string & get_failed_function() const
void encode_raw_data_command(const command_from_xml &xml_cmd_info, const std::vector< parameter > ¶ms, std::vector< uint8_t > &raw_data)