|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Utility functions for manipulating can_msg_t frame buffers. More...
Go to the source code of this file.
Functions | |
| void | CanUtilities_clear_can_message (can_msg_t *can_msg) |
| Clears identifier, payload_count, and all payload bytes in a can_msg_t. | |
| void | CanUtilities_load_can_message (can_msg_t *can_msg, uint32_t identifier, uint8_t payload_size, uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4, uint8_t byte5, uint8_t byte6, uint8_t byte7, uint8_t byte8) |
| Loads identifier, payload size, and all 8 data bytes into a can_msg_t. | |
| uint8_t | CanUtilities_copy_node_id_to_payload (can_msg_t *can_msg, uint64_t node_id, uint8_t start_offset) |
| Copies a 48-bit node_id_t into 6 payload bytes starting at start_offset. | |
| uint8_t | CanUtilities_copy_openlcb_payload_to_can_payload (openlcb_msg_t *openlcb_msg, can_msg_t *can_msg, uint16_t openlcb_start_index, uint8_t can_start_index) |
| Copies payload bytes from an openlcb_msg_t into a can_msg_t. | |
| uint8_t | CanUtilities_append_can_payload_to_openlcb_payload (openlcb_msg_t *openlcb_msg, can_msg_t *can_msg, uint8_t can_start_index) |
| Appends CAN payload bytes to the end of an openlcb_msg_t payload. | |
| uint8_t | CanUtilities_copy_64_bit_to_can_message (can_msg_t *can_msg, uint64_t data) |
| Copies a 64-bit value into all 8 payload bytes of a can_msg_t (big-endian). | |
| uint8_t | CanUtilities_copy_can_message (can_msg_t *can_msg_source, can_msg_t *can_msg_target) |
| Copies identifier and valid payload bytes from source to target can_msg_t. | |
| node_id_t | CanUtilities_extract_can_payload_as_node_id (can_msg_t *can_msg) |
| Reads payload bytes 0-5 and returns them as a 48-bit node_id_t (big-endian). | |
| uint16_t | CanUtilities_extract_source_alias_from_can_identifier (can_msg_t *can_msg) |
| Returns the 12-bit source alias from bits 0-11 of the CAN identifier. | |
| uint16_t | CanUtilities_extract_dest_alias_from_can_message (can_msg_t *can_msg) |
| Returns the 12-bit destination alias from the appropriate location in a can_msg_t. | |
| uint16_t | CanUtilities_convert_can_mti_to_openlcb_mti (can_msg_t *can_msg) |
| Converts the CAN frame MTI bits to the corresponding 16-bit OpenLCB MTI. | |
| uint8_t | CanUtilities_count_nulls_in_payloads (openlcb_msg_t *openlcb_msg, can_msg_t *can_msg) |
| Counts NULL (0x00) bytes across both an openlcb_msg_t and a can_msg_t payload. | |
| bool | CanUtilities_is_openlcb_message (can_msg_t *can_msg) |
| Returns true if the CAN frame carries an OpenLCB message (bit 27 set). | |
Utility functions for manipulating can_msg_t frame buffers.
Includes functions for clearing, loading, copying, and extracting data from CAN frames. Also provides MTI conversion and framing-bit helpers used by both the Rx and Tx paths. All functions are stateless — no internal buffers or side effects beyond the pointers passed in.
|
extern |
Clears identifier, payload_count, and all payload bytes in a can_msg_t.
|
extern |
Loads identifier, payload size, and all 8 data bytes into a can_msg_t.
All 8 byte parameters must be provided even if payload_size is less than 8.
| can_msg | Destination buffer. |
| identifier | 29-bit CAN extended identifier. |
| payload_size | Number of valid payload bytes (0-8). |
| byte1 | Payload byte 1. |
| byte2 | Payload byte 2. |
| byte3 | Payload byte 3. |
| byte4 | Payload byte 4. |
| byte5 | Payload byte 5. |
| byte6 | Payload byte 6. |
| byte7 | Payload byte 7. |
| byte8 | Payload byte 8. |
* @param can_msg Destination buffer. * @param identifier 29-bit CAN extended identifier. * @param payload_size Number of valid payload bytes (0-8). * @param byte1..byte8 Payload bytes in order. *
|
extern |
Copies a 48-bit node_id_t into 6 payload bytes starting at start_offset.
Updates payload_count to start_offset + 6. Valid start_offset range: 0-2 (must fit 6 bytes into the 8-byte payload).
| can_msg | Destination buffer. |
| node_id | 48-bit node_id_t to copy. |
| start_offset | Byte position in payload to begin writing (0-2). |
Copies a 48-bit node_id_t into 6 payload bytes starting at start_offset.
Algorithm:
* @param can_msg Destination buffer. * @param node_id 48-bit @ref node_id_t to copy. * @param start_offset Byte position in payload to begin writing (0-2). *
|
extern |
Copies payload bytes from an openlcb_msg_t into a can_msg_t.
Used to fragment a large OpenLCB payload across multiple CAN frames. Updates can_msg payload_count to reflect total bytes written.
| openlcb_msg | Source OpenLCB message. |
| can_msg | Destination CAN frame buffer. |
| openlcb_start_index | Starting index in the OpenLCB payload. |
| can_start_index | Starting index in the CAN payload (0 or 2). |
Algorithm:
* @param openlcb_msg Source OpenLCB message. * @param can_msg Destination CAN frame buffer. * @param openlcb_start_index Starting index in the OpenLCB payload. * @param can_start_index Starting index in the CAN payload (0 or 2). *
|
extern |
Appends CAN payload bytes to the end of an openlcb_msg_t payload.
Used to reassemble multi-frame CAN messages. Stops when the OpenLCB buffer capacity is reached. Updates openlcb_msg payload_count.
| openlcb_msg | Destination OpenLCB message. |
| can_msg | Source CAN frame. |
| can_start_index | Starting index in the CAN payload. |
Algorithm:
* @param openlcb_msg Destination OpenLCB message. * @param can_msg Source CAN frame. * @param can_start_index Starting index in the CAN payload. *
|
extern |
Copies a 64-bit value into all 8 payload bytes of a can_msg_t (big-endian).
Always sets payload_count to 8.
| can_msg | Destination buffer. |
| data | 64-bit value (e.g. Event ID). |
Copies a 64-bit value into all 8 payload bytes of a can_msg_t (big-endian).
* @param can_msg Destination buffer. * @param data 64-bit value (e.g. Event ID). *
|
extern |
Copies identifier and valid payload bytes from source to target can_msg_t.
Does not copy state flags (allocated). Target payload_count is set to match source.
| can_msg_source | Source buffer. |
| can_msg_target | Destination buffer. |
Does not copy state flags. Target payload_count is set to match source.
* @param can_msg_source Source buffer. * @param can_msg_target Destination buffer. *
|
extern |
Returns the 12-bit source alias from bits 0-11 of the CAN identifier.
| can_msg | Source buffer. |
* @param can_msg Source buffer. *
|
extern |
Returns the 12-bit destination alias from the appropriate location in a can_msg_t.
Addressed messages carry the destination in payload bytes 0-1; datagrams carry it in the identifier. Returns 0 for global (broadcast) frames.
| can_msg | Source buffer. |
Algorithm:
* @param can_msg Source buffer. *
|
extern |
Converts the CAN frame MTI bits to the corresponding 16-bit OpenLCB MTI.
Handles multi-frame PCER and datagram special cases. Returns 0 for CAN control frames (CID, RID, AMD, etc.) which have no OpenLCB MTI.
| can_msg | Source buffer. |
Algorithm:
* @param can_msg Source buffer. *
|
extern |
Counts NULL (0x00) bytes across both an openlcb_msg_t and a can_msg_t payload.
Used to detect SNIP message completion (exactly 6 NULLs required).
| openlcb_msg | OpenLCB message with accumulated SNIP data. |
| can_msg | Current CAN frame being appended. |
Counts NULL (0x00) bytes across both an openlcb_msg_t and a can_msg_t payload.
Used to detect SNIP message completion (exactly 6 NULLs required).
* @param openlcb_msg OpenLCB message with accumulated SNIP data. * @param can_msg Current CAN frame being appended. *
|
extern |
Returns true if the CAN frame carries an OpenLCB message (bit 27 set).
CAN control frames (CID, RID, AMD, AME, AMR) return false.
| can_msg | Source buffer. |
Returns true if the CAN frame carries an OpenLCB message (bit 27 set).
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License