|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Datagram protocol handler for reliable 0-72 byte addressed transfers. More...
Go to the source code of this file.
Data Structures | |
| struct | interface_protocol_datagram_handler_t |
| Callback interface for the datagram handler. lock/unlock are REQUIRED; all memory-operation pointers are optional (NULL = rejected). More... | |
Typedefs | |
| typedef void(* | memory_handler_t) (openlcb_statemachine_info_t *statemachine_info) |
| Function pointer type shared by all per-address-space memory handlers. | |
Functions | |
| void | ProtocolDatagramHandler_initialize (const interface_protocol_datagram_handler_t *interface_protocol_datagram_handler) |
| Stores the callback interface. Call once at startup before any datagram processing. | |
| void | ProtocolDatagramHandler_load_datagram_received_ok_message (openlcb_statemachine_info_t *statemachine_info, uint16_t reply_pending_time_in_seconds) |
| Builds a Datagram Received OK message (MTI 0x0A28). | |
| void | ProtocolDatagramHandler_load_datagram_rejected_message (openlcb_statemachine_info_t *statemachine_info, uint16_t return_code) |
| Builds a Datagram Rejected message (MTI 0x0A48). | |
| void | ProtocolDatagramHandler_datagram (openlcb_statemachine_info_t *statemachine_info) |
| Processes an incoming datagram. Dispatches to the appropriate handler based on the command byte (payload[0]). | |
| void | ProtocolDatagramHandler_datagram_received_ok (openlcb_statemachine_info_t *statemachine_info) |
| Handles an incoming Datagram Received OK reply. Clears the resend flag and frees the stored datagram awaiting acknowledgement. | |
| void | ProtocolDatagramHandler_datagram_rejected (openlcb_statemachine_info_t *statemachine_info) |
| Handles an incoming Datagram Rejected reply. Sets the resend flag for temporary errors; clears retry state for permanent errors. | |
| void | ProtocolDatagramHandler_clear_resend_datagram_message (openlcb_node_t *openlcb_node) |
| Frees any stored datagram and clears the resend flag for the 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 for 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.
Routes incoming datagrams to per-address-space callbacks for read, write, write-under-mask, and stream variants. NULL optional callbacks cause automatic rejection with SUBCOMMAND_UNKNOWN. Handles Datagram Received OK, Datagram Rejected, and retry logic with timeout tracking.
| typedef void(* memory_handler_t) (openlcb_statemachine_info_t *statemachine_info) |
Function pointer type shared by all per-address-space memory handlers.
|
extern |
Stores the callback interface. Call once at startup before any datagram processing.
| interface_protocol_datagram_handler | Pointer to interface_protocol_datagram_handler_t (must remain valid for application lifetime). |
Stores the callback interface. Call once at startup before any datagram processing.
Algorithm:
* @param interface_protocol_datagram_handler Populated callback table. *
|
extern |
Builds a Datagram Received OK message (MTI 0x0A28).
The Reply Pending bit (0x80) is always set. A reply datagram (read data, write OK/fail, etc.) will always follow.
| statemachine_info | Pointer to openlcb_statemachine_info_t context. |
| reply_pending_time_in_seconds | Seconds until reply (rounded up to 2^N); 0 for no specific timeout. |
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. *
|
extern |
Builds a Datagram Rejected message (MTI 0x0A48).
| statemachine_info | Pointer to openlcb_statemachine_info_t context. |
| return_code | OpenLCB error code (0x1xxx permanent, 0x2xxx temporary). |
Builds a Datagram Rejected message (MTI 0x0A48).
Algorithm:
* @param statemachine_info Current context. * @param return_code OpenLCB error code (0x1xxx permanent, 0x2xxx temporary). *
|
extern |
Processes an incoming datagram. Dispatches to the appropriate handler based on the command byte (payload[0]).
| statemachine_info | Pointer to openlcb_statemachine_info_t context with the received datagram. |
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. *
|
extern |
Handles an incoming Datagram Received OK reply. Clears the resend flag and frees the stored datagram awaiting acknowledgement.
| statemachine_info | Pointer to openlcb_statemachine_info_t context with the received reply. |
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. *
|
extern |
Handles an incoming Datagram Rejected reply. Sets the resend flag for temporary errors; clears retry state for permanent errors.
| statemachine_info | Pointer to openlcb_statemachine_info_t context with the received rejection. |
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. *
|
extern |
Frees any stored datagram and clears the resend flag for the node.
| openlcb_node | Pointer to openlcb_node_t target node. |
Frees any stored datagram and clears the resend flag for the node.
Algorithm:
* @param openlcb_node Target node. *
|
extern |
Periodic timer tick for datagram timeout tracking.
Called from the main loop with the current global tick. Currently a placeholder — Item 2 will add timeout handling.
| current_tick | Current value of the global 100ms tick counter. |
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. *
|
extern |
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.
| current_tick | Current value of the global 100ms tick, passed from the main loop. |
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