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

dds config tool repair #13681

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions common/dds-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <rsutils/json.h>
#include <rsutils/json-config.h>
#include <rsutils/os/special-folder.h>
#include <rsutils/string/hexdump.h>
#include <imgui.h>
#include <realsense_imgui.h>

#include <iostream>
#include <fstream>
Expand All @@ -15,6 +18,15 @@ using namespace rs2;
using rsutils::json;
using rsutils::type::ip_address;

namespace rs2 {

uint32_t const GET_ETH_CONFIG = 0xBB;
uint32_t const SET_ETH_CONFIG = 0xBA;

int const CURRENT_VALUES = 0;
int const DEFULT_VALUES = 1;
}

dds_model::dds_model( rs2::device dev )
: _device( dev )
, _window_open( false )
Expand All @@ -24,16 +36,17 @@ dds_model::dds_model( rs2::device dev )
{
if( check_DDS_support() )
{
_defult_config = get_eth_config( _device, DEFULT_VALUES );
_current_config = get_eth_config( _device, ACTUAL_VALUES );
_defult_config = get_eth_config( DEFULT_VALUES );
_current_config = get_eth_config( CURRENT_VALUES );
_changed_config = _current_config;
_dds_supported = true;
}
}

eth_config dds_model::get_eth_config( rs2::debug_protocol dev, bool defult_val )
eth_config dds_model::get_eth_config( int curr_or_default )
{
auto cmd = dev.build_command( GET_ETH_CONFIG, defult_val ? 0 : 1 );
rs2::debug_protocol dev( _device );
auto cmd = dev.build_command( GET_ETH_CONFIG, curr_or_default );
auto data = dev.send_and_receive_raw_data( cmd );
int32_t const & code = *reinterpret_cast< int32_t const * >( data.data() );
data.erase( data.begin(), data.begin() + sizeof( code ) );
Expand Down Expand Up @@ -69,7 +82,7 @@ bool rs2::dds_model::supports_DDS()
return _dds_supported;
}

priority rs2::dds_model::classifyPriority( link_priority & pr )
rs2::dds_model::priority rs2::dds_model::classifyPriority( link_priority & pr )
{
if( pr == link_priority::usb_only || pr == link_priority::usb_first )
{
Expand All @@ -84,10 +97,10 @@ priority rs2::dds_model::classifyPriority( link_priority & pr )

bool dds_model::check_DDS_support()
{
if (_device.is<rs2::debug_protocol>())
if( _device.is< rs2::debug_protocol >() )
{
auto dev = debug_protocol( _device );
auto cmd = dev.build_command( GET_ETH_CONFIG, ACTUAL_VALUES );
auto cmd = dev.build_command( GET_ETH_CONFIG, CURRENT_VALUES );
auto data = dev.send_and_receive_raw_data( cmd );
int32_t const & code = *reinterpret_cast< int32_t const * >( data.data() );
if( code == GET_ETH_CONFIG )
Expand All @@ -114,6 +127,7 @@ void rs2::dds_model::ipInputText( std::string label, ip_address & ip )
}
else
{
// Initialize the ImGui buffer with the current IP address in case of invalid input
std::snprintf( buffer, sizeof( buffer ), "%s", ip.to_string().c_str() );
}
}
Expand All @@ -126,7 +140,7 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
{
try
{
_current_config = get_eth_config( _device, ACTUAL_VALUES );
_current_config = get_eth_config( CURRENT_VALUES );
_changed_config = _current_config;
ImGui::OpenPopup( window_name );
}
Expand Down Expand Up @@ -210,7 +224,9 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
break;
case DYNAMIC:
_changed_config.link.priority
= _current_config.link.speed ? link_priority::dynamic_eth_first : link_priority::dynamic_usb_first;
= _current_config.link.speed
? link_priority::dynamic_eth_first
: link_priority::dynamic_usb_first; // If link speed is not 0 than we are connected by Ethernet
break;
}
}
Expand Down Expand Up @@ -258,7 +274,7 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
}
ImGui::Checkbox( "No Reset after changes", &_no_reset );

if( ImGui::Checkbox( "Load to defult values", &_set_defult ) )
if( ImGui::Checkbox( "Load defult values", &_set_defult ) )
{
if( _set_defult )
_changed_config = _defult_config;
Expand Down Expand Up @@ -350,4 +366,4 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
void rs2::dds_model::open_dds_tool_window()
{
_window_open = true;
}
}
29 changes: 9 additions & 20 deletions common/dds-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,7 @@

#include <librealsense2/rs.hpp>
#include <imgui.h>
#include <realsense_imgui.h>
#include <set>
#include <rsutils/type/ip-address.h>
#include <rsutils/string/hexdump.h>
#include <../third-party/rsutils/include/rsutils/type/eth-config.h>
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
#include <rsutils/json.h>
#include <rsutils/json-config.h>

uint32_t const GET_ETH_CONFIG = 0xBB;
uint32_t const SET_ETH_CONFIG = 0xBA;
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved

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

enum priority {
ETH_FIRST,
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
USB_FIRST,
DYNAMIC
};
#include <rsutils/type/eth-config.h>

namespace rs2
{
Expand All @@ -40,14 +22,21 @@ namespace rs2

void close_window() { ImGui::CloseCurrentPopup(); }

eth_config get_eth_config(rs2::debug_protocol dev, bool defult_val);
eth_config get_eth_config(int curr_or_default);

void set_eth_config(eth_config &new_config , std::string& error_message);

bool supports_DDS();


private:

enum priority {
ETH_FIRST,
USB_FIRST,
DYNAMIC
};

rs2::device _device;

eth_config _defult_config;
Expand Down
24 changes: 10 additions & 14 deletions common/rs-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace rs2

// Retrieves a value from a nested JSON structure using dot notation
template< typename T >
T get_nested( const std::string & path ) const
T get_nested( const std::string & path, const T & def ) const
{
std::istringstream ss( path );
std::string token;
Expand All @@ -99,11 +99,17 @@ namespace rs2
{
if( ! current->contains( token ) )
{
return config_value( "" );
return def;
}
current = &( *current )[token]; // getting to the next level in the JSON structure
}
return current->get< T >();

T ret_value;
if (!current->get_ex<T>(ret_value))
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
{
return def;
}
return ret_value;
}

// Sets a value in a nested JSON structure using dot notation
Expand Down Expand Up @@ -159,7 +165,7 @@ namespace rs2
current = &( *current )[key];
}

// If it doesn't exist, set the default value in both JSON and defaults map
// If it doesn't exist, set the default value in JSON
if( ! exists )
{
current = &_j;
Expand All @@ -172,18 +178,8 @@ namespace rs2
current = &( *current )[keys[i]];
}
( *current )[keys.back()] = default_val;
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved

std::stringstream val_ss;
val_ss << default_val;
_defaults[path] = val_ss.str();
save();
OhadMeir marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
std::stringstream val_ss;
val_ss << ( *current );
_defaults[path] = val_ss.str();
}
}

private:
Expand Down
9 changes: 7 additions & 2 deletions common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,9 @@ namespace rs2
ImGui::PushStyleColor(ImGuiCol_Text, white);
ImGui::PushStyleColor(ImGuiCol_PopupBg, dark_window_background);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5));
ImVec2 child_size = ImVec2(0, ImGui::GetContentRegionAvail().y-50);
if (ImGui::BeginChild("ScrollableRegion", child_size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar))
{
if (tab == 0)
{
int recording_setting = temp_cfg.get(configurations::record::file_save_mode);
Expand Down Expand Up @@ -2811,8 +2814,8 @@ namespace rs2
}

ImGui::Separator();
bool enable_dds = temp_cfg.get_nested<bool>("context.dds.enabled");
int domain_id = temp_cfg.get_nested<int>("context.dds.domain");
bool enable_dds = temp_cfg.get_nested<bool>("context.dds.enabled" , false);
int domain_id = temp_cfg.get_nested<int>("context.dds.domain" , 0);
if( ImGui::Checkbox( "Enable DDS", &enable_dds ) )
{
temp_cfg.set_nested("context.dds.enabled", enable_dds);
Expand Down Expand Up @@ -2897,6 +2900,8 @@ namespace rs2
}
#endif
}
ImGui::EndChild();
}

ImGui::Separator();

Expand Down
Loading