38#ifndef __OPENLCB_OPENLCB_UTILITIES__
39#define __OPENLCB_OPENLCB_UTILITIES__
OpenLCB protocol constants, MTI codes, and memory configuration commands.
Core type definitions, structures, and configuration constants for the OpenLCB library.
uint64_t event_id_t
64-bit Event ID.
Definition openlcb_types.h:340
uint8_t configuration_memory_buffer_t[LEN_DATAGRAM_MAX_PAYLOAD]
Configuration memory read/write operation buffer (64 bytes).
Definition openlcb_types.h:365
event_range_count_enum
Power-of-two event range sizes for range-identified events.
Definition openlcb_types.h:247
broadcast_time_event_type_enum
Broadcast Time Protocol event type decoded from an Event ID.
Definition openlcb_types.h:269
uint64_t node_id_t
48-bit Node ID stored in a 64-bit type (upper 16 bits unused).
Definition openlcb_types.h:359
payload_type_enum
Message buffer payload type identifier.
Definition openlcb_types.h:220
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.
Definition openlcb_utilities.c:285
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.
Definition openlcb_utilities.c:561
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.
Definition openlcb_utilities.c:1071
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.
Definition openlcb_utilities.c:181
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.
Definition openlcb_utilities.c:1245
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.
Definition openlcb_utilities.c:322
void OpenLcbUtilities_clear_openlcb_message_payload(openlcb_msg_t *openlcb_msg)
Zeros all payload bytes and resets payload_count. Header preserved.
Definition openlcb_utilities.c:121
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.
Definition openlcb_utilities.c:1032
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.
Definition openlcb_utilities.c:493
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.
Definition openlcb_utilities.c:816
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.
Definition openlcb_utilities.c:208
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.
Definition openlcb_utilities.c:1088
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.
Definition openlcb_utilities.c:240
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.
Definition openlcb_utilities.c:1122
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.
Definition openlcb_utilities.c:458
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.
Definition openlcb_utilities.c:757
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.
Definition openlcb_utilities.c:1139
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.
Definition openlcb_utilities.c:85
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.
Definition openlcb_utilities.c:56
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.
Definition openlcb_utilities.c:1105
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.
Definition openlcb_utilities.c:157
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.
Definition openlcb_utilities.c:315
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.
Definition openlcb_utilities.c:100
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.
Definition openlcb_utilities.c:421
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).
Definition openlcb_utilities.c:1181
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.
Definition openlcb_utilities.c:364
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.
Definition openlcb_utilities.c:444
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.
Definition openlcb_utilities.c:348
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.
Definition openlcb_utilities.c:172
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.
Definition openlcb_utilities.c:383
bool OpenLcbUtilities_is_broadcast_time_event(event_id_t event_id)
Returns true if the event ID belongs to the broadcast time event space.
Definition openlcb_utilities.c:780
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.
Definition openlcb_utilities.c:514
uint8_t OpenLcbUtilities_extract_train_search_flags(event_id_t event_id)
Extracts the flags byte (byte 7) from a train search event ID.
Definition openlcb_utilities.c:1213
bool OpenLcbUtilities_is_addressed_openlcb_message(openlcb_msg_t *openlcb_msg)
Returns true if the MTI has the destination-address-present bit set.
Definition openlcb_utilities.c:357
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.
Definition openlcb_utilities.c:480
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.
Definition openlcb_utilities.c:735
void OpenLcbUtilities_clear_openlcb_message(openlcb_msg_t *openlcb_msg)
Zeros entire message including header, state flags, and reference count.
Definition openlcb_utilities.c:136
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.
Definition openlcb_utilities.c:823
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.
Definition openlcb_utilities.c:332
bool OpenLcbUtilities_extract_year_from_event_id(event_id_t event_id, uint16_t *year)
Extracts year from a broadcast time event ID.
Definition openlcb_utilities.c:992
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.
Definition openlcb_utilities.c:299
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[].
Definition openlcb_utilities.c:1188
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.
Definition openlcb_utilities.c:1290
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.
Definition openlcb_utilities.c:713
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.
Definition openlcb_utilities.c:665
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.
Definition openlcb_utilities.c:191
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.
Definition openlcb_utilities.c:618
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.
Definition openlcb_utilities.c:268
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.
Definition openlcb_utilities.c:402
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.
Definition openlcb_utilities.c:914
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.
Definition openlcb_utilities.c:468
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.
Definition openlcb_utilities.c:952
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.
Definition openlcb_utilities.c:1220
Request info for a configuration memory read operation.
Definition openlcb_types.h:799
Request info for a configuration memory write operation.
Definition openlcb_types.h:817
Core OpenLCB message structure.
Definition openlcb_types.h:480
OpenLCB virtual node.
Definition openlcb_types.h:679
Complete context passed to protocol handler functions.
Definition openlcb_types.h:743