Skip to content

Commit 5bd9b96

Browse files
committed
Update serial protocol
1 parent d40b2c2 commit 5bd9b96

File tree

33 files changed

+592
-591
lines changed

33 files changed

+592
-591
lines changed

.github/workflows/arduino_esp32.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
5252
mkdir -p $ARDUINO_BASE
5353
cd $ARDUINO_BASE
54-
platformio init -b esp32thing_plus -O "board_build.cmake_extra_args=-DZ_FEATURE_LINK_BLUETOOTH=1" -O "build_flags=-DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC" -O "lib_ldf_mode=deep+"
54+
platformio init -b esp32thing_plus -O "board_build.cmake_extra_args=-DZ_FEATURE_LINK_BLUETOOTH=1 -DZ_FEATURE_LINK_SERIAL=1" -O "build_flags=-DZENOH_DEBUG=3 -DZENOH_COMPILER_GCC" -O "lib_ldf_mode=deep+"
5555
5656
cd $ARDUINO_BASE/lib
5757
ln -s $ZENOH_PICO_BASE

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ file(GLOB_RECURSE Sources
343343
"src/session/*.c"
344344
"src/transport/*.c"
345345
"src/utils/*.c"
346-
"src/system/platform_common.c"
346+
"src/system/common/*.c"
347347
)
348348

349349
if(WITH_ZEPHYR)

examples/rpi_pico/main.c

+3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ void print_ip_address() {
4444

4545
void main_task(void *params) {
4646
(void)params;
47+
#ifndef NDEBUG
4748
vTaskDelay(pdMS_TO_TICKS(3000));
49+
#endif
50+
4851
#if WIFI_SUPPORT_ENABLED
4952
if (cyw43_arch_init()) {
5053
printf("Failed to initialise\n");

include/zenoh-pico/collections/arc_slice.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "refcount.h"
2424
#include "slice.h"
25-
#include "zenoh-pico/system/platform_common.h"
25+
#include "zenoh-pico/system/common/platform.h"
2626

2727
#ifdef __cplusplus
2828
extern "C" {
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Copyright (c) 2024 ZettaScale Technology
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
//
11+
// Contributors:
12+
// ZettaScale Zenoh Team, <[email protected]>
13+
//
14+
15+
#ifndef INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_SERIAL_H
16+
#define INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_SERIAL_H
17+
18+
#include <stdint.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
size_t _z_serial_msg_serialize(uint8_t *dest, size_t dest_len, const uint8_t *src, size_t src_len, uint8_t header,
25+
uint8_t *tmp_buf, size_t tmp_buf_len);
26+
size_t _z_serial_msg_deserialize(const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, uint8_t *header,
27+
uint8_t *tmp_buf, size_t tmp_buf_len);
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_SERIAL_H */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Copyright (c) 2022 ZettaScale Technology
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
//
11+
// Contributors:
12+
// ZettaScale Zenoh Team, <[email protected]>
13+
//
14+
15+
#ifndef INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_SERIAL_H
16+
#define INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_SERIAL_H
17+
18+
#include <stdint.h>
19+
20+
#include "zenoh-pico/link/endpoint.h"
21+
#include "zenoh-pico/protocol/definitions/network.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/// ZSerial Frame Format
28+
///
29+
/// Using COBS
30+
///
31+
/// +-+-+----+------------+--------+-+
32+
/// |O|H|XXXX|ZZZZ....ZZZZ|CCCCCCCC|0|
33+
/// +-+----+------------+--------+-+
34+
/// |O| |Len | Data | CRC32 |C|
35+
/// +-+-+-2--+----N-------+---4----+-+
36+
///
37+
/// Header: 1byte
38+
/// +---------------+
39+
/// |7|6|5|4|3|2|1|0|
40+
/// +---------------+
41+
/// |x|x|x|x|x|R|A|I|
42+
/// +---------------+
43+
///
44+
/// Flags:
45+
/// I - Init
46+
/// A - Ack
47+
/// R - Reset
48+
///
49+
/// Max Frame Size: 1510
50+
/// Max MTU: 1500
51+
/// Max On-the-wire length: 1516 (MFS + Overhead Byte (OHB) + Kind Byte + End of packet (EOP))
52+
53+
#define _Z_FLAG_SERIAL_INIT 0x01
54+
#define _Z_FLAG_SERIAL_ACK 0x02
55+
#define _Z_FLAG_SERIAL_RESET 0x04
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
60+
61+
#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_SERIAL_H*/
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// Copyright (c) 2024 ZettaScale Technology
3+
//
4+
// This program and the accompanying materials are made available under the
5+
// terms of the Eclipse Public License 2.0 which is available at
6+
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7+
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8+
//
9+
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10+
//
11+
// Contributors:
12+
// ZettaScale Zenoh Team, <[email protected]>
13+
//
14+
15+
#ifndef ZENOH_PICO_SYSTEM_COMMON_SERIAL_H
16+
#define ZENOH_PICO_SYSTEM_COMMON_SERIAL_H
17+
18+
#include <stdint.h>
19+
20+
#include "zenoh-pico/system/common/platform.h"
21+
#include "zenoh-pico/utils/result.h"
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
z_result_t _z_connect_serial(const _z_sys_net_socket_t sock);
28+
size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len);
29+
size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len);
30+
size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len);
31+
32+
#ifdef __cplusplus
33+
}
34+
#endif
35+
36+
#endif /* ZENOH_PICO_SYSTEM_COMMON_SERIAL_H */

include/zenoh-pico/system/link/serial.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extern "C" {
2828
#if Z_FEATURE_LINK_SERIAL == 1
2929

3030
#define _Z_SERIAL_MTU_SIZE 1500
31-
#define _Z_SERIAL_MFS_SIZE _Z_SERIAL_MTU_SIZE + 2 + 4 // MTU + Serial Len + Serial CRC32
31+
#define _Z_SERIAL_MFS_SIZE _Z_SERIAL_MTU_SIZE + 1 + 2 + 4 // MTU + Header + Serial Len + Serial CRC32
3232
#define _Z_SERIAL_MAX_COBS_BUF_SIZE \
3333
1516 // Max On-the-wire length for an MFS/MTU of 1510/1500 (MFS + Overhead Byte (OHB) + End of packet (EOP))
3434

@@ -42,8 +42,8 @@ z_result_t _z_listen_serial_from_pins(_z_sys_net_socket_t *sock, uint32_t txpin,
4242
z_result_t _z_listen_serial_from_dev(_z_sys_net_socket_t *sock, char *dev, uint32_t baudrate);
4343
void _z_close_serial(_z_sys_net_socket_t *sock);
4444
size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len);
45-
size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len);
46-
size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len);
45+
size_t _z_read_serial_internal(const _z_sys_net_socket_t sock, uint8_t *header, uint8_t *ptr, size_t len);
46+
size_t _z_send_serial_internal(const _z_sys_net_socket_t sock, uint8_t header, const uint8_t *ptr, size_t len);
4747

4848
#endif
4949

include/zenoh-pico/system/platform.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
#include <stdint.h>
1919

2020
#include "zenoh-pico/config.h"
21-
#include "zenoh-pico/system/platform_common.h"
21+
#include "zenoh-pico/system/common/platform.h"
2222

2323
#endif /* ZENOH_PICO_SYSTEM_PLATFORM_H */

include/zenoh-pico/system/platform/arduino/esp32.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ typedef struct {
4747
BluetoothSerial *_bts; // As pointer to cross the boundary between C and C++
4848
#endif
4949
#if Z_FEATURE_LINK_SERIAL == 1
50-
HardwareSerial *_serial; // As pointer to cross the boundary between C and C++
50+
struct {
51+
HardwareSerial *_serial; // As pointer to cross the boundary between C and C++
52+
uint8_t *tmp_buf;
53+
uint8_t *raw_buf;
54+
};
5155
#endif
5256
};
5357
} _z_sys_net_socket_t;

include/zenoh-pico/system/platform/espidf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ typedef struct {
5858
#if Z_FEATURE_LINK_SERIAL == 1
5959
struct {
6060
uart_port_t _serial;
61-
uint8_t *before_cobs;
62-
uint8_t *after_cobs;
61+
uint8_t *tmp_buf;
62+
uint8_t *raw_buf;
6363
};
6464
#endif
6565
};

include/zenoh-pico/system/platform/flipper.h

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ typedef struct {
4444
#if Z_FEATURE_LINK_SERIAL == 1
4545
FuriStreamBuffer* _rx_stream;
4646
FuriHalSerialHandle* _serial;
47+
uint8_t* tmp_buf;
48+
uint8_t* raw_buf;
4749
#endif
4850
} _z_sys_net_socket_t;
4951

include/zenoh-pico/system/platform/mbed.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ typedef struct {
5151
UDPSocket *_udp; // As pointer to cross the boundary between C and C++
5252
#endif
5353
#if Z_FEATURE_LINK_SERIAL == 1
54-
BufferedSerial *_serial; // As pointer to cross the boundary between C and C++
54+
struct {
55+
BufferedSerial *_serial; // As pointer to cross the boundary between C and C++
56+
uint8_t *tmp_buf;
57+
uint8_t *raw_buf;
58+
};
5559
#endif
5660
};
5761
} _z_sys_net_socket_t;

include/zenoh-pico/system/platform/rpi_pico.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ typedef struct {
6161
int _fd;
6262
#endif
6363
#if Z_FEATURE_LINK_SERIAL == 1
64-
uart_inst_t *_serial;
64+
struct {
65+
uart_inst_t *_serial;
66+
uint8_t *tmp_buf;
67+
uint8_t *raw_buf;
68+
};
6569
#endif
6670
};
6771
} _z_sys_net_socket_t;

include/zenoh-pico/system/platform/zephyr.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ typedef struct {
5050
int _fd;
5151
#endif
5252
#if Z_FEATURE_LINK_SERIAL == 1
53-
const struct device *_serial;
53+
struct {
54+
const struct device *_serial;
55+
uint8_t *tmp_buf;
56+
uint8_t *raw_buf;
57+
};
5458
#endif
5559
};
5660
} _z_sys_net_socket_t;

include/zenoh-pico/utils/logging.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include <stdio.h>
1919

20-
#include "zenoh-pico/system/platform_common.h"
20+
#include "zenoh-pico/system/common/platform.h"
2121

2222
#ifdef __cplusplus
2323
extern "C" {

src/api/api.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#include "zenoh-pico/session/resource.h"
3838
#include "zenoh-pico/session/subscription.h"
3939
#include "zenoh-pico/session/utils.h"
40+
#include "zenoh-pico/system/common/platform.h"
4041
#include "zenoh-pico/system/platform.h"
41-
#include "zenoh-pico/system/platform_common.h"
4242
#include "zenoh-pico/transport/common/tx.h"
4343
#include "zenoh-pico/transport/multicast.h"
4444
#include "zenoh-pico/transport/unicast.h"

src/link/unicast/serial.c

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "zenoh-pico/config.h"
2222
#include "zenoh-pico/link/manager.h"
23+
#include "zenoh-pico/system/common/serial.h"
2324
#include "zenoh-pico/system/link/serial.h"
2425
#include "zenoh-pico/utils/pointers.h"
2526

0 commit comments

Comments
 (0)