Skip to content

Commit

Permalink
update examples & tools
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel committed Aug 14, 2024
1 parent d0ed75b commit 085b009
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 82 deletions.
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ else()
endif()
endif()

# We need tclap for command-line interface
list(APPEND DEPENDENCIES tclap)

add_subdirectory(hello-realsense)
add_subdirectory(software-device)
add_subdirectory(capture)
Expand Down
4 changes: 4 additions & 0 deletions examples/align-advanced/rs-align-advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <librealsense2/rs.hpp>
#include "example-imgui.hpp"
#include <common/cli.h>

#include <sstream>
#include <iostream>
Expand All @@ -18,6 +19,9 @@ bool profile_changed(const std::vector<rs2::stream_profile>& current, const std:

int main(int argc, char * argv[]) try
{
rs2::cli( "rs-aligned-advanced example" )
.parse( argc, argv );

// Create and initialize GUI related objects
window app(1280, 720, "RealSense Align (Advanced) Example"); // Simple window handling
ImGui_ImplGlfw_Init(app, false); // ImGui library intializition
Expand Down
6 changes: 5 additions & 1 deletion examples/align/rs-align.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.
// Copyright(c) 2019-24 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp>
#include "example-imgui.hpp"
#include <common/cli.h>

/*
This example introduces the concept of spatial stream alignment.
Expand Down Expand Up @@ -33,6 +34,9 @@ void render_slider(rect location, float* alpha, direction* dir);

int main(int argc, char * argv[]) try
{
rs2::cli( "rs-align example" )
.parse( argc, argv );

std::string serial;
if (!device_with_streams({ RS2_STREAM_COLOR,RS2_STREAM_DEPTH }, serial))
return EXIT_SUCCESS;
Expand Down
13 changes: 9 additions & 4 deletions examples/hello-realsense/rs-hello-realsense.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.
// Copyright(c) 2019-24 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
#include <iostream> // for cout
#include <librealsense2/rs.hpp> // RealSense Cross Platform API
#include <iostream>

#include <common/cli.h>

// Hello RealSense example demonstrates the basics of connecting to a RealSense device
// and taking advantage of depth data
int main(int argc, char * argv[]) try
{
auto settings = rs2::cli( "hello-realsense example" )
.process( argc, argv );

// Create a Pipeline - this serves as a top-level API for streaming and processing frames
rs2::pipeline p;
rs2::pipeline p( settings.dump() );

// Configure and start the pipeline
p.start();
Expand Down
118 changes: 41 additions & 77 deletions tools/dds/dds-config/rs-dds-config.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2024 Intel Corporation. All Rights Reserved.

#include <librealsense2/rs.hpp>

#include "eth-config.h"

#include <tclap/CmdLine.h>
#include <tclap/ValueArg.h>
#include <common/cli.h>

#include <rsutils/os/special-folder.h>
#include <rsutils/json.h>
Expand All @@ -18,25 +15,12 @@
#include <thread>
#include <set>

using namespace TCLAP;
using rsutils::json;
using rsutils::type::ip_address;


static json load_settings( json const & local_settings )
{
// Load the realsense configuration file settings
std::string 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 );

// Take just the 'context' part
config = rsutils::json_config::load_settings( config, "context", "config-file" );
#include <librealsense2/rs.hpp>

// Patch the given local settings into the configuration
config.override( local_settings, "local settings" );

return config;
}
using cli = rs2::cli_no_dds;
using rsutils::json;
using rsutils::type::ip_address;


uint32_t const GET_ETH_CONFIG = 0xBB;
Expand Down Expand Up @@ -125,7 +109,7 @@ eth_config get_eth_config( rs2::debug_protocol hwm, bool golden )
bool find_device( rs2::context const & ctx,
rs2::device & device,
eth_config & config,
ValueArg< std::string > & sn_arg,
rs2::cli::value< std::string > & sn_arg,
bool const golden,
std::set< std::string > & devices_looked_at )
{
Expand Down Expand Up @@ -159,66 +143,46 @@ bool find_device( rs2::context const & ctx,
int main( int argc, char * argv[] )
try
{
CmdLine cmd( "librealsense rs-dds-config tool", ' ', RS2_API_FULL_VERSION_STR );
SwitchArg debug_arg( "", "debug", "Enable debug (-D-) output; by default only errors (-E-) are shown" );
SwitchArg quiet_arg( "", "quiet", "Suppress regular informational (-I-) messages" );
SwitchArg reset_arg( "", "reset", "Hardware reset without making any changes" );
SwitchArg no_reset_arg( "", "no-reset", "Do not hardware reset after changes are made" );
SwitchArg golden_arg( "", "golden", "Show R/O golden values vs. current; mutually exclusive with any changes" );
SwitchArg factory_reset_arg( "", "factory-reset", "Reset settings back to the --golden values" );
ValueArg< std::string > sn_arg( "", "serial-number",
"Device serial-number to use, if more than one device is available",
false, "", "S/N" );
ValueArg< std::string > ip_arg( "", "ip",
"Device static IP address to use when DHCP is off",
false, "", "1.2.3.4" );
ValueArg< std::string > mask_arg( "", "mask",
"Device static IP network mask to use when DHCP is off",
false, "", "1.2.3.4" );
ValueArg< std::string > gateway_arg( "", "gateway",
"Device static IP network mask to use when DHCP is off",
false, "", "1.2.3.4" );
ValueArg< std::string > dhcp_arg( "", "dhcp",
"DHCP dynamic IP discovery 'on' or 'off'",
false, "on", "on/off" );
ValueArg< uint32_t > dhcp_timeout_arg( "", "dhcp-timeout",
"Seconds before DHCP times out and falls back to a static IP",
false, 30, "seconds" );
ValueArg< uint32_t > link_timeout_arg( "", "link-timeout",
"Milliseconds before --eth-first link times out and falls back to USB",
false, 4000, "milliseconds" );
ValueArg< int > domain_id_arg( "", "domain-id", "DDS Domain ID to use (default is 0)", false, 0, "0-232" );
SwitchArg usb_first_arg( "", "usb-first", "Prioritize USB before Ethernet" );
SwitchArg eth_first_arg( "", "eth-first", "Prioritize Ethernet and fall back to USB after link timeout" );
SwitchArg dynamic_priority_arg( "", "dynamic-priority", "Dynamically prioritize the last-working connection method (the default)" );

// In reverse order to how they will be listed
cmd.add( no_reset_arg );
cmd.add( domain_id_arg );
cmd.add( gateway_arg );
cmd.add( mask_arg );
cmd.add( ip_arg );
cmd.add( dhcp_timeout_arg );
cmd.add( dhcp_arg );
cmd.add( link_timeout_arg );
cmd.add( dynamic_priority_arg );
cmd.add( eth_first_arg );
cmd.add( usb_first_arg );
cmd.add( factory_reset_arg );
cmd.add( golden_arg );
cmd.add( reset_arg );
cmd.add( sn_arg );
cmd.add( quiet_arg );
cmd.add( debug_arg );
cmd.parse( argc, argv );
cli::flag quiet_arg( "quiet", "Suppress regular informational (-I-) messages" );
cli::flag reset_arg( "reset", "Hardware reset without making any changes" );
cli::flag no_reset_arg( "no-reset", "Do not hardware reset after changes are made" );
cli::flag golden_arg( "golden", "Show R/O golden values vs. current; mutually exclusive with any changes" );
cli::flag factory_reset_arg( "factory-reset", "Reset settings back to the --golden values" );
cli::value< std::string > sn_arg( "serial-number", "S/N", "", "Device serial-number to use, if more than one device is available" );
cli::value< std::string > ip_arg( "ip", "address", "", "Device static IP address to use when DHCP is off" );
cli::value< std::string > mask_arg( "mask", "1.2.3.4", "", "Device static IP network mask to use when DHCP is off" );
cli::value< std::string > gateway_arg( "gateway", "1.2.3.4", "", "Device static IP network mask to use when DHCP is off" );
cli::value< std::string > dhcp_arg( "dhcp", "on/off", "on", "DHCP dynamic IP discovery 'on' or 'off'" );
cli::value< uint32_t > dhcp_timeout_arg( "dhcp-timeout", "seconds", 30, "Seconds before DHCP times out and falls back to a static IP" );
cli::value< uint32_t > link_timeout_arg( "link-timeout", "milliseconds", 4000, "Milliseconds before --eth-first link times out and falls back to USB" );
cli::value< int > domain_id_arg( "domain-id", "0-232", 0, "DDS Domain ID to use (default is 0)" );
cli::flag usb_first_arg( "usb-first", "Prioritize USB before Ethernet" );
cli::flag eth_first_arg( "eth-first", "Prioritize Ethernet and fall back to USB after link timeout" );
cli::flag dynamic_priority_arg( "dynamic-priority", "Dynamically prioritize the last-working connection method (the default)" );

json settings = cli( "librealsense rs-dds-config tool" )
.arg( quiet_arg )
.arg( sn_arg )
.arg( reset_arg )
.arg( golden_arg )
.arg( factory_reset_arg )
.arg( usb_first_arg )
.arg( eth_first_arg )
.arg( dynamic_priority_arg )
.arg( link_timeout_arg )
.arg( dhcp_arg )
.arg( dhcp_timeout_arg )
.arg( ip_arg )
.arg( mask_arg )
.arg( gateway_arg )
.arg( domain_id_arg )
.arg( no_reset_arg )
.process( argc, argv );

g_quiet = quiet_arg.isSet();
bool const golden = golden_arg.isSet();

rs2::log_to_console( debug_arg.isSet() ? RS2_LOG_SEVERITY_DEBUG : RS2_LOG_SEVERITY_ERROR );

// Create a RealSense context and look for a device
json settings = load_settings( json::object() );
rs2::context ctx( settings.dump() );

rs2::device device;
Expand Down

0 comments on commit 085b009

Please sign in to comment.