Skip to content

Commit

Permalink
Update serial protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 10, 2024
1 parent d40b2c2 commit 5bd9b96
Show file tree
Hide file tree
Showing 33 changed files with 592 additions and 591 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/arduino_esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
mkdir -p $ARDUINO_BASE
cd $ARDUINO_BASE
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+"
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+"
cd $ARDUINO_BASE/lib
ln -s $ZENOH_PICO_BASE
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ file(GLOB_RECURSE Sources
"src/session/*.c"
"src/transport/*.c"
"src/utils/*.c"
"src/system/platform_common.c"
"src/system/common/*.c"
)

if(WITH_ZEPHYR)
Expand Down
3 changes: 3 additions & 0 deletions examples/rpi_pico/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ void print_ip_address() {

void main_task(void *params) {
(void)params;
#ifndef NDEBUG
vTaskDelay(pdMS_TO_TICKS(3000));
#endif

#if WIFI_SUPPORT_ENABLED
if (cyw43_arch_init()) {
printf("Failed to initialise\n");
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/collections/arc_slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "refcount.h"
#include "slice.h"
#include "zenoh-pico/system/platform_common.h"
#include "zenoh-pico/system/common/platform.h"

#ifdef __cplusplus
extern "C" {
Expand Down
33 changes: 33 additions & 0 deletions include/zenoh-pico/protocol/codec/serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Copyright (c) 2024 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_SERIAL_H
#define INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_SERIAL_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

size_t _z_serial_msg_serialize(uint8_t *dest, size_t dest_len, const uint8_t *src, size_t src_len, uint8_t header,
uint8_t *tmp_buf, size_t tmp_buf_len);
size_t _z_serial_msg_deserialize(const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_len, uint8_t *header,
uint8_t *tmp_buf, size_t tmp_buf_len);

#ifdef __cplusplus
}
#endif

#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_CODEC_SERIAL_H */
61 changes: 61 additions & 0 deletions include/zenoh-pico/protocol/definitions/serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Copyright (c) 2022 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_SERIAL_H
#define INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_SERIAL_H

#include <stdint.h>

#include "zenoh-pico/link/endpoint.h"
#include "zenoh-pico/protocol/definitions/network.h"

#ifdef __cplusplus
extern "C" {
#endif

/// ZSerial Frame Format
///
/// Using COBS
///
/// +-+-+----+------------+--------+-+
/// |O|H|XXXX|ZZZZ....ZZZZ|CCCCCCCC|0|
/// +-+----+------------+--------+-+
/// |O| |Len | Data | CRC32 |C|
/// +-+-+-2--+----N-------+---4----+-+
///
/// Header: 1byte
/// +---------------+
/// |7|6|5|4|3|2|1|0|
/// +---------------+
/// |x|x|x|x|x|R|A|I|
/// +---------------+
///
/// Flags:
/// I - Init
/// A - Ack
/// R - Reset
///
/// Max Frame Size: 1510
/// Max MTU: 1500
/// Max On-the-wire length: 1516 (MFS + Overhead Byte (OHB) + Kind Byte + End of packet (EOP))

#define _Z_FLAG_SERIAL_INIT 0x01
#define _Z_FLAG_SERIAL_ACK 0x02
#define _Z_FLAG_SERIAL_RESET 0x04

#ifdef __cplusplus
}
#endif

#endif /* INCLUDE_ZENOH_PICO_PROTOCOL_DEFINITIONS_SERIAL_H*/
File renamed without changes.
36 changes: 36 additions & 0 deletions include/zenoh-pico/system/common/serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright (c) 2024 ZettaScale Technology
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
//
// Contributors:
// ZettaScale Zenoh Team, <[email protected]>
//

#ifndef ZENOH_PICO_SYSTEM_COMMON_SERIAL_H
#define ZENOH_PICO_SYSTEM_COMMON_SERIAL_H

#include <stdint.h>

#include "zenoh-pico/system/common/platform.h"
#include "zenoh-pico/utils/result.h"

#ifdef __cplusplus
extern "C" {
#endif

z_result_t _z_connect_serial(const _z_sys_net_socket_t sock);
size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len);
size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len);
size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len);

#ifdef __cplusplus
}
#endif

#endif /* ZENOH_PICO_SYSTEM_COMMON_SERIAL_H */
6 changes: 3 additions & 3 deletions include/zenoh-pico/system/link/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#if Z_FEATURE_LINK_SERIAL == 1

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

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

#endif

Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/system/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#include <stdint.h>

#include "zenoh-pico/config.h"
#include "zenoh-pico/system/platform_common.h"
#include "zenoh-pico/system/common/platform.h"

#endif /* ZENOH_PICO_SYSTEM_PLATFORM_H */
6 changes: 5 additions & 1 deletion include/zenoh-pico/system/platform/arduino/esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ typedef struct {
BluetoothSerial *_bts; // As pointer to cross the boundary between C and C++
#endif
#if Z_FEATURE_LINK_SERIAL == 1
HardwareSerial *_serial; // As pointer to cross the boundary between C and C++
struct {
HardwareSerial *_serial; // As pointer to cross the boundary between C and C++
uint8_t *tmp_buf;
uint8_t *raw_buf;
};
#endif
};
} _z_sys_net_socket_t;
Expand Down
4 changes: 2 additions & 2 deletions include/zenoh-pico/system/platform/espidf.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ typedef struct {
#if Z_FEATURE_LINK_SERIAL == 1
struct {
uart_port_t _serial;
uint8_t *before_cobs;
uint8_t *after_cobs;
uint8_t *tmp_buf;
uint8_t *raw_buf;
};
#endif
};
Expand Down
2 changes: 2 additions & 0 deletions include/zenoh-pico/system/platform/flipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ typedef struct {
#if Z_FEATURE_LINK_SERIAL == 1
FuriStreamBuffer* _rx_stream;
FuriHalSerialHandle* _serial;
uint8_t* tmp_buf;
uint8_t* raw_buf;
#endif
} _z_sys_net_socket_t;

Expand Down
6 changes: 5 additions & 1 deletion include/zenoh-pico/system/platform/mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ typedef struct {
UDPSocket *_udp; // As pointer to cross the boundary between C and C++
#endif
#if Z_FEATURE_LINK_SERIAL == 1
BufferedSerial *_serial; // As pointer to cross the boundary between C and C++
struct {
BufferedSerial *_serial; // As pointer to cross the boundary between C and C++
uint8_t *tmp_buf;
uint8_t *raw_buf;
};
#endif
};
} _z_sys_net_socket_t;
Expand Down
6 changes: 5 additions & 1 deletion include/zenoh-pico/system/platform/rpi_pico.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ typedef struct {
int _fd;
#endif
#if Z_FEATURE_LINK_SERIAL == 1
uart_inst_t *_serial;
struct {
uart_inst_t *_serial;
uint8_t *tmp_buf;
uint8_t *raw_buf;
};
#endif
};
} _z_sys_net_socket_t;
Expand Down
6 changes: 5 additions & 1 deletion include/zenoh-pico/system/platform/zephyr.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ typedef struct {
int _fd;
#endif
#if Z_FEATURE_LINK_SERIAL == 1
const struct device *_serial;
struct {
const struct device *_serial;
uint8_t *tmp_buf;
uint8_t *raw_buf;
};
#endif
};
} _z_sys_net_socket_t;
Expand Down
2 changes: 1 addition & 1 deletion include/zenoh-pico/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <stdio.h>

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

#ifdef __cplusplus
extern "C" {
Expand Down
2 changes: 1 addition & 1 deletion src/api/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include "zenoh-pico/session/resource.h"
#include "zenoh-pico/session/subscription.h"
#include "zenoh-pico/session/utils.h"
#include "zenoh-pico/system/common/platform.h"
#include "zenoh-pico/system/platform.h"
#include "zenoh-pico/system/platform_common.h"
#include "zenoh-pico/transport/common/tx.h"
#include "zenoh-pico/transport/multicast.h"
#include "zenoh-pico/transport/unicast.h"
Expand Down
1 change: 1 addition & 0 deletions src/link/unicast/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "zenoh-pico/config.h"
#include "zenoh-pico/link/manager.h"
#include "zenoh-pico/system/common/serial.h"
#include "zenoh-pico/system/link/serial.h"
#include "zenoh-pico/utils/pointers.h"

Expand Down
Loading

0 comments on commit 5bd9b96

Please sign in to comment.