diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7599b0ba4..01fb354b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,10 @@ on: type: string description: Release number required: false + branch: + type: string + description: Release branch + required: false jobs: tag: name: Branch, Bump & tag @@ -44,6 +48,7 @@ jobs: # However, we still need some placeholder version to test that the # version can be reliably bumped. version: ${{ inputs.version || '0.0.0' }} + branch: ${{ inputs.branch }} github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }} - name: Checkout this repository diff --git a/CMakeLists.txt b/CMakeLists.txt index 408ce5d07..21c321878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,12 @@ set(ZENOH_PICO_MINOR ${PROJECT_VERSION_MINOR}) set(ZENOH_PICO_PATCH ${PROJECT_VERSION_PATCH}) set(ZENOH_PICO_TWEAK ${PROJECT_VERSION_TWEAK}) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico.h + @ONLY +) + set(project_version "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") if(NOT DEFINED PROJECT_VERSION_TWEAK) set(project_version "${project_version}") diff --git a/include/zenoh-pico/protocol/definitions/network.h b/include/zenoh-pico/protocol/definitions/network.h index 004897594..023959cce 100644 --- a/include/zenoh-pico/protocol/definitions/network.h +++ b/include/zenoh-pico/protocol/definitions/network.h @@ -78,7 +78,7 @@ typedef _z_qos_t _z_n_qos_t; static inline _z_qos_t _z_n_qos_create(_Bool express, z_congestion_control_t congestion_control, z_priority_t priority) { _z_n_qos_t ret; - _Bool nodrop = (congestion_control != Z_CONGESTION_CONTROL_DROP); + _Bool nodrop = congestion_control == Z_CONGESTION_CONTROL_DROP ? 0 : 1; ret._val = (uint8_t)((express << 4) | (nodrop << 3) | priority); return ret; } diff --git a/include/zenoh-pico/protocol/definitions/transport.h b/include/zenoh-pico/protocol/definitions/transport.h index 30c064585..74f4de973 100644 --- a/include/zenoh-pico/protocol/definitions/transport.h +++ b/include/zenoh-pico/protocol/definitions/transport.h @@ -505,10 +505,12 @@ _z_transport_message_t _z_t_msg_make_open_syn(_z_zint_t lease, _z_zint_t initial _z_transport_message_t _z_t_msg_make_open_ack(_z_zint_t lease, _z_zint_t initial_sn); _z_transport_message_t _z_t_msg_make_close(uint8_t reason, _Bool link_only); _z_transport_message_t _z_t_msg_make_keep_alive(void); -_z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_t messages, _Bool is_reliable); -_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, _Bool is_reliable); -_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, _Bool is_reliable, _Bool is_last); -_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t messages, _Bool is_reliable, _Bool is_last); +_z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_t messages, + z_reliability_t reliability); +_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, z_reliability_t reliability); +_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, _Bool is_last); +_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t messages, z_reliability_t reliability, + _Bool is_last); /*------------------ Copy ------------------*/ void _z_t_msg_copy(_z_transport_message_t *clone, _z_transport_message_t *msg); diff --git a/src/protocol/definitions/transport.c b/src/protocol/definitions/transport.c index 39bbee9d1..28b670f5d 100644 --- a/src/protocol/definitions/transport.c +++ b/src/protocol/definitions/transport.c @@ -209,12 +209,13 @@ _z_transport_message_t _z_t_msg_make_keep_alive(void) { return msg; } -_z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_t messages, _Bool is_reliable) { +_z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_t messages, + z_reliability_t reliability) { _z_transport_message_t msg; msg._header = _Z_MID_T_FRAME; msg._body._frame._sn = sn; - if (is_reliable == true) { + if (reliability == Z_RELIABILITY_RELIABLE) { _Z_SET_FLAG(msg._header, _Z_FLAG_T_FRAME_R); } @@ -224,12 +225,12 @@ _z_transport_message_t _z_t_msg_make_frame(_z_zint_t sn, _z_network_message_vec_ } /*------------------ Frame Message ------------------*/ -_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, _Bool is_reliable) { +_z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, z_reliability_t reliability) { _z_transport_message_t msg; msg._header = _Z_MID_T_FRAME; msg._body._frame._sn = sn; - if (is_reliable == true) { + if (reliability == Z_RELIABILITY_RELIABLE) { _Z_SET_FLAG(msg._header, _Z_FLAG_T_FRAME_R); } @@ -239,16 +240,17 @@ _z_transport_message_t _z_t_msg_make_frame_header(_z_zint_t sn, _Bool is_reliabl } /*------------------ Fragment Message ------------------*/ -_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, _Bool is_reliable, _Bool is_last) { - return _z_t_msg_make_fragment(sn, _z_slice_empty(), is_reliable, is_last); +_z_transport_message_t _z_t_msg_make_fragment_header(_z_zint_t sn, z_reliability_t reliability, _Bool is_last) { + return _z_t_msg_make_fragment(sn, _z_slice_empty(), reliability, is_last); } -_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t payload, _Bool is_reliable, _Bool is_last) { +_z_transport_message_t _z_t_msg_make_fragment(_z_zint_t sn, _z_slice_t payload, z_reliability_t reliability, + _Bool is_last) { _z_transport_message_t msg; msg._header = _Z_MID_T_FRAGMENT; if (is_last == false) { _Z_SET_FLAG(msg._header, _Z_FLAG_T_FRAGMENT_M); } - if (is_reliable == true) { + if (reliability == Z_RELIABILITY_RELIABLE) { _Z_SET_FLAG(msg._header, _Z_FLAG_T_FRAGMENT_R); } diff --git a/src/system/windows/network.c b/src/system/windows/network.c index 821a2883f..77dd68720 100644 --- a/src/system/windows/network.c +++ b/src/system/windows/network.c @@ -64,9 +64,7 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - z_time_t tv; - tv.time = tout / (uint32_t)1000; - tv.millitm = tout % (uint32_t)1000; + DWORD tv = tout; if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { ret = _Z_ERR_GENERIC; } @@ -200,9 +198,7 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - z_time_t tv; - tv.time = tout / (uint32_t)1000; - tv.millitm = tout % (uint32_t)1000; + DWORD tv = tout; if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { ret = _Z_ERR_GENERIC; } @@ -326,9 +322,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin if (addrlen != 0U) { sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - z_time_t tv; - tv.time = tout / (uint32_t)1000; - tv.millitm = tout % (uint32_t)1000; + DWORD tv = tout; if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { ret = _Z_ERR_GENERIC; @@ -430,9 +424,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo if (addrlen != 0U) { sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - z_time_t tv; - tv.time = tout / (uint32_t)1000; - tv.millitm = tout % (uint32_t)1000; + DWORD tv = tout; if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { ret = _Z_ERR_GENERIC; diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c index 132644fce..a40328a28 100644 --- a/src/system/zephyr/system.c +++ b/src/system/zephyr/system.c @@ -96,7 +96,12 @@ void _z_task_free(_z_task_t **task) { /*------------------ Mutex ------------------*/ int8_t _z_mutex_init(_z_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t _z_mutex_drop(_z_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t _z_mutex_drop(_z_mutex_t *m) { + if (m == NULL) { + return 0; + } + return pthread_mutex_destroy(m); +} int8_t _z_mutex_lock(_z_mutex_t *m) { return pthread_mutex_lock(m); } diff --git a/src/transport/multicast/lease.c b/src/transport/multicast/lease.c index 7661d0e87..3a62de042 100644 --- a/src/transport/multicast/lease.c +++ b/src/transport/multicast/lease.c @@ -189,13 +189,14 @@ void *_zp_multicast_lease_task(void *ztm_arg) { int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Init task + ztm->_lease_task_running = true; // Init before z_task_init for concurrency issue + // Init task if (_z_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) { + ztm->_lease_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task ztm->_lease_task = task; - ztm->_lease_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/multicast/read.c b/src/transport/multicast/read.c index 8c8784373..bc9c76f2c 100644 --- a/src/transport/multicast/read.c +++ b/src/transport/multicast/read.c @@ -130,13 +130,14 @@ void *_zp_multicast_read_task(void *ztm_arg) { int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Init task + zt->_transport._multicast._read_task_running = true; // Init before z_task_init for concurrency issue + // Init task if (_z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) { + zt->_transport._multicast._read_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task zt->_transport._multicast._read_task = task; - zt->_transport._multicast._read_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/raweth/read.c b/src/transport/raweth/read.c index 13c100621..5e85dc4a4 100644 --- a/src/transport/raweth/read.c +++ b/src/transport/raweth/read.c @@ -90,13 +90,14 @@ void *_zp_raweth_read_task(void *ztm_arg) { int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); + zt->_transport._unicast._lease_task_running = true; // Init before z_task_init for concurrency issue // Init task if (_z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) { + zt->_transport._unicast._lease_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task zt->_transport._raweth._read_task = task; - zt->_transport._raweth._read_task_running = true; return _Z_RES_OK; } diff --git a/src/transport/unicast/read.c b/src/transport/unicast/read.c index 8b1227aba..fbea2f6d8 100644 --- a/src/transport/unicast/read.c +++ b/src/transport/unicast/read.c @@ -123,13 +123,14 @@ void *_zp_unicast_read_task(void *ztu_arg) { int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, _z_task_t *task) { // Init memory (void)memset(task, 0, sizeof(_z_task_t)); - // Init task + zt->_transport._unicast._read_task_running = true; // Init before z_task_init for concurrency issue + // Init task if (_z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) { + zt->_transport._unicast._read_task_running = false; return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task zt->_transport._unicast._read_task = task; - zt->_transport._unicast._read_task_running = true; return _Z_RES_OK; } diff --git a/tests/fragment.py b/tests/fragment.py index d29295f0f..7b2a6f8d5 100644 --- a/tests/fragment.py +++ b/tests/fragment.py @@ -14,7 +14,7 @@ def check_output(tx_status, tx_output, rx_status, rx_output): # Expected rx output & status z_rx_expected_status = 0 z_rx_expected_output = ( - "[rx]: Received packet on test/zenoh-pico-fragment, len: 10000, validity: 1") + "[rx]: Received packet on test/zenoh-pico-fragment, len: 10000, validity: 1, qos {priority: 4, cong_ctrl: 0}") # Check the exit status of tx if tx_status == z_tx_expected_status: diff --git a/tests/z_client_test.c b/tests/z_client_test.c index ac3b631f4..0317c24fa 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -387,6 +387,13 @@ int main(int argc, char **argv) { z_sleep_s(SLEEP); + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_loan_mut(s1)); + zp_stop_lease_task(z_loan_mut(s1)); + + zp_stop_read_task(z_loan_mut(s2)); + zp_stop_lease_task(z_loan_mut(s2)); + // Close both sessions printf("Closing session 1\n"); z_close(z_move(s1)); diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index 2a6d98e45..5afebbbcb 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -178,6 +178,13 @@ int main(int argc, char **argv) { z_sleep_s(SLEEP); + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_loan_mut(s1)); + zp_stop_lease_task(z_loan_mut(s1)); + + zp_stop_read_task(z_loan_mut(s2)); + zp_stop_lease_task(z_loan_mut(s2)); + // Close both sessions printf("Closing session 1\n"); z_close(z_move(s1)); diff --git a/tests/z_perf_tx.c b/tests/z_perf_tx.c index 906ec2aa1..4c8c7cd0a 100644 --- a/tests/z_perf_tx.c +++ b/tests/z_perf_tx.c @@ -106,6 +106,11 @@ int main(int argc, char **argv) { z_bytes_from_buf(&payload, value, 1, NULL, NULL); z_publisher_put(z_loan(pub), z_move(payload), NULL); + + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_loan_mut(s)); + zp_stop_lease_task(z_loan_mut(s)); + // Clean up z_undeclare_publisher(z_move(pub)); z_close(z_move(s)); diff --git a/tests/z_session_test.c b/tests/z_session_test.c index a78f89a3f..4b662d0a0 100644 --- a/tests/z_session_test.c +++ b/tests/z_session_test.c @@ -17,6 +17,7 @@ #include #include "zenoh-pico.h" +#include "zenoh-pico/api/macros.h" #undef NDEBUG #include @@ -43,6 +44,10 @@ int main(void) { // Commented out wait for 1 second. Stopping should work without it. // z_sleep_ms(1000); + // Stop read and lease tasks for zenoh-pico + zp_stop_read_task(z_loan_mut(s)); + zp_stop_lease_task(z_loan_mut(s)); + // Immediately close the session z_close(&s); } diff --git a/tests/z_test_fragment_rx.c b/tests/z_test_fragment_rx.c index 8edaa5a96..a122fb704 100644 --- a/tests/z_test_fragment_rx.c +++ b/tests/z_test_fragment_rx.c @@ -33,8 +33,9 @@ void data_handler(const z_loaned_sample_t *sample, void *ctx) { break; } } - printf("[rx]: Received packet on %s, len: %d, validity: %d\n", z_string_data(z_loan(keystr)), (int)data_len, - is_valid); + printf("[rx]: Received packet on %s, len: %d, validity: %d, qos {priority: %d, cong_ctrl: %d}\n", + z_string_data(z_loan(keystr)), (int)data_len, is_valid, z_qos_get_priority(sample->qos), + z_qos_get_congestion_control(sample->qos)); z_drop(z_move(value)); } diff --git a/tests/z_test_fragment_tx.c b/tests/z_test_fragment_tx.c index 07ed301b0..bf12b18dc 100644 --- a/tests/z_test_fragment_tx.c +++ b/tests/z_test_fragment_tx.c @@ -76,13 +76,19 @@ int main(int argc, char **argv) { // Put data z_view_keyexpr_t ke; z_view_keyexpr_from_str(&ke, keyexpr); + + z_put_options_t options; + z_put_options_default(&options); + options.priority = Z_PRIORITY_DATA_HIGH; + options.congestion_control = Z_CONGESTION_CONTROL_BLOCK; + for (int i = 0; i < 5; i++) { // Create payload z_owned_bytes_t payload; z_bytes_from_buf(&payload, value, size, NULL, NULL); printf("[tx]: Sending packet on %s, len: %d\n", keyexpr, (int)size); - if (z_put(z_loan(s), z_loan(ke), z_move(payload), NULL) < 0) { + if (z_put(z_loan(s), z_loan(ke), z_move(payload), &options) < 0) { printf("Oh no! Put has failed...\n"); return -1; } diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt new file mode 100644 index 000000000..3559a1c90 --- /dev/null +++ b/zephyr/CMakeLists.txt @@ -0,0 +1,45 @@ +if(CONFIG_ZENOH_PICO) + +zephyr_compile_definitions(ZENOH_ZEPHYR) +zephyr_include_directories(../include) +zephyr_library() + +function(configure_zenoh_feature config) + string(REPLACE CONFIG_ZENOH_PICO Z_FEATURE feature ${config}) + if(${config}) + zephyr_compile_definitions(${feature}=1) + else() + zephyr_compile_definitions(${feature}=0) + endif() +endfunction() + + +configure_zenoh_feature(CONFIG_ZENOH_PICO_LINK_SERIAL) +configure_zenoh_feature(CONFIG_ZENOH_PICO_MULTI_THREAD) +configure_zenoh_feature(CONFIG_ZENOH_PICO_PUBLICATION) +configure_zenoh_feature(CONFIG_ZENOH_PICO_SUBSCRIPTION) +configure_zenoh_feature(CONFIG_ZENOH_PICO_QUERY) +configure_zenoh_feature(CONFIG_ZENOH_PICO_QUERYABLE) +configure_zenoh_feature(CONFIG_ZENOH_PICO_RAWETH_TRANSPORT) +configure_zenoh_feature(CONFIG_ZENOH_PICO_LINK_TCP) +configure_zenoh_feature(CONFIG_ZENOH_PICO_LINK_UDP_UNICAST) +configure_zenoh_feature(CONFIG_ZENOH_PICO_LINK_UDP_MULTICAST) +configure_zenoh_feature(CONFIG_ZENOH_PICO_SCOUTING_UDP) +configure_zenoh_feature(CONFIG_ZENOH_PICO_LINK_WS) + + +file(GLOB_RECURSE Sources + "../src/api/*.c" + "../src/collections/*.c" + "../src/link/*.c" + "../src/net/*.c" + "../src/protocol/*.c" + "../src/session/*.c" + "../src/transport/*.c" + "../src/utils/*.c" +) + +file (GLOB Sources_Zephyr "../src/system/zephyr/*.c") +list(APPEND Sources ${Sources_Zephyr}) +zephyr_library_sources(${Sources}) +endif() diff --git a/zephyr/Kconfig.zenoh b/zephyr/Kconfig.zenoh new file mode 100644 index 000000000..fce27a370 --- /dev/null +++ b/zephyr/Kconfig.zenoh @@ -0,0 +1,69 @@ +config ZENOH_PICO + bool "Zenoh PICO library" + help + Enable Zenoh pico support + +if ZENOH_PICO + +config ZENOH_PICO_LINK_SERIAL + bool "Serial Link" + help + Use serial link + +config ZENOH_PICO_MULTI_THREAD + bool "Multithreading support" + help + Multithreading support + +config ZENOH_PICO_PUBLICATION + bool "Publication Support" + help + Publication support + +config ZENOH_PICO_SUBSCRIPTION + bool "Subscription Support" + help + Subscription Support + +config ZENOH_PICO_QUERY + bool "Query Support" + help + Query Support + +config ZENOH_PICO_QUERYABLE + bool "Queryable Support" + help + Queryable Support + +config ZENOH_PICO_RAWETH_TRANSPORT + bool "Raw Ethernet Support" + help + Raw Ethernet Support + +config ZENOH_PICO_LINK_TCP + bool "TCP Link" + help + TCP Link + +config ZENOH_PICO_LINK_UDP_UNICAST + bool "UDP Unicast" + help + UDP Unicast + +config ZENOH_PICO_LINK_UDP_MULTICAST + bool "UDP Multicast" + help + UDP Multicast + +config ZENOH_PICO_SCOUTING_UDP + bool "Scouting UDP" + help + Scouting UDP + +config ZENOH_PICO_LINK_WS + bool "WS Link" + help + WS Link + +endif + diff --git a/zephyr/module.yml b/zephyr/module.yml index 31f5d4f30..507856e5e 100644 --- a/zephyr/module.yml +++ b/zephyr/module.yml @@ -1,4 +1,4 @@ name: zenoh-pico build: - cmake-ext: True - kconfig-ext: True + cmake: zephyr/ + kconfig: zephyr/Kconfig.zenoh