Skip to content

Commit

Permalink
PR #12688 from OhadMeir: Support FW logs extended format
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir authored Mar 31, 2024
2 parents 51b0194 + 5433869 commit 052cc57
Show file tree
Hide file tree
Showing 26 changed files with 1,467 additions and 789 deletions.
15 changes: 12 additions & 3 deletions common/output-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ void output_model::thread_loop()
rsutils::string::from()
<< "Invalid Hardware Logger XML at '" << hwlogger_xml << "': " << ex.what()
<< "\nEither configure valid XML or remove it" );
continue; // Don't try to get log entries for this device
}
}

fwlogger.start_collecting();
auto message = fwlogger.create_message();
while (fwlogger.get_firmware_log(message))
{
Expand All @@ -68,11 +70,15 @@ void output_model::thread_loop()
{
parsed_ok = true;

std::string module_print = "[" + parsed.module_name() + "]";
if( module_print == "[Unknown]" )
module_print.clear(); // Some devices don't support FW log modules

add_log( message.get_severity(),
parsed.file_name(),
parsed.line(),
rsutils::string::from()
<< "FW-LOG [" << parsed.thread_name() << "] " << parsed.message() );
rsutils::string::from() << "FW-LOG [" << parsed.thread_name() << "]"
<< module_print << parsed.message() );
}
}

Expand All @@ -83,8 +89,11 @@ void output_model::thread_loop()
ss << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(elem) << " ";
add_log(message.get_severity(), __FILE__, 0, ss.str());
}
if (!enable_firmware_logs && fwlogger.get_number_of_fw_logs() == 0)
if( ! enable_firmware_logs && fwlogger.get_number_of_fw_logs() == 0 )
{
fwlogger.stop_collecting();
break;
}
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2709,7 +2709,7 @@ namespace rs2
}

{
ImGui::Text("HWLoggerEvents.xml Path:");
ImGui::Text("FW logs XML file:");
ImGui::SameLine();
static char logpath[256];
memset(logpath, 0, 256);
Expand All @@ -2721,6 +2721,19 @@ namespace rs2
path_str = logpath;
temp_cfg.set(configurations::viewer::hwlogger_xml, path_str);
}

ImGui::SameLine();
if( ImGui::Button( "FW logs XML" ) )
{
auto ret = file_dialog_open(open_file, "XML file\0*.xml\0", NULL, NULL);
if( ret )
{
memset( logpath, 0, 256 );
memcpy( logpath, ret, std::min( 255, static_cast< int >( strlen( ret ) ) ) );
path_str = logpath;
temp_cfg.set( configurations::viewer::hwlogger_xml, path_str );
}
}
}

ImGui::Separator();
Expand Down
28 changes: 26 additions & 2 deletions include/librealsense2/h/rs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ void rs2_software_sensor_add_option(rs2_sensor* sensor, rs2_option option, float
void rs2_software_sensor_detach(rs2_sensor* sensor, rs2_error** error);


/**
* \brief Starts collecting FW log messages in the device.
* \param[in] dev Device that will start collecting log messages.
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are
*/
void rs2_start_collecting_fw_logs( rs2_device * dev, rs2_error ** error );

/**
* \brief Stops collecting FW log messages in the device.
* \param[in] dev Device that will stop collecting log messages.
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are
*/
void rs2_stop_collecting_fw_logs( rs2_device * dev, rs2_error ** error );

/**
* \brief Creates RealSense firmware log message.
* \param[in] dev Device from which the FW log will be taken using the created message
Expand Down Expand Up @@ -483,13 +497,23 @@ const char* rs2_get_fw_log_parsed_message(rs2_firmware_log_parsed_message* fw_lo
const char* rs2_get_fw_log_parsed_file_name(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error);

/**
* \brief Gets RealSense firmware log parsed message thread name.
* \brief Gets RealSense firmware log parsed message source (SoC) or thread name.
* \param[in] fw_log_parsed_msg firmware log parsed message object
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are ignored.
* \return thread name of the firmware log parsed message
* \return source (SoC) or thread name of the firmware log parsed message
*/
const char* rs2_get_fw_log_parsed_thread_name(rs2_firmware_log_parsed_message* fw_log_parsed_msg, rs2_error** error);

/**
* \brief Gets RealSense firmware log parsed message module name.
* \param[in] fw_log_parsed_msg firmware log parsed message object
* \param[out] error If non-null, receives any error that occurs during this call, otherwise, errors are
* ignored. \return module name of the firmware log parsed message
*/
const char * rs2_get_fw_log_parsed_module_name( rs2_firmware_log_parsed_message * fw_log_parsed_msg,
rs2_error ** error );


/**
* \brief Gets RealSense firmware log parsed message severity.
* \param[in] fw_log_parsed_msg firmware log parsed message object
Expand Down
25 changes: 23 additions & 2 deletions include/librealsense2/hpp/rs_internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,16 @@ namespace rs2
std::string thread_name() const
{
rs2_error* e = nullptr;
std::string thread_name(rs2_get_fw_log_parsed_thread_name(_parsed_fw_log.get(), &e));
std::string name(rs2_get_fw_log_parsed_thread_name(_parsed_fw_log.get(), &e));
error::handle(e);
return thread_name;
return name;
}
std::string module_name() const
{
rs2_error * e = nullptr;
std::string name( rs2_get_fw_log_parsed_module_name( _parsed_fw_log.get(), &e ) );
error::handle( e );
return name;
}
std::string severity() const
{
Expand Down Expand Up @@ -450,6 +457,20 @@ namespace rs2
error::handle(e);
}

void start_collecting()
{
rs2_error * e = nullptr;
rs2_start_collecting_fw_logs( _dev.get(), &e );
error::handle( e );
}

void stop_collecting()
{
rs2_error * e = nullptr;
rs2_start_collecting_fw_logs( _dev.get(), &e );
error::handle( e );
}

rs2::firmware_log_message create_message()
{
rs2_error* e = nullptr;
Expand Down
9 changes: 2 additions & 7 deletions src/ds/d500/d500-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ namespace librealsense
register_info(RS2_CAMERA_INFO_FIRMWARE_UPDATE_ID, gvd_parsed_fields.optical_module_sn);
register_info(RS2_CAMERA_INFO_FIRMWARE_VERSION, gvd_parsed_fields.fw_version);
register_info(RS2_CAMERA_INFO_PHYSICAL_PORT, group.uvc_devices.front().device_path);
register_info(RS2_CAMERA_INFO_DEBUG_OP_CODE, std::to_string(static_cast<int>(fw_cmd::GLD)));
register_info(RS2_CAMERA_INFO_DEBUG_OP_CODE, std::to_string(static_cast<int>(fw_cmd::GET_FW_LOGS)));
register_info(RS2_CAMERA_INFO_ADVANCED_MODE, ((advanced_mode) ? "YES" : "NO"));
register_info(RS2_CAMERA_INFO_PRODUCT_ID, pid_hex_str);
register_info(RS2_CAMERA_INFO_PRODUCT_LINE, "D500");
Expand Down Expand Up @@ -702,12 +702,7 @@ namespace librealsense

command d500_device::get_firmware_logs_command() const
{
return command{ ds::GLD, 0x1f4 };
}

command d500_device::get_flash_logs_command() const
{
return command{ ds::FRB, 0x17a000, 0x3f8 };
return command{ ds::GET_FW_LOGS };
}

bool d500_device::check_symmetrization_enabled() const
Expand Down
3 changes: 1 addition & 2 deletions src/ds/d500/d500-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ namespace librealsense
void get_gvd_details(const std::vector<uint8_t>& gvd_buff, ds::d500_gvd_parsed_fields* parsed_fields) const;

bool check_symmetrization_enabled() const;
//TODO - add these to device class as pure virtual methods

command get_firmware_logs_command() const;
command get_flash_logs_command() const;

void init(std::shared_ptr<context> ctx, const platform::backend_device_group& group);
void register_features();
Expand Down
7 changes: 4 additions & 3 deletions src/ds/d500/d500-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class d555e_device
, public d500_color
, public d500_motion
, public ds_advanced_mode_base
, public firmware_logger_device
, public extended_firmware_logger_device
{
public:
d555e_device( std::shared_ptr< const d500_info > dev_info )
Expand All @@ -52,8 +52,9 @@ class d555e_device
, d500_color( dev_info, RS2_FORMAT_YUYV )
, d500_motion( dev_info )
, ds_advanced_mode_base( d500_device::_hw_monitor, get_depth_sensor() )
, firmware_logger_device(
dev_info, d500_device::_hw_monitor, get_firmware_logs_command(), get_flash_logs_command() )
, extended_firmware_logger_device( dev_info,
d500_device::_hw_monitor,
get_firmware_logs_command() )
{
auto emitter_always_on_opt = std::make_shared<emitter_always_on_option>( d500_device::_hw_monitor, ds::LASERONCONST, ds::LASERONCONST);
get_depth_sensor().register_option(RS2_OPTION_EMITTER_ALWAYS_ON,emitter_always_on_opt);
Expand Down
6 changes: 4 additions & 2 deletions src/ds/ds-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace librealsense
FEF = 0x0c, // Erase flash full <Parameter1 Name="0xACE">
FSRU = 0x0d, // Flash status register unlock
FPLOCK = 0x0e, // Permanent lock on lower Quarter region of the flash
GLD = 0x0f, // FW logs
GLD = 0x0f, // Legacy get FW logs command
GVD = 0x10, // camera details
GETINTCAL = 0x15, // Read calibration table
SETINTCAL = 0x16, // Set Internal sub calibration table
Expand Down Expand Up @@ -131,7 +131,8 @@ namespace librealsense
APM_STROBE_GET = 0x99, // Query if Laser on constantly or pulse
SET_HKR_CONFIG_TABLE = 0xA6, // HKR Set Internal sub calibration table
GET_HKR_CONFIG_TABLE = 0xA7, // HKR Get Internal sub calibration table
CALIBRESTOREEPROM = 0xA8 // HKR Store EEPROM Calibration
CALIBRESTOREEPROM = 0xA8, // HKR Store EEPROM Calibration
GET_FW_LOGS = 0xB4 // Get FW logs extended format
};

#define TOSTRING(arg) #arg
Expand Down Expand Up @@ -163,6 +164,7 @@ namespace librealsense
ENUM2STR(SETSUBPRESET);
ENUM2STR(GETSUBPRESET);
ENUM2STR(GETSUBPRESETID);
ENUM2STR(GET_FW_LOGS);
default:
return ( rsutils::string::from() << "Unrecognized FW command " << state );
}
Expand Down
Loading

0 comments on commit 052cc57

Please sign in to comment.