Skip to content

Commit

Permalink
add dds enable to viewer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Noy-Zini committed Jan 1, 2025
1 parent 6cb2c25 commit b03f190
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 42 deletions.
51 changes: 11 additions & 40 deletions common/dds-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,6 @@ void rs2::dds_model::set_eth_config( eth_config & new_config, std::string & erro
}
}

void rs2::dds_model::enable_dds( std::string & error_message )
{
if( _device.get_type() == "DDS" )
{
auto const filename
= rsutils::os::get_special_folder( rsutils::os::special_folder::app_data ) + RS2_CONFIG_FILENAME;
auto config = rsutils::json_config::load_from_file( filename );

bool enabled;
if( ! config.nested( "context", "dds", "enabled" ).get_ex( enabled ) )
{
config["context"]["dds"]["enabled"] = true;
try
{
std::ofstream out( filename );
out << std::setw( 2 ) << config;
out.close();
}
catch( std::exception const & e )
{
error_message = e.what();
close_window();
}
}
}
}

bool rs2::dds_model::supports_DDS()
{
return _dds_supported;
Expand Down Expand Up @@ -199,11 +172,8 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
ImGui::Separator();
ImGui::SetCursorPosY( ImGui::GetCursorPosY() + 15 );

// Version Display
ImGui::Text( "Version: %s", RS2_API_FULL_VERSION_STR );

// Main Scrollable Section
ImGui::BeginChild( "MainContent", ImVec2( w - 10, h - 120 ), true );
ImGui::BeginChild( "MainContent", ImVec2( w - 10, h - 100 ), true );
ImGui::PushItemWidth( 150.0f );

// Connection Priority Section
Expand Down Expand Up @@ -261,12 +231,15 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
ImGui::SetCursorPosX( textbox_align );
ipInputText( "Gateway", _changed_config.configured.gateway );
}
ImGui::Text( "DHCP Timeout (seconds)" );
ImGui::SameLine();
int tempTimeout = static_cast< int >( _changed_config.dhcp.timeout );
if( ImGui::InputInt( "##DHCP Timeout (seconds)", &tempTimeout ) )
else
{
_changed_config.dhcp.timeout = static_cast< uint16_t >( std::max( 0, tempTimeout ) );
ImGui::Text( "DHCP Timeout (seconds)" );
ImGui::SameLine();
int tempTimeout = static_cast< int >( _changed_config.dhcp.timeout );
if( ImGui::InputInt( "##DHCP Timeout (seconds)", &tempTimeout ) )
{
_changed_config.dhcp.timeout = static_cast< uint16_t >( std::max( 0, tempTimeout ) );
}
}
}

Expand All @@ -281,7 +254,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( "Set to defult values", &_set_defult ) )
if( ImGui::Checkbox( "Load to defult values", &_set_defult ) )
{
if( _set_defult )
_changed_config = _defult_config;
Expand All @@ -293,7 +266,7 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
ImGui::EndChild();

// window buttons
float button_width = 105.0f;
float button_width = 115.0f;
float spacing = 10.0f;
float total_buttons_width = button_width * 4 + spacing * 2;
float start_x = ( w - total_buttons_width ) / 2.0f;
Expand All @@ -315,7 +288,6 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
ImGui::SameLine();
if( ImGui::Button( "Factory Reset", ImVec2( button_width, 25 ) ) )
{
enable_dds( error_message );
set_eth_config( _defult_config, error_message );
close_window();
}
Expand Down Expand Up @@ -345,7 +317,6 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
{
if( ImGui::ButtonEx( "Apply", ImVec2( button_width, 25 ) ) )
{
enable_dds( error_message );
set_eth_config( _changed_config, error_message );
close_window();
};
Expand Down
2 changes: 0 additions & 2 deletions common/dds-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace rs2

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

void enable_dds(std::string& error_message);

bool supports_DDS();


Expand Down
5 changes: 5 additions & 0 deletions common/device-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ namespace rs2
{
static const char* enable_writing{ "calibration.enable_writing" };
}
namespace dds
{
static const char* enable_dds{ "context.dds.enabled" };
static const char* domain_id{ "context.dds.domain" };
}
namespace viewer
{
static const char* is_3d_view{ "viewer_model.is_3d_view" };
Expand Down
7 changes: 7 additions & 0 deletions common/ux-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ namespace rs2
config_file::instance().set_default(configurations::viewer::log_filename, path + "librealsense.log");
config_file::instance().set_default(configurations::record::default_path, path);

auto const filename
= rsutils::os::get_special_folder( rsutils::os::special_folder::app_data ) + RS2_CONFIG_FILENAME;
auto config = rsutils::json_config::load_from_file( filename );
bool enable_dds = config.nested( "context", "dds", "enabled" ).get_ex( enable_dds );
int domain_id = config.nested("context", "dds", "domain").get_ex(domain_id);
config_file::instance().set_default( configurations::dds::enable_dds, enable_dds );
config_file::instance().set_default( configurations::dds::domain_id, domain_id );
#ifdef __APPLE__

config_file::instance().set_default(configurations::performance::font_oversample, 2);
Expand Down
28 changes: 28 additions & 0 deletions common/viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,34 @@ namespace rs2
catch (...){}
}
}

ImGui::Separator();
bool enable_dds = temp_cfg.get( configurations::dds::enable_dds );
int domain_id = temp_cfg.get( configurations::dds::domain_id );
if( ImGui::Checkbox( "Enable DDS", &enable_dds ) )
{
temp_cfg.set( configurations::dds::enable_dds, enable_dds );
}
if( enable_dds )
{
ImGui::SameLine();
ImGui::SetCursorPosX( ImGui::GetCursorPosX() + 50 );
ImGui::PushItemWidth( 150.0f );
ImGui::Text( "Domain ID" );
ImGui::SameLine();
if( ImGui::InputInt( "##Domain ID", &domain_id ) )
{
if( domain_id < 0 )
domain_id = 0;
else if( domain_id > 232 )
domain_id = 232;
temp_cfg.set( configurations::dds::domain_id, domain_id );
}
}
ImGui::SameLine();
ImGui::SetCursorPosX( w - 700 );
ImGui::Text(u8"\uf071 Changes will take effect only after restarting the application ");

}

if (tab == 3)
Expand Down

0 comments on commit b03f190

Please sign in to comment.