The field test is done: replies avg 113-205 ms, spikes up to 1.5 s, one
slow reply covered by the retry, 0 failed commands. The #define in
deviceNodeEthernet2Serial.cpp and deviceNodeSensor.cpp is commented out;
uncomment it to get the timing lines again. The reconnect error ("No
reply to N requests in a row") is always logged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
The sensor answers only when queried, and it re-sends its query after
every attempt without reply (idle mode: getState2() in stage 1 again).
The gateway must deliver each of these queries:
- Queued requests are no longer dropped by closePort(). A query queued
while the I/O thread ended for a reconnect is sent on the new
connection (the previous commit dropped it, so the sensor stayed
unqueried for that attempt).
- sendData() queues while the connection is up, while the I/O thread is
still starting (TH_ARMED: the first query right after a connect was
refused with "Trying to Send Data Before Thread is Started!"), while
the thread has ended and the reconnect is pending, and while
create_SOL() is connecting. It refuses only without any connection.
- At most E2UART_MAX_QUEUED (16) requests wait; the oldest are dropped.
A failed reconnect clears the queue, because those queries are stale.
- The "NO reply" debug line shows the request bytes (first 12), so a
repeated query can be recognised in the log.
Tested with a fake device that goes silent after 3 replies: the query
sent while the thread was starting and the query queued during the
reconnect were both answered, and nothing was refused (ASan clean).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
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
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
"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
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