8 #pragma pack(push, 1) // All structs in this file are byte-aligned 20 #define SPI_FLASH_PAGE_SIZE_IN_BYTES 0x100 21 #define SPI_FLASH_SECTOR_SIZE_IN_BYTES 0x1000 22 #define SPI_FLASH_SIZE_IN_SECTORS 256 23 #define SPI_FLASH_TOTAL_SIZE_IN_BYTES (SPI_FLASH_SIZE_IN_SECTORS * SPI_FLASH_SECTOR_SIZE_IN_BYTES) 24 #define SPI_FLASH_PAGES_PER_SECTOR (SPI_FLASH_SECTOR_SIZE_IN_BYTES / SPI_FLASH_PAGE_SIZE_IN_BYTES) 25 #define SPI_FLASH_SECTORS_RESERVED_FOR_FIRMWARE 160 26 #define NV_NON_FIRMWARE_START (SPI_FLASH_SECTORS_RESERVED_FOR_FIRMWARE * SPI_FLASH_SECTOR_SIZE_IN_BYTES) 27 #define NV_ADMIN_DATA_N_ENTRIES 9 28 #define NV_CALIBRATION_DATA_ADDRESS_INDEX 0 29 #define NV_NON_FIRMWARE_ROOT_ADDRESS NV_NON_FIRMWARE_START 30 #define CAM_INFO_BLOCK_LEN 2048 53 std::memset(reserved, 0,
sizeof(reserved));
60 set_control(device,
lr_xu, static_cast<int>(control::command_response), &c,
sizeof(c));
61 get_control(device,
lr_xu, static_cast<int>(control::command_response), &r,
sizeof(r));
65 void bulk_usb_command(uvc::device & device, std::timed_mutex & mutex,
unsigned char out_ep, uint8_t *out,
size_t outSize, uint32_t & op,
unsigned char in_ep, uint8_t *
in,
size_t & inSize,
int timeout)
72 if (!mutex.try_lock_for(std::chrono::milliseconds(timeout)))
throw std::runtime_error(
"timed_mutex::try_lock_for(...) timed out");
73 std::lock_guard<std::timed_mutex> guard(mutex, std::adopt_lock);
75 bulk_transfer(device, out_ep, out, (
int)outSize, &outXfer, timeout);
84 bulk_transfer(device, in_ep, buf,
sizeof(buf), &outXfer, timeout);
85 if (outXfer < (
int)
sizeof(uint32_t))
throw std::runtime_error(
"incomplete bulk usb transfer");
87 op = *(uint32_t *)buf;
88 if (outXfer > (
int)inSize)
throw std::runtime_error(
"bulk transfer failed - user buffer too small");
90 memcpy(in, buf, inSize);
98 if (!nPages || addressTest < 0)
111 for (
unsigned int i = 0; i < nPages; ++i)
113 xu_read(dev,
lr_xu, control::command_response, p, spiLength);
121 unsigned char *
data = (
unsigned char *)dataIn;
122 int lengthInBytes = lengthInBytesIn;
125 uint32_t startAddress =
address;
126 if (startAddress & 0xff)
129 startAddress = startAddress & ~0xff;
130 uint32_t startInPage = address - startAddress;
132 if (lengthToCopy > (uint32_t)lengthInBytes)
133 lengthToCopy = lengthInBytes;
135 memcpy(data, page + startInPage, lengthToCopy);
136 lengthInBytes -= lengthToCopy;
137 data += lengthToCopy;
143 if (nPagesToRead > 0)
154 memcpy(data, page, lengthInBytes);
166 uint32_t pageAddressInBytes = adminSectorAddresses[whichAdminSector];
175 struct RectifiedIntrinsics
180 operator rs_intrinsics ()
const {
return{ (
int)rw, (
int)rh, rpx, rpy, rfx, rfy,
RS_DISTORTION_NONE, {0,0,0,0,0} }; }
187 struct UnrectifiedIntrinsicsV0
193 operator rs_intrinsics ()
const {
return{ (
int)w, (
int)
h, px, py, fx, fy,
RS_DISTORTION_MODIFIED_BROWN_CONRADY, {(float)k[0],(
float)k[1],(float)k[2],(
float)k[3],(float)k[4]} }; }
196 struct CameraCalibrationParametersV0
198 enum { MAX_INTRIN_RIGHT = 2 };
199 enum { MAX_INTRIN_THIRD = 3 };
200 enum { MAX_MODES_LR = 4 };
201 enum { MAX_MODES_THIRD = 4 };
209 UnrectifiedIntrinsicsV0 intrinsicsLeft;
210 UnrectifiedIntrinsicsV0 intrinsicsRight[MAX_INTRIN_RIGHT];
211 UnrectifiedIntrinsicsV0 intrinsicsThird[MAX_INTRIN_THIRD];
213 RectifiedIntrinsics modesLR[MAX_INTRIN_RIGHT][MAX_MODES_LR];
214 RectifiedIntrinsics modesThird[MAX_INTRIN_RIGHT][MAX_INTRIN_THIRD][MAX_MODES_THIRD];
227 const auto & calib =
reinterpret_cast<const CameraCalibrationParametersV0 &
>(flash_data_buffer);
228 for (
int i = 0; i < 3; ++i) cameraCalib.
modesLR[i] = calib.modesLR[0][i];
229 for (
int i = 0; i < 2; ++i)
232 for (
int j = 0; j < 2; ++j) cameraCalib.
modesThird[i][j] = calib.modesThird[0][i][j];
234 for (
int i = 0; i < 9; ++i) cameraCalib.
Rthird[i] = static_cast<float>(calib.Rthird[0][i]);
235 for (
int i = 0; i < 3; ++i) cameraCalib.
T[i] = calib.T[0][i];
236 cameraCalib.
B = calib.B[0];
240 struct UnrectifiedIntrinsicsV2
246 operator rs_intrinsics ()
const {
return{ (
int)w, (
int)
h, px, py, fx, fy,
RS_DISTORTION_MODIFIED_BROWN_CONRADY, {k[0],k[1],k[2],k[3],k[4]} }; }
249 struct CameraCalibrationParametersV2
251 enum { MAX_INTRIN_RIGHT = 2 };
252 enum { MAX_INTRIN_THIRD = 3 };
253 enum { MAX_INTRIN_PLATFORM = 4 };
254 enum { MAX_MODES_LR = 4 };
255 enum { MAX_MODES_THIRD = 3 };
256 enum { MAX_MODES_PLATFORM = 1 };
266 UnrectifiedIntrinsicsV2 intrinsicsLeft;
267 UnrectifiedIntrinsicsV2 intrinsicsRight[MAX_INTRIN_RIGHT];
268 UnrectifiedIntrinsicsV2 intrinsicsThird[MAX_INTRIN_THIRD];
269 UnrectifiedIntrinsicsV2 intrinsicsPlatform[MAX_INTRIN_PLATFORM];
271 RectifiedIntrinsics modesLR[MAX_INTRIN_RIGHT][MAX_MODES_LR];
272 RectifiedIntrinsics modesThird[MAX_INTRIN_RIGHT][MAX_INTRIN_THIRD][MAX_MODES_THIRD];
273 RectifiedIntrinsics modesPlatform[MAX_INTRIN_RIGHT][MAX_INTRIN_PLATFORM][MAX_MODES_PLATFORM];
288 const auto & calib =
reinterpret_cast<const CameraCalibrationParametersV2 &
>(flash_data_buffer);
289 for (
int i = 0; i < 3; ++i) cameraCalib.
modesLR[i] = calib.modesLR[0][i];
290 for (
int i = 0; i < 2; ++i)
293 for (
int j = 0; j < 2; ++j) cameraCalib.
modesThird[i][j] = calib.modesThird[0][i][j];
295 for (
int i = 0; i < 9; ++i) cameraCalib.
Rthird[i] = calib.Rthird[0][i];
296 for (
int i = 0; i < 3; ++i) cameraCalib.
T[i] = calib.T[0][i];
297 cameraCalib.
B = calib.B[0];
301 throw std::runtime_error(
to_string() <<
"Unsupported calibration version: " << cameraCalib.
version);
344 catch (std::runtime_error &err){
LOG_ERROR(
"Failed to read camera info " << err.what()); }
345 catch (...){
LOG_ERROR(
"Failed to read camera info, may not work correctly"); }
353 return reinterpret_cast<const char *
>(response.reserved);
359 return to_string() <<
"0x" << std::hex << response.reserved[4];
369 uint8_t
s[4] = { 255, 255, 255, 255 };
370 xu_read(device,
lr_xu, control::status, s,
sizeof(uint32_t));
379 xu_write(device,
lr_xu, control::sw_reset, &reset,
sizeof(uint8_t));
386 auto byte = xu_read<uint8_t>(device,
lr_xu, control::emitter);
387 if (is_streaming)
return (
byte & 1 ?
true :
false);
388 else if (
byte & 4)
return (
byte & 2 ?
true :
false);
389 else return is_depth_enabled;
394 xu_write(device,
lr_xu, control::emitter, uint8_t(state ? 1 : 0));
407 {5, 5, 192, 1, 512, 6, 24, 27, 7, 24},
408 {5, 5, 0, 0, 1023, 0, 0, 0, 0, 2047},
409 {5, 5, 115, 1, 512, 6, 18, 25, 3, 24},
410 {5, 5, 185, 5, 505, 6, 35, 45, 45, 14},
411 {5, 5, 175, 24, 430, 6, 48, 47, 24, 12},
412 {5, 5, 235, 27, 420, 8, 80, 70, 90, 12},
421 const uvc::guid MOTION_MODULE_USB_DEVICE_GUID = { 0xC0B55A29, 0xD7B6, 0x436E,{ 0xA6, 0xEF, 0x2E, 0x76, 0xED, 0x0A, 0xBC, 0xA5 } };
426 return ds::xu_read<uint8_t>(device,
fisheye_xu, ds::control::fisheye_xu_ext_trig);
436 return ds::xu_read<uint8_t>(device,
fisheye_xu, ds::control::fisheye_xu_strobe);
446 return ds::xu_read<uint16_t>(device,
fisheye_xu, ds::control::fisheye_exposure);
456 claim_aux_interface(device, MOTION_MODULE_USB_DEVICE_GUID, motion_module_interrupt_interface);
#define NV_ADMIN_DATA_N_ENTRIES
CommandResponsePacket send_command_and_receive_response(uvc::device &device, const CommandResponsePacket &command)
#define SPI_FLASH_SECTOR_SIZE_IN_BYTES
uint8_t module_major_version
#define CAM_INFO_BLOCK_LEN
uint16_t get_fisheye_exposure(const uvc::device &device)
void claim_aux_interface(device &device, const guid &interface_guid, int interface_number)
bool read_device_pages(uvc::device &dev, uint32_t address, unsigned char *buffer, uint32_t nPages)
#define SPI_FLASH_PAGES_PER_SECTOR
void set_fisheye_external_trigger(uvc::device &device, uint8_t ext_trig)
struct rs_intrinsics rs_intrinsics
Video stream intrinsics.
uint32_t pack(uint8_t c0, uint8_t c1, uint8_t c2, uint8_t c3)
const uvc::guid MOTION_MODULE_USB_DEVICE_GUID
uint32_t imager_model_number
bool get_emitter_state(const uvc::device &device, bool is_streaming, bool is_depth_enabled)
GLsizei const GLchar *const * string
command_modifier modifier
#define SPI_FLASH_PAGE_SIZE_IN_BYTES
GLenum GLuint GLenum GLsizei const GLchar * buf
#define NV_CALIBRATION_DATA_ADDRESS_INDEX
void xu_read(const uvc::device &device, uvc::extension_unit xu, control xu_ctrl, void *buffer, uint32_t length)
uint8_t module_minor_version
ds_calibration read_calibration_and_rectification_parameters(const uint8_t(&flash_data_buffer)[SPI_FLASH_SECTOR_SIZE_IN_BYTES])
int32_t nominal_baseline_third_imager
void set_register_value(uvc::device &device, uint32_t reg, uint32_t value)
GLbitfield GLuint64 timeout
uint8_t get_fisheye_external_trigger(const uvc::device &device)
void force_firmware_reset(uvc::device &device)
GLfloat GLfloat GLfloat GLfloat h
void read_arbitrary_chunk(uvc::device &dev, uint32_t address, void *dataIn, int lengthInBytesIn)
bool read_admin_sector(uvc::device &dev, unsigned char data[SPI_FLASH_SECTOR_SIZE_IN_BYTES], int whichAdminSector)
void claim_motion_module_interface(uvc::device &device)
void set_fisheye_exposure(uvc::device &device, uint16_t exposure)
#define SPI_FLASH_TOTAL_SIZE_IN_BYTES
void get_control_with_retry(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
ds_calibration calibration
uint32_t camera_head_contents_version
ds_head_content head_content
const uvc::extension_unit lr_xu
void set_emitter_state(uvc::device &device, bool state)
#define NV_NON_FIRMWARE_ROOT_ADDRESS
uint8_t get_fisheye_strobe(const uvc::device &device)
void get_register_value(uvc::device &device, uint32_t reg, uint32_t &value)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
void set_stream_intent(uvc::device &device, uint8_t &intent)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * data
CommandResponsePacket(command code, uint32_t address=0, uint32_t value=0)
ds_lens_coating_type lens_coating_type
rs_intrinsics modesThird[2][2]
void get_stream_status(const uvc::device &device, int &status)
const unsigned short motion_module_interrupt_interface
GLsizei const GLfloat * value
ds_info read_camera_info(uvc::device &device)
uint32_t module_revision_number
rs_intrinsics intrinsicsThird[2]
uint8_t module_skew_version
ds_head_content read_camera_head_contents(const uint8_t(&flash_data_buffer)[SPI_FLASH_SECTOR_SIZE_IN_BYTES], uint32_t &serial_number)
uint32_t nominal_baseline
void bulk_transfer(device &device, unsigned char endpoint, void *data, int length, int *actual_length, unsigned int timeout)
void set_control(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
void set_control_with_retry(device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
void xu_write(uvc::device &device, uvc::extension_unit xu, control xu_ctrl, void *buffer, uint32_t length)
void bulk_usb_command(uvc::device &device, std::timed_mutex &mutex, unsigned char out_ep, uint8_t *out, size_t outSize, uint32_t &op, unsigned char in_ep, uint8_t *in, size_t &inSize, int timeout)
GLuint GLsizei GLsizei * length
GLuint GLuint64EXT address
const uvc::extension_unit fisheye_xu
std::string read_isp_firmware_version(uvc::device &device)
void get_control(const device &device, const extension_unit &xu, uint8_t ctrl, void *data, int len)
ds_lens_type lens_type_third_imager
void set_fisheye_strobe(uvc::device &device, uint8_t strobe)
GLdouble GLdouble GLdouble r
std::string read_firmware_version(uvc::device &device)
GLubyte GLubyte GLubyte GLubyte w
The struct is aligned with the data layout in device.
std::string time_to_string(double val)
ds_lens_coating_type lens_coating_type_third_imager