LSH-Core
Deterministic firmware core for Controllino-based Labo Smart Home nodes
 
Loading...
Searching...
No Matches
BridgeSerial Namespace Reference

Controller-side serial link used to exchange payloads with lsh-bridge. More...

Classes

struct  ReceiveResult
 

Functions

void init ()
 Initialize the serial port used to talk with lsh-bridge.
 
auto receiveAndDispatch (uint16_t maxBytesToConsume) -> ReceiveResult
 Consume a bounded amount of serial input and dispatch at most one payload.
 
void tickSendIdleTimer (uint16_t elapsed_ms)
 Advance the ping idle timer used by canPing().
 
auto canPing () -> bool
 Check whether the bridge link may emit another heartbeat.
 
void updateLastSentTime ()
 Record that a payload has just been transmitted to the bridge.
 
auto isConnected () -> bool
 Check whether the bridge is still considered connected.
 

Variables

uint16_t sendIdleAge_ms = UINT16_MAX
 Elapsed idle time since the last payload was sent, saturated at 65535 ms.
 
uint16_t receiveIdleAge_ms = UINT16_MAX
 Elapsed idle time since the last valid payload was received, saturated at 65535 ms.
 

Detailed Description

Controller-side serial link used to exchange payloads with lsh-bridge.

Function Documentation

◆ canPing()

auto BridgeSerial::canPing ( ) -> bool

Check whether the bridge link may emit another heartbeat.

Heartbeats are rate-limited using PING_INTERVAL_MS so the controller does not flood the serial line when the rest of the loop is otherwise idle.

Returns
true if enough time elapsed since the last transmitted payload.
false if the heartbeat interval is still active.
Here is the caller graph for this function:

◆ init()

void BridgeSerial::init ( )

Initialize the serial port used to talk with lsh-bridge.

The controller and the bridge share one hardware serial link. This helper applies the configured baud rate once during startup so every later send/receive path can assume the port is already ready.

Here is the caller graph for this function:

◆ isConnected()

auto BridgeSerial::isConnected ( ) -> bool

Check whether the bridge is still considered connected.

The bridge is considered online only after the first valid payload has reset the receive idle age and only while the receive timeout window stays open. The age is advanced once by the main loop using the shared bridge-housekeeping delta, avoiding 32-bit timestamp subtraction in network-click routing.

Returns
true if the bridge answered recently enough.
false if the bridge never answered or timed out.
Here is the caller graph for this function:

◆ receiveAndDispatch()

auto BridgeSerial::receiveAndDispatch ( uint16_t  maxBytesToConsume) -> ReceiveResult

Consume a bounded amount of serial input and dispatch at most one payload.

This helper is intentionally bounded both by bytes and by payload count. The caller can therefore keep the controller loop fair even if the UART is carrying noise, truncated frames or a long burst of valid commands.

Parameters
maxBytesToConsumeMaximum number of raw UART bytes this call may drain.
Returns
ReceiveResult Byte-consumption and dispatch information for this receive attempt.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tickSendIdleTimer()

void BridgeSerial::tickSendIdleTimer ( uint16_t  elapsed_ms)

Advance the ping idle timer used by canPing().

The main loop computes one cached elapsed time for bridge housekeeping and feeds it here. Reusing that delta avoids another 32-bit timestamp comparison in canPing() while keeping bridge-link liveness independent from the clickable scan policy.

Parameters
elapsed_msMilliseconds elapsed since the previous bridge housekeeping pass.
Here is the caller graph for this function:

◆ updateLastSentTime()

void BridgeSerial::updateLastSentTime ( )

Record that a payload has just been transmitted to the bridge.

Any successful send resets the idle age to zero so the next ping cannot be emitted until the serial line stayed quiet for the full heartbeat interval again.