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.

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