Skip to content

make hwmon_response product line dependent - #13444

Merged
OhadMeir merged 2 commits into
realsenseai:developmentfrom
AviaAv:hw-monitor-enhance
Oct 30, 2024
Merged

OhadMeir merged 2 commits into
realsenseai:developmentfrom
AviaAv:hw-monitor-enhance

Conversation

@AviaAv

@AviaAv AviaAv commented Oct 20, 2024

Copy link
Copy Markdown
Contributor

Tracked on: [LRS-1105]

@AviaAv
AviaAv requested a review from Nir-Az October 20, 2024 10:51
Comment thread src/ds/d400/d400-device.h Outdated
friend class d400_depth_sensor;

std::shared_ptr<hw_monitor> _hw_monitor;
std::shared_ptr<ds::d400_hwmon_response_handler> hw_monitor_response = std::make_shared<ds::d400_hwmon_response_handler>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why here and not in the constructor?

@Nir-Az
Nir-Az requested review from Nir-Az and OhadMeir and removed request for Nir-Az October 27, 2024 09:13
@Nir-Az

Nir-Az commented Oct 27, 2024

Copy link
Copy Markdown
Collaborator

@OhadMeir please review

Comment thread src/hw-monitor.h Outdated

std::string hwmon_error_string( command const &, hwmon_response e );
typedef int32_t hwmon_response;
class base_hwmon_response_handler { // base class for different product number to implement responses

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have product numbers, you probably meant product ID, which also does not sound correct here. Rephrase to products or product lines

Comment thread src/hw-monitor.h Outdated
typedef int32_t hwmon_response;
class base_hwmon_response_handler { // base class for different product number to implement responses
public:
inline virtual std::string hwmon_error2str(int e) const = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Virtual can be inlined. Remove inline keyword

Comment thread src/hw-monitor.h Outdated
class base_hwmon_response_handler { // base class for different product number to implement responses
public:
inline virtual std::string hwmon_error2str(int e) const = 0;
virtual hwmon_response hwmon_Success() const = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning is ambiguous, can be understood as is_successful or success_value.
According to the rest of the code it's the later, please rename.
Note - naming convention, should not capitalize after underscore.

Comment thread src/hw-monitor.h Outdated

std::string hwmon_error_string( command const &, hwmon_response e );
typedef int32_t hwmon_response;
class base_hwmon_response_handler { // base class for different product number to implement responses

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On most places we name interfaces as XXX_interface. Consider renaming hwmon_response_handler_interface or hwmon_response_interface (are we a "handler"?).
Also can wrap typedef int32_t hwmon_response in the class namespace as hwmon_response_interface::type

Comment thread src/hw-monitor.h Outdated
explicit hw_monitor(std::shared_ptr<locked_transfer> locked_transfer)
: _locked_transfer(std::move(locked_transfer))
explicit hw_monitor(std::shared_ptr<locked_transfer> locked_transfer, std::shared_ptr<base_hwmon_response_handler> hwmon_response_handler)
: _locked_transfer(std::move(locked_transfer)), hwmon_response_handler(hwmon_response_handler)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use _ as a prefix to member variables name

Comment thread src/ds/d400/d400-private.h Outdated
public:
enum d400_hwmon_response_names : int32_t
{
hwm_Success = 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, can shorten the literal names because it's in a class namespace.
d400_hwmon_response::success

Comment thread src/hw-monitor.h Outdated

std::shared_ptr<base_hwmon_response_handler> hwmon_response_handler;

std::string hwmon_error_string(command const&, int e) const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be hwmon_response not int

Comment thread src/hdr-config.cpp Outdated
hwmon_response response;
auto res = _hwm.send( cmd, &response ); // avoid the throw
switch( response )
if (response != _hwm.hwmon_response_handler->hwmon_Success()) // If no subpreset is streaming, the firmware returns "NO_DATA_TO_RETURN" error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exactly equivalent to the former logic. Why was this changed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's becasue now we get the success value from a virtual function. I'm getting an error when trying to use _hwm.hwmon_response_handler->hwmon_Success() as a 'case' value ('this' can not be used in a constant expression)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but now you don't have any reference to hwmon_response::hwm_NoDataToReturn, is it not needed?
You can replace switch with some else if clauses, but here you have changed the logic. Just make sure its intended and works as expected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see, thanks, I will add no_data_to_return_opcode as a member to this class, like we did on alternating_emitter_option

Comment thread src/ds/ds-options.h Outdated
{
public:
alternating_emitter_option(hw_monitor& hwm, bool is_fw_version_using_id);
alternating_emitter_option(hw_monitor& hwm, bool is_fw_version_using_id, int no_data_to_return_opcode);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use hwmon_response type, not int

Comment thread src/ds/d400/d400-private.h Outdated
class d400_hwmon_response_handler : public base_hwmon_response_handler
{
public:
enum d400_hwmon_response_names : int32_t

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too, use the defined hwmon_response type

{
public:
enum d400_hwmon_response_names : int32_t
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename d400_hwmon_response_names to opcodes. It will be under the class namespace.

Comment thread src/ds/d400/d400-device.h
@@ -94,6 +94,7 @@ namespace librealsense
friend class d400_depth_sensor;

std::shared_ptr<hw_monitor> _hw_monitor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Member hw_monitor_response is not needed, create the shared object as you directly pass it into _hw_monitor.
Also, should be prefixed with _

Comment thread src/ds/d500/d500-private.h Outdated
class d500_hwmon_response_handler : public base_hwmon_response_handler
{
public:
enum d500_hwmon_response_names : int32_t

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as d400

@OhadMeir
OhadMeir merged commit 57eed2d into realsenseai:development Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants