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

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

Go to the source code of this file.

Data Structures

struct  interface_openlcb_protocol_snip_t
 Callback interface for SNIP. config_memory_read is REQUIRED. More...
 

Functions

void ProtocolSnip_initialize (const interface_openlcb_protocol_snip_t *interface_openlcb_protocol_snip)
 Stores the callback interface. Call once at startup.
 
void ProtocolSnip_handle_simple_node_info_request (openlcb_statemachine_info_t *statemachine_info)
 Builds a SNIP reply (MTI 0x0A08) from node params + config memory.
 
void ProtocolSnip_handle_simple_node_info_reply (openlcb_statemachine_info_t *statemachine_info)
 Handles an incoming SNIP reply (MTI 0x0A08). No automatic response.
 
uint16_t ProtocolSnip_load_manufacturer_version_id (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copies manufacturer version ID byte (1 byte).
 
uint16_t ProtocolSnip_load_name (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copies manufacturer name string (null-terminated).
 
uint16_t ProtocolSnip_load_model (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copies model string (null-terminated).
 
uint16_t ProtocolSnip_load_hardware_version (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copies hardware version string (null-terminated).
 
uint16_t ProtocolSnip_load_software_version (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copies software version string (null-terminated).
 
uint16_t ProtocolSnip_load_user_version_id (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Copies user version ID byte (1 byte).
 
uint16_t ProtocolSnip_load_user_name (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Reads user name from config memory (null-terminated, max 63 bytes).
 
uint16_t ProtocolSnip_load_user_description (openlcb_node_t *openlcb_node, openlcb_msg_t *outgoing_msg, uint16_t offset, uint16_t requested_bytes)
 Reads user description from config memory (null-terminated, max 64 bytes).
 
bool ProtocolSnip_validate_snip_reply (openlcb_msg_t *snip_reply_msg)
 Validates a SNIP reply: correct MTI, valid length, exactly 6 null terminators.
 

Detailed Description

Simple Node Information Protocol (SNIP) handler.

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.

Returns manufacturer info (from node params) and user name/description (from config memory) in a single reply message. Provides individual field loaders for assembling the SNIP payload and a validation function for incoming SNIP replies.

Author
Jim Kueneman
Date
4 Mar 2026

Function Documentation

◆ ProtocolSnip_initialize()

void ProtocolSnip_initialize ( const interface_openlcb_protocol_snip_t * interface_openlcb_protocol_snip)
extern

Stores the callback interface. Call once at startup.

Parameters
interface_openlcb_protocol_snipPointer to interface_openlcb_protocol_snip_t (must remain valid for application lifetime).

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_handle_simple_node_info_request()

void ProtocolSnip_handle_simple_node_info_request ( openlcb_statemachine_info_t * statemachine_info)
extern

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

Assembles eight fields: mfg version, name, model, HW ver, SW ver, user version, user name, user description. Max 253 bytes.

Parameters
statemachine_infoPointer to openlcb_statemachine_info_t context.

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)
extern

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

Parameters
statemachine_infoPointer to openlcb_statemachine_info_t context.

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

◆ 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 )
extern

Copies manufacturer version ID byte (1 byte).

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

Copies manufacturer name string (null-terminated).

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

Copies model string (null-terminated).

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

Copies hardware version string (null-terminated).

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

Copies software version string (null-terminated).

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

Copies user version ID byte (1 byte).

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

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

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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 )
extern

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

Parameters
openlcb_nodePointer to openlcb_node_t source node.
outgoing_msgPointer to openlcb_msg_t reply being built.
offsetPayload byte offset to write at.
requested_bytesMaximum bytes to copy.
Returns
Bytes actually written.

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_validate_snip_reply()

bool ProtocolSnip_validate_snip_reply ( openlcb_msg_t * snip_reply_msg)
extern

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

Parameters
snip_reply_msgPointer to openlcb_msg_t message to validate.
Returns
true if the message is a well-formed SNIP reply.

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