diff --git a/src/modules/zenoh/CMakeLists.txt b/src/modules/zenoh/CMakeLists.txt index f335136cb1..cac47cbccc 100644 --- a/src/modules/zenoh/CMakeLists.txt +++ b/src/modules/zenoh/CMakeLists.txt @@ -74,6 +74,19 @@ if(CONFIG_ZENOH_SERIAL) target_compile_options(zenohpico_static PRIVATE -DZ_LINK_SERIAL) endif() +add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/default_topics.c +COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../uxrce_dds_client/generate_dds_topics.py + --client-outdir ${CMAKE_CURRENT_BINARY_DIR} + --dds-topics-file ${CMAKE_CURRENT_SOURCE_DIR}/../uxrce_dds_client/dds_topics.yaml + --template_file ${CMAKE_CURRENT_SOURCE_DIR}/default_topics.c.em +DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../uxrce_dds_client/generate_dds_topics.py + ${CMAKE_CURRENT_SOURCE_DIR}/../uxrce_dds_client/dds_topics.yaml + ${CMAKE_CURRENT_SOURCE_DIR}/default_topics.c.em +COMMENT "Generating Default config" +) +add_custom_target(default_topics_config DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/default_topics.c) + px4_add_module( MODULE modules__zenoh @@ -83,6 +96,7 @@ px4_add_module( zenoh_config.cpp publishers/zenoh_publisher.cpp subscribers/zenoh_subscriber.cpp + ${CMAKE_CURRENT_BINARY_DIR}/default_topics.c MODULE_CONFIG module.yaml DEPENDS @@ -92,6 +106,7 @@ px4_add_module( zenohpico_static zenoh_topics git_zenoh-pico + default_topics_config INCLUDES ${PX4_BINARY_DIR}/msg zenoh-pico/include diff --git a/src/modules/zenoh/default_topics.c.em b/src/modules/zenoh/default_topics.c.em new file mode 100644 index 0000000000..0845c004e9 --- /dev/null +++ b/src/modules/zenoh/default_topics.c.em @@ -0,0 +1,32 @@ +@############################################### +@# +@# EmPy template +@# +@############################################### +@# Generates default config fore Zenoh +@# +@# Context: +@# - msgs (List) list of all RTPS messages +@# - topics (List) list of all topic names +@# - spec (msggen.MsgSpec) Parsed specification of the .msg file +@############################################### +@{ +import os + + +}@ + +const char* default_pub_config = +@[ for pub in publications]@ + "@(pub['topic']);@(pub['simple_base_type'])\n" +@[ end for]@ +; + +const char* default_sub_config = +@[ for sub in subscriptions]@ + "@(sub['topic']);@(sub['simple_base_type'])\n" +@[ end for]@ +@[ for sub in subscriptions_multi]@ + "@(sub['topic']);@(sub['simple_base_type'])\n" +@[ end for]@ +; diff --git a/src/modules/zenoh/zenoh.cpp b/src/modules/zenoh/zenoh.cpp index 3820495118..359bc2c8d4 100644 --- a/src/modules/zenoh/zenoh.cpp +++ b/src/modules/zenoh/zenoh.cpp @@ -113,7 +113,7 @@ int ZENOH::generate_rmw_zenoh_topic_keyexpr(const char *topic, const uint8_t *ri if (type_name) { strcpy(type, type_name); toCamelCase(type); // Convert uORB type to camel case - return snprintf(keyexpr, KEYEXPR_SIZE, "%" PRId32 "/%s/" + return snprintf(keyexpr, KEYEXPR_SIZE, "%" PRId32 "%s/" KEYEXPR_MSG_NAME "%s_/RIHS01_" "%02x%02x%02x%02x%02x%02x%02x%02x" "%02x%02x%02x%02x%02x%02x%02x%02x" @@ -156,7 +156,7 @@ int ZENOH::generate_rmw_zenoh_topic_liveliness_keyexpr(const z_id_t *id, const c return snprintf(keyexpr, KEYEXPR_SIZE, "@ros2_lv/%" PRId32 "/" "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x/" - "0/11/%s/%%/%%/px4_%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x/%%%s/" + "0/11/%s/%%/%%/px4_%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x/%s/" KEYEXPR_MSG_NAME "%s_/RIHS01_" "%02x%02x%02x%02x%02x%02x%02x%02x" "%02x%02x%02x%02x%02x%02x%02x%02x" @@ -330,7 +330,6 @@ int ZENOH::setupTopics(px4_pollfd_struct_t *pfds) for (i = 0; i < _pub_count; i++) { if (_config.getPublisherMapping(topic, type)) { - printf("Index %i ret %i Topic %s Type %s", i, ret, topic, type); _zenoh_publishers[i] = genPublisher(type); const uint8_t *rihs_hash = getRIHS01_Hash(type); diff --git a/src/modules/zenoh/zenoh_config.cpp b/src/modules/zenoh/zenoh_config.cpp index 8246482c19..81daca2057 100644 --- a/src/modules/zenoh/zenoh_config.cpp +++ b/src/modules/zenoh/zenoh_config.cpp @@ -51,8 +51,10 @@ const char *default_net_config = Z_CONFIG_MODE_DEFAULT ";" CONFIG_ZENOH_DEFAULT_LOCATOR; -const char *default_pub_config = ""; -const char *default_sub_config = ""; //TODO maybe use YAML + +// Default config generated from default_topics.c.em and dds_topics.yaml +extern const char *default_pub_config; +extern const char *default_sub_config; Zenoh_Config::Zenoh_Config() @@ -285,7 +287,6 @@ int Zenoh_Config::getPubSubMapping(char *topic, char *type, const char *filename if (fp_mapping) { while (fgets(buffer, MAX_LINE_SIZE, fp_mapping) != NULL) { - printf("getPubSubMapping %s", buffer); if (buffer[0] != '\n') { const char *config_type = get_csv_field(buffer, 2);