Skip to content

Conversation

Copy link

Copilot AI commented Dec 8, 2025

Implements TCP/IP transport for OpenLCB using the GridConnect ASCII protocol (:X<ID>N<DATA>;), enabling communication with OpenLCB hubs and network tools.

Changes

GridConnect codec (utilities.py)

  • to_gridconnect() / from_gridconnect() - encode/decode CAN frames to/from ASCII format

TCP transport (interface.py)

  • Accept socket.socket in addition to can.BusABC
  • Background thread for TCP message reception
  • Auto-detect transport type (CAN vs TCP)

Message conversion (message.py)

  • Message.to_gridconnect() / Message.from_gridconnect() methods
  • Extracted _parse_frame_info() to eliminate duplication between CAN and TCP parsing

Node compatibility (node.py)

  • process_message() handles both can.Message and Message objects

Usage

import socket
import pyolcb

# TCP connection (new)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 12021))
interface = pyolcb.Interface(sock)

# CAN connection (unchanged)
# interface = pyolcb.Interface(can.Bus(...))

# Same API for both transports
node = pyolcb.Node(pyolcb.Address('05.01.01.01.8C.00'), interface)
node.produce(pyolcb.Event(125))

Backward compatible - existing CAN functionality unchanged.

Original prompt

Add support for OpenLCB over TCP/IP


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 7 commits December 8, 2025 18:23
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Co-authored-by: ngpaladi <8539865+ngpaladi@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for OpenLCB over TCP/IP Add OpenLCB over TCP/IP support via GridConnect format Dec 8, 2025
Copilot AI requested a review from ngpaladi December 8, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants