forked from autowarefoundation/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
355 additions
and
0 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,66 @@ | ||
cmake_minimum_required(VERSION 2.8.3) | ||
# set compiler | ||
set(CMAKE_CXX_COMPILER "/usr/bin/clang++") | ||
|
||
project(test_c_node) | ||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
set(CMAKE_CXX_FLAGS "-std=c++14 -pthread -Wall -Wextra") | ||
set(CMAKE_CXX_FLAGS_DEBUG "-g") | ||
# NOTE: CHOOSE THE O2/O3 is really important for speed! check more on optimization on compile | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O2") | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") | ||
|
||
set(CURRENT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
message(STATUS "Current dir stored in variable: ${CURRENT_DIR}") | ||
find_package(PkgConfig) | ||
|
||
|
||
|
||
pkg_check_modules(YAMLCPP REQUIRED yaml-cpp>=0.5) | ||
|
||
|
||
include_directories( | ||
${YAMLCPP_INCLUDE_DIRS} | ||
$ENV{HOME}/dora/apis/c/node #dora的头文件路径 node_api.h | ||
#/home/nvidia/dora_project/dora/apis/c/node | ||
$ENV{HOME}/dora/apis/c/operator | ||
$ENV{HOME}/dora/examples/c++-ros2-dataflow/build/ #C++ros的头文件路径 | ||
|
||
) | ||
|
||
add_executable(node_A node_A.cc ) | ||
target_link_libraries(node_A | ||
${YAMLCPP_LIBRARIES} | ||
# glog::glog | ||
$ENV{HOME}/dora/target/release/libdora_node_api_c.a | ||
m | ||
rt | ||
dl | ||
pthread | ||
) | ||
add_executable(node_B node_B.cc ) | ||
target_link_libraries(node_B | ||
${YAMLCPP_LIBRARIES} | ||
# glog::glog | ||
$ENV{HOME}/dora/target/release/libdora_node_api_c.a | ||
m | ||
rt | ||
dl | ||
pthread | ||
) | ||
add_executable(node_C node_C.cpp) | ||
target_link_libraries(node_C | ||
${YAMLCPP_LIBRARIES} | ||
# glog::glog | ||
$ENV{HOME}/dora/target/release/libdora_node_api_c.a | ||
m | ||
rt | ||
dl | ||
pthread | ||
) | ||
|
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 @@ | ||
# C_node_test | ||
|
||
这是一个测试节点,对 https://github.com/dora-rs/dora/issues/502 问题进行测试 | ||
|
||
node_A : 以10Hz频率发布一个长度为3的数组,数组中的数范围是0-255 | ||
|
||
node_B: 以100Hz频率发布一个0-255变化的数 | ||
|
||
node_C: 接受 node_A 和 node_B发送的数据并显示 | ||
|
||
|
||
|
||
测试结论,未出现 502 问题 |
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,25 @@ | ||
nodes: | ||
#rslidar driver node | ||
- id: node_A | ||
custom: | ||
source: build/node_A | ||
inputs: | ||
tick: dora/timer/millis/100 | ||
outputs: | ||
- counter_A | ||
|
||
|
||
- id: node_B | ||
custom: | ||
source: build/node_B | ||
inputs: | ||
tick: dora/timer/millis/10 | ||
outputs: | ||
- counter_B | ||
|
||
- id: node_C | ||
custom: | ||
source: build/node_C | ||
inputs: | ||
counter_A: node_A/counter_A | ||
counter_B: node_B/counter_B |
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,80 @@ | ||
extern "C" | ||
{ | ||
#include "node_api.h" | ||
#include "operator_api.h" | ||
#include "operator_types.h" | ||
} | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
bool to_exit_process; | ||
|
||
int run(void *dora_context) | ||
{ | ||
unsigned char counter[3] ; | ||
|
||
//for (int i = 0; i < 20; i++) | ||
to_exit_process = false; | ||
counter[0] = 0; | ||
while(!to_exit_process) | ||
{ | ||
void *event = dora_next_event(dora_context); | ||
if (event == NULL) | ||
{ | ||
printf("[c node] ERROR: unexpected end of event\n"); | ||
return -1; | ||
} | ||
|
||
enum DoraEventType ty = read_dora_event_type(event); | ||
|
||
if (ty == DoraEventType_Input) | ||
{ | ||
char* output_data = (char *)counter; | ||
|
||
counter[0] += 1; | ||
if(counter[0]>=255) | ||
counter[0]=0; | ||
|
||
std::string out_id = "counter_A"; | ||
size_t data_len = 3 ; | ||
int resultend=dora_send_output(dora_context, &out_id[0], out_id.length(), output_data, data_len); | ||
|
||
std::cout | ||
<< "dora_send_output: out_id "<<out_id<< " out_data_len: "<<data_len<<std::endl; | ||
|
||
if (resultend != 0) | ||
{ | ||
std::cerr << "failed to send output" << std::endl; | ||
return 1; | ||
} | ||
} | ||
else if (ty == DoraEventType_Stop) | ||
{ | ||
printf("[c node] received stop event\n"); | ||
} | ||
else | ||
{ | ||
printf("[c node] received unexpected event: %d\n", ty); | ||
} | ||
|
||
free_dora_event(event); | ||
} | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
std::cout << "dora node A driver" << std::endl; | ||
|
||
auto dora_context = init_dora_context_from_env(); | ||
auto ret = run(dora_context); | ||
free_dora_context(dora_context); | ||
|
||
|
||
to_exit_process = true; | ||
|
||
std::cout << "exit dora node A ..." << std::endl; | ||
return ret; | ||
} | ||
|
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,80 @@ | ||
extern "C" | ||
{ | ||
#include "node_api.h" | ||
#include "operator_api.h" | ||
#include "operator_types.h" | ||
} | ||
|
||
#include <iostream> | ||
#include <vector> | ||
|
||
bool to_exit_process; | ||
|
||
int run(void *dora_context) | ||
{ | ||
unsigned char counter[3] ; | ||
|
||
//for (int i = 0; i < 20; i++) | ||
to_exit_process = false; | ||
counter[0] = 0; | ||
while(!to_exit_process) | ||
{ | ||
void *event = dora_next_event(dora_context); | ||
if (event == NULL) | ||
{ | ||
printf("[c node] ERROR: unexpected end of event\n"); | ||
return -1; | ||
} | ||
|
||
enum DoraEventType ty = read_dora_event_type(event); | ||
|
||
if (ty == DoraEventType_Input) | ||
{ | ||
char* output_data = (char *)counter; | ||
|
||
counter[0] += 1; | ||
if(counter[0]>=255) | ||
counter[0]=0; | ||
|
||
std::string out_id = "counter_B"; | ||
size_t data_len = 1 ; | ||
int resultend=dora_send_output(dora_context, &out_id[0], out_id.length(), output_data, data_len); | ||
|
||
std::cout | ||
<< "dora_send_output: out_id "<<out_id<< " out_data_len: "<<data_len<<std::endl; | ||
|
||
if (resultend != 0) | ||
{ | ||
std::cerr << "failed to send output" << std::endl; | ||
return 1; | ||
} | ||
} | ||
else if (ty == DoraEventType_Stop) | ||
{ | ||
printf("[c node] received stop event\n"); | ||
} | ||
else | ||
{ | ||
printf("[c node] received unexpected event: %d\n", ty); | ||
} | ||
|
||
free_dora_event(event); | ||
} | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
std::cout << "dora node B driver" << std::endl; | ||
|
||
auto dora_context = init_dora_context_from_env(); | ||
auto ret = run(dora_context); | ||
free_dora_context(dora_context); | ||
|
||
|
||
to_exit_process = true; | ||
|
||
std::cout << "exit dora node B ..." << std::endl; | ||
return ret; | ||
} | ||
|
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,91 @@ | ||
extern "C" | ||
{ | ||
#include "node_api.h" | ||
#include "operator_api.h" | ||
#include "operator_types.h" | ||
} | ||
|
||
|
||
#include <chrono> | ||
#include <thread> | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
|
||
#include <nlohmann/json.hpp> | ||
using json = nlohmann::json; | ||
|
||
|
||
int run(void *dora_context) | ||
{ | ||
|
||
while (true) | ||
{ | ||
|
||
void * event = dora_next_event(dora_context); | ||
|
||
if (event == NULL) | ||
{ | ||
printf("[c node] ERROR: unexpected end of event\n"); | ||
return -1; | ||
} | ||
|
||
enum DoraEventType ty = read_dora_event_type(event); | ||
|
||
if (ty == DoraEventType_Input) | ||
{ | ||
char *data; | ||
size_t data_len; | ||
char *data_id; | ||
size_t data_id_len; | ||
read_dora_input_data(event, &data, &data_len); | ||
read_dora_input_id(event, &data_id, &data_id_len); | ||
int len = data_len; | ||
|
||
std::cout << "=======================" <<std::endl; | ||
std::cout << "Input Data length: " << data_len <<" " <<data_id<<std::endl; | ||
if (strcmp("counter_A", data_id) == 0) | ||
{ | ||
char* data_tem_a = reinterpret_cast<char*>(data); | ||
int num_points = data_len / sizeof(char); | ||
std::vector<float> data_node_a(data_tem_a, data_tem_a + num_points); | ||
std::cout << " counter_A Input Data: " <<data_node_a[0]<< std::endl; | ||
} | ||
else if (strcmp("counter_B", data_id) == 0) | ||
{ | ||
char* data_tem_b = reinterpret_cast<char*>(data); | ||
int num_points = data_len / sizeof(char); | ||
std::vector<float> data_node_b(data_tem_b, data_tem_b + num_points); | ||
std::cout << "counter_B Input Data: " <<data_node_b[0]<< std::endl; | ||
} | ||
std::cout << "=======================" <<std::endl; | ||
} | ||
else if (ty == DoraEventType_Stop) | ||
{ | ||
printf("[c node] received stop event\n"); | ||
} | ||
else | ||
{ | ||
printf("[c node] received unexpected event: %d\n", ty); | ||
} | ||
|
||
free_dora_event(event); | ||
} | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
std::cout << "dora node c" << std::endl; | ||
|
||
auto dora_context = init_dora_context_from_env(); | ||
|
||
auto ret = run(dora_context); | ||
free_dora_context(dora_context); | ||
|
||
std::cout << "END dora node c" << std::endl; | ||
|
||
return ret; | ||
} | ||
|
||
|