Documentation
¶
Overview ¶
Package transport implements ISO 11783 Transport Protocol for NMEA 2000 messages that exceed 8 bytes and cannot use fast-packet encoding. It supports two modes:
- BAM (Broadcast Announce Message): one-way broadcast without flow control
- RTS/CTS (Request To Send / Clear To Send): addressed point-to-point with flow control
Both modes use TP.CM (PGN 60416) for connection management control frames and TP.DT (PGN 60160) for data transfer frames.
Index ¶
- Constants
- type Manager
- func (m *Manager) Close()
- func (m *Manager) HandleFrame(frame can.Frame)
- func (m *Manager) HandleFrameWithInfo(frame can.Frame, info pgn.MessageInfo)
- func (m *Manager) SendBAM(pgn uint32, source uint8, payload []byte) error
- func (m *Manager) SendRTSCTS(pgn uint32, source uint8, destination uint8, payload []byte) error
- type ManagerConfig
- type Timer
Constants ¶
const ( // PGNCM is the Connection Management PGN (TP.CM). PGNCM uint32 = 60416 // 0xEC00 // PGNDT is the Data Transfer PGN (TP.DT). PGNDT uint32 = 60160 // 0xEB00 )
TP PGN constants.
const ( ControlRTS uint8 = 16 // Request To Send ControlCTS uint8 = 17 // Clear To Send ControlEndOfMsgAck uint8 = 19 // End of Message Acknowledgement ControlBAM uint8 = 32 // Broadcast Announce Message ControlAbort uint8 = 255 // Connection Abort )
CM control byte values identifying the type of connection management frame.
const ( // DTTimeout is the maximum time to wait for the next DT frame. DTTimeout = 750 * time.Millisecond // CTSTimeout is the maximum time to wait for a CTS response after sending RTS or DT frames. CTSTimeout = 1250 * time.Millisecond )
Timeout durations per ISO 11783-3.
const BAMInterFrameDelay = 50 * time.Millisecond
BAM inter-frame delay (minimum 50ms per spec).
const BroadcastAddr = framer.BroadcastAddr
BroadcastAddr is the broadcast destination address.
const MaxDTDataBytes = 7
MaxDTDataBytes is the number of data bytes carried per DT frame (bytes 1-7).
const MaxPGN = 0x3FFFF
MaxPGN is the largest value representable by an NMEA 2000 18-bit PGN.
const MaxPayloadBytes = 255 * MaxDTDataBytes
MaxPayloadBytes is the largest payload representable by the transport protocol's one-byte DT packet count (255 packets of seven data bytes).
const TPPriority uint8 = 6
Standard priority for transport protocol frames.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager orchestrates ISO 11783 transport protocol sessions, handling both BAM and RTS/CTS modes for receive and transmit.
func NewManager ¶
func NewManager(cfg ManagerConfig) *Manager
NewManager creates a new transport protocol Manager.
func (*Manager) Close ¶
func (m *Manager) Close()
Close stops all active sessions and prevents new ones from being created.
func (*Manager) HandleFrame ¶
HandleFrame routes an incoming CAN frame to the appropriate transport protocol handler based on PGN. Non-TP frames are silently ignored.
func (*Manager) HandleFrameWithInfo ¶ added in v1.0.0
func (m *Manager) HandleFrameWithInfo(frame can.Frame, info pgn.MessageInfo)
HandleFrameWithInfo routes a transport frame while retaining its Adapter, network, timing, and direction context through reassembly.
type ManagerConfig ¶
type ManagerConfig struct {
// WriteFrame sends a CAN frame onto the bus.
WriteFrame func(can.Frame) error
// LocalAddress returns the client's currently claimed address. When set,
// addressed TP traffic for other nodes is ignored. A function is used
// because address claiming may move the client at runtime.
LocalAddress func() uint8
// OnComplete is called when a multi-frame message has been fully reassembled.
// It receives the transported PGN, source address, destination address, and
// the assembled payload.
OnComplete func(pgn uint32, source uint8, destination uint8, data []byte)
// OnCompleteInfo is the source-aware completion callback. The MessageInfo
// comes from the connection-management frame that began the transfer, with
// PGN replaced by the transported PGN.
OnCompleteInfo func(info pgn.MessageInfo, data []byte)
// Logger for transport protocol events. If nil, a no-op logger is used.
Logger *slog.Logger
// AfterFunc schedules a callback after d; nil means time.AfterFunc.
// Tests inject a fake to drive timeouts deterministically.
AfterFunc func(d time.Duration, f func()) Timer
// Sleep pauses between BAM DT frames; nil means time.Sleep.
Sleep func(d time.Duration)
}
ManagerConfig holds the dependencies for a transport protocol Manager.