Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update and improve serial protocol #823

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

sashacmc
Copy link
Member

@sashacmc sashacmc commented Dec 9, 2024

Zenoh Pico side serial protocol changes for serial reopening
ZettaScaleLabs/z-serial#9
eclipse-zenoh/zenoh#1624

Additionally, common code has been moved to a common module

Copy link

github-actions bot commented Dec 9, 2024

PR missing one of the required labels: {'internal', 'breaking-change', 'new feature', 'documentation', 'bug', 'enhancement', 'dependencies'}

@sashacmc sashacmc force-pushed the update_serial_protocol branch from 912084b to 5bd9b96 Compare December 10, 2024 15:51
@sashacmc sashacmc marked this pull request as ready for review December 10, 2024 15:51
@sashacmc sashacmc requested a review from jean-roland December 10, 2024 15:51
@sashacmc sashacmc changed the title Update serial protocol Update and improve serial protocol Dec 10, 2024
@sashacmc sashacmc force-pushed the update_serial_protocol branch 2 times, most recently from 0cd15d8 to db8702a Compare December 11, 2024 08:14
@sashacmc sashacmc force-pushed the update_serial_protocol branch from db8702a to 6207fdf Compare December 11, 2024 08:21
@sashacmc sashacmc requested a review from jean-roland December 11, 2024 08:59
@gabrik gabrik merged commit 64cd525 into eclipse-zenoh:main Dec 11, 2024
64 checks passed
@gabrik gabrik deleted the update_serial_protocol branch December 11, 2024 10:49
@ur8us
Copy link

ur8us commented Dec 11, 2024

Hi! Tried today's main branches of zenoh and zenoh-pico on the RPI Pico2:

2024-12-11T17:14:15.867800Z DEBUG acc-0 ThreadId(12) mio_serial: opening serial port in synchronous blocking mode    
2024-12-11T17:14:15.868211Z DEBUG acc-0 ThreadId(12) mio_serial: switching /dev/ttyACM0 to asynchronous mode    
2024-12-11T17:14:15.868234Z DEBUG acc-0 ThreadId(12) mio_serial: setting VMIN = 1    
2024-12-11T17:14:15.868244Z DEBUG acc-0 ThreadId(12) mio_serial: setting O_NONBLOCK flag    
2024-12-11T17:14:23.530441Z ERROR acc-0 ThreadId(12) zenoh_link_serial::unicast: Read error on Serial link serial//dev/ttyACM0 => serial/22827996-7bf6-4434-9846-e583af8a73b8: Unexpected Init flag in message at io/zenoh-links/zenoh-link-serial/src/unicast.rs:164.
2024-12-11T17:14:23.530458Z DEBUG acc-0 ThreadId(12) zenoh_transport::unicast::establishment::accept: Read error on Serial link serial//dev/ttyACM0 => serial/22827996-7bf6-4434-9846-e583af8a73b8: Read error on Serial link serial//dev/ttyACM0 => serial/22827996-7bf6-4434-9846-e583af8a73b8: Unexpected Init flag in message at io/zenoh-links/zenoh-link-serial/src/unicast.rs:164. at io/zenoh-links/zenoh-link-serial/src/unicast.rs:167.
2024-12-11T17:14:23.646821Z DEBUG acc-0 ThreadId(12) mio_serial: opening serial port in synchronous blocking mode    
2024-12-11T17:14:23.647273Z DEBUG acc-0 ThreadId(12) mio_serial: switching /dev/ttyACM0 to asynchronous mode    

Desynchronized versions? :-(

zenoh-pico:

cmake -Bbuild -DPICO_BOARD="pico2" -DZENOH_CONFIG_CONNECT="serial/8.9#baudrate=115200" -DZENOH_CONFIG_MODE=client 

zenoh:

cargo build --release --bin zenohd  --no-default-features --features transport_tcp --features transport_serial

Run:

RUST_LOG=debug ./target/release/zenohd  -l "serial//dev/ttyACM0#baudrate=115200" -l "tcp/127.0.0.1:7447" --cfg='plugins/storage_manager/storages/demo:{key_expr:"turtle1/cmd_vel",volume:"memory"}'

@sashacmc
Copy link
Member Author

RUST_LOG=debug ./target/release/zenohd  -l "serial//dev/ttyACM0#baudrate=115200" -l "tcp/127.0.0.1:7447" --cfg='plugins/storage_manager/storages/demo:{key_expr:"turtle1/cmd_vel",volume:"memory"}'

Are you sure ttyACM0 is connected to pins 8.9?
This looks more like the USB serial that is provided by the Raspberry Pi Pico and where stdout goes by default.

@ur8us
Copy link

ur8us commented Dec 11, 2024

Absolutely, pins 8.9.

I tried 115200 and 38400 at the rpi pico2 side, in both cases I get the following sequence on the serial terminal's screen when the microprocessor is restarted:

02 01 01 01 01 01 01 01 00

When both zenoh and zenoh-pico were configured for the 115200 baud, there was an error message ("Unexpected init flag").

With both configured to 38400, they were able to connect!

2024-12-11T20:35:38.992816Z DEBUG net-0 ThreadId(11) zenoh::net::runtime::orchestrator: Waiting for UDP datagram...
2024-12-11T20:35:39.093533Z DEBUG acc-0 ThreadId(12) mio_serial: opening serial port in synchronous blocking mode    
2024-12-11T20:35:39.094044Z DEBUG acc-0 ThreadId(12) mio_serial: switching /dev/ttyACM0 to asynchronous mode    
2024-12-11T20:35:39.094059Z DEBUG acc-0 ThreadId(12) mio_serial: setting VMIN = 1    
2024-12-11T20:35:39.094068Z DEBUG acc-0 ThreadId(12) mio_serial: setting O_NONBLOCK flag    
2024-12-11T20:35:42.198992Z DEBUG acc-0 ThreadId(12) zenoh_transport::unicast::manager: Will use Universal transport!
2024-12-11T20:35:42.201820Z DEBUG acc-0 ThreadId(12) zenoh::net::routing::router: New Face{2, 59}
2024-12-11T20:35:42.202057Z DEBUG acc-0 ThreadId(12) zenoh_transport::unicast::manager: New transport opened between 5f29e8c92eb273ae36ac524ffce9f73 and 59 - whatami: client, sn resolution: U32, initial sn: 159016982, qos: false, multilink: false, lowlatency: false
2024-12-11T20:35:42.202079Z DEBUG acc-0 ThreadId(12) zenoh_transport::unicast::establishment::accept: New transport link accepted from 59 to 5f29e8c92eb273ae36ac524ffce9f73: TransportLinkUnicast { link: Link { src: serial//dev/ttyACM0, dst: serial/1a5f52f7-08a4-4533-9bdb-a5a5c9936eea, mtu: 1500, is_reliable: false, is_streamed: false }, config: TransportLinkUnicastConfig { direction: Inbound, batch: BatchConfig { mtu: 1500, is_streamed: false, is_compression: false }, priorities: None, reliability: None } }
2024-12-11T20:35:42.219684Z DEBUG  rx-1 ThreadId(16) zenoh::net::routing::dispatcher::resource: Register resource demo/example/zenoh-pico-pub
2024-12-11T20:35:42.223813Z DEBUG  rx-0 ThreadId(15) zenoh::net::routing::dispatcher::interests: Face{2, 59} Declare interest 2 (demo/example/zenoh-pico-pub)

Back to 115200, error. Same 9 bytes in the serial terminal, although zenoh reports an error.

Very strange!

I will check with another hardware tomorrow.

Guys, thank you so much for making the serial channel work reliably! I really hope this will attract more people to using zenoh and zenoh-pico.

@ur8us
Copy link

ur8us commented Dec 11, 2024

Example file for the z-serial-0.3.1, rpi pico2 is at 115200.

dn@DN:~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/z-serial-0.3.1$ ./target/release/examples/serial-echo /dev/ttyACM0 -s -b 115200
Arguments: Args { port: "/dev/ttyACM0", server: true, baud_rate: 115200, interval: 1.0 }
Got error: Unexpected Init flag in message received [00, 00, 00, 00, 00, 00, 00, 00]

A serial terminal program still shows

02 01 01 01 01 01 01 01 00

@ur8us
Copy link

ur8us commented Dec 11, 2024

Forget it. There must be a problem in my serial-to-USB converter based on the RP2040 debug probe.

@ur8us
Copy link

ur8us commented Dec 12, 2024

Hello!

Another microprocessor: RP2350B. Another serial connection: 0.1. Another USB-to-serial: CH340.

Only the serial port name has changed in the system to /dev/ttyUSB0. Same bad behavior at 115200 baud with both zenoh and serial-echo example. Still works at 38400. :-)

This is very strange that I do not see any debug output from the other CDC port (the one which should be used as stdout for the microcontroller).

I will give up for now.

@ur8us
Copy link

ur8us commented Dec 13, 2024

Hello,

Just ported the latest version of the zenoh-pico library to the STM32/ThreadX platform. 115200 is OK, works with zenohd like a champ!

The cases when the zenoh router is not available during the call of the _z_connect_serial, or the router goes down during the serial session, still need some polishing on the zenoh-pico side, but at least the router itself behaves quite reliably.

Thank you for your great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Things could work better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants