Skip to content

Commit

Permalink
dds config tool repair
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Jan 14, 2025
1 parent 3aebaf9 commit 97b51f5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
27 changes: 19 additions & 8 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,12 @@ using namespace rs2;
using rsutils::json;
using rsutils::type::ip_address;

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

int const ACTUAL_VALUES = 0;
int const DEFULT_VALUES = 1;

dds_model::dds_model( rs2::device dev )
: _device( dev )
, _window_open( false )
Expand All @@ -24,16 +33,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( ACTUAL_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 ? 0 : 1 );
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 +79,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 Down Expand Up @@ -114,6 +124,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 +137,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( ACTUAL_VALUES );
_changed_config = _current_config;
ImGui::OpenPopup( window_name );
}
Expand Down Expand Up @@ -210,7 +221,7 @@ 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 +269,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
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>
#include <rsutils/json.h>
#include <rsutils/json-config.h>

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

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

enum priority {
ETH_FIRST,
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
16 changes: 11 additions & 5 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 char* path, const T & def ) const
{
std::istringstream ss( path );
std::string token;
Expand All @@ -99,16 +99,22 @@ 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))
{
return def;
}
return ret_value;
}

// Sets a value in a nested JSON structure using dot notation
template< typename T >
void set_nested( const std::string & path, const T & val )
void set_nested( const char* path, const T & val )
{
std::vector< std::string > keys;
std::istringstream ss( path );
Expand All @@ -135,7 +141,7 @@ namespace rs2

// Sets a default value to the config and default map
template< typename T >
void set_nested_default( const std::string & path, const T & default_val )
void set_nested_default(const char* path , const T & default_val )
{
std::vector< std::string > keys;
std::istringstream ss( path );
Expand Down
4 changes: 2 additions & 2 deletions common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2811,8 +2811,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

0 comments on commit 97b51f5

Please sign in to comment.