13 using namespace TCLAP;
22 res +=
"0123456789ABCDEF"[n % 16];
26 reverse(res.begin(), res.end());
38 auto t = time(
nullptr);
40 const tm* time = localtime(&
t);
42 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", time);
47 int main(
int argc,
char* argv[])
49 int default_polling_interval_ms = 100;
51 ValueArg<string> xml_arg(
"l",
"load",
"Full file path of HW Logger Events XML file",
false,
"",
"Load HW Logger Events XML file");
52 ValueArg<string> out_arg(
"o",
"out",
"Full file path of output file",
false,
"",
"Print Fw logs to output file");
53 ValueArg<int> polling_interval_arg(
"p",
"polling_interval",
"Time Interval between each log messages polling (in milliseconds)",
false, default_polling_interval_ms,
"");
54 SwitchArg flash_logs_arg(
"f",
"flash",
"Flash Logs Request",
false);
57 cmd.
add(polling_interval_arg);
58 cmd.
add(flash_logs_arg);
59 cmd.
parse(argc, argv);
63 auto use_xml_file =
false;
64 auto output_file_path = out_arg.
getValue();
65 std::ofstream output_file(output_file_path);
67 std::ostream&
out = (!output_file.is_open() ?
std::cout : output_file);
69 auto xml_full_file_path = xml_arg.
getValue();
70 auto polling_interval_ms = polling_interval_arg.
getValue();
71 if (polling_interval_ms < 25 || polling_interval_ms > 300)
73 out <<
"Polling interval time provided: " << polling_interval_ms <<
"ms, is not in the valid range [25,300]. Default value " << default_polling_interval_ms <<
"ms is used." << std::endl;
74 polling_interval_ms = default_polling_interval_ms;
77 bool are_flash_logs_requested = flash_logs_arg.
isSet();
82 bool should_loop_end =
false;
84 while (!should_loop_end)
88 out <<
"\nWaiting for RealSense device to connect...\n";
90 out <<
"RealSense device was connected...\n";
96 bool using_parser =
false;
97 if (!xml_full_file_path.empty())
99 ifstream
f(xml_full_file_path);
102 std::string xml_content((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
103 bool parser_initialized = fw_log_device.init_parser(xml_content);
104 if (parser_initialized)
109 bool are_there_remaining_flash_logs_to_pull =
true;
114 if (are_flash_logs_requested && !are_there_remaining_flash_logs_to_pull)
116 should_loop_end =
true;
121 if (are_flash_logs_requested)
127 result = fw_log_device.get_firmware_log(
log_message);
131 std::vector<string> fw_log_lines;
134 auto parsed_log = fw_log_device.create_parsed_message();
135 bool parsing_result = fw_log_device.parse_log(
log_message, parsed_log);
138 sstr <<
datetime_string() <<
" " << parsed_log.timestamp() <<
" " << parsed_log.sequence_id()
139 <<
" " << parsed_log.severity() <<
" " << parsed_log.thread_name()
140 <<
" " << parsed_log.file_name() <<
" " << parsed_log.line()
141 <<
" " << parsed_log.message();
143 fw_log_lines.push_back(sstr.str());
149 std::vector<uint8_t> msg_data =
log_message.data();
150 for (
int i = 0;
i < msg_data.size(); ++
i)
154 fw_log_lines.push_back(sstr.str());
156 for (
auto&
line : fw_log_lines)
161 if (are_flash_logs_requested)
163 are_there_remaining_flash_logs_to_pull =
false;
166 auto num_of_messages = fw_log_device.get_number_of_fw_logs();
167 if (num_of_messages == 0)
170 auto time_since_previous_polling_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
current_time - time_of_previous_polling_ms).
count();
171 if (time_since_previous_polling_ms < polling_interval_ms)
173 std::this_thread::sleep_for(chrono::milliseconds(polling_interval_ms - time_since_previous_polling_ms));
bool is_connected(const device &dev) const
static const char * log_to_file
GLsizei const GLchar *const * string
const std::string & get_failed_args() const
void parse(int argc, const char *const *argv)
#define RS2_API_VERSION_STR
device wait_for_device() const
const std::string & get_failed_function() const