diff --git a/src/protocol/codec/serial.c b/src/protocol/codec/serial.c index b5c0e0b4a..76356ecdd 100644 --- a/src/protocol/codec/serial.c +++ b/src/protocol/codec/serial.c @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // +#include #include #include @@ -108,7 +109,7 @@ size_t _z_serial_msg_deserialize(const uint8_t *src, size_t src_len, uint8_t *ds uint32_t computed_crc = _z_crc32(dst, wire_size); if (received_crc != computed_crc) { - _Z_DEBUG("CRC mismatch. Received: 0x%08lX, Computed: 0x%08lX", received_crc, computed_crc); + _Z_DEBUG("CRC mismatch. Received: 0x%08" PRIu32 ", Computed: 0x%08" PRIu32, received_crc, computed_crc); return SIZE_MAX; } diff --git a/src/system/common/serial.c b/src/system/common/serial.c index 2104818ea..de1e44450 100644 --- a/src/system/common/serial.c +++ b/src/system/common/serial.c @@ -12,10 +12,9 @@ // ZettaScale Zenoh Team, // -#include "zenoh-pico/protocol/definitions/serial.h" - #include +#include "zenoh-pico/protocol/definitions/serial.h" #include "zenoh-pico/system/common/platform.h" #include "zenoh-pico/system/common/serial.h" #include "zenoh-pico/system/link/serial.h" @@ -23,6 +22,8 @@ #include "zenoh-pico/utils/pointers.h" #include "zenoh-pico/utils/result.h" +#if Z_FEATURE_LINK_SERIAL == 1 + #define SERIAL_CONNECT_THROTTLE_TIME_MS 250 z_result_t _z_connect_serial(const _z_sys_net_socket_t sock) { @@ -30,8 +31,7 @@ z_result_t _z_connect_serial(const _z_sys_net_socket_t sock) { uint8_t header = _Z_FLAG_SERIAL_INIT; _z_send_serial_internal(sock, header, NULL, 0); - uint8_t tmp; - size_t ret = _z_read_serial_internal(sock, &header, &tmp, sizeof(tmp)); + size_t ret = _z_read_serial_internal(sock, &header, NULL, 0); if (ret == SIZE_MAX) { return _Z_ERR_TRANSPORT_RX_FAILED; } @@ -78,3 +78,4 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t return n; } +#endif // Z_FEATURE_LINK_SERIAL == 1 diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index fd827c620..a87c258e4 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -1977,7 +1977,7 @@ void scouting_message(void) { _z_wbuf_clear(&wbf); } -void test_serialize_deserialize() { +void test_serialize_deserialize(void) { uint8_t src_data[] = "Test\0Payload\0Data"; size_t src_len = sizeof(src_data) - 1; uint8_t header = 0xAB; @@ -1985,13 +1985,13 @@ void test_serialize_deserialize() { uint8_t deserialized[256] = {0}; uint8_t tmp_buf[256] = {0}; - int serialized_len = + size_t serialized_len = _z_serial_msg_serialize(serialized, sizeof(serialized), src_data, src_len, header, tmp_buf, sizeof(tmp_buf)); assert(serialized_len > 0); uint8_t decoded_header = 0; - int deserialized_len = _z_serial_msg_deserialize(serialized, serialized_len, deserialized, sizeof(deserialized), - &decoded_header, tmp_buf, sizeof(tmp_buf)); + size_t deserialized_len = _z_serial_msg_deserialize(serialized, serialized_len, deserialized, sizeof(deserialized), + &decoded_header, tmp_buf, sizeof(tmp_buf)); assert(deserialized_len != SIZE_MAX); assert(decoded_header == header); @@ -2000,14 +2000,14 @@ void test_serialize_deserialize() { assert(memcmp(src_data, deserialized, src_len) == 0); } -void test_crc_mismatch() { +void test_crc_mismatch(void) { uint8_t src_data[] = "Test\0Payload\0Data"; size_t src_len = sizeof(src_data) - 1; uint8_t header = 0xCD; uint8_t serialized[256] = {0}; uint8_t tmp_buf[256] = {0}; - int serialized_len = + size_t serialized_len = _z_serial_msg_serialize(serialized, sizeof(serialized), src_data, src_len, header, tmp_buf, sizeof(tmp_buf)); assert(serialized_len != SIZE_MAX); @@ -2015,27 +2015,27 @@ void test_crc_mismatch() { uint8_t decoded_header = 0; uint8_t deserialized[256] = {0}; - int deserialized_len = _z_serial_msg_deserialize(serialized, serialized_len, deserialized, sizeof(deserialized), - &decoded_header, tmp_buf, sizeof(tmp_buf)); + size_t deserialized_len = _z_serial_msg_deserialize(serialized, serialized_len, deserialized, sizeof(deserialized), + &decoded_header, tmp_buf, sizeof(tmp_buf)); assert(deserialized_len == SIZE_MAX); } -void test_buffer_too_small() { +void test_buffer_too_small(void) { uint8_t src_data[] = "Test\0Payload\0Data"; size_t src_len = sizeof(src_data) - 1; uint8_t header = 0xEF; uint8_t serialized[256] = {0}; uint8_t tmp_buf[256] = {0}; - int serialized_len = + size_t serialized_len = _z_serial_msg_serialize(serialized, sizeof(serialized), src_data, src_len, header, tmp_buf, sizeof(tmp_buf)); assert(serialized_len != SIZE_MAX); uint8_t decoded_header = 0; uint8_t deserialized[4] = {0}; // Too small - int deserialized_len = _z_serial_msg_deserialize(serialized, serialized_len, deserialized, sizeof(deserialized), - &decoded_header, tmp_buf, sizeof(tmp_buf)); + size_t deserialized_len = _z_serial_msg_deserialize(serialized, serialized_len, deserialized, sizeof(deserialized), + &decoded_header, tmp_buf, sizeof(tmp_buf)); assert(deserialized_len == SIZE_MAX); } diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index f358d4659..5296ba8ff 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -37,7 +37,7 @@ file(GLOB_RECURSE Sources "../src/session/*.c" "../src/transport/*.c" "../src/utils/*.c" - "../src/system/platform_common.c" + "../src/system/common/*.c" ) file (GLOB Sources_Zephyr "../src/system/zephyr/*.c")