|
OpenLcbCLib 1.0 Alpha
OpenSource C Library to create OpenLcb/Lcc Nodes
|
Bidirectional conversion between CAN messages and GridConnect ASCII format. More...
Go to the source code of this file.
Macros | |
| #define | GRIDCONNECT_STATE_SYNC_START 0 |
| Parser state: Looking for start of GridConnect message (':X' or ':x') | |
| #define | GRIDCONNECT_STATE_SYNC_FIND_HEADER 2 |
| Parser state: Collecting 8-character hexadecimal CAN identifier. | |
| #define | GRIDCONNECT_STATE_SYNC_FIND_DATA 4 |
| Parser state: Collecting data bytes until terminator (';') | |
| #define | GRIDCONNECT_IDENTIFIER_START_POS 2 |
| Position of first character after ':X' prefix (start of identifier) | |
| #define | GRIDCONNECT_IDENTIFIER_LEN 8 |
| Length of CAN identifier in GridConnect format (8 hex characters) | |
| #define | GRIDCONNECT_NORMAL_FLAG_POS 10 |
| Position where 'N' appears (after 8-char identifier) | |
| #define | GRIDCONNECT_DATA_START_POS 11 |
| Position where data bytes start (after ':X', 8-char ID, and 'N') | |
| #define | GRIDCONNECT_HEADER_LEN 12 |
| Number of characters before data section (used for length calculation) | |
| #define | MAX_GRID_CONNECT_LEN 29 |
| Max GridConnect string length: :X(8)N(16); + NUL = 29 bytes. | |
Typedefs | |
| typedef uint8_t | gridconnect_buffer_t[MAX_GRID_CONNECT_LEN] |
| Type definition for GridConnect message buffer. | |
Functions | |
| bool | OpenLcbGridConnect_copy_out_gridconnect_when_done (uint8_t next_byte, gridconnect_buffer_t *gridconnect_buffer) |
| Feeds one byte into the streaming GridConnect parser. | |
| void | OpenLcbGridConnect_to_can_msg (gridconnect_buffer_t *gridconnect_buffer, can_msg_t *can_msg) |
| Converts a validated GridConnect string to a can_msg_t. | |
| void | OpenLcbGridConnect_from_can_msg (gridconnect_buffer_t *gridconnect_buffer, can_msg_t *can_msg) |
| Converts a can_msg_t to a null-terminated GridConnect string. | |
Bidirectional conversion between CAN messages and GridConnect ASCII format.
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.
Converts between can_msg_t structures and the GridConnect ASCII wire format (:X<8-hex-ID>N<hex-data>;). Includes a streaming byte-at-a-time parser with automatic error recovery for use over serial or TCP/IP links.
| #define GRIDCONNECT_STATE_SYNC_START 0 |
Parser state: Looking for start of GridConnect message (':X' or ':x')
| #define GRIDCONNECT_STATE_SYNC_FIND_HEADER 2 |
Parser state: Collecting 8-character hexadecimal CAN identifier.
| #define GRIDCONNECT_STATE_SYNC_FIND_DATA 4 |
Parser state: Collecting data bytes until terminator (';')
| #define GRIDCONNECT_IDENTIFIER_START_POS 2 |
Position of first character after ':X' prefix (start of identifier)
| #define GRIDCONNECT_IDENTIFIER_LEN 8 |
Length of CAN identifier in GridConnect format (8 hex characters)
| #define GRIDCONNECT_NORMAL_FLAG_POS 10 |
Position where 'N' appears (after 8-char identifier)
| #define GRIDCONNECT_DATA_START_POS 11 |
Position where data bytes start (after ':X', 8-char ID, and 'N')
| #define GRIDCONNECT_HEADER_LEN 12 |
Number of characters before data section (used for length calculation)
| #define MAX_GRID_CONNECT_LEN 29 |
Max GridConnect string length: :X(8)N(16); + NUL = 29 bytes.
| typedef uint8_t gridconnect_buffer_t[MAX_GRID_CONNECT_LEN] |
Type definition for GridConnect message buffer.
|
extern |
Feeds one byte into the streaming GridConnect parser.
Uses static state — NOT thread-safe, single context only. Malformed input resets the parser automatically.
| next_byte | Next byte from the incoming stream. |
| gridconnect_buffer | Destination for the completed message. |
Feeds one byte into the streaming GridConnect parser.
Algorithm: Implements a three-state parser that processes GridConnect protocol data one byte at a time:
Use cases:
* @param next_byte Next byte from the incoming GridConnect stream * @param gridconnect_buffer Pointer to buffer where complete message will be stored *
|
extern |
Converts a validated GridConnect string to a can_msg_t.
Input must come from the parser; no format validation is done here.
| gridconnect_buffer | Completed GridConnect string. |
| can_msg | Destination CAN message. |
Converts a validated GridConnect string to a can_msg_t.
Algorithm:
Use cases:
* @param gridconnect_buffer Pointer to GridConnect message buffer (null-terminated) * @param can_msg Pointer to CAN message structure to populate *
|
extern |
Converts a can_msg_t to a null-terminated GridConnect string.
Output is uppercase hex with leading zeros on the 8-char ID.
| gridconnect_buffer | Destination buffer (>= MAX_GRID_CONNECT_LEN). |
| can_msg | Source CAN message. |
Converts a can_msg_t to a null-terminated GridConnect string.
Algorithm:
Use cases:
* @param gridconnect_buffer Pointer to buffer where GridConnect message will be stored * @param can_msg Pointer to source CAN message structure to convert *
Copyright (c) 2026 Jim Kueneman all rights reserved. See the License