OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
Loading...
Searching...
No Matches
can_tx_statemachine.h File Reference

Orchestrates CAN frame transmission for all OpenLCB message types. More...

Go to the source code of this file.

Data Structures

struct  interface_can_tx_statemachine_t
 Dependency-injection interface for the CAN transmit state machine. More...
 

Functions

void CanTxStatemachine_initialize (const interface_can_tx_statemachine_t *interface_can_tx_statemachine)
 Registers the dependency-injection interface for this module.
 
bool CanTxStatemachine_send_openlcb_message (openlcb_msg_t *openlcb_msg)
 Converts and transmits an openlcb_msg_t as one or more CAN frames.
 
bool CanTxStatemachine_send_can_message (can_msg_t *can_msg)
 Transmits a pre-built raw can_msg_t directly to the hardware.
 

Detailed Description

Orchestrates CAN frame transmission for all OpenLCB message types.

Checks hardware buffer availability, selects the correct message-type handler, and manages multi-frame sequencing until the full payload is sent.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ CanTxStatemachine_initialize()

void CanTxStatemachine_initialize ( const interface_can_tx_statemachine_t * interface_can_tx_statemachine)
extern

Registers the dependency-injection interface for this module.

Parameters
interface_can_tx_statemachinePointer to a populated interface_can_tx_statemachine_t. Must remain valid for the lifetime of the application. All 6 pointers must be non-NULL.
Warning
NOT thread-safe - call during single-threaded initialization only.
See also
CanTxMessageHandler_initialize - initialize first

Registers the dependency-injection interface for this module.

◆ CanTxStatemachine_send_openlcb_message()

bool CanTxStatemachine_send_openlcb_message ( openlcb_msg_t * openlcb_msg)
extern

Converts and transmits an openlcb_msg_t as one or more CAN frames.

Returns false immediately if the hardware TX buffer is not empty. Determines message type (addressed / unaddressed / datagram / stream), then loops until the entire payload is transmitted as an atomic multi-frame sequence.

Parameters
openlcb_msgOpenLCB message to transmit. Must not be NULL.
Returns
true when the full message is transmitted, false if the TX buffer was busy or a hardware error occurred.
Warning
May block briefly while transmitting multi-frame messages.
NOT thread-safe - serialize with other callers.
See also
CanTxStatemachine_send_can_message - for raw CAN frames

Converts and transmits an openlcb_msg_t as one or more CAN frames.

Algorithm:

  1. Discard immediately if state.invalid is set (AMR scrub marked it).
  2. If dest_alias == 0 and dest_id != 0, resolve the alias via listener_find_by_node_id (DI, nullable). Drop the message if unresolvable (return true so the caller clears the outgoing slot).
  3. Return false immediately if the TX hardware buffer is busy.
  4. If payload_count == 0: send a single zero-payload frame and return.
  5. Otherwise, send the first frame; if it fails return false.
  6. Loop calling _transmit_openlcb_message until payload_index == payload_count.
  7. Return true when done.
* @param openlcb_msg Message to transmit.
* 
Returns
true if the full message was sent, false if the hardware buffer was busy or failed.
Warning
Blocks until the entire multi-frame message is sent.

◆ CanTxStatemachine_send_can_message()

bool CanTxStatemachine_send_can_message ( can_msg_t * can_msg)
extern

Transmits a pre-built raw can_msg_t directly to the hardware.

No OpenLCB processing and no buffer-availability check — caller is responsible for ensuring the hardware is ready. Used primarily for CAN control frames (CID, RID, AMD) during alias allocation.

Parameters
can_msgFully-constructed CAN frame. Must not be NULL.
Returns
true on success, false on hardware failure.
See also
CanTxStatemachine_send_openlcb_message - for OpenLCB messages

Transmits a pre-built raw can_msg_t directly to the hardware.


Copyright (c) 2026 Jim Kueneman all rights reserved. See the License