You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1500 lines
40 KiB

​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
4 months ago
​
​
4 months ago
​
​
4 months ago
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
4 months ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
4 months ago
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
4 months ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
4 months ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
4 months ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
​
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
​
​
​
​
​
​
4 months ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
​
4 months ago
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
Debug: log communication timing of sensors and the Ethernet2UART gateway DEBUG_COMMUNICATION is turned on in deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp only. It isn't defined project-wide, which would also enable the per-byte hex dumps of protocol.cpp and the serial transports. To turn it off, comment out the #define at the top of the two files. Gateway I/O thread (tag E2UART): - "IO: request #n (x B): NO reply in N ms": nothing within the reply window (E2UART_REPLY_TIMEOUT_MS). - "IO: request #n: reply x B, first byte N ms, done N ms": replies slower than 500 ms (E2UART_SLOW_REPLY_MS), or an incomplete packet. - "IO: late data x B, N ms after request #n": a reply that came after the window (now given to the parser of that request). - "IO stats 60 s [host:port]": requests, replies, first-byte avg/max, slow, without reply, late. Sensor (tag NODSEN): - "COMM: reply/NACK WM STG reply N ms": replies slower than 500 ms (LGS_SLOW_REPLY_MS), NACKs and commands that needed retries, with the time since the first attempt. - "COMM: no reply - WM STG attempt k/17 timed out after N ms": each attempt that timed out. - "COMM: command failed - ...": details next to "Communication Wait State TO!". - "COMM stats 60 s": replies, avg/max reply time, slow, timed-out attempts (with the wait per attempt), failed commands. The gateway's per-chunk "Send/Read x bytes" debug lines are replaced by these per-request lines. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: reconnect when the device goes silent on a live connection Field log (sensor behind 2.54.237.28:8234): normal replies avg 129 ms, spikes up to 2.6 s handled. Then no reply at all to 19 requests in a row while the TCP connection stayed "up" (sending never failed). The sensor failed after 17 attempts and kept using the dead connection. A dead mobile/NAT path isn't reported by the kernel for many minutes, and keepalive only probes idle connections. - TCP_USER_TIMEOUT 10 s (E2UART_TCP_USER_TIMEOUT_MS): sent data not acknowledged by the gateway drops the connection. - After 5 requests in a row (E2UART_NO_REPLY_RECONNECT) without a single reply byte, the I/O thread ends ("No reply to 5 requests in a row - reconnecting to the gateway"). validate() sees the lost link and opens a new connection. Late data resets the count. - closePort() frees the requests still queued for the closed connection. - "NO reply" log lines (DEBUG_COMMUNICATION) and the reconnect error show TCP_INFO: unacked data, retransmits, rtt, last ACK / last data received. Unacked data and an old last ACK mean the network path is dead; ACKs that keep coming mean the gateway/device side doesn't answer. Tested with a fake device that goes silent after 3 replies while keeping the TCP connection open: the reconnect came after the 5th unanswered request, and requests 9-12 were answered on the new connection (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
12 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
​
4 months ago
Ethernet2UART gateway: wait long enough for the device's reply over the Internet "NODSEN: Communication Wait State TO!" with a sensor behind the gateway: in SERIAL_PING_PONG mode the I/O thread waited only 20 x 5 ms (~100 ms, a serial-line value) for the reply to a request, and did not read the socket while no request was queued. A reply slower than that, which is normal over a mobile link, stayed in the socket. It was read with the next request and given to that request's parser, so the sensor ran one reply behind, retried, and after 16 failed attempts reported the timeout. deviceETH2UART I/O thread (SERIAL_PING_PONG) - Waits up to E2UART_REPLY_TIMEOUT_MS (800 ms, below the sensor's 1 s per attempt) for the reply to start, and E2UART_REPLY_GAP_MS (150 ms) between the pieces of a reply split over several TCP segments. It is done as soon as the parser has a complete packet and no more data is waiting (as before). - Reads the socket also between requests. Late data goes to the parser of the last request at once. - Gives data only to a parser that is still bound to the transport (a sensor that disconnected or was deleted is no longer called). Serial resource casts (deviceNode2D, deviceNodeCamera) - dynamic_cast<basicTransport*> instead of static_cast through hardwareResourceSerialProvider. The resource can be a deviceETH2UART, and the old cast was only right because of a matching base-class layout. A NULL transport isn't bound. Tested with a fake device answering after 50/300/700 ms, also split into two TCP pieces. The old code delivered nothing, or the previous request's answer. Now each request gets its own answer (ASan clean). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
13 hours ago
4 months ago
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
​
​
4 months ago
​
​
​
4 months ago
​
​
​
​
​
​
​
4 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
4 months ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Ethernet2UART gateway: fix the reconnect loop, leaked connections and ping check From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234): deviceETH2UART - In TCP mode, link health is the TCP connection itself (socket, I/O thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on mobile networks often don't answer ping, and the working connection was closed every second ("No Ping to device!"). - Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an echo reply from the gateway with our id and sequence counts. A signal (EINTR) no longer ends the wait. The old single recvfrom() with SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART. - TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in select() continues waiting. - create_SOL() closes the previous socket and I/O thread first. It overwrote the socket (the connection leaked) and init() failed while the old thread ran, so each reconnect left an open TCP connection at the gateway and the node stayed invalid although "Connected". If init() fails, the new socket is closed. - create()/validate()/reconnect() are serialised: they run on the node factory thread and on the hardware manager thread. - Registered with the hardware manager once. Re-creation from the hardware manager locked its non-recursive list mutex again (deadlock). - Reconnect back-off 2 s -> 30 s. - recv() == 0 on TCP means the gateway closed the connection (a stale errno was checked before). - Destructor resigns from the hardware manager before closing. deviceNodeFactory - deleteNode() deletes the gateway object. It was only removed from the list and kept running next to the new node created for the same id. - Nodes are deleted after the validation loop (erasing inside it skipped the next node). deviceNode::validate - Compares the configuration only. "online" changes whenever another object of the same node id is created or deleted. hardwareManager::assignResource - Ignores a resource that is already assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
23 hours ago
​
  1. #include "deviceNodeEthernet2Serial.h"
  2. #include "../../data/protocol/protocol.h"
  3. #include "hardwareManager.h"
  4. #include <atomic>
  5. #include <netinet/tcp.h>
  6. #include <poll.h>
  7. #include <time.h>
  8. // #define DEBUG_EXTRA
  9. // #define DEBUG_SERIAL_COMMUNICATION
  10. // Request / reply timing of the I/O thread: no reply, slow and late replies, one-minute summary
  11. // #define DEBUG_COMMUNICATION // timing logs (see the commit "Debug: log communication timing ...")
  12. #ifndef E2UART_SLOW_REPLY_MS
  13. #define E2UART_SLOW_REPLY_MS 500
  14. #endif
  15. #define E2UART_TIMING_REPORT_MS 60000
  16. #define LOG(X) deviceNode::m_pLog->Log("E2UART", this, X)
  17. #ifdef DEBUG
  18. #define LOG_ERROR(X) \
  19. { \
  20. char _tBfrErrMSG2w34[1024]; \
  21. sprintf(_tBfrErrMSG2w34, "In file %s[%d] in func:%s %s", __FILE__, __LINE__, __func__, X); \
  22. deviceNode::m_pLog->Log("E2UART", this, _LOG_ERROR, _tBfrErrMSG2w34); \
  23. }
  24. #else
  25. #define LOG_ERROR(X) deviceNode::m_pLog->Log("E2UART", this, _LOG_ERROR, X);
  26. #endif
  27. deviceETH2UART::deviceETH2UART(uint32_t nodeID) :
  28. deviceNode(nodeID),
  29. hardwareResource(),
  30. basicTransport(),
  31. #ifdef SERIAL_PING_PONG
  32. basicThread()
  33. #else
  34. basicDualThread()
  35. #endif
  36. {
  37. // m_pLog = basicLogCollection::getInstance();
  38. memset(&m_sUartData, 0, sizeof(m_sUartData));
  39. #ifdef SERIAL_PING_PONG
  40. #else
  41. m_nInputBufferSize = 0;
  42. m_nOutputBufferSize = 0;
  43. #endif
  44. m_iDeviceFD = -1;
  45. m_iMasterFD = -1;
  46. m_iInFID = -1;
  47. m_iOutFID = -1;
  48. m_bRegistered = false;
  49. m_bConnecting = false;
  50. #ifdef SERIAL_PING_PONG
  51. m_pLastParser = NULL;
  52. #endif
  53. m_bLastPingOk = true;
  54. m_nNextPingMs = 0;
  55. m_nNextConnectMs = 0;
  56. m_nConnectBackoffMs = 0;
  57. hardwareResource::create(m_sNodeData.aux_parameter, HARDWARE_PROVIDER_SERIAL);
  58. }
  59. // Status of the I/O thread (sender thread in the dual-thread variant)
  60. #ifdef SERIAL_PING_PONG
  61. #define E2U_IO_STATUS m_bThreadStatus
  62. #else
  63. #define E2U_IO_STATUS m_bThreadAStatus
  64. #endif
  65. static uint64_t e2uNowMs(void)
  66. {
  67. struct timespec ts;
  68. clock_gettime(CLOCK_MONOTONIC, &ts);
  69. return (uint64_t) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
  70. }
  71. deviceETH2UART::~deviceETH2UART()
  72. {
  73. // Leave the hardware manager first: its validate() loop holds the resource list locked while it
  74. // calls validate() / create() on us, so once this returns it no longer uses this object
  75. hardwareManager * tH = hardwareManager::getInstance();
  76. if (tH)
  77. {
  78. tH->resignResource(this);
  79. }
  80. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  81. closePort();
  82. #ifdef SERIAL_PING_PONG
  83. m_mBufferProtectorMutex.lock();
  84. while (! m_qIO.empty())
  85. {
  86. free(m_qIO.front());
  87. m_qIO.pop();
  88. };
  89. m_mBufferProtectorMutex.unlock();
  90. #endif
  91. }
  92. bool deviceETH2UART::create(void)
  93. {
  94. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  95. DBC_UART_DATA * tDATA = NULL;
  96. if (m_sResourceSettings.id == 0)
  97. {
  98. return false;
  99. }
  100. if (m_sResourceSettings.aux_id == 0)
  101. {
  102. return false;
  103. }
  104. tDATA = deviceNode::m_pDBC->getUartData(m_sResourceSettings.aux_id);
  105. if (tDATA != NULL)
  106. {
  107. memcpy(&m_sUartData, tDATA, sizeof(DBC_UART_DATA));
  108. #ifdef DEBUG
  109. LOG(m_sUartData.path);
  110. #endif
  111. free(tDATA);
  112. // Also called by the hardware manager to re-create the resource: obeys the back-off
  113. m_bValid = connectSOL();
  114. };
  115. if (m_bValid && ! m_bRegistered)
  116. {
  117. // Once only: the hardware manager calls create() again with its resource list locked -
  118. // assigning from there locked the (non recursive) list mutex twice and added us twice
  119. hardwareManager * tH = hardwareManager::getInstance();
  120. if (tH)
  121. {
  122. tH->assignResource(this);
  123. m_bRegistered = true;
  124. }
  125. };
  126. return m_bValid;
  127. }
  128. /*
  129. Is the link to the gateway still up?
  130. - TCP (SOL_TCP_SERVER: we are the client): the TCP connection itself (socket, I/O thread and
  131. keepalive). ICMP is not used: gateways reached over the Internet (mobile networks, firewalls)
  132. often do not answer ping although the TCP port works - the working connection was closed every
  133. second ("No Ping to device!").
  134. - UDP: no connection state, ICMP echo (at most every E2UART_PING_INTERVAL_MS).
  135. */
  136. bool deviceETH2UART::linkAlive(void)
  137. {
  138. if (m_sUartData.mode == SOL_TCP_SERVER)
  139. {
  140. if (m_iDeviceFD < 0 || m_eConnectionStatus != CS_CONNECTED || E2U_IO_STATUS == TH_PRE_INIT || E2U_IO_STATUS >= TH_ENDED)
  141. {
  142. LOG_ERROR("TCP connection to the gateway lost");
  143. return false;
  144. };
  145. int tErr = 0;
  146. socklen_t tLen = sizeof(tErr);
  147. if (getsockopt(m_iDeviceFD, SOL_SOCKET, SO_ERROR, &tErr, &tLen) == 0 && tErr != 0)
  148. {
  149. char tB[160];
  150. snprintf(tB, sizeof(tB), "TCP connection to the gateway failed: %s", strerror(tErr));
  151. LOG_ERROR(tB);
  152. return false;
  153. };
  154. return true;
  155. };
  156. uint64_t tNow = e2uNowMs();
  157. if (tNow < m_nNextPingMs)
  158. {
  159. return m_bLastPingOk;
  160. };
  161. m_bLastPingOk = pingDevice();
  162. m_nNextPingMs = e2uNowMs() + E2UART_PING_INTERVAL_MS;
  163. return m_bLastPingOk;
  164. }
  165. bool deviceETH2UART::connectSOL(void)
  166. {
  167. uint64_t tNow = e2uNowMs();
  168. if (tNow < m_nNextConnectMs)
  169. {
  170. return false; // waiting for the next attempt (a gateway that is down is not hammered)
  171. };
  172. if (create_SOL())
  173. {
  174. m_nConnectBackoffMs = 0;
  175. m_nNextConnectMs = 0;
  176. m_nNextPingMs = 0;
  177. m_bLastPingOk = true;
  178. return true;
  179. };
  180. #ifdef SERIAL_PING_PONG
  181. // No connection: the queued requests are stale by the next attempt (the protocols query again)
  182. m_mBufferProtectorMutex.lock();
  183. while (! m_qIO.empty())
  184. {
  185. free(m_qIO.front());
  186. m_qIO.pop();
  187. };
  188. m_mBufferProtectorMutex.unlock();
  189. #endif
  190. m_nConnectBackoffMs = (m_nConnectBackoffMs == 0) ? E2UART_RECONNECT_MIN_MS : m_nConnectBackoffMs * 2;
  191. if (m_nConnectBackoffMs > E2UART_RECONNECT_MAX_MS)
  192. {
  193. m_nConnectBackoffMs = E2UART_RECONNECT_MAX_MS;
  194. };
  195. m_nNextConnectMs = e2uNowMs() + m_nConnectBackoffMs;
  196. return false;
  197. }
  198. bool deviceETH2UART::validate(void)
  199. {
  200. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  201. if (m_bValid)
  202. {
  203. m_bValid = linkAlive();
  204. if (! m_bValid)
  205. {
  206. LOG_ERROR("No connection to the device!");
  207. closePort();
  208. };
  209. };
  210. #ifdef DEBUG_EXTRA
  211. LOG("Check Settings For Changes");
  212. #endif
  213. DBC_UART_DATA * tDATA = deviceNode::m_pDBC->getUartData(m_sResourceSettings.aux_id);
  214. if (tDATA != NULL)
  215. {
  216. bool bFlag = true;
  217. if (strcmp(tDATA->path, m_sUartData.path) != 0)
  218. {
  219. bFlag = false;
  220. }
  221. // if( bFlag && ( m_sUartData.speed != tDATA->speed ) ) bFlag = false; //Speed for SOL port Erelevant
  222. if (bFlag && (m_sUartData.mode != tDATA->mode))
  223. {
  224. bFlag = false;
  225. }
  226. if (bFlag && (m_sUartData.port != tDATA->port))
  227. {
  228. bFlag = false;
  229. }
  230. if (! bFlag)
  231. {
  232. #ifdef DEBUG
  233. LOG("Settings Has been Changed!");
  234. #endif
  235. closePort(); // create_SOL() closes too; also stops the I/O thread of the old settings
  236. // Apply new settings
  237. memcpy(&m_sUartData, tDATA, sizeof(DBC_UART_DATA));
  238. #ifdef DEBUG
  239. LOG("Reconect with new settings");
  240. #endif
  241. m_nNextConnectMs = 0; // new address: no back-off
  242. m_bValid = connectSOL();
  243. };
  244. free(tDATA);
  245. }
  246. else
  247. {
  248. LOG_ERROR("Error Fetch DB Data!");
  249. };
  250. // Finally in any case If Not Connected -> try to Connect (after the back-off)
  251. if (! m_bValid && e2uNowMs() >= m_nNextConnectMs)
  252. {
  253. #ifdef DEBUG
  254. LOG("Try to Conncet");
  255. #endif
  256. m_bValid = connectSOL();
  257. };
  258. if (m_bValid)
  259. {
  260. m_bValid = deviceNode::validate();
  261. }
  262. return m_bValid;
  263. }
  264. #include <netinet/ip_icmp.h>
  265. // Define the Packet Constants
  266. // ping packet size
  267. #define PING_PKT_S 64
  268. // Automatic port number
  269. #define PORT_NO 0
  270. // Automatic port number
  271. #define PING_SLEEP_RATE 1000000
  272. // Gives the timeout delay for receiving packets
  273. // in seconds
  274. #define RECV_TIMEOUT 1
  275. // ping packet structure
  276. struct ping_pkt
  277. {
  278. struct icmphdr hdr;
  279. char msg[PING_PKT_S - sizeof(struct icmphdr)];
  280. };
  281. /*
  282. ICMP echo to the gateway: up to E2UART_PING_ATTEMPTS requests, each waiting E2UART_PING_TIMEOUT_MS.
  283. Before: one request and one recvfrom() (3 s - the 300 ms set first was overwritten). A single lost
  284. packet failed the check, a signal (EINTR) ended the wait at once, and ANY ICMP packet received by
  285. the raw socket (e.g. the reply to another gateway's ping) counted as the answer.
  286. Now only an echo reply from the gateway with our id and sequence number counts.
  287. */
  288. bool deviceETH2UART::pingDevice()
  289. {
  290. int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
  291. if (sockfd < 0)
  292. {
  293. char tB[160];
  294. snprintf(tB, sizeof(tB), "ICMP socket failed: %s (needs root / CAP_NET_RAW)", strerror(errno));
  295. LOG_ERROR(tB);
  296. return false;
  297. };
  298. int ttl_val = 64;
  299. if (setsockopt(sockfd, SOL_IP, IP_TTL, &ttl_val, sizeof(ttl_val)) != 0)
  300. {
  301. LOG_ERROR("Setting socket options to TTL failed!");
  302. close(sockfd);
  303. return false;
  304. };
  305. static std::atomic<uint16_t> s_nSequence(0);
  306. uint16_t tId = (uint16_t) (getpid() & 0xFFFF);
  307. char tReason[96] = "no reply";
  308. bool RetVal = false;
  309. for (int tAttempt = 0; tAttempt < E2UART_PING_ATTEMPTS && ! RetVal; tAttempt++)
  310. {
  311. RetVal = pingOnce(sockfd, tId, ++s_nSequence, tReason, sizeof(tReason));
  312. };
  313. close(sockfd);
  314. if (! RetVal)
  315. {
  316. char tB[256];
  317. snprintf(tB, sizeof(tB), "No ICMP reply from %.64s: %s (%d x %d ms)", m_sUartData.path, tReason, E2UART_PING_ATTEMPTS, E2UART_PING_TIMEOUT_MS);
  318. LOG_ERROR(tB);
  319. };
  320. return RetVal;
  321. }
  322. bool deviceETH2UART::pingOnce(int sockfd, uint16_t id, uint16_t seq, char * reason, size_t reasonSize)
  323. {
  324. struct ping_pkt pckt;
  325. struct sockaddr_in ping_addr;
  326. memset(&ping_addr, 0, sizeof(ping_addr));
  327. ping_addr.sin_family = AF_INET;
  328. ping_addr.sin_addr.s_addr = inet_addr(m_sUartData.path);
  329. memset(&pckt, 0, sizeof(pckt));
  330. pckt.hdr.type = ICMP_ECHO;
  331. pckt.hdr.un.echo.id = htons(id);
  332. pckt.hdr.un.echo.sequence = htons(seq);
  333. size_t i;
  334. for (i = 0; i < sizeof(pckt.msg) - 1; i++)
  335. {
  336. pckt.msg[i] = (char) i + '0';
  337. }
  338. pckt.msg[i] = 0;
  339. pckt.hdr.checksum = checksumPing(&pckt, sizeof(pckt));
  340. if (sendto(sockfd, &pckt, sizeof(pckt), 0, (struct sockaddr *) &ping_addr, sizeof(ping_addr)) <= 0)
  341. {
  342. snprintf(reason, reasonSize, "send failed: %s", strerror(errno));
  343. return false;
  344. };
  345. uint64_t tDeadline = e2uNowMs() + E2UART_PING_TIMEOUT_MS;
  346. for (;;)
  347. {
  348. uint64_t tNow = e2uNowMs();
  349. if (tNow >= tDeadline)
  350. {
  351. snprintf(reason, reasonSize, "timeout");
  352. return false;
  353. };
  354. struct pollfd tPfd;
  355. tPfd.fd = sockfd;
  356. tPfd.events = POLLIN;
  357. int tRc = poll(&tPfd, 1, (int) (tDeadline - tNow));
  358. if (tRc < 0)
  359. {
  360. if (errno == EINTR)
  361. {
  362. continue; // a signal is not a missing reply
  363. };
  364. snprintf(reason, reasonSize, "poll failed: %s", strerror(errno));
  365. return false;
  366. };
  367. if (tRc == 0)
  368. {
  369. continue; // deadline check above
  370. };
  371. uint8_t tBuf[1024];
  372. struct sockaddr_in r_addr;
  373. socklen_t addr_len = sizeof(r_addr);
  374. ssize_t tLen = recvfrom(sockfd, tBuf, sizeof(tBuf), MSG_DONTWAIT, (struct sockaddr *) &r_addr, &addr_len);
  375. if (tLen <= 0)
  376. {
  377. continue;
  378. };
  379. // A raw socket returns the IP header too and gets every ICMP packet of the host
  380. size_t tIpLen = (size_t) (tBuf[0] & 0x0F) * 4;
  381. if ((size_t) tLen < tIpLen + sizeof(struct icmphdr))
  382. {
  383. continue;
  384. };
  385. struct icmphdr * tIcmp = (struct icmphdr *) (tBuf + tIpLen);
  386. if (r_addr.sin_addr.s_addr == ping_addr.sin_addr.s_addr && tIcmp->type == ICMP_ECHOREPLY && ntohs(tIcmp->un.echo.id) == id && ntohs(tIcmp->un.echo.sequence) == seq)
  387. {
  388. #ifdef DEBUG_EXTRA
  389. LOG("Device Is OK!");
  390. #endif
  391. return true;
  392. };
  393. };
  394. }
  395. bool deviceETH2UART::create_SOL()
  396. {
  397. /*
  398. if( m_sUartData.mode == SOL_NOT_DEFINED ) {
  399. LOG_ERROR("No Connection Type Defined!");
  400. return false;
  401. };
  402. */
  403. if (m_sUartData.port == 0)
  404. {
  405. LOG_ERROR("No Port Defined!");
  406. return false;
  407. };
  408. if (m_sUartData.speed == 0)
  409. {
  410. LOG_ERROR("No Speed Defined!");
  411. return false;
  412. };
  413. if (m_sUartData.path[0] == (char) 0)
  414. {
  415. LOG_ERROR("No Adress Defined!");
  416. return false;
  417. };
  418. // A previous connection / I/O thread is closed first. Before, the socket number was overwritten
  419. // (the connection leaked) and init() failed while the old thread ran: every reconnect left an open
  420. // TCP connection at the gateway and the node stayed invalid although "Connected".
  421. if (m_iDeviceFD != -1 || E2U_IO_STATUS != TH_PRE_INIT)
  422. {
  423. closePort();
  424. };
  425. struct connectingFlag
  426. {
  427. volatile bool & f;
  428. explicit connectingFlag(volatile bool & x) : f(x) { f = true; }
  429. ~connectingFlag() { f = false; }
  430. } tConnecting(m_bConnecting);
  431. switch (m_sUartData.mode)
  432. {
  433. case SOL_UDP_CLIENT:
  434. {
  435. #ifdef DEBUG
  436. LOG("PORT IS CLIENT - Create UDP Server");
  437. #endif
  438. #ifdef __linux__
  439. // Creating socket file descriptor
  440. if ((m_iDeviceFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  441. {
  442. LOG_ERROR("UDP Socket Creation Failed!");
  443. return false;
  444. };
  445. fcntl(m_iDeviceFD, F_SETFL, O_NONBLOCK);
  446. // Filling server information
  447. struct sockaddr_in tServerAddr;
  448. memset(&tServerAddr, 0, sizeof(tServerAddr));
  449. tServerAddr.sin_family = AF_INET; // IPv4
  450. tServerAddr.sin_addr.s_addr = INADDR_ANY;
  451. tServerAddr.sin_port = htons(m_sUartData.port);
  452. // Bind the socket with the server address
  453. if (bind(m_iDeviceFD, (const struct sockaddr *) &tServerAddr, sizeof(tServerAddr)) < 0)
  454. {
  455. LOG_ERROR("UDP Bind Failed");
  456. return false;
  457. };
  458. #else
  459. WSADATA wsaData;
  460. // Initialize Winsock version 2.2
  461. char tBuff[128];
  462. if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
  463. {
  464. sprintf(tBuff, "WSAStartup failed with error %ld", WSAGetLastError());
  465. LOG_ERROR(tBuff);
  466. return false;
  467. }
  468. else
  469. {
  470. sprintf(tBuff, "The Winsock DLL status is %s.", wsaData.szSystemStatus);
  471. LOG(tBuff);
  472. };
  473. // Set up a SOCKADDR_IN structure that will tell bind that we
  474. // want to receive datagrams from all interfaces using port 5150.
  475. // The IPv4 family
  476. ReceiverAddr.sin_family = AF_INET;
  477. // Port no. 5150
  478. ReceiverAddr.sin_port = htons(m_nPort);
  479. // From all interface (0.0.0.0)
  480. ReceiverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
  481. // Associate the address information with the socket using bind.
  482. // At this point you can receive datagrams on your bound socket.
  483. if (bind(m_sSocket, (SOCKADDR *) &ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR)
  484. {
  485. sprintf(tBuff, "Server: bind() failed!Error : %ld.", WSAGetLastError());
  486. // Close the socket
  487. closesocket(m_sSocket);
  488. // Do the clean up
  489. WSACleanup();
  490. // and exit with error
  491. LOG_ERROR(tBuff);
  492. return false;
  493. }
  494. else
  495. {
  496. LOG("UDP Server: bind() is OK!");
  497. };
  498. // Some info on the receiver side...
  499. SOCKADDR_IN tAddr;
  500. int tLen = sizeof(SOCKADDR_IN);
  501. getsockname(m_sSocket, (SOCKADDR *) &tAddr, &tLen);
  502. sprintf(tBuff, "Receiving IP(s) used : %s", inet_ntoa(tAddr.sin_addr));
  503. LOG(tBuff);
  504. sprintf(tBuff, "Receiving port used : %d", htons(tAddr.sin_port));
  505. LOG(tBuff);
  506. SelectTiming = recvfromTimeOutUDP(m_sSocket, 10, 0);
  507. #endif
  508. break;
  509. };
  510. case SOL_TCP_CLIENT:
  511. {
  512. #ifdef DEBUG
  513. LOG("PORT IS CLIENT - Create TCP Server");
  514. #endif
  515. break;
  516. };
  517. case SOL_UDP_SERVER:
  518. {
  519. #ifdef DEBUG
  520. LOG("PORT IS SERVER - Create UDP Client");
  521. #endif
  522. #ifdef __linux__
  523. // Creating socket file descriptor
  524. if ((m_iDeviceFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
  525. {
  526. LOG_ERROR("Socket Creation Failed!");
  527. return false;
  528. };
  529. fcntl(m_iDeviceFD, F_SETFL, O_NONBLOCK);
  530. // Filling server information
  531. struct sockaddr_in tServerAddr;
  532. memset(&tServerAddr, 0, sizeof(tServerAddr));
  533. tServerAddr.sin_family = AF_INET;
  534. tServerAddr.sin_addr.s_addr = INADDR_ANY;
  535. tServerAddr.sin_port = htons(m_sUartData.port);
  536. #else
  537. #endif
  538. break;
  539. };
  540. case SOL_TCP_SERVER:
  541. {
  542. #ifdef DEBUG
  543. LOG("PORT IS SERVER - Create TCP Client");
  544. #endif
  545. // socket create and varification
  546. m_iDeviceFD = socket(AF_INET, SOCK_STREAM, 0);
  547. if (m_iDeviceFD == -1)
  548. {
  549. LOG_ERROR("Socket creation failed!");
  550. return false;
  551. }
  552. #ifdef DEBUG
  553. else
  554. {
  555. LOG("Socket successfully created");
  556. }
  557. #endif
  558. // Set non-blocking
  559. int arg;
  560. if ((arg = fcntl(m_iDeviceFD, F_GETFL, NULL)) < 0)
  561. {
  562. char tBuf[512];
  563. sprintf(tBuf, "Error fcntl(..., F_GETFL) (%s)", strerror(errno));
  564. LOG_ERROR(tBuf);
  565. return false;
  566. };
  567. arg |= O_NONBLOCK;
  568. if (fcntl(m_iDeviceFD, F_SETFL, arg) < 0)
  569. {
  570. char tBuf[512];
  571. sprintf(tBuf, "Error fcntl(..., F_SETFL) (%s)", strerror(errno));
  572. LOG_ERROR(tBuf);
  573. return false;
  574. };
  575. // Keepalive: a gateway that disappears (no FIN, e.g. mobile link lost) is detected
  576. {
  577. int tOn = 1, tIdle = E2UART_KEEPALIVE_IDLE_S, tIntvl = E2UART_KEEPALIVE_INTVL_S, tCnt = E2UART_KEEPALIVE_CNT;
  578. setsockopt(m_iDeviceFD, SOL_SOCKET, SO_KEEPALIVE, &tOn, sizeof(tOn));
  579. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_KEEPIDLE, &tIdle, sizeof(tIdle));
  580. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_KEEPINTVL, &tIntvl, sizeof(tIntvl));
  581. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_KEEPCNT, &tCnt, sizeof(tCnt));
  582. unsigned int tUserTO = E2UART_TCP_USER_TIMEOUT_MS;
  583. setsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_USER_TIMEOUT, &tUserTO, sizeof(tUserTO));
  584. }
  585. // assign IP, PORT
  586. struct sockaddr_in tServerAddr;
  587. memset(&tServerAddr, 0, sizeof(tServerAddr));
  588. tServerAddr.sin_family = AF_INET;
  589. tServerAddr.sin_addr.s_addr = inet_addr(m_sUartData.path);
  590. tServerAddr.sin_port = htons(m_sUartData.port);
  591. // connect the client socket to server socket
  592. int retVal = connect(m_iDeviceFD, (struct sockaddr *) &tServerAddr, sizeof(tServerAddr));
  593. if (retVal < 0)
  594. {
  595. if (errno == EINPROGRESS)
  596. {
  597. #ifdef DEBUG
  598. LOG("EINPROGRESS in connect() - selecting");
  599. #endif
  600. // Over the Internet a connect takes longer than on a LAN (the timeout was 1 s)
  601. uint64_t tDeadline = e2uNowMs() + E2UART_CONNECT_TIMEOUT_MS;
  602. do
  603. {
  604. uint64_t tNow = e2uNowMs();
  605. uint64_t tLeft = (tNow < tDeadline) ? tDeadline - tNow : 0;
  606. fd_set myset;
  607. struct timeval tv;
  608. tv.tv_sec = tLeft / 1000;
  609. tv.tv_usec = (tLeft % 1000) * 1000;
  610. FD_ZERO(&myset);
  611. FD_SET(m_iDeviceFD, &myset);
  612. retVal = select(m_iDeviceFD + 1, NULL, &myset, NULL, &tv);
  613. if (retVal < 0 && errno == EINTR && e2uNowMs() < tDeadline)
  614. {
  615. continue; // interrupted by a signal: wait the rest of the time
  616. }
  617. if (retVal < 0 && errno != EINTR)
  618. {
  619. char cBuffer[512];
  620. sprintf(cBuffer, "ERROR connect to [%s:%d] %d (%s)", m_sUartData.path, m_sUartData.port, errno, strerror(errno));
  621. LOG_ERROR(cBuffer);
  622. close(m_iDeviceFD);
  623. m_iDeviceFD = -1;
  624. return false;
  625. }
  626. else if (retVal > 0)
  627. {
  628. int valopt;
  629. // Socket selected for write
  630. socklen_t lon = sizeof(int);
  631. if (getsockopt(m_iDeviceFD, SOL_SOCKET, SO_ERROR, (void *) (&valopt), &lon) < 0)
  632. {
  633. char cBuffer[512];
  634. sprintf(cBuffer, "ERROR connect to [%s:%d] %d (%s) in getsockopt", m_sUartData.path, m_sUartData.port, errno, strerror(errno));
  635. LOG_ERROR(cBuffer);
  636. close(m_iDeviceFD);
  637. m_iDeviceFD = -1;
  638. return false;
  639. };
  640. // Check the value returned...
  641. if (valopt)
  642. {
  643. char cBuffer[512];
  644. sprintf(cBuffer, "ERROR in delayed connection() %d - %s\n", valopt, strerror(valopt));
  645. LOG_ERROR(cBuffer);
  646. close(m_iDeviceFD);
  647. m_iDeviceFD = -1;
  648. return false;
  649. };
  650. break;
  651. }
  652. else
  653. {
  654. char cBuffer[160];
  655. snprintf(cBuffer, sizeof(cBuffer), "Timeout (%d ms) connecting to [%.64s:%d] - Cancelling!", E2UART_CONNECT_TIMEOUT_MS, m_sUartData.path, m_sUartData.port);
  656. LOG_ERROR(cBuffer);
  657. close(m_iDeviceFD);
  658. m_iDeviceFD = -1;
  659. return false;
  660. };
  661. }
  662. while (1);
  663. }
  664. else
  665. {
  666. char cBuffer[512];
  667. sprintf(cBuffer, "ERROR connect to [%s:%d] %d (%s)", m_sUartData.path, m_sUartData.port, errno, strerror(errno));
  668. LOG_ERROR(cBuffer);
  669. close(m_iDeviceFD);
  670. m_iDeviceFD = -1;
  671. return false;
  672. };
  673. };
  674. #ifdef DEBUG
  675. {
  676. char cBuffer[512];
  677. sprintf(cBuffer, "Connected to [%s:%d]", m_sUartData.path, m_sUartData.port);
  678. LOG(cBuffer);
  679. }
  680. #endif
  681. setConnectionStatus(CS_CONNECTED);
  682. break;
  683. };
  684. };
  685. if (! init())
  686. {
  687. LOG_ERROR("Can not start the I/O thread - closing the connection");
  688. closePort();
  689. return false;
  690. };
  691. return true;
  692. }
  693. /*
  694. from https://stackoverflow.com/questions/2597608/c-socket-connection-timeout
  695. void connect_w_to(void) {
  696. int res;
  697. struct sockaddr_in addr;
  698. long arg;
  699. fd_set myset;
  700. struct timeval tv;
  701. int valopt;
  702. socklen_t lon;
  703. // Create socket
  704. soc = socket(AF_INET, SOCK_STREAM, 0);
  705. if (soc < 0) {
  706. fprintf(stderr, "Error creating socket (%d %s)\n", errno, strerror(errno));
  707. exit(0);
  708. }
  709. addr.sin_family = AF_INET;
  710. addr.sin_port = htons(2000);
  711. addr.sin_addr.s_addr = inet_addr("192.168.0.1");
  712. // Set non-blocking
  713. if( (arg = fcntl(soc, F_GETFL, NULL)) < 0) {
  714. fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno));
  715. exit(0);
  716. }
  717. arg |= O_NONBLOCK;
  718. if( fcntl(soc, F_SETFL, arg) < 0) {
  719. fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno));
  720. exit(0);
  721. }
  722. // Trying to connect with timeout
  723. res = connect(soc, (struct sockaddr *)&addr, sizeof(addr));
  724. if (res < 0) {
  725. if (errno == EINPROGRESS) {
  726. fprintf(stderr, "EINPROGRESS in connect() - selecting\n");
  727. do {
  728. tv.tv_sec = 15;
  729. tv.tv_usec = 0;
  730. FD_ZERO(&myset);
  731. FD_SET(soc, &myset);
  732. res = select(soc+1, NULL, &myset, NULL, &tv);
  733. if (res < 0 && errno != EINTR) {
  734. fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno));
  735. exit(0);
  736. }
  737. else if (res > 0) {
  738. // Socket selected for write
  739. lon = sizeof(int);
  740. if (getsockopt(soc, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon) < 0) {
  741. fprintf(stderr, "Error in getsockopt() %d - %s\n", errno, strerror(errno));
  742. exit(0);
  743. }
  744. // Check the value returned...
  745. if (valopt) {
  746. fprintf(stderr, "Error in delayed connection() %d - %s\n", valopt, strerror(valopt)
  747. );
  748. exit(0);
  749. }
  750. break;
  751. }
  752. else {
  753. fprintf(stderr, "Timeout in select() - Cancelling!\n");
  754. exit(0);
  755. }
  756. } while (1);
  757. }
  758. else {
  759. fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno));
  760. exit(0);
  761. }
  762. }
  763. // Set to blocking mode again...
  764. if( (arg = fcntl(soc, F_GETFL, NULL)) < 0) {
  765. fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno));
  766. exit(0);
  767. }
  768. arg &= (~O_NONBLOCK);
  769. if( fcntl(soc, F_SETFL, arg) < 0) {
  770. fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno));
  771. exit(0);
  772. }
  773. // I hope that is all
  774. }
  775. */
  776. bool deviceETH2UART::closePort()
  777. {
  778. //char tBuff[128];
  779. setConnectionStatus(CS_DISCONNECTED);
  780. #ifdef SERIAL_PING_PONG
  781. if (m_bThreadStatus != TH_PRE_INIT)
  782. #else
  783. if (m_bThreadAStatus != TH_PRE_INIT && m_bThreadBStatus != TH_PRE_INIT)
  784. #endif
  785. {
  786. uninit();
  787. };
  788. // Requests still queued are kept: a query of the sensor queued during a reconnect is sent on the new
  789. // connection (dropping it left the sensor without a query - it only answers when asked)
  790. if (m_iDeviceFD != -1)
  791. {
  792. switch (m_sUartData.mode)
  793. {
  794. case SOL_UDP_CLIENT:
  795. case SOL_TCP_CLIENT:
  796. case SOL_UDP_SERVER:
  797. {
  798. #ifdef __linux__
  799. if (m_iDeviceFD > -1)
  800. {
  801. close(m_iDeviceFD);
  802. };
  803. #else
  804. // When your application is finished receiving datagrams close the socket.
  805. LOG("Server: Finished receiving.Closing the listening socket...");
  806. if (closesocket(m_sSocket) != 0)
  807. {
  808. sprintf(tBuff, "closesocket() failed!Error code : %ld", WSAGetLastError());
  809. LOG_ERROR(tBuff);
  810. }
  811. else
  812. {
  813. LOG("closesocket() is OK...");
  814. };
  815. // When your application is finished call WSACleanup.
  816. LOG("Server: Cleaning up...");
  817. if (WSACleanup() != 0)
  818. {
  819. sprintf(tBuff, "WSACleanup() failed!Error code : %ld", WSAGetLastError());
  820. LOG_ERROR(tBuff);
  821. }
  822. else
  823. {
  824. LOG("WSACleanup() is OK");
  825. };
  826. #endif
  827. break;
  828. };
  829. case SOL_TCP_SERVER:
  830. {
  831. if (m_iDeviceFD > -1)
  832. {
  833. close(m_iDeviceFD);
  834. };
  835. break;
  836. };
  837. };
  838. m_iDeviceFD = -1;
  839. };
  840. return true;
  841. }
  842. #ifdef SERIAL_PING_PONG
  843. bool deviceETH2UART::isRecipient(protocolParser * p)
  844. {
  845. if (p == NULL)
  846. {
  847. return false;
  848. };
  849. m_mQueueProtectorMutex.lock();
  850. bool tVal = std::find(m_vParsers.begin(), m_vParsers.end(), p) != m_vParsers.end();
  851. m_mQueueProtectorMutex.unlock();
  852. return tVal;
  853. }
  854. /*
  855. Which side is silent: unacked > 0 and a growing "last ACK" -> the network path to the gateway is dead;
  856. ACKs keep coming but no reply -> the gateway / serial line / device does not answer.
  857. */
  858. void deviceETH2UART::tcpInfoText(char * buf, size_t size)
  859. {
  860. struct tcp_info tInfo;
  861. socklen_t tLen = sizeof(tInfo);
  862. memset(&tInfo, 0, sizeof(tInfo));
  863. if (m_iDeviceFD < 0 || m_sUartData.mode != SOL_TCP_SERVER || getsockopt(m_iDeviceFD, IPPROTO_TCP, TCP_INFO, &tInfo, &tLen) != 0)
  864. {
  865. snprintf(buf, size, "no TCP info");
  866. return;
  867. };
  868. snprintf(buf, size, "TCP: unacked %u, retransmits %u, rtt %u ms, last ACK %u ms ago, last data %u ms ago", tInfo.tcpi_unacked, tInfo.tcpi_retransmits,
  869. tInfo.tcpi_rtt / 1000, tInfo.tcpi_last_ack_recv, tInfo.tcpi_last_data_recv);
  870. }
  871. void deviceETH2UART::m_fThreadProc(void)
  872. {
  873. int RetVal;
  874. m_bThreadStatus = TH_WORKING;
  875. #ifdef DEBUG
  876. LOG("Sender Thread Started!");
  877. #endif
  878. pthread_setname_np( pthread_self(), "E2S IO" );
  879. SIO_TZ * tIdle = (SIO_TZ *) malloc(sizeof(SIO_TZ)); // receive buffer for data between requests
  880. int tNoReplyStreak = 0; // requests in a row (with a parser) without any reply byte
  881. #ifdef DEBUG_COMMUNICATION
  882. uint32_t tReqNo = 0, tStReq = 0, tStReply = 0, tStNoReply = 0, tStSlow = 0, tStLate = 0;
  883. uint64_t tStSum = 0, tStMax = 0, tStStart = e2uNowMs(), tLastReqMs = 0;
  884. char tDbg[256];
  885. #endif
  886. while (m_bThreadStatus < TH_ENDED){
  887. #ifdef DEBUG_COMMUNICATION
  888. if (e2uNowMs() - tStStart >= E2UART_TIMING_REPORT_MS){
  889. snprintf(tDbg, sizeof(tDbg), "IO stats %d s [%.64s:%d]: %u requests, %u replies (first byte avg %llu ms, max %llu ms), %u slow (> %d ms), %u without reply in %d ms, %u late",
  890. E2UART_TIMING_REPORT_MS / 1000, m_sUartData.path, m_sUartData.port, tStReq, tStReply, (unsigned long long) (tStReply ? tStSum / tStReply : 0),
  891. (unsigned long long) tStMax, tStSlow, E2UART_SLOW_REPLY_MS, tStNoReply, E2UART_REPLY_TIMEOUT_MS, tStLate);
  892. LOG(tDbg);
  893. tStReq = tStReply = tStNoReply = tStSlow = tStLate = 0;
  894. tStSum = tStMax = 0;
  895. tStStart = e2uNowMs();
  896. };
  897. #endif
  898. SIO_TZ * tIOData = NULL;
  899. m_mBufferProtectorMutex.lock();
  900. if (! m_qIO.empty()){
  901. tIOData = m_qIO.front();
  902. m_qIO.pop();
  903. };
  904. m_mBufferProtectorMutex.unlock();
  905. if (tIOData == NULL){
  906. // No request: still read the socket. A reply that came after the reply window (Internet
  907. // delay) was left in the socket and read with the next request, as that request's reply.
  908. // Now it goes to the parser of the request it answers, as soon as it arrives.
  909. if (tIdle != NULL){
  910. tIdle->inp_size = 0;
  911. RetVal = recptBlock(tIdle->inp_buffer, &tIdle->inp_size);
  912. if (RetVal == -1){
  913. setConnectionStatus(CS_DISCONNECTED);
  914. m_bThreadStatus = TH_ENDED;
  915. LOG_ERROR("Connection Droped on Reception Data");
  916. } else if (tIdle->inp_size > 0){
  917. tNoReplyStreak = 0; // the device answers (late)
  918. #ifdef DEBUG_COMMUNICATION
  919. tStLate++;
  920. snprintf(tDbg, sizeof(tDbg), "IO: late data %d B, %llu ms after request #%u (reply window %d ms)", tIdle->inp_size,
  921. (unsigned long long) (tLastReqMs ? e2uNowMs() - tLastReqMs : 0), tReqNo, E2UART_REPLY_TIMEOUT_MS);
  922. LOG(tDbg);
  923. #endif
  924. if (isRecipient(m_pLastParser)){
  925. m_pLastParser->parse(tIdle->inp_buffer, tIdle->inp_size);
  926. }
  927. #ifdef DEBUG_COMMUNICATION
  928. else {
  929. LOG_ERROR("Data without request dropped");
  930. }
  931. #endif
  932. continue; // more may follow
  933. };
  934. };
  935. SLEEP(5);
  936. continue;
  937. };
  938. //Sending Data to line
  939. #ifdef DEBUG_COMMUNICATION
  940. int tSentBytes = tIOData->out_size;
  941. char tReqHex[3 * 12 + 4];
  942. {
  943. int tN = (tSentBytes < 12) ? tSentBytes : 12;
  944. for (int k = 0; k < tN; k++){
  945. snprintf(tReqHex + 3 * k, 4, "%02X ", tIOData->out_buffer[k]);
  946. };
  947. tReqHex[tN ? 3 * tN - 1 : 0] = 0;
  948. if (tSentBytes > 12){
  949. strcat(tReqHex, "..");
  950. };
  951. }
  952. uint64_t tSendMs = e2uNowMs();
  953. tReqNo++;
  954. tStReq++;
  955. tLastReqMs = tSendMs;
  956. #endif
  957. int index = 0;
  958. while ((index < tIOData->out_size) && (m_bThreadStatus < TH_ENDED)){
  959. RetVal = sendBlock(tIOData->out_buffer + index, tIOData->out_size - index);
  960. if (RetVal > 0){
  961. index += RetVal;
  962. } else {
  963. // if 0 or -(error)
  964. if (RetVal == 0) {
  965. usleep(100);
  966. } else {
  967. setConnectionStatus(CS_DISCONNECTED);
  968. tIOData->out_size = 0;
  969. m_bThreadStatus = TH_ENDED;
  970. LOG_ERROR("Connection Droped on Sending Data");
  971. };
  972. };
  973. };
  974. // A parser detached since the request was queued (sensor disconnected / deleted) gets nothing
  975. protocolParser * tParser = isRecipient(tIOData->boundParser) ? tIOData->boundParser : NULL;
  976. if (tParser != NULL){
  977. m_pLastParser = tParser;
  978. };
  979. //Try to receive the reply: up to E2UART_REPLY_TIMEOUT_MS for its start, then while it keeps
  980. //coming (E2UART_REPLY_GAP_MS between chunks); done when the parser has a complete packet and
  981. //no more data is waiting
  982. tIOData->out_size = 0;
  983. bool tGotData = false;
  984. bool tDataOnline = false;
  985. uint64_t tDeadline = e2uNowMs() + E2UART_REPLY_TIMEOUT_MS;
  986. #ifdef DEBUG_COMMUNICATION
  987. uint64_t tFirstByteMs = 0;
  988. int tReplyBytes = 0;
  989. #endif
  990. do {
  991. RetVal = recptBlock( tIOData->inp_buffer, &tIOData->inp_size );
  992. if( RetVal == -1 ){
  993. setConnectionStatus(CS_DISCONNECTED);
  994. tIOData->inp_size = 0;
  995. m_bThreadStatus = TH_ENDED;
  996. LOG_ERROR("Connection Droped on Reception Data");
  997. } else if( tIOData->inp_size ){
  998. tGotData = true;
  999. #ifdef DEBUG_COMMUNICATION
  1000. if (tFirstByteMs == 0){
  1001. tFirstByteMs = e2uNowMs();
  1002. };
  1003. tReplyBytes += tIOData->inp_size;
  1004. #endif
  1005. uint64_t tGapEnd = e2uNowMs() + E2UART_REPLY_GAP_MS;
  1006. if (tGapEnd > tDeadline){
  1007. tDeadline = tGapEnd;
  1008. };
  1009. if( tParser == NULL ){
  1010. tDataOnline = true;
  1011. } else {
  1012. tDataOnline = tParser->parse( tIOData->inp_buffer, tIOData->inp_size ) || tDataOnline;
  1013. };
  1014. } else {
  1015. if (tDataOnline){
  1016. break; // complete packet and the socket is empty (as before: white space after data)
  1017. };
  1018. SLEEP(5);
  1019. };
  1020. } while ((m_bThreadStatus < TH_ENDED) && (e2uNowMs() < tDeadline));
  1021. #ifdef DEBUG_COMMUNICATION
  1022. {
  1023. uint64_t tDoneMs = e2uNowMs();
  1024. if (tFirstByteMs == 0){
  1025. tStNoReply++;
  1026. char tTcp[160];
  1027. tcpInfoText(tTcp, sizeof(tTcp));
  1028. snprintf(tDbg, sizeof(tDbg), "IO: request #%u [%s]: NO reply in %llu ms - %s", tReqNo, tReqHex, (unsigned long long) (tDoneMs - tSendMs), tTcp);
  1029. LOG(tDbg);
  1030. } else {
  1031. uint64_t tFirst = tFirstByteMs - tSendMs;
  1032. tStReply++;
  1033. tStSum += tFirst;
  1034. if (tFirst > tStMax){
  1035. tStMax = tFirst;
  1036. };
  1037. if (tFirst > E2UART_SLOW_REPLY_MS || ! tDataOnline){
  1038. tStSlow++;
  1039. snprintf(tDbg, sizeof(tDbg), "IO: request #%u (%d B): reply %d B, first byte %llu ms, done %llu ms%s", tReqNo, tSentBytes, tReplyBytes,
  1040. (unsigned long long) tFirst, (unsigned long long) (tDoneMs - tSendMs), tDataOnline ? "" : " - INCOMPLETE packet");
  1041. LOG(tDbg);
  1042. };
  1043. };
  1044. }
  1045. #endif
  1046. if (tGotData){
  1047. tNoReplyStreak = 0;
  1048. } else if (tParser != NULL && m_bThreadStatus < TH_ENDED && ++tNoReplyStreak >= E2UART_NO_REPLY_RECONNECT){
  1049. // The device went silent while the TCP connection stayed "up" (sending works, nothing comes
  1050. // back): end the I/O thread - validate() sees the lost link and opens a new connection
  1051. char tTcp[160];
  1052. char tB[320];
  1053. tcpInfoText(tTcp, sizeof(tTcp));
  1054. snprintf(tB, sizeof(tB), "No reply to %d requests in a row - reconnecting to the gateway (%s)", tNoReplyStreak, tTcp);
  1055. LOG_ERROR(tB);
  1056. setConnectionStatus(CS_DISCONNECTED);
  1057. m_bThreadStatus = TH_ENDED;
  1058. };
  1059. // Free Package
  1060. free(tIOData);
  1061. };
  1062. free(tIdle);
  1063. }
  1064. bool deviceETH2UART::sendData(uint8_t * Data, int DataSize, protocolParser *src ){
  1065. // Queued (sent as soon as the I/O thread runs) while the connection is up, starting (TH_ARMED: the
  1066. // first query right after a connect was refused), ended for a reconnect that validate() will do,
  1067. // or being opened. Refused only without any connection.
  1068. if ( m_bThreadStatus == TH_PRE_INIT && ! m_bConnecting ) {
  1069. LOG_ERROR("Trying to Send Data without connection to the gateway!");
  1070. return false;
  1071. };
  1072. if (DataSize > MAXIMAL_SERIAL_IO_BUFFER_LENGTH) {
  1073. LOG_ERROR("Data Too BIG");
  1074. } else {
  1075. SIO_TZ * tData = (SIO_TZ *) malloc(sizeof(SIO_TZ));
  1076. if (tData) {
  1077. memset( tData, 0, sizeof(SIO_TZ) );
  1078. tData->out_size = DataSize;
  1079. tData->boundParser = src;
  1080. memcpy( tData->out_buffer, Data, DataSize );
  1081. int tDropped = 0;
  1082. m_mBufferProtectorMutex.lock();
  1083. while ((int) m_qIO.size() >= E2UART_MAX_QUEUED){
  1084. free(m_qIO.front());
  1085. m_qIO.pop();
  1086. tDropped++;
  1087. };
  1088. m_qIO.push(tData);
  1089. m_mBufferProtectorMutex.unlock();
  1090. if (tDropped){
  1091. LOG_ERROR("Request queue full - oldest request dropped");
  1092. };
  1093. return true;
  1094. } else {
  1095. LOG_ERROR("MemAlloc Error!");
  1096. };
  1097. };
  1098. return false;
  1099. }
  1100. #else // !SERIAL_PING_PONG
  1101. void deviceETH2UART::m_fThreadAProc(void)
  1102. {
  1103. int index;
  1104. int RetVal;
  1105. m_bThreadAStatus = TH_WORKING;
  1106. #ifdef DEBUG
  1107. LOG("Sender Thread Started!");
  1108. #endif
  1109. pthread_setname_np( pthread_self(), "E2S Sender" );
  1110. while (m_bThreadAStatus < TH_ENDED)
  1111. {
  1112. m_mBufferProtectorMutex.lock();
  1113. if (m_nOutputBufferSize > 0)
  1114. {
  1115. index = 0;
  1116. while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED))
  1117. {
  1118. RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index);
  1119. if (RetVal > 0)
  1120. {
  1121. index += RetVal;
  1122. }
  1123. if (RetVal == -1)
  1124. {
  1125. setConnectionStatus(CS_DISCONNECTED);
  1126. m_nOutputBufferSize = 0;
  1127. m_bThreadBStatus = TH_ENDED;
  1128. m_bThreadAStatus = TH_ENDED;
  1129. LOG_ERROR("Connection Droped on Sending Data");
  1130. };
  1131. };
  1132. m_nOutputBufferSize = 0;
  1133. m_mBufferProtectorMutex.unlock();
  1134. }
  1135. else
  1136. {
  1137. m_mBufferProtectorMutex.unlock();
  1138. SLEEP(5);
  1139. };
  1140. };
  1141. }
  1142. void deviceETH2UART::m_fThreadBProc(void)
  1143. {
  1144. m_bThreadBStatus = TH_WORKING;
  1145. int RetVal;
  1146. #ifdef DEBUG
  1147. LOG("Recipient Thread Started!");
  1148. #endif
  1149. pthread_setname_np( pthread_self(), "E2S Receiver" );
  1150. while (m_bThreadBStatus < TH_ENDED)
  1151. {
  1152. RetVal = recptBlock(m_pInputBuffer, &m_nInputBufferSize);
  1153. if (RetVal == -1)
  1154. {
  1155. setConnectionStatus(CS_DISCONNECTED);
  1156. m_nInputBufferSize = 0;
  1157. // if(!getStatus()) {
  1158. m_bThreadBStatus = TH_ENDED;
  1159. m_bThreadAStatus = TH_ENDED;
  1160. //} else SLEEP(100);
  1161. LOG_ERROR("Connection Droped on Reception Data");
  1162. }
  1163. else if (m_nInputBufferSize > 0)
  1164. {
  1165. do
  1166. {
  1167. m_mQueueProtectorMutex.lock();
  1168. if (m_vParsers.size())
  1169. {
  1170. for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++)
  1171. {
  1172. (*index)->parse(m_pInputBuffer, m_nInputBufferSize);
  1173. }
  1174. m_nInputBufferSize = 0;
  1175. m_mQueueProtectorMutex.unlock();
  1176. }
  1177. else
  1178. {
  1179. m_nInputBufferSize = 0;
  1180. m_mQueueProtectorMutex.unlock();
  1181. #ifdef DEBUG_EXTRA
  1182. LOG_ERROR("Try to parse data but No Parsers Assigned!");
  1183. #endif
  1184. SLEEP(100);
  1185. };
  1186. }
  1187. while ((m_vParsers.size() == 0) && (m_bThreadBStatus < TH_ENDED) && (m_bThreadBStatus < TH_ENDED));
  1188. }
  1189. else
  1190. {
  1191. SLEEP(5);
  1192. };
  1193. };
  1194. }
  1195. bool deviceETH2UART::sendData(uint8_t * Data, int DataSize)
  1196. {
  1197. if (m_bThreadAStatus != TH_WORKING)
  1198. {
  1199. if (m_bThreadAStatus < TH_WORKING)
  1200. {
  1201. LOG_ERROR("Trying to Send Data Before Thread is Started!");
  1202. }
  1203. else
  1204. {
  1205. LOG_ERROR("Trying to Send Data After Thread is Dead!");
  1206. }
  1207. return false;
  1208. };
  1209. m_mBufferProtectorMutex.lock();
  1210. if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_IO_BUFFER_LENGTH)
  1211. {
  1212. m_mBufferProtectorMutex.unlock();
  1213. LOG_ERROR("Data Too BIG");
  1214. return false;
  1215. };
  1216. memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize);
  1217. m_nOutputBufferSize += DataSize;
  1218. m_mBufferProtectorMutex.unlock();
  1219. return true;
  1220. }
  1221. #endif // !SERIAL_PING_PONG
  1222. bool deviceETH2UART::reconnect(void)
  1223. {
  1224. std::lock_guard<std::recursive_mutex> tLock(m_mConnLock);
  1225. m_bValid = create_SOL(); // closes the old connection first
  1226. return m_bValid;
  1227. }
  1228. int deviceETH2UART::recptBlock(unsigned char * Buffer, int * BufferLength)
  1229. {
  1230. #ifdef __linux__
  1231. int RetVal = 0;
  1232. #else
  1233. DWORD RetVal = 0;
  1234. #endif
  1235. if (m_eConnectionStatus == CS_CONNECTED)
  1236. {
  1237. #ifdef __linux__
  1238. if (m_iDeviceFD > -1)
  1239. {
  1240. struct sockaddr ClientAddress;
  1241. socklen_t addr_len = sizeof(ClientAddress); // len is value/resuslt
  1242. // RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len );
  1243. RetVal = recvfrom(m_iDeviceFD, (char *) Buffer, MAXIMAL_SOCKET_IO_BUFFER_LENGTH, MSG_DONTWAIT, (struct sockaddr *) &ClientAddress, &addr_len);
  1244. // TCP: 0 = the gateway closed the connection (errno is not set then: the old check read a
  1245. // stale errno and could keep a closed connection forever). < 0: an error unless EAGAIN/EINTR
  1246. if ((RetVal == 0 && m_sUartData.mode == SOL_TCP_SERVER) || RetVal < 0)
  1247. {
  1248. if (RetVal == 0 || (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR))
  1249. {
  1250. LOG_ERROR("Peer Closes Connection!");
  1251. shutdown(m_iDeviceFD, 2);
  1252. close(m_iDeviceFD);
  1253. *BufferLength = 0;
  1254. m_iDeviceFD = -1;
  1255. setConnectionStatus(CS_DISCONNECTED);
  1256. return -1;
  1257. };
  1258. };
  1259. }
  1260. else
  1261. {
  1262. LOG_ERROR("Not Connected!");
  1263. *BufferLength = 0;
  1264. setConnectionStatus(CS_DISCONNECTED);
  1265. return -1;
  1266. };
  1267. #else
  1268. switch (m_eType)
  1269. {
  1270. case SOL_UDP_CLIENT:
  1271. case SOL_TCP_CLIENT:
  1272. case SOL_UDP_SERVER:
  1273. {
  1274. SOCKADDR_IN tAddr;
  1275. int tLen = sizeof(SOCKADDR_IN);
  1276. RetVal = recvfrom(m_sSocket, (char *) Buffer, MAXIMAL_SOCKET_IO_BUFFER_LENGTH, 0, (struct sockaddr *) &tAddr, &tLen);
  1277. if (RetVal == SOCKET_ERROR)
  1278. {
  1279. char cBuffer[165];
  1280. sprintf(cBuffer, "recvfrom() failed with error code : %d", WSAGetLastError());
  1281. LOG_ERROR(cBuffer);
  1282. };
  1283. break;
  1284. };
  1285. };
  1286. #endif
  1287. }
  1288. else
  1289. {
  1290. // make prep for connection SOL_TCP_SERVER
  1291. if (m_sUartData.mode == SOL_TCP_CLIENT)
  1292. {
  1293. // ACCEPT
  1294. struct sockaddr ClientAddress;
  1295. socklen_t size = (socklen_t) sizeof(struct sockaddr_in);
  1296. // int ClientSocket;
  1297. m_iDeviceFD = accept(m_iMasterFD, &ClientAddress, &size);
  1298. if (m_iDeviceFD < 0)
  1299. {
  1300. setConnectionStatus(CS_DISCONNECTED);
  1301. LOG_ERROR("Connection Accept Failure!");
  1302. };
  1303. }
  1304. else
  1305. {
  1306. LOG_ERROR("RCPT ON not connected!");
  1307. shutdown(m_iDeviceFD, 2);
  1308. close(m_iDeviceFD);
  1309. *BufferLength = 0;
  1310. m_iDeviceFD = -1;
  1311. setConnectionStatus(CS_DISCONNECTED);
  1312. };
  1313. return -1; // Exit after unsuccess reconnect
  1314. };
  1315. if (RetVal > 0)
  1316. {
  1317. #ifdef DEBUG_SERIAL_COMMUNICATION
  1318. char MsgBuffer[CLOG];
  1319. if (RetVal > 1 || RetVal == 0)
  1320. {
  1321. sprintf(MsgBuffer, "Received %d bytes", RetVal);
  1322. }
  1323. else
  1324. {
  1325. sprintf(MsgBuffer, "Received 1 byte");
  1326. };
  1327. LOG(MsgBuffer);
  1328. for (int i = 0; i < RetVal; i++)
  1329. {
  1330. sprintf(MsgBuffer, "0x%02X", Buffer[i]);
  1331. LOG(MsgBuffer);
  1332. };
  1333. #endif
  1334. *BufferLength = RetVal;
  1335. return RetVal;
  1336. };
  1337. *BufferLength = 0;
  1338. if (RetVal == -1)
  1339. {
  1340. return 0;
  1341. }
  1342. if (RetVal == 0)
  1343. {
  1344. errno = 0;
  1345. return 0;
  1346. };
  1347. /* r < -1, should never happen. */
  1348. errno = EIO;
  1349. return 0;
  1350. }
  1351. int deviceETH2UART::sendBlock(unsigned char * Data, int DataSize)
  1352. {
  1353. #ifdef __linux__
  1354. int RetVal = 0;
  1355. #else
  1356. DWORD RetVal = 0;
  1357. #endif
  1358. if (m_eConnectionStatus == CS_CONNECTED)
  1359. {
  1360. #ifdef __linux__
  1361. if (m_iDeviceFD > -1)
  1362. {
  1363. #ifdef DEBUG_EXTRA
  1364. char cBuffer[256];
  1365. sprintf(cBuffer, "Write into Port %d bytes", DataSize);
  1366. LOG(cBuffer);
  1367. #endif
  1368. struct sockaddr ClientAddress;
  1369. socklen_t addr_len = sizeof(ClientAddress);
  1370. RetVal = sendto(m_iDeviceFD, (const char *) Data, DataSize, MSG_CONFIRM, (const struct sockaddr *) &ClientAddress, addr_len);
  1371. if ((RetVal == -1) && (errno != EINTR) && (errno != EWOULDBLOCK))
  1372. {
  1373. LOG_ERROR("Error acures while writing data into the Socket");
  1374. shutdown(m_iDeviceFD, 2);
  1375. close(m_iDeviceFD);
  1376. m_iDeviceFD = -1;
  1377. setConnectionStatus(CS_DISCONNECTED);
  1378. return -1;
  1379. };
  1380. if (RetVal < 0)
  1381. {
  1382. RetVal = 0;
  1383. }
  1384. #ifdef DEBUG_EXTRA
  1385. sprintf(cBuffer, "Bytes Sent: %ld", RetVal);
  1386. LOG(cBuffer);
  1387. #ifdef DEBUG_SERIAL_COMMUNICATION
  1388. for (int zz = 0; zz < RetVal; zz++)
  1389. {
  1390. sprintf(cBuffer, "SD: 0x%02X", (uint8_t) Data[zz]);
  1391. LOG(cBuffer);
  1392. };
  1393. #endif
  1394. #endif
  1395. }
  1396. else
  1397. {
  1398. LOG_ERROR("Not Connected!");
  1399. // m_bConnected = false;
  1400. setConnectionStatus(CS_DISCONNECTED);
  1401. return -1;
  1402. };
  1403. #else // Windows
  1404. if (sendto(m_sSocket, (char *) Data, DataSize, 0, (struct sockaddr *) &ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR)
  1405. {
  1406. char cBuffer[256];
  1407. sprintf(cBuffer, "sendto() failed with error code : %d", WSAGetLastError());
  1408. LOG_ERROR(cBuffer);
  1409. return -1;
  1410. };
  1411. #endif
  1412. }
  1413. else
  1414. {
  1415. #ifdef DEBUG
  1416. LOG("Port is not Ready to Send");
  1417. #endif
  1418. return -1;
  1419. };
  1420. return RetVal;
  1421. }
  1422. #undef E2U_IO_STATUS
  1423. #undef LOG_ERROR
  1424. #undef LOG