Documentation
¶
Overview ¶
Package gateway parses the wire formats spoken by NMEA 2000 network gateways: the Yacht Devices RAW ASCII line protocol and the Actisense binary stream protocol.
Index ¶
- func EncodeSend(m N2KMessage) ([]byte, error)
- func EncodeStartup() []byte
- func FormatYDRawTX(frame can.Frame) []byte
- func ParseYDRaw(line string) (can.Frame, bool)
- func ParseYDRawObservation(line string) (raw.Observation, bool)
- func ReadActisense(r io.Reader, handler func(can.Frame)) error
- func ReadActisenseObservations(r io.Reader, handler func(raw.Observation)) error
- func ReadYDRaw(r io.Reader, handler func(can.Frame)) error
- func ReadYDRawObservations(r io.Reader, handler func(raw.Observation)) error
- func Reframe(m N2KMessage, seq uint8) ([]can.Frame, error)
- func ReframeEmitter(handler func(can.Frame)) func(N2KMessage)
- type ActisenseModeSetupError
- type ActisenseObservationAdapter
- type ActisenseRawSerialBus
- func (b *ActisenseRawSerialBus) Close() error
- func (b *ActisenseRawSerialBus) Ready() <-chan struct{}
- func (b *ActisenseRawSerialBus) Run(ctx context.Context, handler func(can.Frame)) error
- func (b *ActisenseRawSerialBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
- func (b *ActisenseRawSerialBus) WriteFrame(frame can.Frame) error
- type ActisenseRawTCPBus
- func (b *ActisenseRawTCPBus) Close() error
- func (b *ActisenseRawTCPBus) Ready() <-chan struct{}
- func (b *ActisenseRawTCPBus) Run(ctx context.Context, handler func(can.Frame)) error
- func (b *ActisenseRawTCPBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
- func (b *ActisenseRawTCPBus) SetConnectionObserver(observer func(bool, uint64))
- func (b *ActisenseRawTCPBus) WriteFrame(frame can.Frame) error
- type ActisenseReader
- type ActisenseSerialBus
- func (b *ActisenseSerialBus) Close() error
- func (b *ActisenseSerialBus) Ready() <-chan struct{}
- func (b *ActisenseSerialBus) Run(ctx context.Context, handler func(can.Frame)) error
- func (b *ActisenseSerialBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
- func (b *ActisenseSerialBus) WriteFrame(frame can.Frame) error
- func (b *ActisenseSerialBus) WriteMessage(pgnNumber uint32, priority, _ uint8, destination uint8, payload []byte) error
- type ActisenseTCPBus
- func (b *ActisenseTCPBus) Close() error
- func (b *ActisenseTCPBus) Ready() <-chan struct{}
- func (b *ActisenseTCPBus) Run(ctx context.Context, handler func(can.Frame)) error
- func (b *ActisenseTCPBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
- func (b *ActisenseTCPBus) SetConnectionObserver(observer func(bool, uint64))
- func (b *ActisenseTCPBus) WriteFrame(frame can.Frame) error
- func (b *ActisenseTCPBus) WriteMessage(pgnNumber uint32, priority, _ uint8, destination uint8, payload []byte) error
- type Backoff
- type N2KMessage
- type ReconnectPolicy
- type YDRawTCPBus
- func (b *YDRawTCPBus) Close() error
- func (b *YDRawTCPBus) Run(ctx context.Context, handler func(can.Frame)) error
- func (b *YDRawTCPBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
- func (b *YDRawTCPBus) SetConnectionObserver(observer func(bool, uint64))
- func (b *YDRawTCPBus) WriteFrame(frame can.Frame) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodeSend ¶
func EncodeSend(m N2KMessage) ([]byte, error)
EncodeSend renders an assembled N2K message as an Actisense transmit command (0x94). The payload layout is priority (1), PGN (3, little-endian), destination (1), data length (1), data. There is no source-address byte: the gateway transmits under its own claimed bus address, so m.Source is not carried on the wire. The gateway also performs fast-packet fragmentation itself, which is why sends are whole messages rather than CAN frames.
func EncodeStartup ¶
func EncodeStartup() []byte
EncodeStartup renders the historical unacknowledged mode-2 command. Mode 2 disables the receive PGN list only; the transmit list remains active. New session adapters use an acknowledged BEM handshake instead.
func FormatYDRawTX ¶
FormatYDRawTX renders a CAN frame as a Yacht Devices RAW transmit line. Application-to-gateway lines carry no time or direction field — just the 29-bit identifier and the data bytes, CRLF-terminated:
19F51323 01 02<CR><LF>
Once the gateway transmits the frame onto the bus it echoes the line back with a timestamp and direction T, which ParseYDRaw accepts like any other frame. Filtered or malformed lines get no echo.
func ParseYDRaw ¶
ParseYDRaw parses one line of the Yacht Devices RAW protocol (YDWG-02 and compatible gateways), e.g.
17:33:21.107 R 09F11201 01 5C 3D FF 7F FF 7F FC
The direction field is R (received from the bus) or T (transmitted to the bus); both carry frames. Returns ok=false for service messages, blank lines, and anything else that does not carry a CAN data frame.
func ParseYDRawObservation ¶ added in v1.0.0
func ParseYDRawObservation(line string) (raw.Observation, bool)
ParseYDRawObservation preserves the gateway's relative timestamp and receive/transmit direction in addition to the CAN frame.
func ReadActisense ¶ added in v0.2.0
ReadActisense reassembles Actisense messages from r and emits CAN frames. Message-level D0 records and gateway diagnostics require the Observation Interface and are intentionally omitted by this compatibility helper.
func ReadActisenseObservations ¶ added in v1.0.0
func ReadActisenseObservations(r io.Reader, handler func(raw.Observation)) error
ReadActisenseObservations decodes all supported BDTP/BST datagrams until EOF.
func ReadYDRaw ¶ added in v0.2.0
ReadYDRaw delivers Yacht Devices RAW lines from r as CAN frames until EOF or a read error. It is the single reader for the RAW protocol, shared by the TCP bus and the read-only network sources.
func ReadYDRawObservations ¶ added in v1.0.0
func ReadYDRawObservations(r io.Reader, handler func(raw.Observation)) error
ReadYDRawObservations preserves direction and gateway-relative timestamps.
func Reframe ¶
func Reframe(m N2KMessage, seq uint8) ([]can.Frame, error)
Reframe converts an assembled N2K message back into wire CAN frames: a single frame for non-fast PGNs up to 8 bytes, fast-packet frames for fast PGNs up to 223 bytes. PGNs absent from the metadata tables are framed by size (fast iff the payload exceeds 8 bytes). seq is the fast-packet sequence ID (0-7).
func ReframeEmitter ¶
func ReframeEmitter(handler func(can.Frame)) func(N2KMessage)
ReframeEmitter adapts a CAN-frame handler into an assembled-message consumer: each message is re-framed into wire CAN frames (rotating the fast-packet sequence ID per message) and fed to the handler. Messages that cannot be re-framed are dropped.
Types ¶
type ActisenseModeSetupError ¶ added in v1.1.0
type ActisenseModeSetupError struct {
RequestedMode actisense.OperatingMode
Err error
}
ActisenseModeSetupError reports a failed acknowledged operating-mode setup. The public package translates it into ActisenseModeError.
func (*ActisenseModeSetupError) Error ¶ added in v1.1.0
func (e *ActisenseModeSetupError) Error() string
func (*ActisenseModeSetupError) Unwrap ¶ added in v1.1.0
func (e *ActisenseModeSetupError) Unwrap() error
type ActisenseObservationAdapter ¶ added in v1.1.0
type ActisenseObservationAdapter struct {
// contains filtered or unexported fields
}
ActisenseObservationAdapter exposes the transport-neutral BST-to-Observation Adapter to capture readers without exporting protocol state from this internal package.
func NewActisenseObservationAdapter ¶ added in v1.1.0
func NewActisenseObservationAdapter() *ActisenseObservationAdapter
func (*ActisenseObservationAdapter) HandleDatagram ¶ added in v1.1.0
func (a *ActisenseObservationAdapter) HandleDatagram(datagram actisense.Datagram, handler func(raw.Observation))
func (*ActisenseObservationAdapter) HandleDecodeError ¶ added in v1.1.0
func (a *ActisenseObservationAdapter) HandleDecodeError(err actisense.DecodeError, handler func(raw.Observation))
type ActisenseRawSerialBus ¶ added in v1.1.0
type ActisenseRawSerialBus struct {
// contains filtered or unexported fields
}
ActisenseRawSerialBus is a source-authoritative BST-95 raw CAN Bus over a direct 115200 8N1 serial connection.
func NewActisenseRawSerialBus ¶ added in v1.1.0
func NewActisenseRawSerialBus(log *slog.Logger, port string) *ActisenseRawSerialBus
func (*ActisenseRawSerialBus) Close ¶ added in v1.1.0
func (b *ActisenseRawSerialBus) Close() error
func (*ActisenseRawSerialBus) Ready ¶ added in v1.1.0
func (b *ActisenseRawSerialBus) Ready() <-chan struct{}
func (*ActisenseRawSerialBus) RunObservations ¶ added in v1.1.0
func (b *ActisenseRawSerialBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
func (*ActisenseRawSerialBus) WriteFrame ¶ added in v1.1.0
func (b *ActisenseRawSerialBus) WriteFrame(frame can.Frame) error
type ActisenseRawTCPBus ¶ added in v1.1.0
type ActisenseRawTCPBus struct {
// contains filtered or unexported fields
}
ActisenseRawTCPBus is a source-authoritative BST-95 raw CAN Bus.
func NewActisenseRawTCPBus ¶ added in v1.1.0
func NewActisenseRawTCPBus(log *slog.Logger, addr string, reconnect *ReconnectPolicy) *ActisenseRawTCPBus
func (*ActisenseRawTCPBus) Close ¶ added in v1.1.0
func (b *ActisenseRawTCPBus) Close() error
func (*ActisenseRawTCPBus) Ready ¶ added in v1.1.0
func (b *ActisenseRawTCPBus) Ready() <-chan struct{}
func (*ActisenseRawTCPBus) RunObservations ¶ added in v1.1.0
func (b *ActisenseRawTCPBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
func (*ActisenseRawTCPBus) SetConnectionObserver ¶ added in v1.1.0
func (b *ActisenseRawTCPBus) SetConnectionObserver(observer func(bool, uint64))
func (*ActisenseRawTCPBus) WriteFrame ¶ added in v1.1.0
func (b *ActisenseRawTCPBus) WriteFrame(frame can.Frame) error
type ActisenseReader ¶
type ActisenseReader struct {
// contains filtered or unexported fields
}
ActisenseReader is an incremental decoder for the Actisense binary stream protocol. It tolerates arbitrary buffer boundaries: bytes are fed as they arrive and complete messages are emitted as they are recognized.
func NewActisenseReader ¶
func NewActisenseReader() *ActisenseReader
NewActisenseReader returns a reader ready to consume stream bytes.
func (*ActisenseReader) Feed ¶
func (r *ActisenseReader) Feed(buf []byte, emit func(N2KMessage))
Feed consumes raw stream bytes; emit is called once per complete, checksum-valid N2K message (command 0x93). Garbage between messages is skipped and messages that fail their checksum are dropped silently.
type ActisenseSerialBus ¶ added in v1.1.0
type ActisenseSerialBus struct {
// contains filtered or unexported fields
}
ActisenseSerialBus is the gateway-owned BST-93/94 message session over a direct 115200 8N1 serial connection.
func NewActisenseSerialBus ¶ added in v1.1.0
func NewActisenseSerialBus(log *slog.Logger, port string) *ActisenseSerialBus
func (*ActisenseSerialBus) Close ¶ added in v1.1.0
func (b *ActisenseSerialBus) Close() error
func (*ActisenseSerialBus) Ready ¶ added in v1.1.0
func (b *ActisenseSerialBus) Ready() <-chan struct{}
func (*ActisenseSerialBus) RunObservations ¶ added in v1.1.0
func (b *ActisenseSerialBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
func (*ActisenseSerialBus) WriteFrame ¶ added in v1.1.0
func (b *ActisenseSerialBus) WriteFrame(frame can.Frame) error
func (*ActisenseSerialBus) WriteMessage ¶ added in v1.1.0
type ActisenseTCPBus ¶
type ActisenseTCPBus struct {
// contains filtered or unexported fields
}
ActisenseTCPBus is the v1-compatible, gateway-owned BST-93/94 message session. It is retained for compatibility; raw CAN mode is the authoritative Client Bus.
func NewActisenseTCPBus ¶
func NewActisenseTCPBus(log *slog.Logger, addr string, reconnect *ReconnectPolicy) *ActisenseTCPBus
func (*ActisenseTCPBus) Close ¶
func (b *ActisenseTCPBus) Close() error
func (*ActisenseTCPBus) Ready ¶ added in v1.1.0
func (b *ActisenseTCPBus) Ready() <-chan struct{}
func (*ActisenseTCPBus) RunObservations ¶ added in v1.0.0
func (b *ActisenseTCPBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
func (*ActisenseTCPBus) SetConnectionObserver ¶ added in v1.0.0
func (b *ActisenseTCPBus) SetConnectionObserver(observer func(bool, uint64))
func (*ActisenseTCPBus) WriteFrame ¶
func (b *ActisenseTCPBus) WriteFrame(frame can.Frame) error
func (*ActisenseTCPBus) WriteMessage ¶
type Backoff ¶ added in v0.2.0
type Backoff struct {
// contains filtered or unexported fields
}
Backoff is a re-armable exponential backoff sequencer. It is not safe for concurrent use; a single reconnect loop owns one Backoff.
func NewBackoff ¶ added in v0.2.0
func NewBackoff(policy ReconnectPolicy) *Backoff
NewBackoff returns a Backoff seeded from policy, substituting defaults for any non-positive field.
type N2KMessage ¶
N2KMessage is one NMEA 2000 message carried by an Actisense stream. Data is the assembled PGN payload (fast-packet PGNs arrive already assembled).
type ReconnectPolicy ¶ added in v0.2.0
type ReconnectPolicy struct {
// InitialBackoff is the delay before the first reconnect attempt after a
// drop, and the delay restored after any successful connection.
InitialBackoff time.Duration
// MaxBackoff caps the exponentially growing delay between attempts while a
// connection cannot be re-established.
MaxBackoff time.Duration
}
ReconnectPolicy configures automatic re-dialing of a dropped gateway connection. A nil *ReconnectPolicy means reconnection is disabled: a dropped connection ends the read loop (the historical behavior).
type YDRawTCPBus ¶
type YDRawTCPBus struct {
// contains filtered or unexported fields
}
YDRawTCPBus is a read/write bus over a TCP gateway speaking the Yacht Devices RAW line protocol (YDWG-02 RAW server mode and compatibles). RAW mode is frame-level in both directions, so the full client stack — address claiming included — works exactly as it does on CAN hardware. The gateway echoes transmitted frames back with direction T, so the client also observes its own traffic.
func NewYDRawTCPBus ¶
func NewYDRawTCPBus(log *slog.Logger, addr string, reconnect *ReconnectPolicy) *YDRawTCPBus
NewYDRawTCPBus returns an unconnected bus; Run dials. A non-nil reconnect policy makes Run re-dial dropped connections.
func (*YDRawTCPBus) Run ¶
Run connects and delivers incoming frames to handler until ctx is cancelled or (without a reconnect policy) the connection fails.
func (*YDRawTCPBus) RunObservations ¶ added in v1.0.0
func (b *YDRawTCPBus) RunObservations(ctx context.Context, handler func(raw.Observation)) error
RunObservations preserves gateway transport context.
func (*YDRawTCPBus) SetConnectionObserver ¶ added in v1.0.0
func (b *YDRawTCPBus) SetConnectionObserver(observer func(bool, uint64))
SetConnectionObserver installs reconnect lifecycle observation for Client.
func (*YDRawTCPBus) WriteFrame ¶
func (b *YDRawTCPBus) WriteFrame(frame can.Frame) error
WriteFrame transmits one CAN frame as a RAW line.