-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add LiDAR type definition. * Add CLI configuration example. * Fix formating and linting * Fix build error. * Update documentations. * Update LiDAR setting documentation * Fix version selector to have descending order. --------- Co-authored-by: Jongkuk Lim <limjk@jmarple.ai>
- Loading branch information
Showing
18 changed files
with
666 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "examples/config_cli/libs/cli"] | ||
path = examples/config_cli/libs/cli | ||
url = https://github.com/daniele77/cli.git | ||
branch = v2.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
project(slambox_serial_config_cli_example) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "") | ||
|
||
find_package(glog 0.6.0 REQUIRED) | ||
|
||
add_executable(slambox_serial_config_cli_example config_cli.cpp config_cli_app.cpp) | ||
|
||
if (NOT DEFINED slambox_sdk_LIBRARIES) | ||
find_package(slambox_sdk 0.2.0 REQUIRED) | ||
else() | ||
set(slambox_sdk_LIBRARIES ${slambox_sdk_LIBRARIES};slambox_sdk_static) | ||
endif() | ||
|
||
target_link_libraries(slambox_serial_config_cli_example | ||
glog::glog | ||
cli::cli | ||
${slambox_sdk_LIBRARIES} | ||
) | ||
|
||
add_subdirectory("libs/cli") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Config CLI | ||
|
||
This example demonstrates how to create CLI application for SLAMBOX setting with SLAMBOX Protocol. | ||
|
||
## Dependency | ||
|
||
- This example requires [cli](https://github.com/daniele77/cli.git) library. Since [cli](https://github.com/daniele77/cli.git) library is included as submodule of this repository, you may need to update the submodules. | ||
|
||
``` | ||
git submodule update --init --recursive | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/// @file | ||
/// @author Jongkuk Lim <limjk@jmarple.ai> | ||
/// @copyright 2023 J.Marple | ||
/// @brief SLAMBOX CLI configurator application | ||
|
||
#include <cli/cli.h> | ||
#include <cli/clilocalsession.h> | ||
#include <cli/filehistorystorage.h> | ||
#include <cli/loopscheduler.h> | ||
#include <glog/logging.h> | ||
|
||
#include "include/config_cli_app.hpp" | ||
|
||
/// @brief Print application usage | ||
/// @param argv arguments | ||
void print_usage(const std::string &binary_name) { | ||
std::cout << "Usage: " << binary_name << " <serial_port> <baudrate>" | ||
<< std::endl; | ||
std::cout << " ex) " << binary_name << " /dev/ttyUSB0 1500000" | ||
<< std::endl; | ||
} | ||
|
||
/// @brief Process arguments and set port name and baudrate | ||
/// @param argc argument count | ||
/// @param argv argument values | ||
/// @param port_name port name to be set | ||
/// @param baudrate baudrate to be set | ||
/// @return 0 if success, otherwise 1 | ||
/// @note If argc is 2, then argv[1] is config file path | ||
/// @note If argc is 3, then argv[1] is serial port name and argv[2] is baudrate | ||
/// @note `port_name` and `baudrate` are inplace modified | ||
int handle_arguments(int argc, char **argv, std::string *port_name, | ||
int *baudrate) { | ||
if (argc == 3) { | ||
*port_name = argv[1]; | ||
try { | ||
*baudrate = std::stoi(argv[2]); | ||
} catch (const std::invalid_argument &e) { | ||
std::cout << "Error parsing baudrate " << argv[2] << std::endl; | ||
std::cout << "Reason: " << e.what() << std::endl; | ||
|
||
print_usage(argv[0]); | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
// Handle arguments exception | ||
if (argc < 2 || argc > 3) { | ||
print_usage(argv[0]); | ||
return 1; | ||
} | ||
|
||
// Parse arguments | ||
std::string port_name = "/dev/ttyUSB0"; | ||
int baudrate = -1; | ||
|
||
if (handle_arguments(argc, argv, &port_name, &baudrate) != 0) { | ||
return 1; | ||
} | ||
|
||
FLAGS_stderrthreshold = google::INFO; | ||
FLAGS_colorlogtostderr = true; | ||
google::InitGoogleLogging(argv[0]); | ||
|
||
LOG(INFO) << "port_name: " << port_name << ", baud_rate: " << baudrate; | ||
|
||
try { | ||
sbox::ConfigCLIApp config_cli_app(port_name, baudrate); | ||
std::unique_ptr<cli::Menu> root_menu = config_cli_app.create_root_menu(); | ||
cli::Cli cli( | ||
std::move(root_menu), | ||
std::make_unique<cli::FileHistoryStorage>(".config_cli_history")); | ||
|
||
cli.EnterAction([](std::ostream &out) { out << "Welcome" << std::endl; }); | ||
cli.ExitAction([](std::ostream &out) { out << "Bye" << std::endl; }); | ||
|
||
cli.StdExceptionHandler( | ||
[](std::ostream &out, const std::string &cmd, const std::exception &e) { | ||
out << "Exception caught in cli handler: " << e.what() | ||
<< " handling command: " << cmd << ".\n"; | ||
}); | ||
|
||
cli::SetColor(); | ||
cli::LoopScheduler scheduler; | ||
cli::CliLocalTerminalSession local_session(cli, scheduler, std::cout, 200); | ||
local_session.ExitAction([&scheduler, &config_cli_app](auto &out) { | ||
out << "Closing App...\n"; | ||
scheduler.Stop(); | ||
config_cli_app.stop(); | ||
}); | ||
|
||
config_cli_app.set_session(&local_session); | ||
config_cli_app.set_loop_scheduler(&scheduler); | ||
config_cli_app.run(); | ||
|
||
if (!config_cli_app.is_running()) { | ||
std::cerr << "Error: Failed to open serial communication" << std::endl; | ||
return 1; | ||
} | ||
|
||
scheduler.Run(); | ||
|
||
return 0; | ||
} catch (const std::exception &e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return 1; | ||
} catch (...) { | ||
std::cerr << "Error: Unknown exception" << std::endl; | ||
return 1; | ||
} | ||
|
||
return 1; | ||
} |
Oops, something went wrong.