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

Simple Node Information Protocol (SNIP) implementation. More...

Functions

void ProtocolSnip_initialize (const interface_openlcb_protocol_snip_t *interface_openlcb_protocol_snip)
 Stores the callback interface. Call once at startup.
 
uint16_t ProtocolSnip_load_manufacturer_version_id (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copy mfg version byte into payload. Returns updated offset.
 
uint16_t ProtocolSnip_load_name (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copy manufacturer name string into payload. Returns updated offset.
 
uint16_t ProtocolSnip_load_model (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copy model string into payload. Returns updated offset.
 
uint16_t ProtocolSnip_load_hardware_version (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copy hardware version string into payload. Returns updated offset.
 
uint16_t ProtocolSnip_load_software_version (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copy software version string into payload. Returns updated offset.
 
uint16_t ProtocolSnip_load_user_version_id (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copy user version byte into payload. Returns updated offset.
 
uint16_t ProtocolSnip_load_user_name (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Read user name from config memory and copy into payload.
 
uint16_t ProtocolSnip_load_user_description (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Read user description from config memory and copy into payload.
 
void ProtocolSnip_handle_simple_node_info_request (openlcb_statemachine_info_t *statemachine_info)
 Build and return a SNIP reply (MTI 0x0A08).
 
void ProtocolSnip_handle_simple_node_info_reply (openlcb_statemachine_info_t *statemachine_info)
 Handle incoming SNIP reply — no automatic response generated.
 
bool ProtocolSnip_validate_snip_reply (openlcb_msg_t *snip_reply_msg)
 Validate a SNIP reply: correct MTI, valid length, exactly 6 nulls.
 

Detailed Description

Simple Node Information Protocol (SNIP) implementation.

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.

Builds and validates SNIP reply messages from node parameters and config memory. Provides individual field loaders for assembling the SNIP payload and a validation function for incoming SNIP replies.

Author
Jim Kueneman
Date
4 Mar 2026
See also
protocol_snip.h
SimpleNodeInformationS.pdf

Function Documentation

◆ ProtocolSnip_initialize()

void ProtocolSnip_initialize ( const interface_openlcb_protocol_snip_t * interface_openlcb_protocol_snip)

Stores the callback interface. Call once at startup.

Algorithm:

  1. Cast away const and store pointer in module-level static
* @param interface_openlcb_protocol_snip  Populated callback table.
* 
Warning
Structure must remain valid for application lifetime.

◆ ProtocolSnip_load_manufacturer_version_id()

uint16_t ProtocolSnip_load_manufacturer_version_id ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Copy mfg version byte into payload. Returns updated offset.

Copies manufacturer version ID byte (1 byte).

◆ ProtocolSnip_load_name()

uint16_t ProtocolSnip_load_name ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Copy manufacturer name string into payload. Returns updated offset.

Copies manufacturer name string (null-terminated).

◆ ProtocolSnip_load_model()

uint16_t ProtocolSnip_load_model ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Copy model string into payload. Returns updated offset.

Copies model string (null-terminated).

◆ ProtocolSnip_load_hardware_version()

uint16_t ProtocolSnip_load_hardware_version ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Copy hardware version string into payload. Returns updated offset.

Copies hardware version string (null-terminated).

◆ ProtocolSnip_load_software_version()

uint16_t ProtocolSnip_load_software_version ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Copy software version string into payload. Returns updated offset.

Copies software version string (null-terminated).

◆ ProtocolSnip_load_user_version_id()

uint16_t ProtocolSnip_load_user_version_id ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Copy user version byte into payload. Returns updated offset.

Copies user version ID byte (1 byte).

◆ ProtocolSnip_load_user_name()

uint16_t ProtocolSnip_load_user_name ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Read user name from config memory and copy into payload.

Reads user name from config memory (null-terminated, max 63 bytes).

Algorithm:

  1. Compute config-memory address (base + low_address offset if valid)
  2. Read via config_memory_read callback
  3. Copy into payload via _process_snip_string
* @param openlcb_node      Source node.
* @param outgoing_msg      Destination message.
* @param offset            Current payload offset.
* @param requested_bytes   Max bytes to copy.
* 
Returns
Updated offset.

◆ ProtocolSnip_load_user_description()

uint16_t ProtocolSnip_load_user_description ( openlcb_node_t * openlcb_node,
openlcb_msg_t * outgoing_msg,
uint16_t offset,
uint16_t requested_bytes )

Read user description from config memory and copy into payload.

Reads user description from config memory (null-terminated, max 64 bytes).

Algorithm:

  1. Compute config-memory address (base + low_address offset if valid)
  2. Read via config_memory_read callback
  3. Copy into payload via _process_snip_string
* @param openlcb_node      Source node.
* @param outgoing_msg      Destination message.
* @param offset            Current payload offset.
* @param requested_bytes   Max bytes to copy.
* 
Returns
Updated offset.

◆ ProtocolSnip_handle_simple_node_info_request()

void ProtocolSnip_handle_simple_node_info_request ( openlcb_statemachine_info_t * statemachine_info)

Build and return a SNIP reply (MTI 0x0A08).

Builds a SNIP reply (MTI 0x0A08) from node params + config memory.

Algorithm:

  1. Prepare outgoing message header addressed to the requester
  2. Append 8 fields sequentially: mfg version, name, model, HW ver, SW ver, user version, user name, user description
  3. Mark outgoing message valid
* @param statemachine_info  Context with the incoming SNIP request.
* 

◆ ProtocolSnip_handle_simple_node_info_reply()

void ProtocolSnip_handle_simple_node_info_reply ( openlcb_statemachine_info_t * statemachine_info)

Handle incoming SNIP reply — no automatic response generated.

Handles an incoming SNIP reply (MTI 0x0A08). No automatic response.

◆ ProtocolSnip_validate_snip_reply()

bool ProtocolSnip_validate_snip_reply ( openlcb_msg_t * snip_reply_msg)

Validate a SNIP reply: correct MTI, valid length, exactly 6 nulls.

Validates a SNIP reply: correct MTI, valid length, exactly 6 null terminators.

Algorithm:

  1. Reject if payload_count > LEN_MESSAGE_BYTES_SNIP
  2. Reject if MTI != MTI_SIMPLE_NODE_INFO_REPLY
  3. Count null bytes in payload; must equal 6
* @param snip_reply_msg  Message to validate.
* 
Returns
true if the message is a well-formed SNIP reply.

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