|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Datagram protocol handler — reliable 0–72 byte addressed transfers. More...
Macros | |
| #define | DATAGRAM_TIMEOUT_TICKS 30 |
| Default datagram timeout in 100ms ticks (3 seconds). | |
| #define | DATAGRAM_MAX_RETRIES 3 |
| Maximum datagram retry attempts before abandoning. | |
Functions | |
| void | ProtocolDatagramHandler_initialize (const interface_protocol_datagram_handler_t *interface_protocol_datagram_handler) |
| Stores the callback interface. Call once at startup. | |
| void | ProtocolDatagramHandler_datagram (openlcb_statemachine_info_t *statemachine_info) |
| Main entry point — switches on payload[0] command byte. | |
| void | ProtocolDatagramHandler_load_datagram_received_ok_message (openlcb_statemachine_info_t *statemachine_info, uint16_t reply_pending_time_in_seconds) |
| Build a Datagram Received OK message (MTI 0x0A28). | |
| void | ProtocolDatagramHandler_load_datagram_rejected_message (openlcb_statemachine_info_t *statemachine_info, uint16_t return_code) |
| Build a Datagram Rejected message (MTI 0x0A48). | |
| void | ProtocolDatagramHandler_datagram_received_ok (openlcb_statemachine_info_t *statemachine_info) |
| Handle incoming Datagram Received OK (MTI 0x0A28). | |
| void | ProtocolDatagramHandler_datagram_rejected (openlcb_statemachine_info_t *statemachine_info) |
| Handle incoming Datagram Rejected (MTI 0x0A48). | |
| void | ProtocolDatagramHandler_clear_resend_datagram_message (openlcb_node_t *openlcb_node) |
| Free stored datagram and clear resend flag for a node. | |
| void | ProtocolDatagramHandler_100ms_timer_tick (uint8_t current_tick) |
| Periodic timer tick for datagram timeout tracking. | |
| void | ProtocolDatagramHandler_check_timeouts (uint8_t current_tick) |
| Scans for timed-out or max-retried pending datagrams and frees them. | |
Datagram protocol handler — reliable 0–72 byte addressed transfers.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Dispatches incoming datagrams to per-address-space callbacks for read, write, write-under-mask, and stream variants (both datagram- and stream-transport). Callback-based: the application populates an interface_protocol_datagram_handler_t with handler pointers; NULL pointers cause automatic rejection with SUBCOMMAND_UNKNOWN.
Also handles Datagram Received OK / Rejected replies including retry logic for temporary errors.
| #define DATAGRAM_TIMEOUT_TICKS 30 |
Default datagram timeout in 100ms ticks (3 seconds).
| #define DATAGRAM_MAX_RETRIES 3 |
Maximum datagram retry attempts before abandoning.
| void ProtocolDatagramHandler_initialize | ( | const interface_protocol_datagram_handler_t * | interface_protocol_datagram_handler | ) |
Stores the callback interface. Call once at startup.
Stores the callback interface. Call once at startup before any datagram processing.
Algorithm:
* @param interface_protocol_datagram_handler Populated callback table. *
| void ProtocolDatagramHandler_datagram | ( | openlcb_statemachine_info_t * | statemachine_info | ) |
Main entry point — switches on payload[0] command byte.
Processes an incoming datagram. Dispatches to the appropriate handler based on the command byte (payload[0]).
Algorithm:
* @param statemachine_info Context with the received datagram. *
| void ProtocolDatagramHandler_load_datagram_received_ok_message | ( | openlcb_statemachine_info_t * | statemachine_info, |
| uint16_t | reply_pending_time_in_seconds ) |
Build a Datagram Received OK message (MTI 0x0A28).
Builds a Datagram Received OK message (MTI 0x0A28).
Algorithm:
* @param statemachine_info Current context. * @param reply_pending true if a reply datagram will follow. * @param reply_pending_time_in_seconds Seconds until reply (rounded up to 2^N). * Ignored when reply_pending is false. *
| void ProtocolDatagramHandler_load_datagram_rejected_message | ( | openlcb_statemachine_info_t * | statemachine_info, |
| uint16_t | return_code ) |
Build a Datagram Rejected message (MTI 0x0A48).
Builds a Datagram Rejected message (MTI 0x0A48).
Algorithm:
* @param statemachine_info Current context. * @param return_code OpenLCB error code (0x1xxx permanent, 0x2xxx temporary). *
| void ProtocolDatagramHandler_datagram_received_ok | ( | openlcb_statemachine_info_t * | statemachine_info | ) |
Handle incoming Datagram Received OK (MTI 0x0A28).
Handles an incoming Datagram Received OK reply. Clears the resend flag and frees the stored datagram awaiting acknowledgement.
Algorithm:
* @param statemachine_info Context with the received OK reply. *
| void ProtocolDatagramHandler_datagram_rejected | ( | openlcb_statemachine_info_t * | statemachine_info | ) |
Handle incoming Datagram Rejected (MTI 0x0A48).
Handles an incoming Datagram Rejected reply. Sets the resend flag for temporary errors; clears retry state for permanent errors.
Algorithm:
* @param statemachine_info Context with the received rejection. *
| void ProtocolDatagramHandler_clear_resend_datagram_message | ( | openlcb_node_t * | openlcb_node | ) |
Free stored datagram and clear resend flag for a node.
Frees any stored datagram and clears the resend flag for the node.
Algorithm:
* @param openlcb_node Target node. *
| void ProtocolDatagramHandler_100ms_timer_tick | ( | uint8_t | current_tick | ) |
Periodic timer tick for datagram timeout tracking.
Called from the main loop with the current global tick. Currently a placeholder — timeout scanning is done by ProtocolDatagramHandler_check_timeouts().
* @param current_tick Current value of the global 100ms tick counter. *
| void ProtocolDatagramHandler_check_timeouts | ( | uint8_t | current_tick | ) |
Scans for timed-out or max-retried pending datagrams and frees them.
Must be called from the main processing loop, not from an interrupt. Acquires the shared resource lock internally.
* @param current_tick Current value of the global 100ms tick, passed from the main loop. *
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License