lplexc

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package lplexc provides a Go client for lplex, a CAN bus HTTP bridge for NMEA 2000.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discover

func Discover(ctx context.Context) (string, error)

Discover browses for a _lplex._tcp mDNS service on the local network and returns the URL of the first instance found. It blocks until a service is discovered or the context is cancelled.

A default 3-second timeout is applied if the context has no deadline.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client communicates with an lplex server over HTTP.

func NewClient

func NewClient(baseURL string) *Client

NewClient creates a new lplex client pointing at the given server URL.

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, cfg SessionConfig) (*Session, error)

CreateSession creates or reconnects a buffered session on the server.

func (*Client) Devices

func (c *Client) Devices(ctx context.Context) ([]Device, error)

Devices returns a snapshot of all NMEA 2000 devices discovered by the server.

func (*Client) Send

func (c *Client) Send(ctx context.Context, pgn uint32, src, dst, prio uint8, data []byte) error

Send transmits a CAN frame through the server.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, filter *Filter) (*Subscription, error)

Subscribe opens an ephemeral SSE stream (GET /events) with the given filter. Returns a Subscription that yields events until closed or the context is cancelled.

type Device

type Device struct {
	Src              uint8  `json:"src"`
	Name             string `json:"name"`
	Manufacturer     string `json:"manufacturer"`
	ManufacturerCode uint16 `json:"manufacturer_code"`
	DeviceClass      uint8  `json:"device_class"`
	DeviceFunction   uint8  `json:"device_function"`
	DeviceInstance   uint8  `json:"device_instance"`
	UniqueNumber     uint32 `json:"unique_number"`
	ModelID          string `json:"model_id"`
	SoftwareVersion  string `json:"software_version"`
	ModelVersion     string `json:"model_version"`
	ModelSerial      string `json:"model_serial"`
	ProductCode      uint16 `json:"product_code"`
	FirstSeen        string `json:"first_seen"`
	LastSeen         string `json:"last_seen"`
	PacketCount      uint64 `json:"packet_count"`
	ByteCount        uint64 `json:"byte_count"`
}

Device represents an NMEA 2000 device discovered on the bus.

type Event

type Event struct {
	Frame  *Frame
	Device *Device
}

Event is a message received from an lplex SSE stream. Exactly one of Frame or Device will be non-nil.

type Filter

type Filter struct {
	PGNs          []uint32 `json:"pgn,omitempty"`
	Manufacturers []string `json:"manufacturer,omitempty"`
	Instances     []uint8  `json:"instance,omitempty"`
	Names         []string `json:"name,omitempty"`
}

Filter specifies which CAN frames to receive. Categories are AND'd, values within a category are OR'd.

func (*Filter) IsEmpty

func (f *Filter) IsEmpty() bool

IsEmpty returns true if no filter criteria are set.

type Frame

type Frame struct {
	Seq  uint64 `json:"seq"`
	Ts   string `json:"ts"`
	Prio uint8  `json:"prio"`
	PGN  uint32 `json:"pgn"`
	Src  uint8  `json:"src"`
	Dst  uint8  `json:"dst"`
	Data string `json:"data"`
}

Frame represents a single CAN frame received from the lplex server.

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is a buffered connection to an lplex server with cursor tracking and automatic reconnect replay.

func (*Session) Ack

func (s *Session) Ack(ctx context.Context, seq uint64) error

Ack advances the cursor for this session to the given sequence number.

func (*Session) Info

func (s *Session) Info() SessionInfo

Info returns the session metadata from the server.

func (*Session) LastAcked

func (s *Session) LastAcked() uint64

LastAcked returns the last sequence number that was successfully acknowledged.

func (*Session) Subscribe

func (s *Session) Subscribe(ctx context.Context) (*Subscription, error)

Subscribe opens the SSE stream for this session (GET /clients/{id}/events). Replays any buffered frames from the cursor, then streams live.

type SessionConfig

type SessionConfig struct {
	ClientID      string
	BufferTimeout string // ISO 8601 duration, e.g. "PT5M"
	Filter        *Filter
	AckInterval   time.Duration // how often to auto-ACK (0 = manual only)
}

SessionConfig configures a buffered client session.

type SessionInfo

type SessionInfo struct {
	ClientID string   `json:"client_id"`
	Seq      uint64   `json:"seq"`
	Cursor   uint64   `json:"cursor"`
	Devices  []Device `json:"devices"`
}

SessionInfo is the response from creating or reconnecting a session.

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription reads events from an SSE stream.

func (*Subscription) Close

func (s *Subscription) Close() error

Close terminates the SSE stream.

func (*Subscription) Next

func (s *Subscription) Next() (Event, error)

Next blocks until the next event is available, the stream closes, or an error occurs. Returns io.EOF when the stream ends.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL