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

Common utility functions for OpenLCB message and buffer manipulation. More...

Go to the source code of this file.

Functions

void OpenLcbUtilities_load_openlcb_message (openlcb_msg_t *openlcb_msg, uint16_t source_alias, uint64_t source_id, uint16_t dest_alias, uint64_t dest_id, uint16_t mti)
 Loads message header fields and clears the payload to zeros.
 
void OpenLcbUtilities_clear_openlcb_message_payload (openlcb_msg_t *openlcb_msg)
 Zeros all payload bytes and resets payload_count. Header preserved.
 
void OpenLcbUtilities_clear_openlcb_message (openlcb_msg_t *openlcb_msg)
 Zeros entire message including header, state flags, and reference count.
 
void OpenLcbUtilities_copy_event_id_to_openlcb_payload (openlcb_msg_t *openlcb_msg, event_id_t event_id)
 Copies an 8-byte event ID to payload at offset 0.
 
void OpenLcbUtilities_copy_node_id_to_openlcb_payload (openlcb_msg_t *openlcb_msg, node_id_t node_id, uint16_t offset)
 Copies a 6-byte node ID to payload at the given offset.
 
void OpenLcbUtilities_copy_byte_to_openlcb_payload (openlcb_msg_t *openlcb_msg, uint8_t byte, uint16_t offset)
 Copies one byte to payload at the given offset.
 
void OpenLcbUtilities_copy_word_to_openlcb_payload (openlcb_msg_t *openlcb_msg, uint16_t word, uint16_t offset)
 Copies a 16-bit word (big-endian) to payload at the given offset.
 
void OpenLcbUtilities_copy_dword_to_openlcb_payload (openlcb_msg_t *openlcb_msg, uint32_t doubleword, uint16_t offset)
 Copies a 32-bit doubleword (big-endian) to payload at the given offset.
 
uint16_t OpenLcbUtilities_copy_string_to_openlcb_payload (openlcb_msg_t *openlcb_msg, const char string[], uint16_t offset)
 Copies a null-terminated string into the payload.
 
uint16_t OpenLcbUtilities_copy_byte_array_to_openlcb_payload (openlcb_msg_t *openlcb_msg, const uint8_t byte_array[], uint16_t offset, uint16_t requested_bytes)
 Copies a byte array into the payload.
 
node_id_t OpenLcbUtilities_extract_node_id_from_openlcb_payload (openlcb_msg_t *openlcb_msg, uint16_t offset)
 Extracts a 6-byte node ID from payload at the given offset.
 
event_id_t OpenLcbUtilities_extract_event_id_from_openlcb_payload (openlcb_msg_t *openlcb_msg)
 Extracts an 8-byte event ID from payload at offset 0.
 
uint8_t OpenLcbUtilities_extract_byte_from_openlcb_payload (openlcb_msg_t *openlcb_msg, uint16_t offset)
 Extracts one byte from payload at the given offset.
 
uint16_t OpenLcbUtilities_extract_word_from_openlcb_payload (openlcb_msg_t *openlcb_msg, uint16_t offset)
 Extracts a 16-bit word (big-endian) from payload at the given offset.
 
uint32_t OpenLcbUtilities_extract_dword_from_openlcb_payload (openlcb_msg_t *openlcb_msg, uint16_t offset)
 Extracts a 32-bit doubleword (big-endian) from payload at the given offset.
 
uint8_t OpenLcbUtilities_count_nulls_in_openlcb_payload (openlcb_msg_t *openlcb_msg)
 Returns the count of null bytes (0x00) in the payload. Used for SNIP validation.
 
bool OpenLcbUtilities_is_addressed_openlcb_message (openlcb_msg_t *openlcb_msg)
 Returns true if the MTI has the destination-address-present bit set.
 
bool OpenLcbUtilities_is_addressed_message_for_node (openlcb_node_t *openlcb_node, openlcb_msg_t *openlcb_msg)
 Returns true if the message destination matches this node's alias or ID.
 
void OpenLcbUtilities_set_multi_frame_flag (uint8_t *target, uint8_t flag)
 Sets the multi-frame control flag in the upper nibble of target, preserving the lower nibble.
 
bool OpenLcbUtilities_is_producer_event_assigned_to_node (openlcb_node_t *openlcb_node, event_id_t event_id, uint16_t *event_index)
 Searches the node's producer list for a matching event ID.
 
bool OpenLcbUtilities_is_consumer_event_assigned_to_node (openlcb_node_t *openlcb_node, event_id_t event_id, uint16_t *event_index)
 Searches the node's consumer list for a matching event ID.
 
uint32_t OpenLcbUtilities_calculate_memory_offset_into_node_space (openlcb_node_t *openlcb_node)
 Returns the byte offset into global config memory where this node's space begins.
 
uint16_t OpenLcbUtilities_payload_type_to_len (payload_type_enum payload_type)
 Converts a payload_type_enum to its maximum byte length. Returns 0 for unknown types.
 
node_id_t OpenLcbUtilities_extract_node_id_from_config_mem_buffer (configuration_memory_buffer_t *buffer, uint8_t index)
 Extracts a 6-byte node ID from a config memory buffer at the given index.
 
uint16_t OpenLcbUtilities_extract_word_from_config_mem_buffer (configuration_memory_buffer_t *buffer, uint8_t index)
 Extracts a 16-bit word from a config memory buffer at the given index.
 
void OpenLcbUtilities_copy_node_id_to_config_mem_buffer (configuration_memory_buffer_t *buffer, node_id_t node_id, uint8_t index)
 Copies a 6-byte node ID into a config memory buffer at the given index.
 
void OpenLcbUtilities_copy_event_id_to_config_mem_buffer (configuration_memory_buffer_t *buffer, event_id_t event_id, uint8_t index)
 Copies an 8-byte event ID into a config memory buffer at the given index.
 
event_id_t OpenLcbUtilities_copy_config_mem_buffer_to_event_id (configuration_memory_buffer_t *buffer, uint8_t index)
 Extracts an 8-byte event ID from a config memory buffer at the given index.
 
void OpenLcbUtilities_load_config_mem_reply_write_fail_message_header (openlcb_statemachine_info_t *statemachine_info, config_mem_write_request_info_t *config_mem_write_request_info, uint16_t error_code)
 Builds a config memory write-failure reply datagram header.
 
void OpenLcbUtilities_load_config_mem_reply_write_ok_message_header (openlcb_statemachine_info_t *statemachine_info, config_mem_write_request_info_t *config_mem_write_request_info)
 Builds a config memory write-success reply datagram header.
 
void OpenLcbUtilities_load_config_mem_reply_read_fail_message_header (openlcb_statemachine_info_t *statemachine_info, config_mem_read_request_info_t *config_mem_read_request_info, uint16_t error_code)
 Builds a config memory read-failure reply datagram header.
 
void OpenLcbUtilities_load_config_mem_reply_read_ok_message_header (openlcb_statemachine_info_t *statemachine_info, config_mem_read_request_info_t *config_mem_read_request_info)
 Builds a config memory read-success reply datagram header only.
 
event_id_t OpenLcbUtilities_generate_event_range_id (event_id_t base_event_id, event_range_count_enum count)
 Generates a masked Event ID covering a range of consecutive events.
 
bool OpenLcbUtilities_is_event_id_in_consumer_ranges (openlcb_node_t *openlcb_node, event_id_t event_id)
 Returns true if the event ID falls within any of the node's consumer ranges.
 
bool OpenLcbUtilities_is_event_id_in_producer_ranges (openlcb_node_t *openlcb_node, event_id_t event_id)
 Returns true if the event ID falls within any of the node's producer ranges.
 
bool OpenLcbUtilities_is_broadcast_time_event (event_id_t event_id)
 Returns true if the event ID belongs to the broadcast time event space.
 
uint64_t OpenLcbUtilities_extract_clock_id_from_time_event (event_id_t event_id)
 Extracts the 48-bit clock ID (upper 6 bytes) from a broadcast time event ID.
 
broadcast_time_event_type_enum OpenLcbUtilities_get_broadcast_time_event_type (event_id_t event_id)
 Returns the broadcast_time_event_type_enum for a broadcast time event ID.
 
bool OpenLcbUtilities_extract_time_from_event_id (event_id_t event_id, uint8_t *hour, uint8_t *minute)
 Extracts hour and minute from a broadcast time event ID.
 
bool OpenLcbUtilities_extract_date_from_event_id (event_id_t event_id, uint8_t *month, uint8_t *day)
 Extracts month and day from a broadcast time event ID.
 
bool OpenLcbUtilities_extract_year_from_event_id (event_id_t event_id, uint16_t *year)
 Extracts year from a broadcast time event ID.
 
bool OpenLcbUtilities_extract_rate_from_event_id (event_id_t event_id, int16_t *rate)
 Extracts the 12-bit signed fixed-point rate from a broadcast time event ID.
 
event_id_t OpenLcbUtilities_create_time_event_id (uint64_t clock_id, uint8_t hour, uint8_t minute, bool is_set)
 Creates a Report/Set Time event ID from clock_id, hour, minute.
 
event_id_t OpenLcbUtilities_create_date_event_id (uint64_t clock_id, uint8_t month, uint8_t day, bool is_set)
 Creates a Report/Set Date event ID from clock_id, month, day.
 
event_id_t OpenLcbUtilities_create_year_event_id (uint64_t clock_id, uint16_t year, bool is_set)
 Creates a Report/Set Year event ID from clock_id, year.
 
event_id_t OpenLcbUtilities_create_rate_event_id (uint64_t clock_id, int16_t rate, bool is_set)
 Creates a Report/Set Rate event ID from clock_id, rate.
 
event_id_t OpenLcbUtilities_create_command_event_id (uint64_t clock_id, broadcast_time_event_type_enum command)
 Creates a command event ID (Query, Start, Stop, Date Rollover) for the given clock.
 
bool OpenLcbUtilities_is_train_search_event (event_id_t event_id)
 Returns true if the event ID belongs to the train search space (upper 4 bytes = 0x090099FF).
 
void OpenLcbUtilities_extract_train_search_digits (event_id_t event_id, uint8_t *digits)
 Extracts 6 search-query nibbles from a train search event ID into digits[].
 
uint8_t OpenLcbUtilities_extract_train_search_flags (event_id_t event_id)
 Extracts the flags byte (byte 7) from a train search event ID.
 
uint16_t OpenLcbUtilities_train_search_digits_to_address (const uint8_t *digits)
 Converts a 6-nibble digit array to a numeric DCC address, skipping leading 0xF nibbles.
 
event_id_t OpenLcbUtilities_create_train_search_event_id (uint16_t address, uint8_t flags)
 Creates a train search event ID from a DCC address and flags byte.
 
bool OpenLcbUtilities_is_emergency_event (event_id_t event_id)
 Returns true if the event ID is one of the 4 well-known emergency events.
 

Detailed Description

Common utility functions for OpenLCB message and buffer manipulation.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

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.

Provides helpers for message construction, payload insert/extract, configuration memory buffer operations, event range calculations, broadcast time event encoding/decoding, and train search event encoding/decoding.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ OpenLcbUtilities_load_openlcb_message()

void OpenLcbUtilities_load_openlcb_message ( openlcb_msg_t * openlcb_msg,
uint16_t source_alias,
uint64_t source_id,
uint16_t dest_alias,
uint64_t dest_id,
uint16_t mti )
extern

Loads message header fields and clears the payload to zeros.

Parameters
openlcb_msgPointer to the openlcb_msg_t to initialize
source_alias12-bit CAN alias of the source node
source_id48-bit node_id_t of the source node
dest_alias12-bit CAN alias of the destination (0 for global)
dest_id48-bit node_id_t of the destination (0 for global)
mtiMessage Type Indicator
Warning
NULL pointer causes undefined behavior.

◆ OpenLcbUtilities_clear_openlcb_message_payload()

void OpenLcbUtilities_clear_openlcb_message_payload ( openlcb_msg_t * openlcb_msg)
extern

Zeros all payload bytes and resets payload_count. Header preserved.

Parameters
openlcb_msgPointer to the openlcb_msg_t to clear payload from.

◆ OpenLcbUtilities_clear_openlcb_message()

void OpenLcbUtilities_clear_openlcb_message ( openlcb_msg_t * openlcb_msg)
extern

Zeros entire message including header, state flags, and reference count.

Parameters
openlcb_msgPointer to the openlcb_msg_t to fully clear.

◆ OpenLcbUtilities_copy_event_id_to_openlcb_payload()

void OpenLcbUtilities_copy_event_id_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
event_id_t event_id )
extern

Copies an 8-byte event ID to payload at offset 0.

Parameters
openlcb_msgPointer to the openlcb_msg_t to write into.
event_id64-bit event_id_t to store in the payload.

◆ OpenLcbUtilities_copy_node_id_to_openlcb_payload()

void OpenLcbUtilities_copy_node_id_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
node_id_t node_id,
uint16_t offset )
extern

Copies a 6-byte node ID to payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to write into.
node_id48-bit node_id_t to store in the payload.
offsetStarting byte offset in the payload.

Copies a 6-byte node ID to payload at the given offset.

◆ OpenLcbUtilities_copy_byte_to_openlcb_payload()

void OpenLcbUtilities_copy_byte_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint8_t byte,
uint16_t offset )
extern

Copies one byte to payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to write into.
byteByte value to store.
offsetByte offset in the payload.

◆ OpenLcbUtilities_copy_word_to_openlcb_payload()

void OpenLcbUtilities_copy_word_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint16_t word,
uint16_t offset )
extern

Copies a 16-bit word (big-endian) to payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to write into.
word16-bit value to store in big-endian order.
offsetStarting byte offset in the payload.

◆ OpenLcbUtilities_copy_dword_to_openlcb_payload()

void OpenLcbUtilities_copy_dword_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint32_t doubleword,
uint16_t offset )
extern

Copies a 32-bit doubleword (big-endian) to payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to write into.
doubleword32-bit value to store in big-endian order.
offsetStarting byte offset in the payload.

◆ OpenLcbUtilities_copy_string_to_openlcb_payload()

uint16_t OpenLcbUtilities_copy_string_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
const char string[],
uint16_t offset )
extern

Copies a null-terminated string into the payload.

Truncates if payload space is insufficient but always adds a null terminator.

Parameters
openlcb_msgPointer to the openlcb_msg_t
stringNull-terminated source string
offsetStarting byte offset in the payload
Returns
Number of bytes written including the null terminator.

Truncates if payload space is insufficient but always adds a null terminator.

◆ OpenLcbUtilities_copy_byte_array_to_openlcb_payload()

uint16_t OpenLcbUtilities_copy_byte_array_to_openlcb_payload ( openlcb_msg_t * openlcb_msg,
const uint8_t byte_array[],
uint16_t offset,
uint16_t requested_bytes )
extern

Copies a byte array into the payload.

May copy fewer bytes than requested if payload space is exhausted.

Parameters
openlcb_msgPointer to the openlcb_msg_t
byte_arraySource data
offsetStarting byte offset in the payload
requested_bytesNumber of bytes to attempt to copy
Returns
Actual number of bytes copied.

Copies a byte array into the payload.

◆ OpenLcbUtilities_extract_node_id_from_openlcb_payload()

node_id_t OpenLcbUtilities_extract_node_id_from_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint16_t offset )
extern

Extracts a 6-byte node ID from payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to read from.
offsetStarting byte offset in the payload.
Returns
48-bit node_id_t assembled from the payload bytes.

◆ OpenLcbUtilities_extract_event_id_from_openlcb_payload()

event_id_t OpenLcbUtilities_extract_event_id_from_openlcb_payload ( openlcb_msg_t * openlcb_msg)
extern

Extracts an 8-byte event ID from payload at offset 0.

Parameters
openlcb_msgPointer to the openlcb_msg_t to read from.
Returns
64-bit event_id_t assembled from the payload bytes.

◆ OpenLcbUtilities_extract_byte_from_openlcb_payload()

uint8_t OpenLcbUtilities_extract_byte_from_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint16_t offset )
extern

Extracts one byte from payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to read from.
offsetByte offset in the payload.
Returns
Byte value at the specified offset.

◆ OpenLcbUtilities_extract_word_from_openlcb_payload()

uint16_t OpenLcbUtilities_extract_word_from_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint16_t offset )
extern

Extracts a 16-bit word (big-endian) from payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to read from.
offsetStarting byte offset in the payload.
Returns
16-bit value assembled from two big-endian payload bytes.

◆ OpenLcbUtilities_extract_dword_from_openlcb_payload()

uint32_t OpenLcbUtilities_extract_dword_from_openlcb_payload ( openlcb_msg_t * openlcb_msg,
uint16_t offset )
extern

Extracts a 32-bit doubleword (big-endian) from payload at the given offset.

Parameters
openlcb_msgPointer to the openlcb_msg_t to read from.
offsetStarting byte offset in the payload.
Returns
32-bit value assembled from four big-endian payload bytes.

◆ OpenLcbUtilities_count_nulls_in_openlcb_payload()

uint8_t OpenLcbUtilities_count_nulls_in_openlcb_payload ( openlcb_msg_t * openlcb_msg)
extern

Returns the count of null bytes (0x00) in the payload. Used for SNIP validation.

Parameters
openlcb_msgPointer to the openlcb_msg_t to scan.
Returns
Number of null bytes found in the payload.

◆ OpenLcbUtilities_is_addressed_openlcb_message()

bool OpenLcbUtilities_is_addressed_openlcb_message ( openlcb_msg_t * openlcb_msg)
extern

Returns true if the MTI has the destination-address-present bit set.

Parameters
openlcb_msgPointer to the openlcb_msg_t to check.
Returns
true if the message is addressed, false if global.

◆ OpenLcbUtilities_is_addressed_message_for_node()

bool OpenLcbUtilities_is_addressed_message_for_node ( openlcb_node_t * openlcb_node,
openlcb_msg_t * openlcb_msg )
extern

Returns true if the message destination matches this node's alias or ID.

Parameters
openlcb_nodePointer to the openlcb_node_t to match against.
openlcb_msgPointer to the openlcb_msg_t to check.
Returns
true if the message is addressed to this node.

◆ OpenLcbUtilities_set_multi_frame_flag()

void OpenLcbUtilities_set_multi_frame_flag ( uint8_t * target,
uint8_t flag )
extern

Sets the multi-frame control flag in the upper nibble of target, preserving the lower nibble.

Parameters
targetPointer to the byte whose upper nibble will be replaced.
flagFlag value to write into the upper nibble.

◆ OpenLcbUtilities_is_producer_event_assigned_to_node()

bool OpenLcbUtilities_is_producer_event_assigned_to_node ( openlcb_node_t * openlcb_node,
event_id_t event_id,
uint16_t * event_index )
extern

Searches the node's producer list for a matching event ID.

Parameters
openlcb_nodeNode to search
event_idEvent ID to find
event_indexReceives the list index if found (undefined on false return)
Returns
true if event found in producer list.

◆ OpenLcbUtilities_is_consumer_event_assigned_to_node()

bool OpenLcbUtilities_is_consumer_event_assigned_to_node ( openlcb_node_t * openlcb_node,
event_id_t event_id,
uint16_t * event_index )
extern

Searches the node's consumer list for a matching event ID.

Parameters
openlcb_nodeNode to search
event_idEvent ID to find
event_indexReceives the list index if found (undefined on false return)
Returns
true if event found in consumer list.

◆ OpenLcbUtilities_calculate_memory_offset_into_node_space()

uint32_t OpenLcbUtilities_calculate_memory_offset_into_node_space ( openlcb_node_t * openlcb_node)
extern

Returns the byte offset into global config memory where this node's space begins.

Parameters
openlcb_nodePointer to the openlcb_node_t to calculate the offset for.
Returns
Byte offset into the global configuration memory array.

◆ OpenLcbUtilities_payload_type_to_len()

uint16_t OpenLcbUtilities_payload_type_to_len ( payload_type_enum payload_type)
extern

Converts a payload_type_enum to its maximum byte length. Returns 0 for unknown types.

Parameters
payload_typeThe payload_type_enum value to convert.
Returns
Maximum payload byte length for the given type, or 0 if unknown.

Converts a payload_type_enum to its maximum byte length. Returns 0 for unknown types.

◆ OpenLcbUtilities_extract_node_id_from_config_mem_buffer()

node_id_t OpenLcbUtilities_extract_node_id_from_config_mem_buffer ( configuration_memory_buffer_t * buffer,
uint8_t index )
extern

Extracts a 6-byte node ID from a config memory buffer at the given index.

Parameters
bufferPointer to the configuration_memory_buffer_t to read from.
indexStarting byte index in the buffer.
Returns
48-bit node_id_t assembled from the buffer bytes.

◆ OpenLcbUtilities_extract_word_from_config_mem_buffer()

uint16_t OpenLcbUtilities_extract_word_from_config_mem_buffer ( configuration_memory_buffer_t * buffer,
uint8_t index )
extern

Extracts a 16-bit word from a config memory buffer at the given index.

Parameters
bufferPointer to the configuration_memory_buffer_t to read from.
indexStarting byte index in the buffer.
Returns
16-bit value assembled from two big-endian buffer bytes.

◆ OpenLcbUtilities_copy_node_id_to_config_mem_buffer()

void OpenLcbUtilities_copy_node_id_to_config_mem_buffer ( configuration_memory_buffer_t * buffer,
node_id_t node_id,
uint8_t index )
extern

Copies a 6-byte node ID into a config memory buffer at the given index.

Parameters
bufferPointer to the configuration_memory_buffer_t to write into.
node_id48-bit node_id_t to store.
indexStarting byte index in the buffer.

◆ OpenLcbUtilities_copy_event_id_to_config_mem_buffer()

void OpenLcbUtilities_copy_event_id_to_config_mem_buffer ( configuration_memory_buffer_t * buffer,
event_id_t event_id,
uint8_t index )
extern

Copies an 8-byte event ID into a config memory buffer at the given index.

Parameters
bufferPointer to the configuration_memory_buffer_t to write into.
event_id64-bit event_id_t to store.
indexStarting byte index in the buffer.

◆ OpenLcbUtilities_copy_config_mem_buffer_to_event_id()

event_id_t OpenLcbUtilities_copy_config_mem_buffer_to_event_id ( configuration_memory_buffer_t * buffer,
uint8_t index )
extern

Extracts an 8-byte event ID from a config memory buffer at the given index.

Parameters
bufferPointer to the configuration_memory_buffer_t to read from.
indexStarting byte index in the buffer.
Returns
64-bit event_id_t assembled from the buffer bytes.

◆ OpenLcbUtilities_load_config_mem_reply_write_fail_message_header()

void OpenLcbUtilities_load_config_mem_reply_write_fail_message_header ( openlcb_statemachine_info_t * statemachine_info,
config_mem_write_request_info_t * config_mem_write_request_info,
uint16_t error_code )
extern

Builds a config memory write-failure reply datagram header.

Parameters
statemachine_infoopenlcb_statemachine_info_t context
config_mem_write_request_infoconfig_mem_write_request_info_t from original request
error_code16-bit error code

Error code placement depends on address encoding: ADDRESS_SPACE_IN_BYTE_6 places it at offset 7, otherwise offset 6.

◆ OpenLcbUtilities_load_config_mem_reply_write_ok_message_header()

void OpenLcbUtilities_load_config_mem_reply_write_ok_message_header ( openlcb_statemachine_info_t * statemachine_info,
config_mem_write_request_info_t * config_mem_write_request_info )
extern

Builds a config memory write-success reply datagram header.

Parameters
statemachine_infoPointer to the openlcb_statemachine_info_t context.
config_mem_write_request_infoPointer to the config_mem_write_request_info_t from the original request.

◆ OpenLcbUtilities_load_config_mem_reply_read_fail_message_header()

void OpenLcbUtilities_load_config_mem_reply_read_fail_message_header ( openlcb_statemachine_info_t * statemachine_info,
config_mem_read_request_info_t * config_mem_read_request_info,
uint16_t error_code )
extern

Builds a config memory read-failure reply datagram header.

Parameters
statemachine_infoopenlcb_statemachine_info_t context
config_mem_read_request_infoconfig_mem_read_request_info_t from original request
error_code16-bit error code

Error code is placed at the data_start offset where actual data would have been.

◆ OpenLcbUtilities_load_config_mem_reply_read_ok_message_header()

void OpenLcbUtilities_load_config_mem_reply_read_ok_message_header ( openlcb_statemachine_info_t * statemachine_info,
config_mem_read_request_info_t * config_mem_read_request_info )
extern

Builds a config memory read-success reply datagram header only.

Caller must append actual data bytes separately after this call.

Parameters
statemachine_infoopenlcb_statemachine_info_t context
config_mem_read_request_infoconfig_mem_read_request_info_t from original request

Caller must append actual data bytes separately after this call.

◆ OpenLcbUtilities_generate_event_range_id()

event_id_t OpenLcbUtilities_generate_event_range_id ( event_id_t base_event_id,
event_range_count_enum count )
extern

Generates a masked Event ID covering a range of consecutive events.

Parameters
base_event_idStarting event_id_t of the range
countNumber of events in the range (event_range_count_enum)
Returns
Masked event_id_t for a Range Identified message.

◆ OpenLcbUtilities_is_event_id_in_consumer_ranges()

bool OpenLcbUtilities_is_event_id_in_consumer_ranges ( openlcb_node_t * openlcb_node,
event_id_t event_id )
extern

Returns true if the event ID falls within any of the node's consumer ranges.

Parameters
openlcb_nodePointer to the openlcb_node_t whose consumer ranges are checked.
event_id64-bit event_id_t to test.
Returns
true if the event ID falls within a consumer range.

◆ OpenLcbUtilities_is_event_id_in_producer_ranges()

bool OpenLcbUtilities_is_event_id_in_producer_ranges ( openlcb_node_t * openlcb_node,
event_id_t event_id )
extern

Returns true if the event ID falls within any of the node's producer ranges.

Parameters
openlcb_nodePointer to the openlcb_node_t whose producer ranges are checked.
event_id64-bit event_id_t to test.
Returns
true if the event ID falls within a producer range.

◆ OpenLcbUtilities_is_broadcast_time_event()

bool OpenLcbUtilities_is_broadcast_time_event ( event_id_t event_id)
extern

Returns true if the event ID belongs to the broadcast time event space.

Parameters
event_id64-bit event_id_t to test.
Returns
true if the event ID is a broadcast time event.

◆ OpenLcbUtilities_extract_clock_id_from_time_event()

uint64_t OpenLcbUtilities_extract_clock_id_from_time_event ( event_id_t event_id)
extern

Extracts the 48-bit clock ID (upper 6 bytes) from a broadcast time event ID.

Parameters
event_idBroadcast time event_id_t to extract from.
Returns
48-bit clock identifier masked from the event ID.

◆ OpenLcbUtilities_get_broadcast_time_event_type()

broadcast_time_event_type_enum OpenLcbUtilities_get_broadcast_time_event_type ( event_id_t event_id)
extern

Returns the broadcast_time_event_type_enum for a broadcast time event ID.

Parameters
event_idBroadcast time event_id_t to classify.
Returns
The broadcast_time_event_type_enum indicating the event type.

◆ OpenLcbUtilities_extract_time_from_event_id()

bool OpenLcbUtilities_extract_time_from_event_id ( event_id_t event_id,
uint8_t * hour,
uint8_t * minute )
extern

Extracts hour and minute from a broadcast time event ID.

Parameters
event_idBroadcast time event ID
hourReceives hour (0-23)
minuteReceives minute (0-59)
Returns
true if values are valid, false if out of range.

Extracts hour and minute from a broadcast time event ID.

◆ OpenLcbUtilities_extract_date_from_event_id()

bool OpenLcbUtilities_extract_date_from_event_id ( event_id_t event_id,
uint8_t * month,
uint8_t * day )
extern

Extracts month and day from a broadcast time event ID.

Parameters
event_idBroadcast time event ID
monthReceives month (1-12)
dayReceives day (1-31)
Returns
true if values are valid, false if out of range.

Extracts month and day from a broadcast time event ID.

◆ OpenLcbUtilities_extract_year_from_event_id()

bool OpenLcbUtilities_extract_year_from_event_id ( event_id_t event_id,
uint16_t * year )
extern

Extracts year from a broadcast time event ID.

Parameters
event_idBroadcast time event ID
yearReceives year (0-4095)
Returns
true if extraction successful.

Extracts year from a broadcast time event ID.

◆ OpenLcbUtilities_extract_rate_from_event_id()

bool OpenLcbUtilities_extract_rate_from_event_id ( event_id_t event_id,
int16_t * rate )
extern

Extracts the 12-bit signed fixed-point rate from a broadcast time event ID.

Parameters
event_idBroadcast time event ID
rateReceives rate (10.2 fixed point, e.g. 0x0004 = 1.00)
Returns
true if extraction successful.

Rate format is 10.2 fixed point. Sign-extends bit 11 for negative rates.

◆ OpenLcbUtilities_create_time_event_id()

event_id_t OpenLcbUtilities_create_time_event_id ( uint64_t clock_id,
uint8_t hour,
uint8_t minute,
bool is_set )
extern

Creates a Report/Set Time event ID from clock_id, hour, minute.

Parameters
clock_id48-bit clock identifier.
hourHour value (0-23).
minuteMinute value (0-59).
is_settrue for a Set command, false for a Report.
Returns
Encoded event_id_t for the time event.

◆ OpenLcbUtilities_create_date_event_id()

event_id_t OpenLcbUtilities_create_date_event_id ( uint64_t clock_id,
uint8_t month,
uint8_t day,
bool is_set )
extern

Creates a Report/Set Date event ID from clock_id, month, day.

Parameters
clock_id48-bit clock identifier.
monthMonth value (1-12).
dayDay value (1-31).
is_settrue for a Set command, false for a Report.
Returns
Encoded event_id_t for the date event.

◆ OpenLcbUtilities_create_year_event_id()

event_id_t OpenLcbUtilities_create_year_event_id ( uint64_t clock_id,
uint16_t year,
bool is_set )
extern

Creates a Report/Set Year event ID from clock_id, year.

Parameters
clock_id48-bit clock identifier.
yearYear value (0-4095).
is_settrue for a Set command, false for a Report.
Returns
Encoded event_id_t for the year event.

◆ OpenLcbUtilities_create_rate_event_id()

event_id_t OpenLcbUtilities_create_rate_event_id ( uint64_t clock_id,
int16_t rate,
bool is_set )
extern

Creates a Report/Set Rate event ID from clock_id, rate.

Parameters
clock_id48-bit clock identifier.
rate12-bit signed fixed-point rate (10.2 format).
is_settrue for a Set command, false for a Report.
Returns
Encoded event_id_t for the rate event.

◆ OpenLcbUtilities_create_command_event_id()

event_id_t OpenLcbUtilities_create_command_event_id ( uint64_t clock_id,
broadcast_time_event_type_enum command )
extern

Creates a command event ID (Query, Start, Stop, Date Rollover) for the given clock.

Parameters
clock_id48-bit clock identifier.
commandbroadcast_time_event_type_enum specifying the command type.
Returns
Encoded event_id_t for the command event.

◆ OpenLcbUtilities_is_train_search_event()

bool OpenLcbUtilities_is_train_search_event ( event_id_t event_id)
extern

Returns true if the event ID belongs to the train search space (upper 4 bytes = 0x090099FF).

Parameters
event_id64-bit event_id_t to test.
Returns
true if the event ID is a train search event.

Returns true if the event ID belongs to the train search space (upper 4 bytes = 0x090099FF).

◆ OpenLcbUtilities_extract_train_search_digits()

void OpenLcbUtilities_extract_train_search_digits ( event_id_t event_id,
uint8_t * digits )
extern

Extracts 6 search-query nibbles from a train search event ID into digits[].

Parameters
event_idTrain search event_id_t to decode.
digitsPointer to a 6-element uint8_t array that receives the nibble values.

◆ OpenLcbUtilities_extract_train_search_flags()

uint8_t OpenLcbUtilities_extract_train_search_flags ( event_id_t event_id)
extern

Extracts the flags byte (byte 7) from a train search event ID.

Parameters
event_idTrain search event_id_t to decode.
Returns
Flags byte from the lowest byte of the event ID.

◆ OpenLcbUtilities_train_search_digits_to_address()

uint16_t OpenLcbUtilities_train_search_digits_to_address ( const uint8_t * digits)
extern

Converts a 6-nibble digit array to a numeric DCC address, skipping leading 0xF nibbles.

Parameters
digitsPointer to a 6-element uint8_t array of nibble values.
Returns
Numeric DCC address decoded from the digit array.

◆ OpenLcbUtilities_create_train_search_event_id()

event_id_t OpenLcbUtilities_create_train_search_event_id ( uint16_t address,
uint8_t flags )
extern

Creates a train search event ID from a DCC address and flags byte.

Parameters
addressDCC address to encode into the search event.
flagsFlags byte placed in the lowest byte of the event ID.
Returns
Encoded event_id_t for the train search query.

◆ OpenLcbUtilities_is_emergency_event()

bool OpenLcbUtilities_is_emergency_event ( event_id_t event_id)
extern

Returns true if the event ID is one of the 4 well-known emergency events.

Parameters
event_id64-bit event_id_t to test.
Returns
true if the event ID matches a well-known emergency event.

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