|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
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. | |
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:
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.
|
extern |
Loads message header fields and clears the payload to zeros.
| openlcb_msg | Pointer to the openlcb_msg_t to initialize |
| source_alias | 12-bit CAN alias of the source node |
| source_id | 48-bit node_id_t of the source node |
| dest_alias | 12-bit CAN alias of the destination (0 for global) |
| dest_id | 48-bit node_id_t of the destination (0 for global) |
| mti | Message Type Indicator |
|
extern |
Zeros all payload bytes and resets payload_count. Header preserved.
| openlcb_msg | Pointer to the openlcb_msg_t to clear payload from. |
|
extern |
Zeros entire message including header, state flags, and reference count.
| openlcb_msg | Pointer to the openlcb_msg_t to fully clear. |
|
extern |
Copies an 8-byte event ID to payload at offset 0.
| openlcb_msg | Pointer to the openlcb_msg_t to write into. |
| event_id | 64-bit event_id_t to store in the payload. |
|
extern |
Copies a 6-byte node ID to payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to write into. |
| node_id | 48-bit node_id_t to store in the payload. |
| offset | Starting byte offset in the payload. |
Copies a 6-byte node ID to payload at the given offset.
|
extern |
Copies one byte to payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to write into. |
| byte | Byte value to store. |
| offset | Byte offset in the payload. |
|
extern |
Copies a 16-bit word (big-endian) to payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to write into. |
| word | 16-bit value to store in big-endian order. |
| offset | Starting byte offset in the payload. |
|
extern |
Copies a 32-bit doubleword (big-endian) to payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to write into. |
| doubleword | 32-bit value to store in big-endian order. |
| offset | Starting byte offset in the payload. |
|
extern |
Copies a null-terminated string into the payload.
Truncates if payload space is insufficient but always adds a null terminator.
| openlcb_msg | Pointer to the openlcb_msg_t |
| string | Null-terminated source string |
| offset | Starting byte offset in the payload |
Truncates if payload space is insufficient but always adds a null terminator.
|
extern |
Copies a byte array into the payload.
May copy fewer bytes than requested if payload space is exhausted.
| openlcb_msg | Pointer to the openlcb_msg_t |
| byte_array | Source data |
| offset | Starting byte offset in the payload |
| requested_bytes | Number of bytes to attempt to copy |
Copies a byte array into the payload.
|
extern |
Extracts a 6-byte node ID from payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to read from. |
| offset | Starting byte offset in the payload. |
|
extern |
Extracts an 8-byte event ID from payload at offset 0.
| openlcb_msg | Pointer to the openlcb_msg_t to read from. |
|
extern |
Extracts one byte from payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to read from. |
| offset | Byte offset in the payload. |
|
extern |
Extracts a 16-bit word (big-endian) from payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to read from. |
| offset | Starting byte offset in the payload. |
|
extern |
Extracts a 32-bit doubleword (big-endian) from payload at the given offset.
| openlcb_msg | Pointer to the openlcb_msg_t to read from. |
| offset | Starting byte offset in the payload. |
|
extern |
Returns the count of null bytes (0x00) in the payload. Used for SNIP validation.
| openlcb_msg | Pointer to the openlcb_msg_t to scan. |
|
extern |
Returns true if the MTI has the destination-address-present bit set.
| openlcb_msg | Pointer to the openlcb_msg_t to check. |
|
extern |
Returns true if the message destination matches this node's alias or ID.
| openlcb_node | Pointer to the openlcb_node_t to match against. |
| openlcb_msg | Pointer to the openlcb_msg_t to check. |
|
extern |
Sets the multi-frame control flag in the upper nibble of target, preserving the lower nibble.
| target | Pointer to the byte whose upper nibble will be replaced. |
| flag | Flag value to write into the upper nibble. |
|
extern |
Searches the node's producer list for a matching event ID.
| openlcb_node | Node to search |
| event_id | Event ID to find |
| event_index | Receives the list index if found (undefined on false return) |
|
extern |
Searches the node's consumer list for a matching event ID.
| openlcb_node | Node to search |
| event_id | Event ID to find |
| event_index | Receives the list index if found (undefined on false return) |
|
extern |
Returns the byte offset into global config memory where this node's space begins.
| openlcb_node | Pointer to the openlcb_node_t to calculate the offset for. |
|
extern |
Converts a payload_type_enum to its maximum byte length. Returns 0 for unknown types.
| payload_type | The payload_type_enum value to convert. |
Converts a payload_type_enum to its maximum byte length. Returns 0 for unknown types.
|
extern |
Extracts a 6-byte node ID from a config memory buffer at the given index.
| buffer | Pointer to the configuration_memory_buffer_t to read from. |
| index | Starting byte index in the buffer. |
|
extern |
Extracts a 16-bit word from a config memory buffer at the given index.
| buffer | Pointer to the configuration_memory_buffer_t to read from. |
| index | Starting byte index in the buffer. |
|
extern |
Copies a 6-byte node ID into a config memory buffer at the given index.
| buffer | Pointer to the configuration_memory_buffer_t to write into. |
| node_id | 48-bit node_id_t to store. |
| index | Starting byte index in the buffer. |
|
extern |
Copies an 8-byte event ID into a config memory buffer at the given index.
| buffer | Pointer to the configuration_memory_buffer_t to write into. |
| event_id | 64-bit event_id_t to store. |
| index | Starting byte index in the buffer. |
|
extern |
Extracts an 8-byte event ID from a config memory buffer at the given index.
| buffer | Pointer to the configuration_memory_buffer_t to read from. |
| index | Starting byte index in the buffer. |
|
extern |
Builds a config memory write-failure reply datagram header.
| statemachine_info | openlcb_statemachine_info_t context |
| config_mem_write_request_info | config_mem_write_request_info_t from original request |
| error_code | 16-bit error code |
Error code placement depends on address encoding: ADDRESS_SPACE_IN_BYTE_6 places it at offset 7, otherwise offset 6.
|
extern |
Builds a config memory write-success reply datagram header.
| statemachine_info | Pointer to the openlcb_statemachine_info_t context. |
| config_mem_write_request_info | Pointer to the config_mem_write_request_info_t from the original request. |
|
extern |
Builds a config memory read-failure reply datagram header.
| statemachine_info | openlcb_statemachine_info_t context |
| config_mem_read_request_info | config_mem_read_request_info_t from original request |
| error_code | 16-bit error code |
Error code is placed at the data_start offset where actual data would have been.
|
extern |
Builds a config memory read-success reply datagram header only.
Caller must append actual data bytes separately after this call.
| statemachine_info | openlcb_statemachine_info_t context |
| config_mem_read_request_info | config_mem_read_request_info_t from original request |
Caller must append actual data bytes separately after this call.
|
extern |
Generates a masked Event ID covering a range of consecutive events.
| base_event_id | Starting event_id_t of the range |
| count | Number of events in the range (event_range_count_enum) |
|
extern |
Returns true if the event ID falls within any of the node's consumer ranges.
| openlcb_node | Pointer to the openlcb_node_t whose consumer ranges are checked. |
| event_id | 64-bit event_id_t to test. |
|
extern |
Returns true if the event ID falls within any of the node's producer ranges.
| openlcb_node | Pointer to the openlcb_node_t whose producer ranges are checked. |
| event_id | 64-bit event_id_t to test. |
|
extern |
Returns true if the event ID belongs to the broadcast time event space.
| event_id | 64-bit event_id_t to test. |
|
extern |
Extracts the 48-bit clock ID (upper 6 bytes) from a broadcast time event ID.
| event_id | Broadcast time event_id_t to extract from. |
|
extern |
Returns the broadcast_time_event_type_enum for a broadcast time event ID.
| event_id | Broadcast time event_id_t to classify. |
|
extern |
Extracts hour and minute from a broadcast time event ID.
| event_id | Broadcast time event ID |
| hour | Receives hour (0-23) |
| minute | Receives minute (0-59) |
Extracts hour and minute from a broadcast time event ID.
|
extern |
Extracts month and day from a broadcast time event ID.
| event_id | Broadcast time event ID |
| month | Receives month (1-12) |
| day | Receives day (1-31) |
Extracts month and day from a broadcast time event ID.
|
extern |
Extracts year from a broadcast time event ID.
| event_id | Broadcast time event ID |
| year | Receives year (0-4095) |
Extracts year from a broadcast time event ID.
|
extern |
Extracts the 12-bit signed fixed-point rate from a broadcast time event ID.
| event_id | Broadcast time event ID |
| rate | Receives rate (10.2 fixed point, e.g. 0x0004 = 1.00) |
Rate format is 10.2 fixed point. Sign-extends bit 11 for negative rates.
|
extern |
Creates a Report/Set Time event ID from clock_id, hour, minute.
| clock_id | 48-bit clock identifier. |
| hour | Hour value (0-23). |
| minute | Minute value (0-59). |
| is_set | true for a Set command, false for a Report. |
|
extern |
Creates a Report/Set Date event ID from clock_id, month, day.
| clock_id | 48-bit clock identifier. |
| month | Month value (1-12). |
| day | Day value (1-31). |
| is_set | true for a Set command, false for a Report. |
|
extern |
Creates a Report/Set Year event ID from clock_id, year.
| clock_id | 48-bit clock identifier. |
| year | Year value (0-4095). |
| is_set | true for a Set command, false for a Report. |
|
extern |
Creates a Report/Set Rate event ID from clock_id, rate.
| clock_id | 48-bit clock identifier. |
| rate | 12-bit signed fixed-point rate (10.2 format). |
| is_set | true for a Set command, false for a Report. |
|
extern |
Creates a command event ID (Query, Start, Stop, Date Rollover) for the given clock.
| clock_id | 48-bit clock identifier. |
| command | broadcast_time_event_type_enum specifying the command type. |
|
extern |
Returns true if the event ID belongs to the train search space (upper 4 bytes = 0x090099FF).
| event_id | 64-bit event_id_t to test. |
Returns true if the event ID belongs to the train search space (upper 4 bytes = 0x090099FF).
|
extern |
Extracts 6 search-query nibbles from a train search event ID into digits[].
| event_id | Train search event_id_t to decode. |
| digits | Pointer to a 6-element uint8_t array that receives the nibble values. |
|
extern |
Extracts the flags byte (byte 7) from a train search event ID.
| event_id | Train search event_id_t to decode. |
|
extern |
Converts a 6-nibble digit array to a numeric DCC address, skipping leading 0xF nibbles.
| digits | Pointer to a 6-element uint8_t array of nibble values. |
|
extern |
Creates a train search event ID from a DCC address and flags byte.
| address | DCC address to encode into the search event. |
| flags | Flags byte placed in the lowest byte of the event ID. |
|
extern |
Returns true if the event ID is one of the 4 well-known emergency events.
| event_id | 64-bit event_id_t to test. |
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License