Skip to content

Commit

Permalink
Handle PR#12688 comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadMeir committed Feb 25, 2024
1 parent 48fec4f commit 6e12b10
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/ds/d500/d500-factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class d555e_device
, firmware_logger_device( dev_info,
d500_device::_hw_monitor,
get_firmware_logs_command(),
get_flash_logs_command(),
{ { 0, "HKR" } } )
get_flash_logs_command() )
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/firmware_logger_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ namespace librealsense
bool is_d400 = std::string( get_info( RS2_CAMERA_INFO_PRODUCT_LINE ) ) == "D400";

if( is_d400 )
_parser = std::make_unique< fw_logs::legacy_fw_logs_parser >( xml_content, _parser_source_id_to_name );
_parser = std::make_unique< fw_logs::legacy_fw_logs_parser >( xml_content );
else
_parser = std::make_unique< fw_logs::fw_logs_parser >( xml_content, _parser_source_id_to_name );
_parser = std::make_unique< fw_logs::fw_logs_parser >( xml_content );

return ( _parser != nullptr );
}
Expand Down
10 changes: 8 additions & 2 deletions src/fw-logs/fw-log-data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ namespace librealsense

uint32_t fw_logs_binary_data::get_timestamp() const
{
const legacy_fw_log_binary * log_binary = reinterpret_cast< const legacy_fw_log_binary * >( logs_buffer.data() );
return log_binary->timestamp;
const fw_log_binary * log_binary = reinterpret_cast< const fw_log_binary * >( logs_buffer.data() );
if( log_binary->magic_number == 0xA5 )
return reinterpret_cast< const extended_fw_log_binary * >( this )->soc_timestamp;
if( log_binary->magic_number == 0xA0 )
return reinterpret_cast< const legacy_fw_log_binary * >( this )->timestamp;

throw librealsense::invalid_value_exception(
rsutils::string::from() << "Received unfamiliar FW log 'magic number' " << log_binary->magic_number );
}

rs2_log_severity fw_logs_severity_to_rs2_log_severity( int32_t severity )
Expand Down
10 changes: 4 additions & 6 deletions src/fw-logs/fw-logs-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ namespace librealsense
{
namespace fw_logs
{
fw_logs_parser::fw_logs_parser( const std::string & definitions_xml,
const std::map< int, std::string > & source_id_to_name )
fw_logs_parser::fw_logs_parser( const std::string & definitions_xml )
: _source_to_formatting_options()
, _source_id_to_name( source_id_to_name )
{
fw_logs_xml_helper helper;
_source_id_to_name = helper.get_listed_sources( definitions_xml );
for( auto & source : _source_id_to_name )
{
std::string path = helper.get_source_parser_file_path( source.first, definitions_xml );
Expand Down Expand Up @@ -146,9 +145,8 @@ namespace librealsense
return fw_logs::fw_logs_severity_to_rs2_log_severity( severity );
}

legacy_fw_logs_parser::legacy_fw_logs_parser( const std::string & xml_content,
const std::map< int, std::string > & source_id_to_name )
: fw_logs_parser( xml_content, source_id_to_name )
legacy_fw_logs_parser::legacy_fw_logs_parser( const std::string & xml_content )
: fw_logs_parser( xml_content )
{
// Check expected size here, no need to check repeatedly in parse functions
if( _source_to_formatting_options.size() != 1 )
Expand Down
6 changes: 2 additions & 4 deletions src/fw-logs/fw-logs-parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ namespace librealsense
class fw_logs_parser : public std::enable_shared_from_this<fw_logs_parser>
{
public:
explicit fw_logs_parser( const std::string & definitions_xml,
const std::map< int, std::string > & source_id_to_name );
explicit fw_logs_parser( const std::string & definitions_xml );
virtual ~fw_logs_parser() = default;

fw_log_data parse_fw_log( const fw_logs_binary_data * fw_log_msg );
Expand Down Expand Up @@ -55,8 +54,7 @@ namespace librealsense
class legacy_fw_logs_parser : public fw_logs_parser
{
public:
explicit legacy_fw_logs_parser( const std::string & xml_content,
const std::map< int, std::string > & source_id_to_name );
explicit legacy_fw_logs_parser( const std::string & xml_content );

size_t get_log_size( const uint8_t * log ) const override;

Expand Down
22 changes: 22 additions & 0 deletions src/fw-logs/fw-logs-xml-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ std::string get_file_path( const xml_node<> * source_node )
return {};
}

std::map< int, std::string > fw_logs_xml_helper::get_listed_sources( const std::string & definitions_xml ) const
{
std::map< int, std::string > source_ids_to_names;

std::vector< char > buffer = string_to_char_buffer( definitions_xml );
xml_document<> document;
load_external_xml( &document, buffer );

// Loop through all elements to find 'Source' nodes, when found look for id attribure and compare to requested id.
for( xml_node<> * node = get_first_node( &document ); node; node = node->next_sibling() )
{
std::string tag( node->name(), node->name() + node->name_size() );
if( tag.compare( "Source" ) == 0 )
{
source_ids_to_names.insert( { get_id_attribute( node ), get_name_attribute( node ) } );
}
}

return source_ids_to_names;
}


std::string fw_logs_xml_helper::get_source_parser_file_path( int source_id, const std::string & definitions_xml ) const
{
std::vector< char > buffer = string_to_char_buffer( definitions_xml );
Expand Down
2 changes: 2 additions & 0 deletions src/fw-logs/fw-logs-xml-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>
#include <unordered_map>
#include <map>


namespace librealsense
Expand All @@ -15,6 +16,7 @@ namespace librealsense
class fw_logs_xml_helper
{
public:
std::map< int, std::string > get_listed_sources( const std::string & definitions_xml ) const;
std::string get_source_parser_file_path( int source_id, const std::string & definitions_xml ) const;

// Return a mapping of source module IDs to their requested verbosity level.
Expand Down

0 comments on commit 6e12b10

Please sign in to comment.