Skip to content

Commit aa3eace

Browse files
authored
PR realsenseai#14154 from OhadMeir: Support Ethernet traffic shaping
2 parents a79d8b8 + 4833ba6 commit aa3eace

6 files changed

Lines changed: 257 additions & 97 deletions

File tree

common/dds-model.cpp

Lines changed: 94 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@ namespace rs2 {
2323
uint32_t const GET_ETH_CONFIG = 0xBB;
2424
uint32_t const SET_ETH_CONFIG = 0xBA;
2525

26-
int const CURRENT_VALUES = 0;
27-
int const DEFULT_VALUES = 1;
26+
int const CURRENT_VALUES = 1;
27+
int const DEFAULT_VALUES = 0;
2828
}
2929

3030
dds_model::dds_model( rs2::device dev )
3131
: _device( dev )
3232
, _window_open( false )
3333
, _no_reset( false )
34-
, _set_defult( false )
3534
, _dds_supported( false )
3635
{
3736
if( check_DDS_support() )
3837
{
39-
_defult_config = get_eth_config( DEFULT_VALUES );
38+
_default_config = get_eth_config( DEFAULT_VALUES );
4039
_current_config = get_eth_config( CURRENT_VALUES );
4140
_changed_config = _current_config;
4241
_dds_supported = true;
@@ -55,25 +54,33 @@ eth_config dds_model::get_eth_config( int curr_or_default )
5554

5655
void rs2::dds_model::set_eth_config( eth_config & new_config, std::string & error_message )
5756
{
58-
rs2::debug_protocol hwm( _device );
59-
auto cmd = hwm.build_command( SET_ETH_CONFIG, 0, 0, 0, 0, new_config.build_command() );
60-
auto data = hwm.send_and_receive_raw_data( cmd );
61-
int32_t const & code = *reinterpret_cast< int32_t const * >( data.data() );
62-
if( data.size() != sizeof( code ) )
57+
try
6358
{
64-
error_message = rsutils::string::from() << "Failed to change: bad response size " << data.size() << ' '
65-
<< rsutils::string::hexdump( data.data(), data.size() );
66-
close_window();
67-
}
68-
if( code != SET_ETH_CONFIG )
69-
{
70-
error_message = rsutils::string::from() << "Failed to change: bad response " << code;
71-
close_window();
59+
rs2::debug_protocol hwm( _device );
60+
auto cmd = hwm.build_command( SET_ETH_CONFIG, 0, 0, 0, 0, new_config.build_command() );
61+
auto data = hwm.send_and_receive_raw_data( cmd );
62+
int32_t const & code = *reinterpret_cast< int32_t const * >( data.data() );
63+
if( data.size() != sizeof( code ) )
64+
{
65+
error_message = rsutils::string::from() << "Failed to change: bad response size " << data.size() << ' '
66+
<< rsutils::string::hexdump( data.data(), data.size() );
67+
close_window();
68+
}
69+
if( code != SET_ETH_CONFIG )
70+
{
71+
error_message = rsutils::string::from() << "Failed to change: bad response " << code;
72+
close_window();
73+
}
74+
if( ! _no_reset )
75+
{
76+
close_window();
77+
_device.hardware_reset();
78+
}
7279
}
73-
if( ! _no_reset )
80+
catch( const std::exception & e )
7481
{
82+
error_message = rsutils::string::from() << "Failed to set Ethernet configuration: " << e.what();
7583
close_window();
76-
_device.hardware_reset();
7784
}
7885
}
7986

@@ -203,14 +210,29 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
203210
ImGui::Separator();
204211
ImGui::SetCursorPosY( ImGui::GetCursorPosY() + 15 );
205212

213+
// Window button sizes
214+
float button_width = 115.0f;
215+
float spacing = 10.0f;
216+
float total_buttons_width = button_width * 3 + spacing * 2;
217+
float start_x = ( w - total_buttons_width ) / 2.0f;
218+
206219
// Main Scrollable Section
207220
ImGui::BeginChild( "MainContent", ImVec2( w - 10, h - 100 ), true );
208221
ImGui::PushItemWidth( 150.0f );
209222

210-
// Connection Priority Section
211-
priority connection_priority = classifyPriority( _changed_config.link.priority );
223+
ImGui::Text( "Domain ID" );
224+
ImGui::SameLine();
225+
if( ImGui::InputInt( "##Domain ID", &_changed_config.dds.domain_id ) )
226+
{
227+
if( _changed_config.dds.domain_id < 0 )
228+
_changed_config.dds.domain_id = 0;
229+
else if( _changed_config.dds.domain_id > 232 )
230+
_changed_config.dds.domain_id = 232;
231+
}
232+
212233
if( ImGui::CollapsingHeader( "Connection Priority" ) )
213234
{
235+
priority connection_priority = classifyPriority( _changed_config.link.priority );
214236
ImGui::Text( "Select connection priority:" );
215237
ImGui::RadioButton( "Ethernet First", reinterpret_cast< int * >( &connection_priority ), 0 );
216238
if( static_cast< int >( connection_priority ) == 0 )
@@ -227,6 +249,11 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
227249
}
228250
ImGui::RadioButton( "USB First", reinterpret_cast< int * >( &connection_priority ), 1 );
229251
ImGui::RadioButton( "Dynamic Priority", reinterpret_cast< int * >( &connection_priority ), 2 );
252+
if( ImGui::IsItemHovered() )
253+
{
254+
window.link_hovered();
255+
RsImGui::CustomTooltip( "%s", "Try connection type from last power up, switch if changed" );
256+
}
230257
switch( connection_priority )
231258
{
232259
case ETH_FIRST:
@@ -244,7 +271,6 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
244271
}
245272
}
246273

247-
// Network Configuration Section
248274
if( ImGui::CollapsingHeader( "Network Configuration" ) )
249275
{
250276
ImGui::Checkbox( "Enable DHCP", &_changed_config.dhcp.on );
@@ -266,43 +292,68 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
266292
}
267293
else
268294
{
269-
ImGui::Text( "DHCP Timeout (seconds)" );
295+
ImGui::Text( "DHCP Timeout [seconds]" );
270296
ImGui::SameLine();
271297
int tempTimeout = static_cast< int >( _changed_config.dhcp.timeout );
272-
if( ImGui::InputInt( "##DHCP Timeout (seconds)", &tempTimeout ) )
298+
if( ImGui::InputInt( "##DHCP Timeout", &tempTimeout ) )
273299
{
274300
_changed_config.dhcp.timeout = static_cast< uint16_t >( std::max( 0, tempTimeout ) );
275301
}
276302
}
277303
}
278304

279-
ImGui::Text( "Domain ID" );
280-
ImGui::SameLine();
281-
if( ImGui::InputInt( "##Domain ID", &_changed_config.dds.domain_id ) )
305+
if( ImGui::CollapsingHeader( "Traffic Shaping" ) )
282306
{
283-
if( _changed_config.dds.domain_id < 0 )
284-
_changed_config.dds.domain_id = 0;
285-
else if( _changed_config.dds.domain_id > 232 )
286-
_changed_config.dds.domain_id = 232;
307+
ImGui::Text( "MTU [bytes]" );
308+
ImGui::SameLine();
309+
int temp_mtu = static_cast< int >( _changed_config.link.mtu );
310+
if( ImGui::InputInt( "##MTU", &temp_mtu, 500 ) )
311+
{
312+
if( temp_mtu < 500 )
313+
temp_mtu = 500;
314+
else if( temp_mtu > 9000 )
315+
temp_mtu = 9000;
316+
_changed_config.link.mtu = static_cast< uint32_t >( temp_mtu );
317+
}
318+
319+
ImGui::Text( "Transmission Delay [us]" );
320+
ImGui::SameLine();
321+
int temp_delay = static_cast< int >( _changed_config.transmission_delay );
322+
if( ImGui::InputInt( "##Transmission Delay", &temp_delay, 3 ) )
323+
{
324+
if( temp_delay < 0 )
325+
temp_delay = 0;
326+
else if( temp_delay > 144 )
327+
temp_delay = 144;
328+
_changed_config.transmission_delay = static_cast< uint32_t >( temp_delay );
329+
}
287330
}
331+
332+
ImGui::Separator();
288333
ImGui::Checkbox( "No Reset after changes", &_no_reset );
289-
290-
if( ImGui::Checkbox( "Load defult values", &_set_defult ) )
334+
if( ImGui::Button( "Default values" ) )
291335
{
292-
if( _set_defult )
293-
_changed_config = _defult_config;
294-
else
295-
_changed_config = _current_config;
336+
_changed_config = _default_config;
337+
}
338+
if( ImGui::IsItemHovered() )
339+
{
340+
window.link_hovered();
341+
RsImGui::CustomTooltip( "%s", "Use default configuration values" );
342+
}
343+
ImGui::SameLine();
344+
if( ImGui::Button( "Revert changes" ) )
345+
{
346+
_changed_config = _current_config;
347+
}
348+
if( ImGui::IsItemHovered() )
349+
{
350+
window.link_hovered();
351+
RsImGui::CustomTooltip( "%s", "Revert to current configuration values" );
296352
}
297353

298354
ImGui::PopItemWidth();
299355
ImGui::EndChild();
300356

301-
// window buttons
302-
float button_width = 115.0f;
303-
float spacing = 10.0f;
304-
float total_buttons_width = button_width * 4 + spacing * 2;
305-
float start_x = ( w - total_buttons_width ) / 2.0f;
306357
bool hasChanges = ( _changed_config != _current_config );
307358

308359
ImGui::SetCursorPosY( ImGui::GetCursorPosY() + 8 );
@@ -321,7 +372,7 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
321372
ImGui::SameLine();
322373
if( ImGui::Button( "Factory Reset", ImVec2( button_width, 25 ) ) )
323374
{
324-
set_eth_config( _defult_config, error_message );
375+
set_eth_config( _default_config, error_message );
325376
close_window();
326377
}
327378
if( ImGui::IsItemHovered() )
@@ -330,21 +381,6 @@ void dds_model::render_dds_config_window( ux_window & window, std::string & erro
330381
RsImGui::CustomTooltip( "%s", "Reset settings back to defult values" );
331382
}
332383
ImGui::SameLine();
333-
RsImGui::RsImButton(
334-
[&]()
335-
{
336-
if( ImGui::ButtonEx( "Revert changes", ImVec2( button_width, 25 ) ) )
337-
{
338-
_changed_config = _current_config;
339-
};
340-
},
341-
! hasChanges );
342-
if( ImGui::IsItemHovered() )
343-
{
344-
window.link_hovered();
345-
RsImGui::CustomTooltip( "%s", "Revert to current configuration values" );
346-
}
347-
ImGui::SameLine();
348384
RsImGui::RsImButton(
349385
[&]()
350386
{

common/dds-model.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ namespace rs2
3939

4040
rs2::device _device;
4141

42-
eth_config _defult_config;
42+
eth_config _default_config;
4343
eth_config _current_config;
4444
eth_config _changed_config;
4545

4646
bool _window_open;
4747
bool _no_reset;
48-
bool _set_defult;
4948
bool _dds_supported;
5049

5150
void ipInputText(std::string label, rsutils::type::ip_address &ip);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// License: Apache 2.0. See LICENSE file in root directory.
2+
// Copyright(c) 2025 Intel Corporation. All Rights Reserved.
3+
#pragma once
4+
5+
#include "eth-config-header.h"
6+
7+
8+
#pragma pack( push, 1 )
9+
10+
// The structure data for eth config info, version 4
11+
// See table definition in HWMC v0.54 spec
12+
// Changes from v3 - 2 reserved bytes defined as transmission_delay, 40 reserved bytes added.
13+
struct eth_config_v4
14+
{
15+
eth_config_header header;
16+
uint32_t link_check_timeout; // The threshold to wait eth link(ms).
17+
uint8_t config_ip[4]; // static IP
18+
uint8_t config_netmask[4]; // static netmask
19+
uint8_t config_gateway[4]; // static gateway
20+
uint8_t actual_ip[4]; // actual IP when dhcp is ON, read-only
21+
uint8_t actual_netmask[4]; // actual netmask when dhcp is ON, read-only
22+
uint8_t actual_gateway[4]; // actual gateway when dhcp is ON, read-only
23+
uint32_t link_speed; // Mbps read-only
24+
uint32_t mtu; // read-only
25+
uint8_t dhcp_on; // 0=off
26+
uint8_t dhcp_timeout; // The threshold to wait valid ip when DHCP is on(s).
27+
uint8_t domain_id; // dds domain id
28+
uint8_t link_priority; // device link priority. 0-USB_ONLY, 1-ETH_ONLY, 2-ETH_FIRST, 3 USB_FIRST
29+
uint8_t mac_address[6]; // read-only
30+
uint16_t transmission_delay; // Inter-MTU transmission delay, microseconds.
31+
uint8_t reserved[40]; // For future growth, struct size should be multiplication of 4.
32+
};
33+
34+
#pragma pack( pop )
35+
36+
37+
static_assert( sizeof( eth_config_v4 ) % 4 == 0, "eth config v4 struct size must be divisible by 4" );
38+

0 commit comments

Comments
 (0)