Skip to content

Commit

Permalink
move extract_firmware_version_string() into ds::, d400-private
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Dec 2, 2023
1 parent 5a2749b commit c50c61a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace librealsense
throw librealsense::invalid_value_exception(
rsutils::string::from() << "Unsupported firmware binary image provided - " << image.size() << " bytes" );

std::string fw_version = firmware_check_interface::extract_firmware_version_string( image );
std::string fw_version = ds::extract_firmware_version_string( image );

auto it = ds::d400_device_to_fw_min_version.find( _pid );
if( it == ds::d400_device_to_fw_min_version.end() )
Expand Down
2 changes: 1 addition & 1 deletion src/ds/d400/d400-fw-update-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ds_d400_update_device::ds_d400_update_device(
throw librealsense::invalid_value_exception(
rsutils::string::from() << "Unsupported firmware binary image provided - " << image.size() << " bytes" );

std::string fw_version = extract_firmware_version_string(image);
std::string fw_version = ds::extract_firmware_version_string(image);
auto it = ds::d400_device_to_fw_min_version.find(_usb_device->get_info().pid);
if (it == ds::d400_device_to_fw_min_version.end())
throw librealsense::invalid_value_exception(
Expand Down
17 changes: 17 additions & 0 deletions src/ds/d400/d400-private.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ namespace librealsense
return results;
}

std::string extract_firmware_version_string( const std::vector< uint8_t > & fw_image )
{
auto version_offset = offsetof( platform::dfu_header, bcdDevice );
if( fw_image.size() < ( version_offset + sizeof( size_t ) ) )
throw std::runtime_error( "Firmware binary image might be corrupted - size is only: "
+ std::to_string( fw_image.size() ) );

auto version = fw_image.data() + version_offset;
uint8_t major = *( version + 3 );
uint8_t minor = *( version + 2 );
uint8_t patch = *( version + 1 );
uint8_t build = *( version );

return std::to_string( major ) + "." + std::to_string( minor ) + "." + std::to_string( patch ) + "."
+ std::to_string( build );
}

rs2_intrinsics get_d400_intrinsic_by_resolution(const vector<uint8_t>& raw_data, d400_calibration_table_id table_id, uint32_t width, uint32_t height)
{
switch (table_id)
Expand Down
2 changes: 2 additions & 0 deletions src/ds/d400/d400-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ namespace librealsense
return min_gvd_version <= cur_gvd_version;
}

std::string extract_firmware_version_string( const std::vector< uint8_t > & fw_image );

enum class d400_calibration_table_id
{
coefficients_table_id = 25,
Expand Down
8 changes: 1 addition & 7 deletions src/ds/d500/d500-fw-update-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ ds_d500_update_device::ds_d500_update_device( std::shared_ptr< const device_info
bool ds_d500_update_device::check_fw_compatibility(const std::vector<uint8_t>& image) const
{
// Currently we cannot extract FW version from HKR FW image
bool result = true;

// TODO::: Once verified we can check against the minimal FW version map
std::string fw_version = extract_firmware_version_string(image);
LOG_INFO( "FW version extracted from the FW image is" + fw_version );

return result;
return true;
}

std::string ds_d500_update_device::parse_serial_number(const std::vector<uint8_t>& buffer) const
Expand Down
14 changes: 0 additions & 14 deletions src/fw-update/fw-update-device-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ namespace librealsense
{
public:
virtual bool check_fw_compatibility(const std::vector<uint8_t>& image) const = 0;
static std::string extract_firmware_version_string(const std::vector<uint8_t>& fw_image)
{
auto version_offset = offsetof(platform::dfu_header, bcdDevice);
if (fw_image.size() < (version_offset + sizeof(size_t)))
throw std::runtime_error("Firmware binary image might be corrupted - size is only: " + std::to_string( fw_image.size() ));

auto version = fw_image.data() + version_offset;
uint8_t major = *(version + 3);
uint8_t minor = *(version + 2);
uint8_t patch = *(version + 1);
uint8_t build = *(version);

return std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch) + "." + std::to_string(build);
}
};

class updatable : public firmware_check_interface
Expand Down

0 comments on commit c50c61a

Please sign in to comment.