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

Unable to connect to tinyproto after second connection. #42

Open
Watayut opened this issue Sep 6, 2022 · 1 comment
Open

Unable to connect to tinyproto after second connection. #42

Watayut opened this issue Sep 6, 2022 · 1 comment

Comments

@Watayut
Copy link

Watayut commented Sep 6, 2022

I found this issue when I ported the library to my target board, then I tried to reproduce this issue with your example code.

My Setup

I created virtual serial port and run 2 tiny_loopbacks example to communicate with each other. With your example I can close one program and restart it without any issue. But after I added couple of delay to generator side, I found the issue.

Virtual Serial port
socat -d -d pty,raw,echo=0 pty,raw,echo=0

Generator side
$TINYPROTO_EXAMPLE_PATH/linux/loopback/tiny_loopback -p /dev/pts/30 -g

Loopback side
$TINYPROTO_EXAMPLE_PATH/linux/loopback/tiny_loopback -p /dev/pts/31

Build

rm -rf build &&
mkdir build &&
cd build &&
cmake -DENABLE_FD_LOGS=ON -DEXAMPLES=ON ..
make

My edited code (tiny_loopback.cpp)
image

image

diff --git a/examples/linux/loopback/tiny_loopback.cpp b/examples/linux/loopback/tiny_loopback.cpp
index cf327fa..5176661 100644
--- a/examples/linux/loopback/tiny_loopback.cpp
+++ b/examples/linux/loopback/tiny_loopback.cpp
@@ -193,6 +193,8 @@ static int run_fd(tiny_serial_handle_t port)
     proto.setSendTimeout(s_generatorEnabled ? 1000 : 0);
     proto.setReceiveCallback(onReceiveFrameFd);
     proto.setSendCallback(onSendFrameFd);
+    proto.setConnectEventCallback([](void *userData, uint8_t addr, bool connected) -> void
+                                  { printf("peer %x, connected %d\n", addr, connected); });
     s_protoFd = &proto;
 
     proto.begin();
@@ -227,6 +229,8 @@ static int run_fd(tiny_serial_handle_t port)
             {
                 fprintf(stderr, "Failed to send packet\n");
             }
+
+            std::this_thread::sleep_for(std::chrono::milliseconds(1000));
         }
         else
         {

Result of first connection. (Left side is generator / Right side is loopback)
image

Result of second/third connection. (I close the generator side and restart it)
image
Generator side try to connect and then fail and the this loop happens repeatedly.

Do you have any clue or workaround for this issue?
Thanks.

@lexus2k
Copy link
Owner

lexus2k commented Jun 18, 2023

I was trying to reproduce the issues but I failed. Adding delay from your commit doesn't cause any issues with communication.
If you have any automatic script to reproduce the issue, please let me know.

PS. There are 2 branches supported: master branch and cpp_api. Could you please check if cpp_api has the same issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants