diff --git a/ChangeLog.md b/ChangeLog.md index 39d9284f..8a5bade8 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Add new subcommands `app` and `device` under import and export subcommands - The documentation about the different available `buffer_id` has been updated to provide the complete list for each compatible device. - add `O3R_ODS_RENDERED_ZONES` `buffer_id` - Add `ovp8xx`,`o3x1xx` and `o3d3xx` and `discover` commands as a primary level subcommands to ifm3d command line interface diff --git a/modules/tools/include/ifm3d/tools.h b/modules/tools/include/ifm3d/tools.h index 34080402..b1e97672 100644 --- a/modules/tools/include/ifm3d/tools.h +++ b/modules/tools/include/ifm3d/tools.h @@ -15,12 +15,16 @@ #include #include #include +#include +#include #include #include #include #include #include #include +#include +#include #include #include #include diff --git a/modules/tools/include/ifm3d/tools/legacy/export_app.h b/modules/tools/include/ifm3d/tools/legacy/export_app.h index 03620122..a92d59aa 100644 --- a/modules/tools/include/ifm3d/tools/legacy/export_app.h +++ b/modules/tools/include/ifm3d/tools/legacy/export_app.h @@ -29,9 +29,6 @@ namespace ifm3d virtual void Execute(CLI::App* app) override; virtual CLI::App* CreateCommand(CLI::App* parent) override; - std::string output_file{"-"}; - int application_index{-1}; - }; // end: class ExportApp } // end: namespace ifm3d diff --git a/modules/tools/include/ifm3d/tools/legacy/export_application_app.h b/modules/tools/include/ifm3d/tools/legacy/export_application_app.h new file mode 100644 index 00000000..ed78eeca --- /dev/null +++ b/modules/tools/include/ifm3d/tools/legacy/export_application_app.h @@ -0,0 +1,35 @@ +// -*- c++ -*- +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef IFM3D_TOOLS_EXPORT_APPLICATION_APP_H +#define IFM3D_TOOLS_EXPORT_APPLICATION_APP_H + +#include +#include +#include + +namespace ifm3d +{ + /** + * Concrete implementation of the `export app` subcommand to the `ifm3d` + * command-line utility. + */ + class ExportApplicationApp : public Command + { + public: + ~ExportApplicationApp(); + virtual void Execute(CLI::App* app) override; + virtual CLI::App* CreateCommand(CLI::App* parent) override; + + int application_index{0}; + std::string output_file{"-"}; + + }; // end: class ExportApplicationApp + +} // end: namespace ifm3d + +#endif // IFM3D_TOOLS_EXPORT_APPLICATION_APP_H diff --git a/modules/tools/include/ifm3d/tools/legacy/export_device_app.h b/modules/tools/include/ifm3d/tools/legacy/export_device_app.h new file mode 100644 index 00000000..3f9d2554 --- /dev/null +++ b/modules/tools/include/ifm3d/tools/legacy/export_device_app.h @@ -0,0 +1,38 @@ +// -*- c++ -*- +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef IFM3D_TOOLS_EXPORT_DEVICE_APP_H +#define IFM3D_TOOLS_EXPORT_DEVICE_APP_H + +#include +#include +#include + +namespace ifm3d +{ + /** + * Concrete implementation of the `export device` subcommand to the `ifm3d` + * command-line utility. + * + * `export` provides compatibility with Vision Assistant - it can produce + * exported applications/configurations that can be consumed by Vision + * Assistant. + */ + class ExportDeviceApp : public Command + { + public: + ~ExportDeviceApp(); + virtual void Execute(CLI::App* app) override; + virtual CLI::App* CreateCommand(CLI::App* parent) override; + + std::string output_file{"-"}; + + }; // end: class ExportDeviceApp + +} // end: namespace ifm3d + +#endif // IFM3D_TOOLS_EXPORT_DEVICE_APP_H diff --git a/modules/tools/include/ifm3d/tools/legacy/import_app.h b/modules/tools/include/ifm3d/tools/legacy/import_app.h index 57ae4678..db68a38e 100644 --- a/modules/tools/include/ifm3d/tools/legacy/import_app.h +++ b/modules/tools/include/ifm3d/tools/legacy/import_app.h @@ -28,12 +28,6 @@ namespace ifm3d virtual void Execute(CLI::App* app) override; virtual CLI::App* CreateCommand(CLI::App* parent) override; - std::string input_file{"-"}; - CLI::Option* config; - bool global_config{false}; - bool network_config{false}; - bool app_config{false}; - }; // end: class ImportApp } // end: namespace ifm3d diff --git a/modules/tools/include/ifm3d/tools/legacy/import_application_app.h b/modules/tools/include/ifm3d/tools/legacy/import_application_app.h new file mode 100644 index 00000000..906bdc37 --- /dev/null +++ b/modules/tools/include/ifm3d/tools/legacy/import_application_app.h @@ -0,0 +1,33 @@ +// -*- c++ -*- +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef IFM3D_TOOLS_IMPORT_APPLICATION_APP_H +#define IFM3D_TOOLS_IMPORT_APPLICATION_APP_H + +#include +#include +#include + +namespace ifm3d +{ + /** + * Concrete implementation of the `import app` subcommand to the `ifm3d` + * command-line utility. + */ + class ImportApplicationApp : public Command + { + public: + ~ImportApplicationApp(); + virtual void Execute(CLI::App* app) override; + virtual CLI::App* CreateCommand(CLI::App* parent) override; + + std::string input_file{"-"}; + + }; // end: class ImportApplicationApp +} // end: namespace ifm3d + +#endif // IFM3D_TOOLS_IMPORT_APPLICATION_APP_H diff --git a/modules/tools/include/ifm3d/tools/legacy/import_device_app.h b/modules/tools/include/ifm3d/tools/legacy/import_device_app.h new file mode 100644 index 00000000..fbe6ebcb --- /dev/null +++ b/modules/tools/include/ifm3d/tools/legacy/import_device_app.h @@ -0,0 +1,36 @@ +// -*- c++ -*- +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef IFM3D_TOOLS_IMPORT_DEVICE_APP_H +#define IFM3D_TOOLS_IMPORT_DEVICE_APP_H + +#include +#include +#include + +namespace ifm3d +{ + /** + * Concrete implementation of the `import device` subcommand to the `ifm3d` + * command-line utility. + */ + class ImportDeviceApp : public Command + { + public: + ~ImportDeviceApp(); + virtual void Execute(CLI::App* app) override; + virtual CLI::App* CreateCommand(CLI::App* parent) override; + + std::string input_file{"-"}; + bool no_global_config; + bool no_network_config; + bool no_app_config; + + }; // end: class ImportDeviceApp +} // end: namespace ifm3d + +#endif // IFM3D_TOOLS_IMPORT_DEVICE_APP_H diff --git a/modules/tools/src/libifm3d_tools/legacy/export_app.cpp b/modules/tools/src/libifm3d_tools/legacy/export_app.cpp index 950038b5..2b23aac3 100644 --- a/modules/tools/src/libifm3d_tools/legacy/export_app.cpp +++ b/modules/tools/src/libifm3d_tools/legacy/export_app.cpp @@ -5,44 +5,12 @@ */ #include -#include -#include -#include -#include -#include -#include ifm3d::ExportApp::~ExportApp() {} void ifm3d::ExportApp::Execute(CLI::App* app) -{ - auto device = Parent()->GetDevice(); - - std::vector bytes; - - if (this->application_index <= 0) - { - bytes = std::static_pointer_cast(device) - ->ExportIFMConfig(); - } - else - { - bytes = - std::static_pointer_cast(device)->ExportIFMApp( - this->application_index); - } - - if (this->output_file == "-") - { - std::cout.write(reinterpret_cast(bytes.data()), bytes.size()); - } - else - { - std::ofstream(this->output_file, std::ios::binary) - .write(reinterpret_cast(bytes.data()), bytes.size()); - } -} +{} CLI::App* ifm3d::ExportApp::CreateCommand(CLI::App* parent) @@ -53,21 +21,10 @@ ifm3d::ExportApp::CreateCommand(CLI::App* parent) "Export an application or whole " "sensor configuration into a format compatible with " "ifm Vision Assistant.") - ->require_subcommand(0, 0); - - command - ->add_option( - "--file", - this->output_file, - "Output file, defaults to `stdout' (good for piping to other tools)") - ->default_val("-"); + ->require_subcommand(1); - command - ->add_option( - "--index", - this->application_index, - "If provided, this specifies the index of an application to export") - ->default_val(-1); + RegisterSubcommand(command); + RegisterSubcommand(command); return command; } diff --git a/modules/tools/src/libifm3d_tools/legacy/export_application_app.cpp b/modules/tools/src/libifm3d_tools/legacy/export_application_app.cpp new file mode 100644 index 00000000..47174815 --- /dev/null +++ b/modules/tools/src/libifm3d_tools/legacy/export_application_app.cpp @@ -0,0 +1,75 @@ +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +ifm3d::ExportApplicationApp::~ExportApplicationApp() {} + +void +ifm3d::ExportApplicationApp::Execute(CLI::App* app) +{ + auto device = Parent()->GetDevice(); + + std::vector bytes; + + if (Parent()) + { + bytes = + std::static_pointer_cast(device)->ExportIFMApp( + this->application_index); + } + else + { + bytes = + std::static_pointer_cast(device)->ExportIFMApp(1); + } + + if (this->output_file == "-") + { + std::cout.write(reinterpret_cast(bytes.data()), bytes.size()); + } + else + { + std::ofstream(this->output_file, std::ios::binary) + .write(reinterpret_cast(bytes.data()), bytes.size()); + } +} + +CLI::App* +ifm3d::ExportApplicationApp::CreateCommand(CLI::App* parent) +{ + CLI::App* command = + parent + ->add_subcommand("app", + "Export an application that is compatible with ifm " + "Vision Assistant's export format (*.o3d3xxapp).") + ->require_subcommand(0, 0); + + if (Parent()) + { + command + ->add_option("--index", + this->application_index, + "The index of an application to export") + ->default_val(0) + ->required(); + } + + command + ->add_option( + "--file", + this->output_file, + "Output file, defaults to `stdout' (good for piping to other tools)") + ->default_val("-"); + + return command; +} diff --git a/modules/tools/src/libifm3d_tools/legacy/export_device_app.cpp b/modules/tools/src/libifm3d_tools/legacy/export_device_app.cpp new file mode 100644 index 00000000..b44482a0 --- /dev/null +++ b/modules/tools/src/libifm3d_tools/legacy/export_device_app.cpp @@ -0,0 +1,56 @@ +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include + +ifm3d::ExportDeviceApp::~ExportDeviceApp() {} + +void +ifm3d::ExportDeviceApp::Execute(CLI::App* app) +{ + auto device = Parent()->GetDevice(); + + std::vector bytes; + + bytes = + std::static_pointer_cast(device)->ExportIFMConfig(); + + if (this->output_file == "-") + { + std::cout.write(reinterpret_cast(bytes.data()), bytes.size()); + } + else + { + std::ofstream(this->output_file, std::ios::binary) + .write(reinterpret_cast(bytes.data()), bytes.size()); + } +} + +CLI::App* +ifm3d::ExportDeviceApp::CreateCommand(CLI::App* parent) +{ + CLI::App* command = + parent + ->add_subcommand("device", + "Export a device configuration that is compatible with " + "ifm Vision Assistant's export format. (*.o3d3xxcfg)") + ->require_subcommand(0, 0); + + command + ->add_option( + "--file", + this->output_file, + "Output file, defaults to `stdout' (good for piping to other tools)") + ->default_val("-"); + + return command; +} diff --git a/modules/tools/src/libifm3d_tools/legacy/import_app.cpp b/modules/tools/src/libifm3d_tools/legacy/import_app.cpp index 002f76fd..88ea760a 100644 --- a/modules/tools/src/libifm3d_tools/legacy/import_app.cpp +++ b/modules/tools/src/libifm3d_tools/legacy/import_app.cpp @@ -5,98 +5,12 @@ */ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include ifm3d::ImportApp::~ImportApp() {} void ifm3d::ImportApp::Execute(CLI::App* app) -{ - auto device = Parent()->GetDevice(); - - std::shared_ptr ifs; - std::vector bytes; - - if (this->input_file == "-") - { - if (ifm3d::IsStdinAvailable()) - { - ifs.reset(&std::cin, [](...) {}); - - char b; - while (ifs->get(b)) - { - bytes.push_back(*(reinterpret_cast(&b))); - } - } - else - { - throw ifm3d::Error(IFM3D_NO_INPUT_PROVIDED); - } - } - else - { - ifs.reset( - new std::ifstream(this->input_file, std::ios::in | std::ios::binary)); - if (!*ifs) - { - std::cerr << "Could not open file: " << this->input_file - << std::endl; - throw ifm3d::Error(IFM3D_IO_ERROR); - } - - ifs->unsetf(std::ios::skipws); - std::streampos file_size; - ifs->seekg(0, std::ios::end); - file_size = ifs->tellg(); - ifs->seekg(0, std::ios::beg); - - bytes.reserve(file_size); - bytes.insert(bytes.begin(), - std::istream_iterator(*ifs), - std::istream_iterator()); - } - - std::uint16_t mask = 0x0; - if (!config->count()) - { - std::static_pointer_cast(device)->ImportIFMApp( - bytes); - } - else - { - if (global_config) - { - mask |= static_cast( - ifm3d::LegacyDevice::import_flags::GLOBAL); - } - - if (network_config) - { - mask |= - static_cast(ifm3d::LegacyDevice::import_flags::NET); - } - - if (app_config) - { - mask |= static_cast( - ifm3d::LegacyDevice::import_flags::APPS); - } - - std::static_pointer_cast(device)->ImportIFMConfig( - bytes, - mask); - } -} +{} CLI::App* ifm3d::ImportApp::CreateCommand(CLI::App* parent) @@ -106,37 +20,11 @@ ifm3d::ImportApp::CreateCommand(CLI::App* parent) ->add_subcommand("import", "Import an application or whole sensor configuration " "that is compatible with " - "ifm Vision Assistant's export format.") - ->require_subcommand(0, 0); - - command - ->add_option( - "--file", - this->input_file, - "Input file, defaults to `stdin' (good for reading off a pipeline)") - ->default_val("-"); - - config = command->add_flag( - "-c,--config", - "Flag indicating the input is an entire sensor config (app otherwise)"); - - command - ->add_flag("-g,--global", - this->global_config, - "If `-c', import the global configuration") - ->needs(config); - - command - ->add_flag("-n,--net", - this->network_config, - "If `-c', import the network configuration") - ->needs(config); + "ifm Vision Assistant's export format (*.o3d3xxapp).") + ->require_subcommand(1); - command - ->add_flag("-a,--app", - this->app_config, - "If `-c', import the application configuration") - ->needs(config); + RegisterSubcommand(command); + RegisterSubcommand(command); return command; } diff --git a/modules/tools/src/libifm3d_tools/legacy/import_application_app.cpp b/modules/tools/src/libifm3d_tools/legacy/import_application_app.cpp new file mode 100644 index 00000000..e7e665d2 --- /dev/null +++ b/modules/tools/src/libifm3d_tools/legacy/import_application_app.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ifm3d::ImportApplicationApp::~ImportApplicationApp() {} + +void +ifm3d::ImportApplicationApp::Execute(CLI::App* app) +{ + auto device = Parent()->GetDevice(); + + std::shared_ptr ifs; + std::vector bytes; + + if (this->input_file == "-") + { + if (ifm3d::IsStdinAvailable()) + { + ifs.reset(&std::cin, [](...) {}); + + char b; + while (ifs->get(b)) + { + bytes.push_back(*(reinterpret_cast(&b))); + } + } + else + { + throw ifm3d::Error(IFM3D_NO_INPUT_PROVIDED); + } + } + else + { + ifs.reset( + new std::ifstream(this->input_file, std::ios::in | std::ios::binary)); + if (!*ifs) + { + std::cerr << "Could not open file: " << this->input_file + << std::endl; + throw ifm3d::Error(IFM3D_IO_ERROR); + } + + ifs->unsetf(std::ios::skipws); + std::streampos file_size; + ifs->seekg(0, std::ios::end); + file_size = ifs->tellg(); + ifs->seekg(0, std::ios::beg); + + bytes.reserve(file_size); + bytes.insert(bytes.begin(), + std::istream_iterator(*ifs), + std::istream_iterator()); + } + std::static_pointer_cast(device)->ImportIFMApp(bytes); +} + +CLI::App* +ifm3d::ImportApplicationApp::CreateCommand(CLI::App* parent) +{ + CLI::App* command = + parent + ->add_subcommand("app", + "Import an application that is compatible with ifm " + "Vision Assistant's export format (*.o3d3xxapp).") + ->require_subcommand(0, 0); + + command + ->add_option( + "--file", + this->input_file, + "Input file, defaults to `stdin' (good for reading off a pipeline)") + ->default_val("-"); + + return command; +} diff --git a/modules/tools/src/libifm3d_tools/legacy/import_device_app.cpp b/modules/tools/src/libifm3d_tools/legacy/import_device_app.cpp new file mode 100644 index 00000000..393b9f9b --- /dev/null +++ b/modules/tools/src/libifm3d_tools/legacy/import_device_app.cpp @@ -0,0 +1,122 @@ +/* + * Copyright 2018-present ifm electronic, gmbh + * Copyright 2017 Love Park Robotics, LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +ifm3d::ImportDeviceApp::~ImportDeviceApp() {} + +void +ifm3d::ImportDeviceApp::Execute(CLI::App* app) +{ + auto device = Parent()->GetDevice(); + + std::shared_ptr ifs; + std::vector bytes; + + if (this->input_file == "-") + { + if (ifm3d::IsStdinAvailable()) + { + ifs.reset(&std::cin, [](...) {}); + + char b; + while (ifs->get(b)) + { + bytes.push_back(*(reinterpret_cast(&b))); + } + } + else + { + throw ifm3d::Error(IFM3D_NO_INPUT_PROVIDED); + } + } + else + { + ifs.reset( + new std::ifstream(this->input_file, std::ios::in | std::ios::binary)); + if (!*ifs) + { + std::cerr << "Could not open file: " << this->input_file + << std::endl; + throw ifm3d::Error(IFM3D_IO_ERROR); + } + + ifs->unsetf(std::ios::skipws); + std::streampos file_size; + ifs->seekg(0, std::ios::end); + file_size = ifs->tellg(); + ifs->seekg(0, std::ios::beg); + + bytes.reserve(file_size); + bytes.insert(bytes.begin(), + std::istream_iterator(*ifs), + std::istream_iterator()); + } + + std::uint16_t mask = 0x0; + if (!no_global_config) + { + mask |= + static_cast(ifm3d::LegacyDevice::import_flags::GLOBAL); + } + + if (!no_network_config) + { + mask |= + static_cast(ifm3d::LegacyDevice::import_flags::NET); + } + + if (!no_app_config) + { + mask |= + static_cast(ifm3d::LegacyDevice::import_flags::APPS); + } + + std::static_pointer_cast(device)->ImportIFMConfig(bytes, + mask); +} + +CLI::App* +ifm3d::ImportDeviceApp::CreateCommand(CLI::App* parent) +{ + CLI::App* command = + parent + ->add_subcommand("device", + "Import a device configuration that is compatible with " + "ifm Vision Assistant's export format. (*.o3d3xxcfg)") + ->require_subcommand(0, 0); + + command + ->add_option( + "--file", + this->input_file, + "Input file, defaults to `stdin' (good for reading off a pipeline)") + ->default_val("-"); + + command->add_flag("--no-global", + this->no_global_config, + "Skip the global configuration."); + + command->add_flag("--no-net", + this->no_network_config, + "Skip the network configuration."); + + command->add_flag("--no-app", + this->no_app_config, + "Skip the application configuration."); + + return command; +}