Skip to content

Commit

Permalink
Merge pull request #9 from Robotics010/cli-tool/feature/add-subcomman…
Browse files Browse the repository at this point in the history
…ds-add-remove-status-result

Cli tool/feature/add subcommands add remove status result
  • Loading branch information
Robotics010 authored Sep 23, 2023
2 parents 86391c3 + 7a66ecf commit 516ec65
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 33 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Typically a software team has a production code to be tested; a simulation tool

Current project is under active development and is not ready yet to be in use.

Help wanted:
* Windows integration
* Cmake review

## Notes

### service notes
Expand All @@ -17,7 +21,14 @@ Current project is under active development and is not ready yet to be in use.
~/cycle_on/service$ cmake --build build
~/cycle_on/service$ (cd build && ctest)
~/cycle_on/service$ ./build/src/hello_world
~/cycle_on/service$ ./build/src/service
```

### service integration

```
~/cycle_on/$ sudo bash docker/installers/install_essentials.sh
~/cycle_on/$ sudo bash docker/installers/install_boost.sh
```

### cli-tool notes
Expand All @@ -26,7 +37,11 @@ $ python3 -m pip install build
$ python3 -m pip install setuptools
$ python3 -m pip install --user virtualenv --force-reinstall
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py data/config.json
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py add --reuse_global_config
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py remove id
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py status id
~/cycle_on/cli_tool$ python3 src/cycleon/cmd.py result id
~/cycle_on/cli_tool$ python3 -m pytest test/
~/cycle_on/cli_tool$ python3 -m build
~/cycle_on/cli_tool$ python3 -m pip install dist/cycleon-0.0.1-py3-none-any.whl --force-reinstall
Expand Down
20 changes: 0 additions & 20 deletions cli_tool/data/config.json

This file was deleted.

41 changes: 41 additions & 0 deletions cli_tool/data/global_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"network": {
"address": "localhost",
"port": 8181
},
"action": {
"modules": [
{
"command": "ros2",
"parameters": [
"launch",
"carla_autoware_bridge",
"carla_autoware_demo.launch.py",
"port:=3000",
"timeout:=5"
]
},
{
"command": "ros2",
"parameters": [
"launch",
"carla_launch",
"e2e_simulator.launch.xml",
"map_path:=/home/robo/autoware_map/carla-town-1",
"vehicle_model:=carla_tesla_model3",
"sensor_model:=sample_sensor_kit"
]
}
],
"simulators": [
{
"command": "/home/robo/CARLA_0.9.12/CarlaUE4.sh",
"parameters": [
"-prefernvidia",
"-carla-rpc-port=3000",
"-quality-level=Low"
]
}
]
}
}
44 changes: 36 additions & 8 deletions cli_tool/src/cycleon/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,57 @@


def process(args):
GLOBAL_CONFIG_PATH = 'data/global_config.json'
config_reader = ConfigReader()
config_reader.implementation = JsonConfig()
config = config_reader.Open(args.config)
config = config_reader.Open(GLOBAL_CONFIG_PATH)

client = Client()
client.interface = TcpClient(
address=config.network.address,
port=config.network.port)
client.adapter = JsonTcpAdapter()

# ToDo: add low-level client cmd execute
action_id = client.Add(config.action)
print(f'action_id: {action_id}')
# client.Remove(action_id)
# status = client.GetStatus(action_id)
# result = client.GetResult(action_id)
if args.command == 'add':
action_id = client.Add(config.action)
print(f'added with action_id: {action_id}')
elif args.command == 'remove':
client.Remove(int(args.id))
print(f'removed action_id: {args.id}')
elif args.command == 'status':
status = client.GetStatus(int(args.id))
print(f'status of action_id {args.id}: {status}')
elif args.command == 'result':
result = client.GetResult(int(args.id))
print(f'result of action_id {args.id}: {result}')
else:
raise RuntimeError(f'unsupported command "{args.command}"')

# ToDo: add high-level scenario group execution


def main():
parser = argparse.ArgumentParser()
parser.add_argument('config', help='path to config file')
# parser.add_argument('--config', help='path to global config file', required=True)

subparsers = parser.add_subparsers(help='sub-command', required=True, dest='command')

add_cmd_subparser = subparsers.add_parser('add', help='request new action to perform')
add_config_group = add_cmd_subparser.add_mutually_exclusive_group(required=True)
add_config_group.add_argument('--reuse_global_config', action='store_true',
help='get action from global config')
add_config_group.add_argument('--config', type=str,
help='path to config file with action to perform')

remove_cmd_subparser = subparsers.add_parser('remove', help='cancel selected action')
remove_cmd_subparser.add_argument('id', help='unique index of the action')

status_cmd_subparser = subparsers.add_parser('status', help='get status of selected action')
status_cmd_subparser.add_argument('id', help='unique index of the action')

result_cmd_subparser = subparsers.add_parser('result', help='get result of selected action')
result_cmd_subparser.add_argument('id', help='unique index of the action')

args = parser.parse_args()

process(args)
Expand Down
5 changes: 4 additions & 1 deletion cli_tool/src/cycleon/network/message/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class Type(Enum):
INVALID = 0
ADD_ACTION = 1
# REMOVE_ACTION = 2
REMOVE_ACTION = 2
GET_ACTION_STATUS = 3
GET_ACTION_RESULT = 4

Expand All @@ -28,6 +28,9 @@ class Result:
def __init__(self) -> None:
self._type = ResultType.INVALID
self._message = ''

def __str__(self) -> str:
return f'({self._type},{self._message})'

@property
def type(self) -> ResultType:
Expand Down
1 change: 1 addition & 0 deletions service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
find_package(Threads REQUIRED)
find_package(Boost REQUIRED COMPONENTS
filesystem)

Expand Down
11 changes: 9 additions & 2 deletions service/src/runner/child.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ using namespace cycleon::runner;
Child::Child(const std::vector<std::string>& arguments)
: arguments_(arguments) {}

void Child::Open() { child_.reset(new bp::child(bp::args(arguments_))); }
void Child::Open() {
child_.reset(new bp::child(bp::args(arguments_), group_));
// std::cout << "Child: id " << child_->id() << std::endl;
}

void Child::Close() { child_->terminate(); }
void Child::Close() {
group_.terminate();
child_->wait();
// std::cout << "Child: exit_code " << child_->exit_code() << std::endl;
}
2 changes: 2 additions & 0 deletions service/src/runner/child.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RUNNER_CHILD_H_

#include <boost/process/child.hpp>
#include <boost/process/group.hpp>
#include <memory>

#include "runner/module.hpp"
Expand All @@ -20,6 +21,7 @@ class Child final : public ModuleBase {

private:
childPtr child_;
bp::group group_;
std::vector<std::string> arguments_;
};

Expand Down
1 change: 1 addition & 0 deletions service/src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target_link_libraries(
tcp_server
handler
nlohmann_json::nlohmann_json
Threads::Threads
)

target_include_directories(
Expand Down

0 comments on commit 516ec65

Please sign in to comment.