lexus2k/tinyproto

Unable to connect to tinyproto after second connection.

Watayut opened this issue · 1 comments

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.

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?