Documentation
¶
Overview ¶
Package lplexc provides a Go client for lplex, a CAN bus HTTP bridge for NMEA 2000.
Index ¶
- func Discover(ctx context.Context) (string, error)
- type Client
- func (c *Client) CreateSession(ctx context.Context, cfg SessionConfig) (*Session, error)
- func (c *Client) Devices(ctx context.Context) ([]Device, error)
- func (c *Client) Send(ctx context.Context, pgn uint32, src, dst, prio uint8, data []byte) error
- func (c *Client) Subscribe(ctx context.Context, filter *Filter) (*Subscription, error)
- type Device
- type Event
- type Filter
- type Frame
- type Session
- type SessionConfig
- type SessionInfo
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with an lplex server over HTTP.
func (*Client) CreateSession ¶
CreateSession creates or reconnects a buffered session on the server.
func (*Client) Devices ¶
Devices returns a snapshot of all NMEA 2000 devices discovered by the server.
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 ¶
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.
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) Info ¶
func (s *Session) Info() SessionInfo
Info returns the session metadata from the server.
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) 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.