Skip to content

Commit c527dab

Browse files
committed
align to GVD spec 0.4
1 parent fd45b37 commit c527dab

5 files changed

Lines changed: 89 additions & 55 deletions

File tree

src/ds/d500/d500-device.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -455,22 +455,14 @@ namespace librealsense
455455
group_multiple_fw_calls(depth_sensor, [&]() {
456456

457457
_hw_monitor->get_gvd(gvd_buff.size(), gvd_buff.data(), ds::fw_cmd::GVD);
458-
459-
constexpr auto gvd_header_size = 8;
460458
get_gvd_details(gvd_buff, &gvd_parsed_fields);
461-
auto gvd_payload_data = gvd_buff.data() + gvd_header_size;
462-
auto computed_crc = calc_crc32(gvd_payload_data, gvd_parsed_fields.payload_size);
463-
LOG_INFO("gvd version = " << gvd_parsed_fields.gvd_version);
464-
LOG_INFO("gvd payload size = " << gvd_parsed_fields.payload_size);
465-
LOG_INFO("gvd crc = " << gvd_parsed_fields.crc32);
466-
LOG_INFO("gvd optical module sn = " << gvd_parsed_fields.optical_module_sn);
467-
if (computed_crc != gvd_parsed_fields.crc32)
468-
LOG_ERROR("CRC mismatch in D500 GVD - received CRC = " << gvd_parsed_fields.crc32 << ", computed CRC = " << computed_crc);
469-
459+
470460
_device_capabilities = ds_caps::CAP_ACTIVE_PROJECTOR | ds_caps::CAP_RGB_SENSOR | ds_caps::CAP_IMU_SENSOR |
471461
ds_caps::CAP_BMI_085 | ds_caps::CAP_GLOBAL_SHUTTER | ds_caps::CAP_INTERCAM_HW_SYNC;
472462

473-
_fw_version = firmware_version(gvd_parsed_fields.fw_version);
463+
// TODO Currently D500 version format does not match the expected format of rsutils::version
464+
// This will need some special handling
465+
//_fw_version = firmware_version(gvd_parsed_fields.fw_version);
474466

475467
auto _usb_mode = usb3_type;
476468
usb_type_str = usb_spec_names.at(_usb_mode);
@@ -799,12 +791,28 @@ namespace librealsense
799791

800792
void d500_device::get_gvd_details(const std::vector<uint8_t>& gvd_buff, ds::d500_gvd_parsed_fields* parsed_fields) const
801793
{
802-
parsed_fields->gvd_version = *reinterpret_cast<const uint16_t*>(gvd_buff.data() + static_cast<int>(ds::d500_gvd_fields::version_offset));
803-
parsed_fields->payload_size = *reinterpret_cast<const uint32_t*>(gvd_buff.data() + static_cast<int>(ds::d500_gvd_fields::payload_size_offset));
804-
parsed_fields->crc32 = *reinterpret_cast<const uint32_t*>(gvd_buff.data() + static_cast<int>(ds::d500_gvd_fields::crc32_offset));
805-
parsed_fields->optical_module_sn = _hw_monitor->get_module_serial_string(gvd_buff, static_cast<size_t>(ds::d500_gvd_fields::optical_module_serial_offset));
806-
parsed_fields->mb_module_sn = _hw_monitor->get_module_serial_string(gvd_buff, static_cast<size_t>(ds::d500_gvd_fields::mb_module_serial_offset));
807-
parsed_fields->fw_version = _hw_monitor->get_firmware_version_string(gvd_buff, static_cast<size_t>(ds::d500_gvd_fields::fw_version_offset));
808-
parsed_fields->safety_sw_suite_version = _hw_monitor->get_firmware_version_string(gvd_buff, static_cast<size_t>(ds::d500_gvd_fields::safety_sw_suite_version_offset), 3);
794+
parsed_fields->gvd_version[0] = *reinterpret_cast<const uint8_t*>(gvd_buff.data() + ds::d500_gvd_offsets::version_offset);
795+
parsed_fields->gvd_version[1] = *reinterpret_cast<const uint8_t*>(gvd_buff.data() + ds::d500_gvd_offsets::version_offset + sizeof(uint8_t));
796+
797+
parsed_fields->payload_size = *reinterpret_cast<const uint32_t*>(gvd_buff.data() + ds::d500_gvd_offsets::payload_size_offset);
798+
parsed_fields->crc32 = *reinterpret_cast<const uint32_t*>(gvd_buff.data() + ds::d500_gvd_offsets::crc32_offset);
799+
parsed_fields->optical_module_sn = _hw_monitor->get_module_serial_string(gvd_buff, ds::d500_gvd_offsets::optical_module_serial_offset);
800+
parsed_fields->mb_module_sn = _hw_monitor->get_module_serial_string(gvd_buff, ds::d500_gvd_offsets::mb_module_serial_offset);
801+
parsed_fields->fw_version = _hw_monitor->get_firmware_version_string<uint16_t>(gvd_buff, ds::d500_gvd_offsets::fw_version_offset, 4, false);
802+
803+
constexpr size_t gvd_header_size = 8;
804+
auto gvd_payload_data = gvd_buff.data() + gvd_header_size;
805+
auto computed_crc = calc_crc32( gvd_payload_data, parsed_fields->payload_size );
806+
LOG_INFO( "D500 GVD version is: " << static_cast< int >( parsed_fields->gvd_version[0] )
807+
<< "."
808+
<< static_cast< int >( parsed_fields->gvd_version[1] ) );
809+
LOG_INFO( "D500 GVD payload_size is: " << parsed_fields->payload_size );
810+
811+
if( computed_crc != parsed_fields->crc32 )
812+
{
813+
LOG_ERROR( "CRC mismatch in D500 GVD - received CRC = "
814+
<< parsed_fields->crc32 << ", computed CRC = " << computed_crc );
815+
}
816+
809817
}
810818
}

src/ds/d500/d500-private.h

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,33 @@ namespace librealsense
4343
bool d500_try_fetch_usb_device(std::vector<platform::usb_device_info>& devices,
4444
const platform::uvc_device_info& info, platform::usb_device_info& result);
4545

46-
// Keep sorted
47-
enum class d500_gvd_fields // gvd fields for Safety Camera
46+
namespace d500_gvd_offsets
4847
{
49-
version_offset = 0, //ES1
50-
payload_size_offset = 0x2, //ES1
51-
crc32_offset = 0x4, //ES1
52-
optical_module_serial_offset = 0x54, //ES1
53-
mb_module_serial_offset = 0x7a, //ES2
54-
fw_version_offset = 0xba, //ES2
55-
safety_sw_suite_version_offset = 0x10F //ES2
56-
//rgb_sensor = 0x17,
57-
//imu_sensor = 0x19,
58-
//active_projector = 0x1a,
59-
//camera_fw_version_offset = 0x8c,
60-
//is_camera_locked_offset = 0x9e,
61-
};
48+
constexpr size_t version_offset = 0;
49+
constexpr size_t payload_size_offset = 0x2;
50+
constexpr size_t crc32_offset = 0x4;
51+
constexpr size_t optical_module_serial_offset = 0x54;
52+
constexpr size_t mb_module_serial_offset = 0x7a;
53+
constexpr size_t fw_version_offset = 0xba;
54+
}; // namespace d500_gvd_offsets
6255

6356
struct d500_gvd_parsed_fields
6457
{
65-
uint16_t gvd_version;
58+
uint8_t gvd_version[2];
6659
uint16_t payload_size;
6760
uint32_t crc32;
6861
std::string optical_module_sn;
6962
std::string mb_module_sn;
7063
std::string fw_version;
71-
std::string safety_sw_suite_version;
7264
};
7365

7466
enum class d500_calibration_table_id
7567
{
7668
depth_eeprom_toc_id = 0xb0,
77-
module_info_id = 0xb1,
69+
module_info_id = 0x1b1,
7870
rgb_lens_shading_id = 0xb2,
79-
str_lens_shading_id = 0xb3,
71+
left_lens_shading_id = 0x1b3,
72+
right_lens_shading_id = 0x2b3,
8073
depth_calibration_id = 0xb4,
8174
left_x_lut_id = 0xb5,
8275
left_y_lut_id = 0xb6,
@@ -91,9 +84,10 @@ namespace librealsense
9184
const std::map<ds::d500_calibration_table_id, uint32_t> d500_calibration_tables_size =
9285
{
9386
{d500_calibration_table_id::depth_eeprom_toc_id, 640},
94-
{d500_calibration_table_id::module_info_id, 320},
87+
{d500_calibration_table_id::module_info_id, 512},
9588
{d500_calibration_table_id::rgb_lens_shading_id, 1088},
96-
{d500_calibration_table_id::str_lens_shading_id, 1088},
89+
{d500_calibration_table_id::left_lens_shading_id, 576},
90+
{d500_calibration_table_id::right_lens_shading_id, 512},
9791
{d500_calibration_table_id::depth_calibration_id, 512},
9892
{d500_calibration_table_id::left_x_lut_id, 4160},
9993
{d500_calibration_table_id::left_y_lut_id, 4160},
@@ -146,7 +140,9 @@ namespace librealsense
146140
single_sensor_coef_table left_coefficients_table;
147141
single_sensor_coef_table right_coefficients_table;
148142
float baseline; // the baseline between the cameras in mm units
149-
uint16_t translation_dir;
143+
uint8_t translation_dir;
144+
uint8_t realignement_essential; // 1/0 - indicates whether the vertical alignement
145+
// is required to avoiid overflow in the REC buffer
150146
int16_t vertical_shift; // in pixels
151147
mini_intrinsics rectified_intrinsics;
152148
uint8_t reserved[148];

src/ds/ds-device-common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace librealsense
124124
{
125125
optic_serial = _hw_monitor->get_module_serial_string(gvd_buff, module_serial_offset);
126126
asic_serial = _hw_monitor->get_module_serial_string(gvd_buff, module_asic_serial_offset);
127-
fwv = _hw_monitor->get_firmware_version_string(gvd_buff, camera_fw_version_offset);
127+
fwv = _hw_monitor->get_firmware_version_string<uint8_t>(gvd_buff, camera_fw_version_offset);
128128
}
129129

130130
std::vector<uint8_t> ds_device_common::backup_flash(update_progress_callback_ptr callback)

src/hw-monitor.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99

1010
namespace librealsense
1111
{
12-
std::string hw_monitor::get_firmware_version_string(const std::vector<uint8_t>& buff, size_t index, size_t length)
13-
{
14-
std::stringstream formattedBuffer;
15-
std::string s = "";
16-
for (auto i = 1; i <= length; i++)
17-
{
18-
formattedBuffer << s << static_cast<int>(buff[index + (length - i)]);
19-
s = ".";
20-
}
21-
22-
return formattedBuffer.str();
23-
}
2412

2513
std::string hw_monitor::get_module_serial_string(const std::vector<uint8_t>& buff, size_t index, size_t length)
2614
{

src/hw-monitor.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <mutex>
88
#include "platform/command-transfer.h"
99
#include <string>
10+
#include <algorithm>
11+
#include <vector>
1012

1113

1214
namespace librealsense
@@ -350,7 +352,47 @@ namespace librealsense
350352
size_t dataLength = 0);
351353

352354
void get_gvd(size_t sz, unsigned char* gvd, uint8_t gvd_cmd) const;
353-
static std::string get_firmware_version_string(const std::vector<uint8_t>& buff, size_t index, size_t length = 4);
355+
356+
template<typename T>
357+
std::string get_firmware_version_string( const std::vector< uint8_t > & buff,
358+
size_t index,
359+
size_t length = 4,
360+
bool reversed = true )
361+
{
362+
std::stringstream formattedBuffer;
363+
auto component_bytes_size = sizeof( T );
364+
std::string s = "";
365+
if( buff.size() < index + ( length * component_bytes_size ))
366+
{
367+
// Don't throw as we want to be back compatible even w/o a working version
368+
LOG_ERROR( "GVD FW version cannot be read!" );
369+
return formattedBuffer.str();
370+
}
371+
372+
// We iterate through the version components (major.minor.patch.build) and append each
373+
// string value to the result string
374+
std::vector<int> components_value;
375+
for( auto i = 0; i < length; i++ )
376+
{
377+
size_t component_index = index + ( i * component_bytes_size );
378+
379+
// We use int on purpose as types like uint8_t doesn't work as expected with << operator
380+
int component_value = *reinterpret_cast< const T * >( buff.data() + component_index );
381+
components_value.push_back(component_value);
382+
}
383+
384+
if( reversed )
385+
std::reverse( components_value.begin(), components_value.end() );
386+
387+
for( auto & element : components_value )
388+
{
389+
formattedBuffer << s << element;
390+
s = ".";
391+
}
392+
393+
return formattedBuffer.str();
394+
}
395+
354396
static std::string get_module_serial_string(const std::vector<uint8_t>& buff, size_t index, size_t length = 6);
355397
bool is_camera_locked(uint8_t gvd_cmd, uint32_t offset) const;
356398

0 commit comments

Comments
 (0)