Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dds config tool #13628

Merged

Conversation

Noy-Zini
Copy link

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
@@ -0,0 +1,332 @@
#include "dds-model.h"
// License: Apache 2.0. See LICENSE file in root directory.
Copy link
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

@@ -9,6 +9,7 @@ file( GLOB_RECURSE RS_DDS_CONFIG_SOURCE_FILES
LIST_DIRECTORIES false
RELATIVE ${PROJECT_SOURCE_DIR}
"${CMAKE_CURRENT_LIST_DIR}/*"
"${PROJECT_SOURCE_DIR}/../../../third-party/rsutils/include/rsutils/type/*"
Copy link
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
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/*"

@@ -1457,6 +1472,7 @@ namespace rs2
}

_calib_model.update(window, error_message);
_dds_model.render_dds_config_window(window , error_message);
Copy link
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
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.

@@ -1435,6 +1436,20 @@ namespace rs2
}
}
}
ImGuiSelectableFlags is_streaming_flag = (is_streaming) ? ImGuiSelectableFlags_Disabled : 0;
Copy link
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
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
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?

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

eth_config _current_config;
eth_config _changed_config;

bool _window_open;
Copy link
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
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
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

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

if (rsutils::type::ip_address(new_ip_str).is_valid()) {
ip = rsutils::type::ip_address(new_ip_str);
}
else {
Copy link
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 {

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
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
Copy link
Collaborator

Nir-Az commented Dec 29, 2024

@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

bool rs2::dds_model::supports_DDS()
{
return _dds_suported;
Copy link
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
@@ -105,7 +105,7 @@ bool eth_config::operator==( eth_config const & other ) const noexcept
// Only compare those items that are configurable
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
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
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
}
current = &( *current )[token]; // getting to the next level in the JSON structure
}
return current->get< T >();
Copy link
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.

@@ -87,6 +87,105 @@ namespace rs2

static config_file& instance();

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

{
( *current )[keys[i]] = rsutils::json::object();
}
current = &( *current )[keys[i]];
Copy link
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

std::stringstream val_ss;
val_ss << default_val;
_defaults[path] = val_ss.str();
save();
Copy link
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

#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
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

bool const ACTUAL_VALUES = 0;
bool const DEFULT_VALUES = 1;

enum priority {
Copy link
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

#include <rsutils/json.h>
#include <rsutils/json-config.h>

uint32_t const GET_ETH_CONFIG = 0xBB;
Copy link
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

#include <realsense_imgui.h>
#include <set>
#include <rsutils/type/ip-address.h>
#include <rsutils/string/hexdump.h>
Copy link
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

{
if( check_DDS_support() )
{
_defult_config = get_eth_config( _device, DEFULT_VALUES );
Copy link
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.

if( check_DDS_support() )
{
_defult_config = get_eth_config( _device, DEFULT_VALUES );
_current_config = get_eth_config( _device, ACTUAL_VALUES );
Copy link
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.

}
else
{
std::snprintf( buffer, sizeof( buffer ), "%s", ip.to_string().c_str() );
Copy link
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?

break;
case DYNAMIC:
_changed_config.link.priority
= _current_config.link.speed ? link_priority::dynamic_eth_first : link_priority::dynamic_usb_first;
Copy link
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"

}
ImGui::Checkbox( "No Reset after changes", &_no_reset );

if( ImGui::Checkbox( "Load to defult values", &_set_defult ) )
Copy link
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
Copy link
Contributor

OhadMeir commented Jan 9, 2025

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

Copy link
Contributor

@OhadMeir OhadMeir left a comment

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 IntelRealSense:development Jan 9, 2025
23 checks passed
@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