Skip to content

add dds config tool - #13628

Merged
OhadMeir merged 5 commits into
realsenseai:developmentfrom
Noy-Zini:add-dds-config-tool-to-viewer
Jan 9, 2025
Merged

add dds config tool#13628
OhadMeir merged 5 commits into
realsenseai:developmentfrom
Noy-Zini:add-dds-config-tool-to-viewer

Conversation

@Noy-Zini

Copy link
Copy Markdown
Contributor

Tracked on : [RSDEV-2884]

@Noy-Zini
Noy-Zini force-pushed the add-dds-config-tool-to-viewer branch 2 times, most recently from 4c15cb3 to 6234882 Compare December 25, 2024 12:13
@Noy-Zini
Noy-Zini force-pushed the add-dds-config-tool-to-viewer branch from 6234882 to 7e2db73 Compare December 25, 2024 13:24
@Noy-Zini
Noy-Zini requested a review from Nir-Az December 25, 2024 14:55
Comment thread common/dds-model.cpp
@@ -0,0 +1,332 @@
#include "dds-model.h"
// License: Apache 2.0. See LICENSE file in root directory.

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.

Misplaced, should be on top

Comment thread tools/dds/dds-config/CMakeLists.txt Outdated
LIST_DIRECTORIES false
RELATIVE ${PROJECT_SOURCE_DIR}
"${CMAKE_CURRENT_LIST_DIR}/*"
"${PROJECT_SOURCE_DIR}/../../../third-party/rsutils/include/rsutils/type/*"

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.

This path seems weird..
relative to the source dir we only need third-party/rsutils/include/rsutils/type/* no?

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.

The source dir for the dds tool is librealsense\tools\dds\dds-config so only using part of the path won't work but I can set the THIRD_PARTY_DIR so it looks more readable:
set(THIRD_PARTY_DIR "${PROJECT_SOURCE_DIR}/../../../third-party")
"${THIRD_PARTY_DIR}/rsutils/include/rsutils/type/*"

Comment thread common/device-model.cpp Outdated
}

_calib_model.update(window, error_message);
_dds_model.render_dds_config_window(window , error_message);

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.

Will this work id we build with DDS off?

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'll add a check to see if the device supports DDS before using this function.
But in general, yes the functionality works with DDS off because the function already checks whether the window should be open. If the device doesn't support DDS, the window is closed by default.

Comment thread common/device-model.cpp Outdated
}
}
}
ImGuiSelectableFlags is_streaming_flag = (is_streaming) ? ImGuiSelectableFlags_Disabled : 0;

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.

What is the difference between 0 and ImGuiSelectableFlags_Disabled?

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.

0 is equal to ImGuiSelectableFlags_None that will show the "DDS Configuration" option an enabled
and using the ImGuiSelectableFlags_Disabled will show this option as disabled (faded and not allowing clicks on it)

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.

So why not replace 0 with ImGuiSelectableFlags_None?

Comment thread common/dds-model.h Outdated
#include <set>
#include <rsutils/type/ip-address.h>
#include <rsutils/string/hexdump.h>
#include "../third-party/rsutils/include/rsutils/type/eth-config.h"

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.

Can we also use <>?
<party/rsutils/include/rsutils/type/eth-config.h>?

Comment thread common/dds-model.h
eth_config _current_config;
eth_config _changed_config;

bool _window_open;

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.

Not initialized but other is?

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.

initialized _window_open to false as well

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.

initialized in the constructor initialization list

Comment thread common/dds-model.cpp Outdated
if (ImGui::InputText(label_name.c_str(), buffer, sizeof(buffer))) {
std::string new_ip_str(buffer);
if (rsutils::type::ip_address(new_ip_str).is_valid()) {
ip = rsutils::type::ip_address(new_ip_str);

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 calling it twice?
Maybe call it once and use it on both cases?

Comment thread common/dds-model.cpp Outdated
if (rsutils::type::ip_address(new_ip_str).is_valid()) {
ip = rsutils::type::ip_address(new_ip_str);
}
else {

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.

new line please for the {

Comment thread common/dds-model.cpp Outdated
ImGui::Text("DHCP Timeout (seconds)");
ImGui::SameLine();
int tempTimeout = static_cast<int>(_changed_config.dhcp.timeout);
if (ImGui::InputInt("##DHCP Timeout (seconds)", &tempTimeout)) {

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.

Please place { on a new line for all uses here.
I will send you a mail about using clang format

@Nir-Az

Nir-Az commented Dec 29, 2024

Copy link
Copy Markdown
Collaborator

@Noy-Zini can you please build a version for us to play with and check?

@Noy-Zini
Noy-Zini force-pushed the add-dds-config-tool-to-viewer branch from 4bead95 to 16d7803 Compare December 31, 2024 12:03
@Noy-Zini
Noy-Zini requested a review from Nir-Az December 31, 2024 12:54
Comment thread common/dds-model.cpp Outdated

bool rs2::dds_model::supports_DDS()
{
return _dds_suported;

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.

supported

@Noy-Zini
Noy-Zini force-pushed the add-dds-config-tool-to-viewer branch from 16d7803 to 6cb2c25 Compare December 31, 2024 13:41
@Noy-Zini
Noy-Zini requested a review from OhadMeir January 8, 2025 10:16
return configured.ip == other.configured.ip && configured.netmask == other.configured.netmask
&& configured.gateway == other.configured.gateway && dds.domain_id == other.dds.domain_id
&& dhcp.on == other.dhcp.on && link.priority == other.link.priority && link.timeout == other.link.timeout;
&& dhcp.on == other.dhcp.on && link.priority == other.link.priority && link.timeout == other.link.timeout && dhcp.timeout != other.dhcp.timeout;

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 ==?

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.

yes thank I fixed it 👍

@Noy-Zini
Noy-Zini force-pushed the add-dds-config-tool-to-viewer branch from 896a47d to 81fa5a9 Compare January 9, 2025 06:39
Comment thread common/rs-config.h
}
current = &( *current )[token]; // getting to the next level in the JSON structure
}
return current->get< 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.

get might throw if value is of wrong type.
You can use get_ex to get value and success indication.

Comment thread common/rs-config.h

// Retrieves a value from a nested JSON structure using dot notation
template< typename T >
T get_nested( const std::string & path ) 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 we return T or config_value like get?

Comment thread common/rs-config.h
{
( *current )[keys[i]] = rsutils::json::object();
}
current = &( *current )[keys[i]];

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.

I think that working with a reference, not a pointer, will be easier and the syntax clearer

Comment thread common/rs-config.h
std::stringstream val_ss;
val_ss << default_val;
_defaults[path] = val_ss.str();
save();

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.

Why are we saving to file here? User did not select apply

Comment thread common/dds-model.h
#include <set>
#include <rsutils/type/ip-address.h>
#include <rsutils/string/hexdump.h>
#include <../third-party/rsutils/include/rsutils/type/eth-config.h>

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.

Can shorten #include <rsutils/type/eth-config.h> like the other includes

Comment thread common/dds-model.h
bool const ACTUAL_VALUES = 0;
bool const DEFULT_VALUES = 1;

enum priority {

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.

Define under the class namespace. Looks like it can be private

Comment thread common/dds-model.h
#include <rsutils/json.h>
#include <rsutils/json-config.h>

uint32_t const GET_ETH_CONFIG = 0xBB;

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.

Constsants should be under a namespace at minimum. Better yet, move to CPP as these are internal details that don't need to be included by users

Comment thread common/dds-model.h
#include <realsense_imgui.h>
#include <set>
#include <rsutils/type/ip-address.h>
#include <rsutils/string/hexdump.h>

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.

Are all these includes needed here? Move to cpp what's used only by implementation and doesn't need to be declared here

Comment thread common/dds-model.cpp
{
if( check_DDS_support() )
{
_defult_config = get_eth_config( _device, DEFULT_VALUES );

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.

You implicitly convert int to bool and later check the bool and convert back to int. Better just pass int as parameter and use it int curr_or_default.

Comment thread common/dds-model.cpp
if( check_DDS_support() )
{
_defult_config = get_eth_config( _device, DEFULT_VALUES );
_current_config = get_eth_config( _device, ACTUAL_VALUES );

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 need the first parameter, it is always _device and can be used internally.

Comment thread common/dds-model.cpp
}
else
{
std::snprintf( buffer, sizeof( buffer ), "%s", ip.to_string().c_str() );

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.

Why is this needed?

Comment thread common/dds-model.cpp
break;
case DYNAMIC:
_changed_config.link.priority
= _current_config.link.speed ? link_priority::dynamic_eth_first : link_priority::dynamic_usb_first;

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.

Logic not clear. Add a comment "If link speed is not 0 than we are connected by Ethernet"

Comment thread common/dds-model.cpp
}
ImGui::Checkbox( "No Reset after changes", &_no_reset );

if( ImGui::Checkbox( "Load to defult values", &_set_defult ) )

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.

"Load default values", "to" is redundant

@OhadMeir

OhadMeir commented Jan 9, 2025

Copy link
Copy Markdown
Contributor

Need to add scroll bars to the settings when minimized. In another PR.

@OhadMeir OhadMeir left a comment

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.

Great PR, helpful capability.

As discussed offline, we will merge now, open comments will be handled in a follow-up PR

@OhadMeir
OhadMeir merged commit 273a8f7 into realsenseai:development Jan 9, 2025
@Nir-Az Nir-Az mentioned this pull request Jan 12, 2025
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