Skip to content

Commit

Permalink
Merge branch 'bugfix/issue_341_import_export' into 'main'
Browse files Browse the repository at this point in the history
Add new subcommands 'app' and 'device' under import and export subcommands

See merge request syntron/support/csr/ifm3d/ifm3d!414
  • Loading branch information
NikitaS20 committed Oct 24, 2024
2 parents 2513648 + a577166 commit 6671dc7
Show file tree
Hide file tree
Showing 14 changed files with 498 additions and 173 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions modules/tools/include/ifm3d/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
#include <ifm3d/tools/common/discover_app.h>
#include <ifm3d/tools/common/dump_app.h>
#include <ifm3d/tools/legacy/export_app.h>
#include <ifm3d/tools/legacy/export_application_app.h>
#include <ifm3d/tools/legacy/export_device_app.h>
#include <ifm3d/tools/ovp8xx/get_diagnostic_app.h>
#include <ifm3d/tools/ovp8xx/get_filter_schema_app.h>
#include <ifm3d/tools/ovp8xx/get_init_app.h>
#include <ifm3d/tools/ovp8xx/get_service_report_app.h>
#include <ifm3d/tools/legacy/imager_types_app.h>
#include <ifm3d/tools/legacy/import_app.h>
#include <ifm3d/tools/legacy/import_application_app.h>
#include <ifm3d/tools/legacy/import_device_app.h>
#include <ifm3d/tools/ovp8xx/jsonschema_app.h>
#include <ifm3d/tools/legacy/ls_app.h>
#include <ifm3d/tools/legacy/passwd_app.h>
Expand Down
3 changes: 0 additions & 3 deletions modules/tools/include/ifm3d/tools/legacy/export_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions modules/tools/include/ifm3d/tools/legacy/export_application_app.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <ifm3d/tools/command.hpp>
#include <ifm3d/tools/main_command.hpp>

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
38 changes: 38 additions & 0 deletions modules/tools/include/ifm3d/tools/legacy/export_device_app.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <ifm3d/tools/command.hpp>
#include <ifm3d/tools/main_command.hpp>

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
6 changes: 0 additions & 6 deletions modules/tools/include/ifm3d/tools/legacy/import_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions modules/tools/include/ifm3d/tools/legacy/import_application_app.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <ifm3d/tools/command.hpp>
#include <ifm3d/tools/main_command.hpp>

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
36 changes: 36 additions & 0 deletions modules/tools/include/ifm3d/tools/legacy/import_device_app.h
Original file line number Diff line number Diff line change
@@ -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 <string>
#include <ifm3d/tools/command.hpp>
#include <ifm3d/tools/main_command.hpp>

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
51 changes: 4 additions & 47 deletions modules/tools/src/libifm3d_tools/legacy/export_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,12 @@
*/

#include <ifm3d/tools/legacy/export_app.h>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ifm3d/device.h>

ifm3d::ExportApp::~ExportApp() {}

void
ifm3d::ExportApp::Execute(CLI::App* app)
{
auto device = Parent<MainCommand>()->GetDevice();

std::vector<std::uint8_t> bytes;

if (this->application_index <= 0)
{
bytes = std::static_pointer_cast<ifm3d::LegacyDevice>(device)
->ExportIFMConfig();
}
else
{
bytes =
std::static_pointer_cast<ifm3d::LegacyDevice>(device)->ExportIFMApp(
this->application_index);
}

if (this->output_file == "-")
{
std::cout.write(reinterpret_cast<char*>(bytes.data()), bytes.size());
}
else
{
std::ofstream(this->output_file, std::ios::binary)
.write(reinterpret_cast<char*>(bytes.data()), bytes.size());
}
}
{}

CLI::App*
ifm3d::ExportApp::CreateCommand(CLI::App* parent)
Expand All @@ -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<ifm3d::ExportApplicationApp>(command);
RegisterSubcommand<ifm3d::ExportDeviceApp>(command);

return command;
}
75 changes: 75 additions & 0 deletions modules/tools/src/libifm3d_tools/legacy/export_application_app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2018-present ifm electronic, gmbh
* Copyright 2017 Love Park Robotics, LLC
* SPDX-License-Identifier: Apache-2.0
*/

#include <ifm3d/tools/legacy/export_application_app.h>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ifm3d/device.h>

ifm3d::ExportApplicationApp::~ExportApplicationApp() {}

void
ifm3d::ExportApplicationApp::Execute(CLI::App* app)
{
auto device = Parent<MainCommand>()->GetDevice();

std::vector<std::uint8_t> bytes;

if (Parent<ifm3d::O3D3XX>())
{
bytes =
std::static_pointer_cast<ifm3d::LegacyDevice>(device)->ExportIFMApp(
this->application_index);
}
else
{
bytes =
std::static_pointer_cast<ifm3d::LegacyDevice>(device)->ExportIFMApp(1);
}

if (this->output_file == "-")
{
std::cout.write(reinterpret_cast<char*>(bytes.data()), bytes.size());
}
else
{
std::ofstream(this->output_file, std::ios::binary)
.write(reinterpret_cast<char*>(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<ifm3d::O3D3XX>())
{
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;
}
56 changes: 56 additions & 0 deletions modules/tools/src/libifm3d_tools/legacy/export_device_app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2018-present ifm electronic, gmbh
* Copyright 2017 Love Park Robotics, LLC
* SPDX-License-Identifier: Apache-2.0
*/

#include <ifm3d/tools/legacy/export_device_app.h>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ifm3d/device.h>

ifm3d::ExportDeviceApp::~ExportDeviceApp() {}

void
ifm3d::ExportDeviceApp::Execute(CLI::App* app)
{
auto device = Parent<MainCommand>()->GetDevice();

std::vector<std::uint8_t> bytes;

bytes =
std::static_pointer_cast<ifm3d::LegacyDevice>(device)->ExportIFMConfig();

if (this->output_file == "-")
{
std::cout.write(reinterpret_cast<char*>(bytes.data()), bytes.size());
}
else
{
std::ofstream(this->output_file, std::ios::binary)
.write(reinterpret_cast<char*>(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;
}
Loading

0 comments on commit 6671dc7

Please sign in to comment.