From 085b0097901775c7a3dabfd41b610eb01a37c5d8 Mon Sep 17 00:00:00 2001 From: Eran Date: Tue, 13 Aug 2024 13:30:37 +0300 Subject: [PATCH] update examples & tools --- examples/CMakeLists.txt | 3 + examples/align-advanced/rs-align-advanced.cpp | 4 + examples/align/rs-align.cpp | 6 +- .../hello-realsense/rs-hello-realsense.cpp | 13 +- tools/dds/dds-config/rs-dds-config.cpp | 118 ++++++------------ 5 files changed, 62 insertions(+), 82 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 083e15493cf..d999896b284 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) diff --git a/examples/align-advanced/rs-align-advanced.cpp b/examples/align-advanced/rs-align-advanced.cpp index ee094444747..ec8eaf06393 100644 --- a/examples/align-advanced/rs-align-advanced.cpp +++ b/examples/align-advanced/rs-align-advanced.cpp @@ -3,6 +3,7 @@ #include #include "example-imgui.hpp" +#include #include #include @@ -18,6 +19,9 @@ bool profile_changed(const std::vector& 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 diff --git a/examples/align/rs-align.cpp b/examples/align/rs-align.cpp index dc3a3763979..0f5ec6cdf4b 100644 --- a/examples/align/rs-align.cpp +++ b/examples/align/rs-align.cpp @@ -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 #include "example-imgui.hpp" +#include /* This example introduces the concept of spatial stream alignment. @@ -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; diff --git a/examples/hello-realsense/rs-hello-realsense.cpp b/examples/hello-realsense/rs-hello-realsense.cpp index 46be1804f4b..07fed49c996 100644 --- a/examples/hello-realsense/rs-hello-realsense.cpp +++ b/examples/hello-realsense/rs-hello-realsense.cpp @@ -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 // Include RealSense Cross Platform API -#include // for cout +#include // RealSense Cross Platform API +#include + +#include // 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(); diff --git a/tools/dds/dds-config/rs-dds-config.cpp b/tools/dds/dds-config/rs-dds-config.cpp index 2b5959eccef..ad65d28d64d 100644 --- a/tools/dds/dds-config/rs-dds-config.cpp +++ b/tools/dds/dds-config/rs-dds-config.cpp @@ -1,12 +1,9 @@ // License: Apache 2.0. See LICENSE file in root directory. // Copyright(c) 2024 Intel Corporation. All Rights Reserved. -#include - #include "eth-config.h" -#include -#include +#include #include #include @@ -18,25 +15,12 @@ #include #include -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 - // 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; @@ -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 ) { @@ -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;