forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rs-fw-logger.cpp
131 lines (107 loc) · 4 KB
/
rs-fw-logger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.
#include <librealsense2/rs.hpp>
#include <fstream>
#include <thread>
#include "tclap/CmdLine.h"
#include "fw-logs-parser.h"
using namespace std;
using namespace TCLAP;
using namespace fw_logger;
using namespace rs2;
string hexify(unsigned char n)
{
string res;
do
{
res += "0123456789ABCDEF"[n % 16];
n >>= 4;
} while (n);
reverse(res.begin(), res.end());
if (res.size() == 1)
{
res.insert(0, "0");
}
return res;
}
string datetime_string()
{
auto t = time(nullptr);
char buffer[20] = {};
const tm* time = localtime(&t);
if (nullptr != time)
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", time);
return string(buffer);
}
int main(int argc, char* argv[])
{
CmdLine cmd("librealsense rs-fw-logger example tool", ' ', RS2_API_VERSION_STR);
ValueArg<string> xml_arg("l", "load", "Full file path of HW Logger Events XML file", false, "", "Load HW Logger Events XML file");
cmd.add(xml_arg);
cmd.parse(argc, argv);
log_to_file(RS2_LOG_SEVERITY_WARN, "librealsense.log");
// Obtain a list of devices currently present on the system
unique_ptr<fw_logs_parser> fw_log_parser;
auto use_xml_file = false;
auto xml_full_file_path = xml_arg.getValue();
if (!xml_full_file_path.empty())
{
ifstream f(xml_full_file_path);
if (f.good())
{
fw_log_parser = unique_ptr<fw_logs_parser>(new fw_logs_parser(xml_full_file_path));
use_xml_file = true;
}
}
context ctx;
device_hub hub(ctx);
while (true)
{
try
{
cout << "\nWaiting for RealSense device to connect...\n";
auto dev = hub.wait_for_device();
cout << "RealSense device was connected...\n";
vector<uint8_t> input;
auto str_op_code = dev.get_info(RS2_CAMERA_INFO_DEBUG_OP_CODE);
auto op_code = static_cast<uint8_t>(stoi(str_op_code));
input = {0x14, 0x00, 0xab, 0xcd, op_code, 0x00, 0x00, 0x00,
0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
cout << "Device Name: " << dev.get_info(RS2_CAMERA_INFO_NAME) << endl <<
"Device Location: " << dev.get_info(RS2_CAMERA_INFO_PHYSICAL_PORT) << endl << endl;
setvbuf(stdout, NULL, _IONBF, 0); // unbuffering stdout
while (hub.is_connected(dev))
{
this_thread::sleep_for(chrono::milliseconds(100));
auto raw_data = dev.as<debug_protocol>().send_and_receive_raw_data(input);
vector<string> fw_log_lines = {""};
if (raw_data.size() <= 4)
continue;
if (use_xml_file)
{
fw_logs_binary_data fw_logs_binary_data = {raw_data};
fw_logs_binary_data.logs_buffer.erase(fw_logs_binary_data.logs_buffer.begin(),fw_logs_binary_data.logs_buffer.begin()+4);
fw_log_lines = fw_log_parser->get_fw_log_lines(fw_logs_binary_data);
for (auto& elem : fw_log_lines)
elem = datetime_string() + " " + elem;
}
else
{
stringstream sstr;
sstr << datetime_string() << " FW_Log_Data:";
for (size_t i = 0; i < raw_data.size(); ++i)
sstr << hexify(raw_data[i]) << " ";
fw_log_lines.push_back(sstr.str());
}
for (auto& line : fw_log_lines)
cout << line << endl;
}
}
catch (const error & e)
{
cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << endl;
}
}
return EXIT_SUCCESS;
}