diff --git a/common/output-model.cpp b/common/output-model.cpp index 937478a8b3..9ebe9b473a 100644 --- a/common/output-model.cpp +++ b/common/output-model.cpp @@ -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") @@ -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); } @@ -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); } } diff --git a/include/librealsense2/hpp/rs_device.hpp b/include/librealsense2/hpp/rs_device.hpp index 4068dc5a53..bc7af22454 100644 --- a/include/librealsense2/hpp/rs_device.hpp +++ b/include/librealsense2/hpp/rs_device.hpp @@ -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 diff --git a/include/librealsense2/rs.h b/include/librealsense2/rs.h index d6059c85c1..b767a2225d 100644 --- a/include/librealsense2/rs.h +++ b/include/librealsense2/rs.h @@ -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 diff --git a/src/core/debug.h b/src/core/debug.h index 1d5956e4aa..5d232b068d 100644 --- a/src/core/debug.h +++ b/src/core/debug.h @@ -4,6 +4,7 @@ #include "extension.h" #include +#include namespace librealsense { @@ -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); diff --git a/src/dds/rs-dds-device-proxy.cpp b/src/dds/rs-dds-device-proxy.cpp index 94bd86e0ae..bc01659712 100644 --- a/src/dds/rs-dds-device-proxy.cpp +++ b/src/dds/rs-dds-device-proxy.cpp @@ -28,6 +28,7 @@ #include #include +#include using rsutils::json; @@ -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 ) { diff --git a/src/dds/rs-dds-device-proxy.h b/src/dds/rs-dds-device-proxy.h index f442b1f5b4..797cbf4e9a 100644 --- a/src/dds/rs-dds-device-proxy.h +++ b/src/dds/rs-dds-device-proxy.h @@ -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: diff --git a/src/ds/d400/d400-device.cpp b/src/ds/d400/d400-device.cpp index 5018b15992..d63f190bf4 100644 --- a/src/ds/d400/d400-device.cpp +++ b/src/ds/d400/d400-device.cpp @@ -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 diff --git a/src/ds/d400/d400-device.h b/src/ds/d400/d400-device.h index 0816b54d03..03de43540e 100644 --- a/src/ds/d400/d400-device.h +++ b/src/ds/d400/d400-device.h @@ -66,6 +66,7 @@ namespace librealsense std::vector backup_flash( rs2_update_progress_callback_sptr callback) override; void update_flash(const std::vector& image, rs2_update_progress_callback_sptr callback, int update_mode) override; bool check_fw_compatibility(const std::vector& image) const override; + std::string get_opcode_string(int opcode) const override; protected: std::shared_ptr _ds_device_common; diff --git a/src/ds/d500/d500-device.cpp b/src/ds/d500/d500-device.cpp index 9778971fc5..d456ab0123 100644 --- a/src/ds/d500/d500-device.cpp +++ b/src/ds/d500/d500-device.cpp @@ -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: diff --git a/src/ds/d500/d500-device.h b/src/ds/d500/d500-device.h index a3dba10e59..3679e16f5c 100644 --- a/src/ds/d500/d500-device.h +++ b/src/ds/d500/d500-device.h @@ -72,6 +72,7 @@ namespace librealsense std::vector backup_flash( rs2_update_progress_callback_sptr callback ) override; void update_flash(const std::vector& image, rs2_update_progress_callback_sptr callback, int update_mode) override; bool check_fw_compatibility( const std::vector& image ) const override { return true; }; + std::string get_opcode_string(int opcode) const override; protected: std::shared_ptr _ds_device_common; diff --git a/src/realsense.def b/src/realsense.def index 06f4507611..607307aaf6 100644 --- a/src/realsense.def +++ b/src/realsense.def @@ -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 \ No newline at end of file diff --git a/src/rs.cpp b/src/rs.cpp index ba1dd7649c..5078ece181 100644 --- a/src/rs.cpp +++ b/src/rs.cpp @@ -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)