src/android/fw-logger/rs-fw-logger.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include "rs-fw-logger.h"
5 
6 #include <android/log.h>
7 #include <sstream>
8 #include <thread>
9 #include <chrono>
10 #include <fstream>
11 
12 #include "../../../tools/fw-logger/fw-logs-parser.h"
13 #include "../../../include/librealsense2/hpp/rs_context.hpp"
14 
15 #define TAG "rs_fw_log"
16 
18 {
19  __android_log_print(ANDROID_LOG_INFO, TAG, "%s", message.c_str());
20 }
21 
22 std::string hexify(unsigned char n)
23 {
25 
26  do
27  {
28  res += "0123456789ABCDEF"[n % 16];
29  n >>= 4;
30  } while (n);
31 
32  std::reverse(res.begin(), res.end());
33 
34  if (res.size() == 1)
35  {
36  res.insert(0, "0");
37  }
38 
39  return res;
40 }
41 
43 {
44  _active = true;
45 
46  std::unique_ptr<fw_logger::fw_logs_parser> fw_log_parser;
47  auto use_xml_file = false;
48  if (!_xml_path.empty())
49  {
50  std::ifstream f(_xml_path);
51  if (f.good())
52  {
53  fw_log_parser = std::unique_ptr<fw_logger::fw_logs_parser>(new fw_logger::fw_logs_parser(_xml_path));
54  use_xml_file = true;
55  }
56  }
57 
58  while(_active)
59  { try
60  {
62  auto devs = ctx.query_devices();
63  if(devs.size() == 0){
64  _active = false;
65  break;
66  }
67  auto dev = ctx.query_devices()[0];
68 
69  std::vector<uint8_t> input;
70  auto str_op_code = dev.get_info(RS2_CAMERA_INFO_DEBUG_OP_CODE);
71  auto op_code = static_cast<uint8_t>(std::stoi(str_op_code));
72  input = {0x14, 0x00, 0xab, 0xcd, op_code, 0x00, 0x00, 0x00,
73  0xf4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
75 
76  std::stringstream dev_info;
77  dev_info << "Device Name: " << dev.get_info(RS2_CAMERA_INFO_NAME) << "\nDevice Location: " << dev.get_info(RS2_CAMERA_INFO_PHYSICAL_PORT) << "\n\n";
78  log(dev_info.str());
79 
80  while (_active)
81  {
82  std::this_thread::sleep_for(std::chrono::milliseconds(_sample_rate));
83 
84  auto raw_data = dev.as<rs2::debug_protocol>().send_and_receive_raw_data(input);
85  std::vector<std::string> fw_log_lines = {""};
86  if (raw_data.size() <= 4)
87  continue;
88 
89  if (use_xml_file)
90  {
91  fw_logger::fw_logs_binary_data fw_logs_binary_data = {raw_data};
92  fw_logs_binary_data.logs_buffer.erase(fw_logs_binary_data.logs_buffer.begin(),fw_logs_binary_data.logs_buffer.begin()+4);
93  fw_log_lines = fw_log_parser->get_fw_log_lines(fw_logs_binary_data);
94  }
95  else
96  {
97  std::stringstream sstr;
98  sstr << "FW_Log_Data:";
99  for (size_t i = 0; i < raw_data.size(); ++i)
100  sstr << hexify(raw_data[i]) << " ";
101 
102  fw_log_lines.push_back(sstr.str());
103  }
104 
105  for (auto& line : fw_log_lines)
106  log(line);
107 
108  }
109  }
110  catch (const rs2::error & e)
111  {
112  std::stringstream cerr;
113  cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what();
114 
115  log(cerr.str());
116  }
117  }
118 }
119 
120 android_fw_logger::android_fw_logger(std::string xml_path, int sample_rate) : _xml_path(xml_path), _sample_rate(sample_rate)
121 {
122  log("StartReadingFwLogs");
123  _thread = std::thread(&android_fw_logger::read_log_loop, this);
124 }
125 
127 {
128  log("StopReadingFwLogs");
129  _active = false;
130  _thread.join();
131 }
GLenum GLuint GLenum GLsizei const GLchar * message
std::string _xml_path
Definition: rs-fw-logger.h:16
device_list query_devices() const
Definition: rs_context.hpp:112
android_fw_logger(std::string xml_path="", int sample_rate=100)
GLsizei const GLchar *const * string
GLdouble n
Definition: glext.h:1966
unsigned char uint8_t
Definition: stdint.h:78
e
Definition: rmse.py:177
const std::string & get_failed_args() const
Definition: rs_types.hpp:117
GLdouble f
std::thread _thread
Definition: rs-fw-logger.h:15
std::string hexify(unsigned char n)
GLenum GLenum GLenum input
Definition: glext.h:10805
void log(std::string message)
std::ostream & cerr()
int stoi(const std::string &value)
int i
GLuint res
Definition: glext.h:8856
const std::string & get_failed_function() const
Definition: rs_types.hpp:112


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40