hw-monitor.h
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 #pragma once
5 
6 #include "sensor.h"
7 #include <mutex>
8 #include "command_transfer.h"
9 
10 namespace librealsense
11 {
16  const uint8_t IV_COMMAND_ZUNIT = 0x05;
24 
34 
44 
45  class uvc_sensor;
46 
48  {
68  hwm_WrongCRC = -19,
81  hwm_Timeout = -32,
100  hwm_HotLaserPwrReduce = -51, // reported to error depth XU control
101  hwm_HotLaserDisable = -52, // reported to error depth XU control
102  hwm_FlagBLaserDisable = -53, // reported to error depth XU control
112  hwm_IspFail = -63,
113  hwm_Unknown = -64,
115  };
116 
117  // Elaborate HW Monitor response
118  const std::map< hwmon_response, std::string> hwmon_response_report = {
119  { hwmon_response::hwm_Success, "Success" },
120  { hwmon_response::hwm_WrongCommand, "Invalid Command" },
121  { hwmon_response::hwm_StartNGEndAddr, "Start NG End Address" },
122  { hwmon_response::hwm_AddressSpaceNotAligned, "Address space not aligned" },
123  { hwmon_response::hwm_AddressSpaceTooSmall, "Address space too small" },
124  { hwmon_response::hwm_ReadOnly, "Read-only" },
125  { hwmon_response::hwm_WrongParameter, "Invalid parameter" },
126  { hwmon_response::hwm_HWNotReady, "HW not ready" },
127  { hwmon_response::hwm_I2CAccessFailed, "I2C access failed" },
128  { hwmon_response::hwm_NoExpectedUserAction, "No expected user action" },
129  { hwmon_response::hwm_IntegrityError, "Integrity error" },
130  { hwmon_response::hwm_NullOrZeroSizeString, "Null or zero size string" },
131  { hwmon_response::hwm_GPIOPinNumberInvalid, "GPIOP in number invalid" },
132  { hwmon_response::hwm_GPIOPinDirectionInvalid, "GPIOP in direction invalid" },
133  { hwmon_response::hwm_IllegalAddress, "Illegal address" },
134  { hwmon_response::hwm_IllegalSize, "Illegal size" },
135  { hwmon_response::hwm_ParamsTableNotValid, "Params table not valid" },
136  { hwmon_response::hwm_ParamsTableIdNotValid, "Params table id not valid" },
137  { hwmon_response::hwm_ParamsTableWrongExistingSize, "Params rable wrong existing size" },
138  { hwmon_response::hwm_WrongCRC, "Invalid CRC" },
139  { hwmon_response::hwm_NotAuthorisedFlashWrite, "Not authorised flash write" },
140  { hwmon_response::hwm_NoDataToReturn, "No data to return" },
141  { hwmon_response::hwm_SpiReadFailed, "Spi read failed" },
142  { hwmon_response::hwm_SpiWriteFailed, "Spi write failed" },
143  { hwmon_response::hwm_SpiEraseSectorFailed, "Spi erase sector failed" },
144  { hwmon_response::hwm_TableIsEmpty, "Table is empty" },
145  { hwmon_response::hwm_I2cSeqDelay, "I2c seq delay" },
146  { hwmon_response::hwm_CommandIsLocked, "Command is locked" },
147  { hwmon_response::hwm_CalibrationWrongTableId, "Calibration invalid table id" },
148  { hwmon_response::hwm_ValueOutOfRange, "Value out of range" },
149  { hwmon_response::hwm_InvalidDepthFormat, "Invalid depth format" },
150  { hwmon_response::hwm_DepthFlowError, "Depth flow error" },
151  { hwmon_response::hwm_Timeout, "Timeout" },
152  { hwmon_response::hwm_NotSafeCheckFailed, "Not safe check failed" },
153  { hwmon_response::hwm_FlashRegionIsLocked, "Flash region is locked" },
154  { hwmon_response::hwm_SummingEventTimeout, "Summing event timeout" },
155  { hwmon_response::hwm_SDSCorrupted, "SDS corrupted" },
156  { hwmon_response::hwm_SDSVerifyFailed, "SDS verification failed" },
157  { hwmon_response::hwm_IllegalHwState, "Illegal HW state" },
158  { hwmon_response::hwm_RealtekNotLoaded, "Realtek not loaded" },
159  { hwmon_response::hwm_WakeUpDeviceNotSupported, "Wake up device not supported" },
160  { hwmon_response::hwm_ResourceBusy, "Resource busy" },
161  { hwmon_response::hwm_MaxErrorValue, "Max error value" },
162  { hwmon_response::hwm_PwmNotSupported, "Pwm not supported" },
163  { hwmon_response::hwm_PwmStereoModuleNotConnected, "Pwm stereo module not connected" },
164  { hwmon_response::hwm_UvcStreamInvalidStreamRequest,"Uvc stream invalid stream request" },
165  { hwmon_response::hwm_UvcControlManualExposureInvalid,"Uvc control manual exposure invalid" },
166  { hwmon_response::hwm_UvcControlManualGainInvalid, "Uvc control manual gain invalid" },
167  { hwmon_response::hwm_EyesafetyPayloadFailure, "Eyesafety payload failure" },
168  { hwmon_response::hwm_ProjectorTestFailed, "Projector test failed" },
169  { hwmon_response::hwm_ThreadModifyFailed, "Thread modify failed" },
170  { hwmon_response::hwm_HotLaserPwrReduce, "Hot laser pwr reduce" },
171  { hwmon_response::hwm_HotLaserDisable, "Hot laser disable" },
172  { hwmon_response::hwm_FlagBLaserDisable, "FlagB laser disable" },
173  { hwmon_response::hwm_NoStateChange, "No state change" },
174  { hwmon_response::hwm_EEPROMIsLocked, "EEPROM is locked" },
175  { hwmon_response::hwm_EEPROMIsLocked, "EEPROM Is locked" },
176  { hwmon_response::hwm_OEMIdWrong, "OEM invalid id" },
177  { hwmon_response::hwm_RealtekNotUpdated, "Realtek not updated" },
178  { hwmon_response::hwm_FunctionNotSupported, "Function not supported" },
179  { hwmon_response::hwm_IspNotImplemented, "Isp not implemented" },
180  { hwmon_response::hwm_IspNotSupported, "Isp not supported" },
181  { hwmon_response::hwm_IspNotPermited, "Isp not permited" },
182  { hwmon_response::hwm_IspNotExists, "Isp not present" },
183  { hwmon_response::hwm_IspFail, "Isp fail" },
184  { hwmon_response::hwm_Unknown, "Unresolved error" },
185  { hwmon_response::hwm_LastError, "Last error" },
186  };
187 
189  if (hwmon_response_report.find(e) != hwmon_response_report.end())
190  return hwmon_response_report.at(e);
191  return {};
192  }
193 
195  {
196  public:
197  locked_transfer(std::shared_ptr<platform::command_transfer> command_transfer, uvc_sensor& uvc_ep)
198  :_command_transfer(command_transfer),
199  _uvc_sensor_base(uvc_ep)
200  {}
201 
202  std::vector<uint8_t> send_receive(
203  const std::vector<uint8_t>& data,
204  int timeout_ms = 5000,
205  bool require_response = true)
206  {
207  std::shared_ptr<int> token(_heap.allocate(), [&](int* ptr)
208  {
209  if (ptr) _heap.deallocate(ptr);
210  });
211  if (!token.get()) throw;
212 
213  std::lock_guard<std::recursive_mutex> lock(_local_mtx);
216  {
217  std::lock_guard<platform::uvc_device> lock(dev);
218  return _command_transfer->send_receive(data, timeout_ms, require_response);
219  });
220  }
221 
223  {
225  }
226  private:
227  std::shared_ptr<platform::command_transfer> _command_transfer;
229  std::recursive_mutex _local_mtx;
231  };
232 
233  struct command
234  {
236  int param1;
237  int param2;
238  int param3;
239  int param4;
240  std::vector<uint8_t> data;
241  int timeout_ms = 5000;
242  bool require_response = true;
243 
244  explicit command(uint8_t cmd, int param1 = 0, int param2 = 0,
245  int param3 = 0, int param4 = 0, int timeout_ms = 5000,
246  bool require_response = true)
247  : cmd(cmd), param1(param1),
248  param2(param2),
249  param3(param3), param4(param4),
250  timeout_ms(timeout_ms), require_response(require_response)
251  {
252  }
253  };
254 
256 
258  {
259  struct hwmon_cmd
260  {
262  int param1;
263  int param2;
264  int param3;
265  int param4;
268  long timeOut;
270  uint8_t receivedCommandData[HW_MONITOR_BUFFER_SIZE];
272  uint8_t receivedOpcode[4];
273 
274  explicit hwmon_cmd(uint8_t cmd_id)
275  : cmd(cmd_id),
276  param1(0),
277  param2(0),
278  param3(0),
279  param4(0),
280  sizeOfSendCommandData(0),
281  timeOut(5000),
282  oneDirection(false),
283  receivedCommandDataLength(0)
284  {}
285 
286 
287  explicit hwmon_cmd(const command& cmd)
288  : cmd(cmd.cmd),
289  param1(cmd.param1),
290  param2(cmd.param2),
291  param3(cmd.param3),
292  param4(cmd.param4),
293  sizeOfSendCommandData(std::min((uint16_t)cmd.data.size(), HW_MONITOR_BUFFER_SIZE)),
294  timeOut(cmd.timeout_ms),
295  oneDirection(!cmd.require_response),
296  receivedCommandDataLength(0)
297  {
298  librealsense::copy(data, cmd.data.data(), sizeOfSendCommandData);
299  }
300  };
301 
303  {
305  std::array<uint8_t, HW_MONITOR_BUFFER_SIZE> sendCommandData;
307  long timeOut;
308  std::array<uint8_t, 4> receivedOpcode;
309  std::array<uint8_t, HW_MONITOR_BUFFER_SIZE> receivedCommandData;
311  };
312 
313  void execute_usb_command(uint8_t *out, size_t outSize, uint32_t& op, uint8_t* in, size_t& inSize) const;
314  static void update_cmd_details(hwmon_cmd_details& details, size_t receivedCmdLen, unsigned char* outputBuffer);
315  void send_hw_monitor_command(hwmon_cmd_details& details) const;
316 
317  std::shared_ptr<locked_transfer> _locked_transfer;
318  public:
319  explicit hw_monitor(std::shared_ptr<locked_transfer> locked_transfer)
320  : _locked_transfer(std::move(locked_transfer))
321  {}
322 
323  static void fill_usb_buffer( int opCodeNumber,
324  int p1,
325  int p2,
326  int p3,
327  int p4,
328  uint8_t const * data,
329  int dataLength,
330  uint8_t * bufferToSend,
331  int & length );
332 
333  std::vector< uint8_t > send( std::vector< uint8_t > const & data ) const;
334  std::vector<uint8_t> send( command cmd, hwmon_response * = nullptr, bool locked_transfer = false ) const;
335  void get_gvd(size_t sz, unsigned char* gvd, uint8_t gvd_cmd) const;
336  static std::string get_firmware_version_string(const std::vector<uint8_t>& buff, size_t index, size_t length = 4);
337  static std::string get_module_serial_string(const std::vector<uint8_t>& buff, size_t index, size_t length = 6);
338  bool is_camera_locked(uint8_t gvd_cmd, uint32_t offset) const;
339 
340  template <typename T>
341  T get_gvd_field(const std::vector<uint8_t>& data, size_t index)
342  {
343  T rv = 0;
344  if (index + sizeof(T) >= data.size())
345  throw new std::runtime_error("get_gvd_field - index out of bounds, buffer size: " +
346  std::to_string(data.size()) + ", index: " + std::to_string(index));
347  for (int i = 0; i < sizeof(T); i++)
348  rv += data[index + i] << (i * 8);
349  return rv;
350  }
351  };
352 }
static const textual_icon lock
Definition: model-views.h:218
void deallocate(T *item)
Definition: src/types.h:1201
const uint8_t IVCAM_MIN_SUPPORTED_VERSION
Definition: hw-monitor.h:28
std::shared_ptr< platform::command_transfer > _command_transfer
Definition: hw-monitor.h:227
const uint8_t IV_COMMAND_FILTER_OPTION
Definition: hw-monitor.h:21
std::string hwmon_error2str(hwmon_response e)
Definition: hw-monitor.h:188
auto invoke_powered(T action) -> decltype(action(*static_cast< platform::uvc_device * >(nullptr)))
Definition: sensor.h:343
const uint16_t HW_MONITOR_DATA_SIZE_OFFSET
Definition: hw-monitor.h:42
const uint8_t IVCAM_MONITOR_HEADER_SIZE
Definition: hw-monitor.h:29
const uint8_t IV_COMMAND_GET_CALIBRATION_DATA
Definition: hw-monitor.h:13
unsigned short uint16_t
Definition: stdint.h:79
GLsizei const GLchar *const * string
std::shared_ptr< locked_transfer > _locked_transfer
Definition: hw-monitor.h:317
std::array< uint8_t, HW_MONITOR_BUFFER_SIZE > receivedCommandData
Definition: hw-monitor.h:309
unsigned char uint8_t
Definition: stdint.h:78
e
Definition: rmse.py:177
const uint16_t IVCAM_MONITOR_MUTEX_TIMEOUT
Definition: hw-monitor.h:39
const uint8_t IV_COMMAND_DEPTH_ACCURACY
Definition: hw-monitor.h:15
GLuint index
const uint8_t PARAMETERS2_BUFFER_SIZE
Definition: hw-monitor.h:31
const uint8_t IVCAM_MONITOR_ENDPOINT_OUT
Definition: hw-monitor.h:26
locked_transfer(std::shared_ptr< platform::command_transfer > command_transfer, uvc_sensor &uvc_ep)
Definition: hw-monitor.h:197
const uint8_t IVCAM_MONITOR_INTERFACE
Definition: hw-monitor.h:25
const uint16_t MAX_SIZE_OF_CALIB_PARAM_BYTES
Definition: hw-monitor.h:35
GLsizeiptr size
const uint16_t IVCAM_MONITOR_MAGIC_NUMBER
Definition: hw-monitor.h:37
unsigned int uint32_t
Definition: stdint.h:80
const uint8_t IVCAM_MONITOR_ENDPOINT_IN
Definition: hw-monitor.h:27
std::vector< uint8_t > send_receive(const std::vector< uint8_t > &data, int timeout_ms=5000, bool require_response=true)
Definition: hw-monitor.h:202
small_heap< int, 256 > _heap
Definition: hw-monitor.h:230
std::vector< uint8_t > data
Definition: hw-monitor.h:240
const uint16_t SIZE_OF_CALIB_PARAM_BYTES
Definition: hw-monitor.h:36
const uint8_t SIZE_OF_CALIB_HEADER_BYTES
Definition: hw-monitor.h:32
const uint8_t IV_COMMAND_INTENSITY_IMAGE_TYPE
Definition: hw-monitor.h:18
const uint8_t IV_COMMAND_FIRMWARE_UPDATE_MODE
Definition: hw-monitor.h:12
const uint8_t NUM_OF_CALIBRATION_COEFFS
Definition: hw-monitor.h:33
std::string hwmon_error_string(command const &cmd, hwmon_response e)
Definition: hw-monitor.cpp:177
const uint8_t IV_COMMAND_VERSION
Definition: hw-monitor.h:22
const std::map< hwmon_response, std::string > hwmon_response_report
Definition: hw-monitor.h:118
std::array< uint8_t, 4 > receivedOpcode
Definition: hw-monitor.h:308
const uint16_t HW_MONITOR_COMMAND_SIZE
Definition: hw-monitor.h:40
const uint8_t IV_COMMAND_POWER_GEAR
Definition: hw-monitor.h:20
GLuint in
Definition: glext.h:8859
int min(int a, int b)
Definition: lz4s.c:73
command(uint8_t cmd, int param1=0, int param2=0, int param3=0, int param4=0, int timeout_ms=5000, bool require_response=true)
Definition: hw-monitor.h:244
typename::boost::move_detail::remove_reference< T >::type && move(T &&t) BOOST_NOEXCEPT
const uint8_t IV_COMMAND_CONFIDENCE_THRESHHOLD
Definition: hw-monitor.h:23
const uint8_t IV_COMMAND_LOW_CONFIDENCE_LEVEL
Definition: hw-monitor.h:17
const uint16_t SIZE_OF_HW_MONITOR_HEADER
Definition: hw-monitor.h:43
int i
GLenum GLuint GLenum GLsizei length
T get_gvd_field(const std::vector< uint8_t > &data, size_t index)
Definition: hw-monitor.h:341
const uint8_t NUM_OF_CALIBRATION_PARAMS
Definition: hw-monitor.h:30
signed int int32_t
Definition: stdint.h:77
const uint8_t IV_COMMAND_LASER_POWER
Definition: hw-monitor.h:14
std::array< uint8_t, HW_MONITOR_BUFFER_SIZE > sendCommandData
Definition: hw-monitor.h:305
const uint16_t HW_MONITOR_BUFFER_SIZE
Definition: hw-monitor.h:41
const uint8_t IV_COMMAND_ZUNIT
Definition: hw-monitor.h:16
const uint16_t IVCAM_MONITOR_MAX_BUFFER_SIZE
Definition: hw-monitor.h:38
hw_monitor(std::shared_ptr< locked_transfer > locked_transfer)
Definition: hw-monitor.h:319
Definition: parser.hpp:150
const uint8_t IV_COMMAND_MOTION_VS_RANGE_TRADE
Definition: hw-monitor.h:19
void copy(void *dst, void const *src, size_t size)
Definition: types.cpp:836
GLintptr offset
std::recursive_mutex _local_mtx
Definition: hw-monitor.h:229
std::string to_string(T value)


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