Skip to content

Commit

Permalink
PR #13498 from AviaAv: Adding string to opcode mismatch error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nir-Az authored Nov 11, 2024
2 parents bca6605 + 180a91b commit 960edef
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 2 deletions.
12 changes: 10 additions & 2 deletions common/output-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ void output_model::add_log(rs2_log_severity severity, std::string filename, int

void output_model::run_command(std::string command, device_models_list & device_models)
{
std::string opcode_error_as_string = "";
try
{
if (to_lower(command) == "clear")
Expand Down Expand Up @@ -990,7 +991,11 @@ void output_model::run_command(std::string command, device_models_list & device_
{
found = true;
auto res = dbg.send_and_receive_raw_data(buffer);

if (res.data())
{
int8_t opcode = *res.data();
opcode_error_as_string = dbg.get_opcode_string(opcode);
}
std::string response = rsutils::string::from() << "\n" << terminal_parser.parse_response(to_lower(command), res);
add_log(RS2_LOG_SEVERITY_INFO, __FILE__, 0, response);
}
Expand All @@ -1006,7 +1011,10 @@ void output_model::run_command(std::string command, device_models_list & device_
}
catch(const std::exception& ex)
{
add_log( RS2_LOG_SEVERITY_ERROR, __FILE__, __LINE__, ex.what() );
std::string error_string = rsutils::string::from() << ex.what();
if (opcode_error_as_string != "")
error_string = rsutils::string::from() << error_string << " (" << opcode_error_as_string << ")";
add_log( RS2_LOG_SEVERITY_ERROR, __FILE__, __LINE__, error_string);
}
}

Expand Down
8 changes: 8 additions & 0 deletions include/librealsense2/hpp/rs_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,14 @@ namespace rs2

return results;
}

std::string get_opcode_string(int opcode)
{
rs2_error* e = nullptr;
char buffer[1024];
rs2_hw_monitor_get_opcode_string(opcode, buffer, sizeof(buffer), _dev.get(), &e);
return std::string(buffer);
}
};

class device_list
Expand Down
2 changes: 2 additions & 0 deletions include/librealsense2/rs.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ float rs2_depth_frame_get_distance(const rs2_frame* frame_ref, int x, int y, rs2
*/
rs2_time_t rs2_get_time( rs2_error** error);

void rs2_hw_monitor_get_opcode_string(int opcode, char* buffer, size_t buffer_size,rs2_device* device, rs2_error** error);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/core/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "extension.h"
#include <vector>
#include <string>

namespace librealsense
{
Expand All @@ -18,6 +19,7 @@ namespace librealsense
uint32_t param4 = 0,
uint8_t const * data = nullptr,
size_t dataLength = 0) const = 0;
virtual std::string get_opcode_string(int opcode) const = 0;
};

MAP_EXTENSION(RS2_EXTENSION_DEBUG, librealsense::debug_interface);
Expand Down
17 changes: 17 additions & 0 deletions src/dds/rs-dds-device-proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <src/ds/d500/d500-auto-calibration.h>
#include <src/ds/d500/d500-debug-protocol-calibration-engine.h>
#include <src/ds/d400/d400-private.h>
using rsutils::json;


Expand Down Expand Up @@ -578,6 +579,22 @@ void dds_device_proxy::hardware_reset()
_dds_dev->send_control( control, &reply );
}

std::string dds_device_proxy::get_opcode_string(int opcode) const
{
std::string product_line = get_info(RS2_CAMERA_INFO_PRODUCT_LINE);
if (product_line.find("D400") != std::string::npos)
{
// d400 device
return ds::d400_hwmon_response().hwmon_error2str(opcode);
}
else if (product_line.find("D500") != std::string::npos)
{
// d500 device
return ds::d500_hwmon_response().hwmon_error2str(opcode);
}
return "";
}


std::vector< uint8_t > dds_device_proxy::send_receive_raw_data( const std::vector< uint8_t > & input )
{
Expand Down
1 change: 1 addition & 0 deletions src/dds/rs-dds-device-proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class dds_device_proxy
uint32_t param4 = 0,
uint8_t const * data = nullptr,
size_t dataLength = 0 ) const override;
std::string get_opcode_string(int opcode) const override;

// updatable: unsigned, non-recovery-mode
private:
Expand Down
5 changes: 5 additions & 0 deletions src/ds/d400/d400-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ namespace librealsense
return result;
}

std::string d400_device::get_opcode_string(int opcode) const
{
return ds::d400_hwmon_response().hwmon_error2str(opcode);
}

class d400_depth_sensor
: public synthetic_sensor
, public video_sensor_interface
Expand Down
1 change: 1 addition & 0 deletions src/ds/d400/d400-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace librealsense
std::vector<uint8_t> backup_flash( rs2_update_progress_callback_sptr callback) override;
void update_flash(const std::vector<uint8_t>& image, rs2_update_progress_callback_sptr callback, int update_mode) override;
bool check_fw_compatibility(const std::vector<uint8_t>& image) const override;
std::string get_opcode_string(int opcode) const override;

protected:
std::shared_ptr<ds_device_common> _ds_device_common;
Expand Down
5 changes: 5 additions & 0 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ namespace librealsense
throw not_implemented_exception("D500 device does not support unsigned FW update");
}

std::string d500_device::get_opcode_string(int opcode) const
{
return _hw_monitor_response->hwmon_error2str(opcode);
}

class d500_depth_sensor : public synthetic_sensor, public video_sensor_interface, public depth_stereo_sensor, public roi_sensor_base
{
public:
Expand Down
1 change: 1 addition & 0 deletions src/ds/d500/d500-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace librealsense
std::vector<uint8_t> backup_flash( rs2_update_progress_callback_sptr callback ) override;
void update_flash(const std::vector<uint8_t>& image, rs2_update_progress_callback_sptr callback, int update_mode) override;
bool check_fw_compatibility( const std::vector<uint8_t>& image ) const override { return true; };
std::string get_opcode_string(int opcode) const override;
protected:
std::shared_ptr<ds_device_common> _ds_device_common;

Expand Down
1 change: 1 addition & 0 deletions src/realsense.def
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,4 @@ EXPORTS
rs2_project_color_pixel_to_depth_pixel
rs2_get_calibration_config
rs2_set_calibration_config
rs2_hw_monitor_get_opcode_string
10 changes: 10 additions & 0 deletions src/rs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4452,3 +4452,13 @@ void rs2_set_calibration_config(
auto_calib->set_calibration_config(calibration_config_json_str);
}
HANDLE_EXCEPTIONS_AND_RETURN(, device, calibration_config_json_str)

void rs2_hw_monitor_get_opcode_string(int opcode, char* buffer, size_t buffer_size,
rs2_device* device,
rs2_error** error) BEGIN_API_CALL
{
VALIDATE_NOT_NULL(device);
auto device_interface = VALIDATE_INTERFACE(device->device, librealsense::debug_interface);
strncpy(buffer, device_interface->get_opcode_string(opcode).c_str(), buffer_size);
}
HANDLE_EXCEPTIONS_AND_RETURN(, device)

0 comments on commit 960edef

Please sign in to comment.