Documentation
¶
Overview ¶
Package actisense implements the bounded BDTP, BST, BEM, and EBL wire protocols used by Actisense-format gateways. Transport adapters live in internal/gateway; this package owns protocol framing and session state.
Index ¶
- Constants
- Variables
- func CANConfigSet(config CANConfig) []byte
- func DecodeCANInfoField(response BEMResponse, field CANInfoField) (string, error)
- func DecodeEcho(response BEMResponse) ([]byte, error)
- func DecodeTotalTime(response BEMResponse) (uint32, error)
- func EncodeBEMRequest(command byte, data []byte) ([]byte, error)
- func EncodeCANFrame(frame can.Frame, direction Direction, timestamp time.Duration, ...) ([]byte, error)
- func EncodeCANInfoField(text string) ([]byte, error)
- func EncodeDatagram(id byte, payload []byte) ([]byte, error)
- func EncodeEcho(payload []byte) ([]byte, error)
- func EncodeMessage94(message Message) ([]byte, error)
- func EncodeMessageD0(message Message) ([]byte, error)
- func EncodePortPCodes(codes []PortPCode) ([]byte, error)
- func IsType2(id byte) bool
- func OperatingModeRequest() []byte
- func OperatingModeSet(mode OperatingMode) []byte
- func PortBaudrateGet(port uint8) []byte
- func PortBaudrateSet(port uint8, sessionBaud, storeBaud uint32) []byte
- func RxPGNEnableGet(pgn uint32) []byte
- func RxPGNEnableSet(pgn uint32, flag PGNEnableFlag, mask *uint32) []byte
- func TotalTimeSet(seconds, passkey uint32) []byte
- func TxPGNEnableGet(pgn uint32) []byte
- func TxPGNEnableSet(pgn uint32, enabled bool) []byte
- func TxPGNEnableSetFull(pgn uint32, flag PGNEnableFlag, rate *uint32) []byte
- type BEMOrigin
- type BEMPath
- type BEMResponse
- type CANConfig
- type CANFrame
- type CANInfoField
- type CANStatus
- type CommandSet
- func (c *CommandSet) ActivatePGNLists(ctx context.Context) error
- func (c *CommandSet) CommitEEPROM(ctx context.Context) error
- func (c *CommandSet) CommitFlash(ctx context.Context) error
- func (c *CommandSet) DefaultPGNLists(ctx context.Context, selector PGNListSelector) error
- func (c *CommandSet) DeletePGNLists(ctx context.Context, selector PGNListSelector) error
- func (c *CommandSet) DeviceCapabilities() DeviceCapabilities
- func (c *CommandSet) DeviceSerialNumber() uint32
- func (c *CommandSet) Echo(ctx context.Context, payload []byte) ([]byte, error)
- func (c *CommandSet) GetCANConfig(ctx context.Context) (CANConfig, error)
- func (c *CommandSet) GetCANInfoField(ctx context.Context, field CANInfoField) (string, error)
- func (c *CommandSet) GetOperatingMode(ctx context.Context) (OperatingMode, error)
- func (c *CommandSet) GetPGNListParameters(ctx context.Context) (PGNListParameters, error)
- func (c *CommandSet) GetPortBaudrate(ctx context.Context, port uint8) (PortBaudrate, error)
- func (c *CommandSet) GetPortDuplicateDelete(ctx context.Context) ([]PortDuplicateDelete, error)
- func (c *CommandSet) GetPortInventory(ctx context.Context) (PortInventory, error)
- func (c *CommandSet) GetPortPCodes(ctx context.Context) ([]PortPCode, error)
- func (c *CommandSet) GetProductInfo(ctx context.Context) (ProductInfo, error)
- func (c *CommandSet) GetRxPGN(ctx context.Context, pgn uint32) (RxPGNState, error)
- func (c *CommandSet) GetRxPGNEnableList(ctx context.Context) (RxPGNEnableList, error)
- func (c *CommandSet) GetRxPGNEnableListF1(ctx context.Context) (RxPGNEnableListF1, error)
- func (c *CommandSet) GetSupportedPGNs(ctx context.Context) (SupportedPGNList, error)
- func (c *CommandSet) GetTotalTime(ctx context.Context) (uint32, error)
- func (c *CommandSet) GetTxPGN(ctx context.Context, pgn uint32) (TxPGNState, error)
- func (c *CommandSet) GetTxPGNEnableList(ctx context.Context) (TxPGNEnableList, error)
- func (c *CommandSet) GetTxPGNEnableListF1(ctx context.Context) (TxPGNEnableListF1, error)
- func (c *CommandSet) RawRequest(ctx context.Context, command byte, data []byte) (BEMResponse, error)
- func (c *CommandSet) RawRequestMulti(ctx context.Context, command byte, data []byte, ...) ([]BEMResponse, error)
- func (c *CommandSet) Reinitialize(ctx context.Context) error
- func (c *CommandSet) SetCANConfig(ctx context.Context, config CANConfig) (CANConfig, error)
- func (c *CommandSet) SetCANInfoField(ctx context.Context, field CANInfoField, text string) (string, error)
- func (c *CommandSet) SetOperatingMode(ctx context.Context, mode OperatingMode) error
- func (c *CommandSet) SetPortBaudrate(ctx context.Context, port uint8, sessionBaud, storeBaud uint32) (PortBaudrate, error)
- func (c *CommandSet) SetPortDuplicateDelete(ctx context.Context, settings []PortDuplicateDelete) ([]PortDuplicateDelete, error)
- func (c *CommandSet) SetPortPCodes(ctx context.Context, codes []PortPCode) ([]PortPCode, error)
- func (c *CommandSet) SetRxPGN(ctx context.Context, pgn uint32, flag PGNEnableFlag, mask *uint32) (RxPGNState, error)
- func (c *CommandSet) SetTotalTime(ctx context.Context, seconds, passkey uint32) (uint32, error)
- func (c *CommandSet) SetTxPGN(ctx context.Context, pgn uint32, flag PGNEnableFlag, rate *uint32) (TxPGNState, error)
- type CommandSetConfig
- type Datagram
- type DecodeError
- type DecodeErrorKind
- type DeviceCapabilities
- type DeviceError
- type Diagnostic
- type DiagnosticKind
- type Direction
- type ErrorReport
- type HardwareProtocol
- type IndividualBufferStatus
- type Message
- type MessageType
- type ModelID
- type NegativeAck
- type NegativeAckError
- type OperatingMode
- type PGNEnableFlag
- type PGNListParameters
- type PGNListSelector
- type Parser
- func (p *Parser) BufferedBytes() int
- func (p *Parser) End(report func(DecodeError))
- func (p *Parser) EndWithUnframed(report func(DecodeError), unframed func([]byte))
- func (p *Parser) Feed(buf []byte, emit func(Datagram), report func(DecodeError))
- func (p *Parser) FeedWithUnframed(buf []byte, emit func(Datagram), report func(DecodeError), ...)
- func (p *Parser) UnframedBytes() uint64
- type PortBaudrate
- type PortDuplicateDelete
- type PortInventory
- type PortInventoryEntry
- type PortMedia
- type PortPCode
- type ProductInfo
- type ProprietaryPGNList
- type Requester
- type RxPGNEnableList
- type RxPGNEnableListF1
- type RxPGNListEntry
- type RxPGNListF1Entry
- type RxPGNState
- type Session
- func (s *Session) ActivatePGNLists(ctx context.Context) error
- func (s *Session) Close(err error)
- func (s *Session) GetOperatingMode(ctx context.Context) (OperatingMode, error)
- func (s *Session) GetTxPGN(ctx context.Context, pgn uint32) (TxPGNState, error)
- func (s *Session) Metrics() SessionMetrics
- func (s *Session) Request(ctx context.Context, command byte, data []byte) (BEMResponse, error)
- func (s *Session) RequestMulti(ctx context.Context, command byte, data []byte, inactivity time.Duration, ...) ([]BEMResponse, error)
- func (s *Session) Run(reader io.Reader) error
- func (s *Session) SetOperatingMode(ctx context.Context, mode OperatingMode) error
- func (s *Session) SetTxPGN(ctx context.Context, pgn uint32, enabled bool) error
- func (s *Session) Write(buf []byte) error
- func (s *Session) WriteContext(ctx context.Context, buf []byte) error
- type SessionConfig
- type SessionMetrics
- type StartupStatus
- type SupportedPGN
- type SupportedPGNList
- type SystemStatus
- type TxPGNEnableList
- type TxPGNEnableListF1
- type TxPGNListEntry
- type TxPGNListF1Entry
- type TxPGNState
- type UnifiedBufferStatus
- type WireDirection
Constants ¶
const ( DLE = 0x10 STX = 0x02 ETX = 0x03 // MaxDatagramLength bounds an unframed BST datagram excluding its checksum. // It covers a 1785-byte NMEA 2000 transport payload plus the 13-byte BST-D0 // header, while remaining within the EBL tag capacity used by field captures. MaxDatagramLength = 1800 )
const ( BEMReinitialize = 0x00 BEMCommitEEPROM = 0x01 BEMCommitFlash = 0x02 BEMOperatingMode = 0x11 BEMPortPCode = 0x13 BEMTotalTime = 0x15 BEMPortBaudrate = 0x17 BEMEcho = 0x18 BEMPortInventory = 0x1B BEMSupportedPGNList = 0x40 BEMProductInfo = 0x41 BEMCANConfig = 0x42 BEMCANInfoField1 = 0x43 BEMCANInfoField2 = 0x44 BEMCANInfoField3 = 0x45 BEMRxPGNEnable = 0x46 BEMTxPGNEnable = 0x47 BEMDeletePGNLists = 0x4A BEMActivatePGNLists = 0x4B BEMDefaultPGNLists = 0x4C BEMPGNListParameters = 0x4D BEMRxPGNEnableListF2 = 0x4E BEMTxPGNEnableListF2 = 0x4F BEMStartupStatus = 0xF0 BEMErrorReport = 0xF1 BEMSystemStatus = 0xF2 BEMNegativeAck = 0xF4 )
const ( BaudRateNoChange uint32 = 0xFFFFFFFF BaudRateDefault uint32 = 0xFFFFFFFE BaudRateAdoptAlternate uint32 = 0xFFFFFFFC )
const ( BEMPortDuplicateDelete = 0x14 BEMRxPGNEnableListF1 = 0x48 BEMTxPGNEnableListF1 = 0x49 )
const ( ProprietaryDP0Base = uint32(0x0000FF00) ProprietaryDP1Base = uint32(0x0001FF00) )
const ( RxPGNMaskPGN = uint32(0x03FFFF00) RxPGNMaskPDUFormat = uint32(0x03FF0000) RxPGNMaskPDUNibble = uint32(0x03F00000) RxPGNMaskDataPage = uint32(0x03000000) RxPGNMaskDefault = uint32(0xFFFFFFFE) RxPGNMaskNoChange = uint32(0xFFFFFFFF) TxPGNRateNoChange = uint32(0xFFFF) TxPGNRateEvent = uint32(0) // Deprecated: this value means no change, not accept all. Use RxPGNMaskNoChange. RxPGNMaskAcceptAll = RxPGNMaskNoChange // Deprecated: this value leaves the rate unchanged. Use TxPGNRateNoChange. TxPGNRateDefault = uint32(0xFFFFFFFF) )
const ( BSTN2KReceive = 0x93 BSTN2KTransmit = 0x94 BSTCANFrame = 0x95 BSTBEMResponse = 0xA0 BSTBEMCommand = 0xA1 BSTN2KMessage = 0xD0 MaxNMEA2000Payload = 1785 )
Variables ¶
var ( ErrSessionClosed = errors.New("actisense: session closed") ErrRequestInFlight = errors.New("actisense: request already in flight") )
var LocalBEMOrigin = BEMOrigin{Path: BEMPathLocal, Source: 255}
Functions ¶
func CANConfigSet ¶ added in v1.2.0
func DecodeCANInfoField ¶ added in v1.2.0
func DecodeCANInfoField(response BEMResponse, field CANInfoField) (string, error)
func DecodeEcho ¶ added in v1.2.0
func DecodeEcho(response BEMResponse) ([]byte, error)
func DecodeTotalTime ¶ added in v1.2.0
func DecodeTotalTime(response BEMResponse) (uint32, error)
func EncodeBEMRequest ¶
EncodeBEMRequest renders a local BEM command using BST-A1.
func EncodeCANFrame ¶
func EncodeCANFrame(frame can.Frame, direction Direction, timestamp time.Duration, resolution uint8) ([]byte, error)
EncodeCANFrame renders a source-authoritative raw CAN frame as BST-95.
func EncodeCANInfoField ¶ added in v1.2.0
func EncodeDatagram ¶
EncodeDatagram wraps a BST ID and payload in BDTP framing with the applicable Type 1 or Type 2 length field and zero-sum checksum.
func EncodeEcho ¶ added in v1.2.0
func EncodeMessage94 ¶
EncodeMessage94 renders one legacy gateway-owned assembled message.
func EncodeMessageD0 ¶
EncodeMessageD0 renders an assembled NMEA 2000 message using BST Type 2.
func EncodePortPCodes ¶ added in v1.2.0
func OperatingModeRequest ¶
func OperatingModeRequest() []byte
func OperatingModeSet ¶
func OperatingModeSet(mode OperatingMode) []byte
func PortBaudrateGet ¶ added in v1.2.0
func PortBaudrateSet ¶ added in v1.2.0
func RxPGNEnableGet ¶ added in v1.2.0
func RxPGNEnableSet ¶ added in v1.2.0
func RxPGNEnableSet(pgn uint32, flag PGNEnableFlag, mask *uint32) []byte
func TotalTimeSet ¶ added in v1.2.0
func TxPGNEnableGet ¶
func TxPGNEnableSet ¶
func TxPGNEnableSetFull ¶ added in v1.2.0
func TxPGNEnableSetFull(pgn uint32, flag PGNEnableFlag, rate *uint32) []byte
Types ¶
type BEMOrigin ¶ added in v1.2.0
BEMOrigin distinguishes the locally attached gateway from a remote Actisense device reached through PGN 126720. Source is 255 for local responses and the responding NMEA 2000 source address for remote responses.
type BEMPath ¶ added in v1.2.0
type BEMPath uint8
BEMPath identifies how a BEM response reached the library.
type BEMResponse ¶
type BEMResponse struct {
BSTID byte
BEMID byte
Origin BEMOrigin
Sequence uint8
ModelID uint16
SerialNumber uint32
ErrorCode int32
Data []byte
}
BEMResponse is the common local gateway response envelope. Data is owned.
func DecodeBEMResponse ¶
func DecodeBEMResponse(d Datagram) (response BEMResponse, ok bool, err error)
DecodeBEMResponse decodes the 12-byte response header carried by local BEM response BST IDs. ok is false when d is not a BEM response datagram.
type CANConfig ¶ added in v1.2.0
type CANConfig struct {
NAME uint64
// SourceAddress is the stored preferred/previous address, not the live
// ISO-claimed address. Arbitration can assign a different bus address.
SourceAddress uint8
}
func DecodeCANConfig ¶ added in v1.2.0
func DecodeCANConfig(response BEMResponse) (CANConfig, error)
type CANFrame ¶
type CANFrame struct {
Frame can.Frame
Timestamp time.Duration
HasTimestamp bool
Direction Direction
Resolution uint8
}
CANFrame is one raw CAN Frame plus BST-95 transport metadata.
type CANInfoField ¶ added in v1.2.0
type CANInfoField uint8
const ( CANInfoInstallationDescription1 CANInfoField = 1 CANInfoInstallationDescription2 CANInfoField = 2 CANInfoManufacturerInformation CANInfoField = 3 )
type CommandSet ¶ added in v1.2.0
type CommandSet struct {
// contains filtered or unexported fields
}
CommandSet is the typed, envelope-independent Actisense BEM Interface. Persistent and rebooting verbs are methods but are never called implicitly.
func NewCommandSet ¶ added in v1.2.0
func NewCommandSet(requester Requester, config CommandSetConfig) *CommandSet
func (*CommandSet) ActivatePGNLists ¶ added in v1.2.0
func (c *CommandSet) ActivatePGNLists(ctx context.Context) error
func (*CommandSet) CommitEEPROM ¶ added in v1.2.0
func (c *CommandSet) CommitEEPROM(ctx context.Context) error
CommitEEPROM explicitly persists staged session settings to EEPROM. It is never invoked automatically.
func (*CommandSet) CommitFlash ¶ added in v1.2.0
func (c *CommandSet) CommitFlash(ctx context.Context) error
CommitFlash explicitly persists staged session settings to flash. It is never invoked automatically.
func (*CommandSet) DefaultPGNLists ¶ added in v1.2.0
func (c *CommandSet) DefaultPGNLists(ctx context.Context, selector PGNListSelector) error
func (*CommandSet) DeletePGNLists ¶ added in v1.2.0
func (c *CommandSet) DeletePGNLists(ctx context.Context, selector PGNListSelector) error
func (*CommandSet) DeviceCapabilities ¶ added in v1.2.0
func (c *CommandSet) DeviceCapabilities() DeviceCapabilities
DeviceCapabilities returns the last model identity observed on this handle. It is Unknown until at least one response has arrived.
func (*CommandSet) DeviceSerialNumber ¶ added in v1.2.0
func (c *CommandSet) DeviceSerialNumber() uint32
func (*CommandSet) GetCANConfig ¶ added in v1.2.0
func (c *CommandSet) GetCANConfig(ctx context.Context) (CANConfig, error)
func (*CommandSet) GetCANInfoField ¶ added in v1.2.0
func (c *CommandSet) GetCANInfoField(ctx context.Context, field CANInfoField) (string, error)
func (*CommandSet) GetOperatingMode ¶ added in v1.2.0
func (c *CommandSet) GetOperatingMode(ctx context.Context) (OperatingMode, error)
func (*CommandSet) GetPGNListParameters ¶ added in v1.2.0
func (c *CommandSet) GetPGNListParameters(ctx context.Context) (PGNListParameters, error)
func (*CommandSet) GetPortBaudrate ¶ added in v1.2.0
func (c *CommandSet) GetPortBaudrate(ctx context.Context, port uint8) (PortBaudrate, error)
func (*CommandSet) GetPortDuplicateDelete ¶ added in v1.4.0
func (c *CommandSet) GetPortDuplicateDelete(ctx context.Context) ([]PortDuplicateDelete, error)
GetPortDuplicateDelete reads the documented BEM-14 port filter settings. Support depends on device firmware; unsupported devices return a BEM error.
func (*CommandSet) GetPortInventory ¶ added in v1.2.0
func (c *CommandSet) GetPortInventory(ctx context.Context) (PortInventory, error)
func (*CommandSet) GetPortPCodes ¶ added in v1.2.0
func (c *CommandSet) GetPortPCodes(ctx context.Context) ([]PortPCode, error)
func (*CommandSet) GetProductInfo ¶ added in v1.2.0
func (c *CommandSet) GetProductInfo(ctx context.Context) (ProductInfo, error)
func (*CommandSet) GetRxPGN ¶ added in v1.2.0
func (c *CommandSet) GetRxPGN(ctx context.Context, pgn uint32) (RxPGNState, error)
func (*CommandSet) GetRxPGNEnableList ¶ added in v1.2.0
func (c *CommandSet) GetRxPGNEnableList(ctx context.Context) (RxPGNEnableList, error)
func (*CommandSet) GetRxPGNEnableListF1 ¶ added in v1.4.0
func (c *CommandSet) GetRxPGNEnableListF1(ctx context.Context) (RxPGNEnableListF1, error)
GetRxPGNEnableListF1 reads the two ordered legacy response parts. F1 was discontinued at firmware 2.500 and is not implemented by NGX/W2K products. Prefer GetRxPGNEnableList. No automatic fallback or list mutation occurs.
func (*CommandSet) GetSupportedPGNs ¶ added in v1.2.0
func (c *CommandSet) GetSupportedPGNs(ctx context.Context) (SupportedPGNList, error)
GetSupportedPGNs performs the command's caller-driven chunk walk. Each sub-list is a distinct request and all transfer invariants are checked.
func (*CommandSet) GetTotalTime ¶ added in v1.2.0
func (c *CommandSet) GetTotalTime(ctx context.Context) (uint32, error)
func (*CommandSet) GetTxPGN ¶ added in v1.2.0
func (c *CommandSet) GetTxPGN(ctx context.Context, pgn uint32) (TxPGNState, error)
func (*CommandSet) GetTxPGNEnableList ¶ added in v1.2.0
func (c *CommandSet) GetTxPGNEnableList(ctx context.Context) (TxPGNEnableList, error)
func (*CommandSet) GetTxPGNEnableListF1 ¶ added in v1.4.0
func (c *CommandSet) GetTxPGNEnableListF1(ctx context.Context) (TxPGNEnableListF1, error)
GetTxPGNEnableListF1 reads PGNs, rates, timeouts, and priorities in order. Prefer GetTxPGNEnableList on current firmware. Partial results retain the completed parts when a response train fails or times out.
func (*CommandSet) RawRequest ¶ added in v1.2.0
func (c *CommandSet) RawRequest(ctx context.Context, command byte, data []byte) (BEMResponse, error)
RawRequest sends one BEM command through this handle's local or remote envelope. Prefer typed methods when a command is known.
func (*CommandSet) RawRequestMulti ¶ added in v1.4.0
func (c *CommandSet) RawRequestMulti(ctx context.Context, command byte, data []byte, complete func(BEMResponse) (bool, error)) ([]BEMResponse, error)
RawRequestMulti collects a bounded response train for a caller-defined BEM command. complete receives each response in arrival order; returning true ends the train. On failure, all received responses are returned with the error.
func (*CommandSet) Reinitialize ¶ added in v1.2.0
func (c *CommandSet) Reinitialize(ctx context.Context) error
Reinitialize explicitly asks the device to reboot. It is never invoked by connection setup, restore, or Close.
func (*CommandSet) SetCANConfig ¶ added in v1.2.0
SetCANConfig changes the device's NMEA 2000 NAME and preferred address. Some firmware persists this operation itself; the library never calls it automatically.
func (*CommandSet) SetCANInfoField ¶ added in v1.2.0
func (c *CommandSet) SetCANInfoField(ctx context.Context, field CANInfoField, text string) (string, error)
SetCANInfoField writes installation description 1 or 2. Manufacturer information is read-only. Firmware may persist these fields immediately.
func (*CommandSet) SetOperatingMode ¶ added in v1.2.0
func (c *CommandSet) SetOperatingMode(ctx context.Context, mode OperatingMode) error
func (*CommandSet) SetPortBaudrate ¶ added in v1.2.0
func (c *CommandSet) SetPortBaudrate(ctx context.Context, port uint8, sessionBaud, storeBaud uint32) (PortBaudrate, error)
SetPortBaudrate changes the session and stored rates explicitly. Passing a sentinel such as BaudRateNoChange preserves the corresponding value. The stored value may be written to non-volatile memory by device firmware.
func (*CommandSet) SetPortDuplicateDelete ¶ added in v1.4.0
func (c *CommandSet) SetPortDuplicateDelete(ctx context.Context, settings []PortDuplicateDelete) ([]PortDuplicateDelete, error)
SetPortDuplicateDelete supplies every port, using NoChange for unchanged entries. Firmware applies and persists this operation immediately.
func (*CommandSet) SetPortPCodes ¶ added in v1.2.0
func (*CommandSet) SetRxPGN ¶ added in v1.2.0
func (c *CommandSet) SetRxPGN(ctx context.Context, pgn uint32, flag PGNEnableFlag, mask *uint32) (RxPGNState, error)
SetRxPGN accepts one of the four documented PGN masks or a default/no-change sentinel. A nil mask selects the device default. Source filtering is not supported.
func (*CommandSet) SetTotalTime ¶ added in v1.2.0
func (*CommandSet) SetTxPGN ¶ added in v1.2.0
func (c *CommandSet) SetTxPGN(ctx context.Context, pgn uint32, flag PGNEnableFlag, rate *uint32) (TxPGNState, error)
SetTxPGN uses milliseconds for rates 1-65534 and zero for event-driven data. A nil rate or any value >= 65535 leaves the current rate unchanged. This command has no restore-default rate sentinel.
type CommandSetConfig ¶ added in v1.2.0
type Datagram ¶
Datagram is an owned, checksum-validated BST record. Raw contains the BST ID, length field, and payload without BDTP markers or the checksum byte.
type DecodeError ¶
type DecodeError struct {
Kind DecodeErrorKind
ID byte
Err error
}
DecodeError describes one discarded datagram. A Parser remains usable after reporting it and continues hunting for the next DLE/STX marker.
func (DecodeError) Error ¶
func (e DecodeError) Error() string
func (DecodeError) Unwrap ¶
func (e DecodeError) Unwrap() error
type DecodeErrorKind ¶
type DecodeErrorKind string
DecodeErrorKind identifies a recoverable BDTP/BST stream defect.
const ( DecodeFraming DecodeErrorKind = "framing" DecodeChecksum DecodeErrorKind = "checksum" DecodeLength DecodeErrorKind = "length" DecodeOversize DecodeErrorKind = "oversize" )
type DeviceCapabilities ¶ added in v1.2.0
type DeviceCapabilities struct {
ModelID ModelID
ModelName string
ProprietaryPGNEnableListF2 bool
ReceiveAllOmitsISOControlPGNs bool
RewritesHostTransmitSID bool
}
DeviceCapabilities records behavior that varies by known Actisense model. Unknown future models are deliberately conservative until verified.
func CapabilitiesForModel ¶ added in v1.2.0
func CapabilitiesForModel(model ModelID) DeviceCapabilities
type DeviceError ¶
DeviceError reports a command that reached the gateway but was rejected.
func (*DeviceError) Error ¶
func (e *DeviceError) Error() string
type Diagnostic ¶
type Diagnostic struct {
Kind DiagnosticKind
Response BEMResponse
Startup *StartupStatus
ErrorReport *ErrorReport
System *SystemStatus
NegativeAck *NegativeAck
}
Diagnostic retains the common response origin alongside one typed payload.
func DecodeDiagnostic ¶
func DecodeDiagnostic(response BEMResponse) (diagnostic Diagnostic, ok bool, err error)
DecodeDiagnostic decodes F0/F1/F2/F4. ok is false for ordinary solicited responses.
type DiagnosticKind ¶
type DiagnosticKind string
DiagnosticKind identifies an unsolicited local BEM event.
const ( DiagnosticStartup DiagnosticKind = "startup_status" DiagnosticError DiagnosticKind = "error_report" DiagnosticSystem DiagnosticKind = "system_status" DiagnosticNegativeAck DiagnosticKind = "negative_ack" )
type ErrorReport ¶
type HardwareProtocol ¶ added in v1.2.0
type HardwareProtocol uint8
HardwareProtocol identifies the protocol carried over a gateway port.
const ( HardwareSerialNMEA0183 HardwareProtocol = 0 HardwareSerialBST HardwareProtocol = 1 HardwareCANNMEA2000 HardwareProtocol = 32 HardwareCANJ1939 HardwareProtocol = 33 HardwareEthernetBST HardwareProtocol = 64 HardwareEthernetNMEA0183 HardwareProtocol = 65 HardwareEthernetOneNet HardwareProtocol = 66 )
type IndividualBufferStatus ¶
type Message ¶
type Message struct {
Priority uint8
PGN uint32
Destination uint8
Source uint8
HasSource bool
Data []byte
Timestamp time.Duration
HasTimestamp bool
Direction Direction
Type MessageType
InternalSource bool
FastSequence uint8
}
Message is one assembled NMEA 2000 payload carried in BST-93, BST-94, or BST-D0. Data is always owned.
type MessageType ¶
type MessageType uint8
MessageType identifies the NMEA 2000 transfer form reported by BST-D0.
const ( MessageSingle MessageType = iota MessageFast MessageTransport MessageUnknown )
type ModelID ¶ added in v1.2.0
type ModelID uint16
ModelID is the Actisense hardware model identifier carried in every BEM response header.
type NegativeAck ¶
type NegativeAckError ¶
NegativeAckError reports an asynchronous F4 rejection correlated to an in-flight command.
func (*NegativeAckError) Error ¶
func (e *NegativeAckError) Error() string
type OperatingMode ¶
type OperatingMode uint16
OperatingMode is an Actisense gateway operating-mode wire value.
const ( ModeUndefined OperatingMode = 0 ModeTransferNormal OperatingMode = 1 ModeTransferReceiveAll OperatingMode = 2 ModeTransferLegacyRaw OperatingMode = 3 ModeConvertNormal OperatingMode = 4 ModeCANPacket OperatingMode = 5 ModeCANPacketASCII OperatingMode = 6 ModeBuffer1 OperatingMode = 16 ModeBuffer2 OperatingMode = 17 ModeBuffer3 OperatingMode = 18 ModeAutoswitchDirect OperatingMode = 19 ModeAutoswitchSmart OperatingMode = 20 ModeCombineSlow OperatingMode = 21 ModeCombineFast OperatingMode = 22 ModeTest1 OperatingMode = 23 ModeNSI1 OperatingMode = 24 ModeLastStandard OperatingMode = 253 ModeNormal OperatingMode = 512 ModePredefined1 OperatingMode = 40000 ModePredefined2 OperatingMode = 40001 ModePredefinedEnd OperatingMode = 40255 ModeUserStart OperatingMode = 50000 ModeUser1 OperatingMode = ModeUserStart ModeUser2 OperatingMode = 50001 ModeUser3 OperatingMode = 50002 ModeUser4 OperatingMode = 50003 ModeUser5 OperatingMode = 50004 ModeUserEnd OperatingMode = 59999 ModeNull OperatingMode = 65535 )
func DecodeOperatingMode ¶
func DecodeOperatingMode(response BEMResponse) (OperatingMode, error)
type PGNEnableFlag ¶ added in v1.2.0
type PGNEnableFlag uint8
const ( PGNDisabled PGNEnableFlag = 0 PGNEnabled PGNEnableFlag = 1 PGNRespondMode PGNEnableFlag = 2 )
type PGNListParameters ¶ added in v1.2.0
type PGNListParameters struct {
RxMaximum uint16
RxSession uint16
RxActive uint16
TxMaximum uint16
TxSession uint16
TxActive uint16
RxSync uint8
TxSync uint8
}
func DecodePGNListParameters ¶ added in v1.2.0
func DecodePGNListParameters(response BEMResponse) (PGNListParameters, error)
func (PGNListParameters) RxSynchronized ¶ added in v1.2.0
func (p PGNListParameters) RxSynchronized() bool
func (PGNListParameters) Synchronized ¶ added in v1.2.0
func (p PGNListParameters) Synchronized() bool
func (PGNListParameters) TxSynchronized ¶ added in v1.2.0
func (p PGNListParameters) TxSynchronized() bool
type PGNListSelector ¶ added in v1.2.0
type PGNListSelector uint8
PGNListSelector chooses the Rx list, Tx list, or both lists for delete and default operations.
const ( PGNListRx PGNListSelector = 0 PGNListTx PGNListSelector = 1 PGNListBoth PGNListSelector = 2 )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser incrementally decodes a BDTP byte stream. Its retained state is bounded by MaxDatagramLength plus one checksum byte.
func NewParser ¶
func NewParser() *Parser
NewParser returns a parser ready for one connection epoch.
func (*Parser) BufferedBytes ¶
BufferedBytes reports retained partial-frame bytes for diagnostics and bounded-state tests.
func (*Parser) End ¶
func (p *Parser) End(report func(DecodeError))
End reports and discards an incomplete candidate at an input boundary such as connection close or end-of-file.
func (*Parser) EndWithUnframed ¶ added in v1.2.0
func (p *Parser) EndWithUnframed(report func(DecodeError), unframed func([]byte))
EndWithUnframed is End with exact delivery of a pending unframed DLE.
func (*Parser) Feed ¶
func (p *Parser) Feed(buf []byte, emit func(Datagram), report func(DecodeError))
Feed consumes arbitrary stream chunks. Complete datagrams and recoverable errors are delivered synchronously in wire order.
func (*Parser) FeedWithUnframed ¶ added in v1.2.0
func (p *Parser) FeedWithUnframed(buf []byte, emit func(Datagram), report func(DecodeError), unframed func([]byte))
FeedWithUnframed additionally delivers exact bytes found outside BDTP frames. This supports boot-banner evidence and mode-6 binary/ASCII demux. The callback must not retain its one-byte slice.
func (*Parser) UnframedBytes ¶ added in v1.2.0
UnframedBytes reports how many bytes were discarded while hunting for a DLE/STX marker. It includes a pending DLE flushed by End.
type PortBaudrate ¶ added in v1.2.0
type PortBaudrate struct {
TotalPorts uint8
PortNumber uint8
Protocol HardwareProtocol
SessionBaud uint32
StoreBaud uint32
}
func DecodePortBaudrate ¶ added in v1.2.0
func DecodePortBaudrate(response BEMResponse) (PortBaudrate, error)
type PortDuplicateDelete ¶ added in v1.4.0
type PortDuplicateDelete uint8
const ( PortDuplicateDeleteOff PortDuplicateDelete = 0 PortDuplicateDeleteOn PortDuplicateDelete = 1 PortDuplicateDeleteNoChange PortDuplicateDelete = 255 )
type PortInventory ¶ added in v1.2.0
type PortInventory struct {
TransferID uint8
Ports []PortInventoryEntry
}
type PortInventoryEntry ¶ added in v1.2.0
type PortInventoryEntry struct {
PortIndex uint8
SystemStatusIndex uint8
BaudratePortNumber uint8
Media PortMedia
Protocol HardwareProtocol
Capabilities uint8
SessionBaud uint32
StoreBaud uint32
Name string
}
PortInventoryEntry maps the independent inventory, System Status, and Port Baudrate index spaces without guessing.
func (PortInventoryEntry) CanReceive ¶ added in v1.2.0
func (e PortInventoryEntry) CanReceive() bool
func (PortInventoryEntry) CanTransmit ¶ added in v1.2.0
func (e PortInventoryEntry) CanTransmit() bool
func (PortInventoryEntry) HasBaudrateControl ¶ added in v1.2.0
func (e PortInventoryEntry) HasBaudrateControl() bool
func (PortInventoryEntry) HasSessionOverride ¶ added in v1.2.0
func (e PortInventoryEntry) HasSessionOverride() bool
func (PortInventoryEntry) HasSystemStatus ¶ added in v1.2.0
func (e PortInventoryEntry) HasSystemStatus() bool
type PortMedia ¶ added in v1.2.0
type PortMedia uint8
PortMedia identifies the physical medium independently from its protocol.
const ( PortMediaCAN PortMedia = 0 PortMediaUART PortMedia = 1 PortMediaUSB PortMedia = 2 PortMediaBLE PortMedia = 3 PortMediaWiFi PortMedia = 4 PortMediaEthernet PortMedia = 5 PortMediaIPStream PortMedia = 6 PortMediaUnknown PortMedia = 0xFF PortIndexNone = uint8(0xFF) PortCanReceive = uint8(0x01) PortCanTransmit = uint8(0x02) )
type PortPCode ¶ added in v1.2.0
type PortPCode uint8
func DecodePortPCodes ¶ added in v1.2.0
func DecodePortPCodes(response BEMResponse) ([]PortPCode, error)
type ProductInfo ¶ added in v1.2.0
type ProductInfo struct {
StructureVariant uint32
NMEA2000Version uint16
ProductCode uint16
Model string
SoftwareVersion string
ModelVersion string
SerialCode string
Certification uint8
LoadEquivalency uint8
DeviceModelID ModelID
DeviceSerialNumber uint32
Legacy bool
}
ProductInfo is the complete BEM 0x41 response. Legacy devices send five replies; current devices send one Format-2 reply.
func DecodeProductInfo ¶ added in v1.2.0
func DecodeProductInfo(response BEMResponse) (ProductInfo, error)
type ProprietaryPGNList ¶ added in v1.2.0
type Requester ¶ added in v1.2.0
type Requester interface {
Request(context.Context, byte, []byte) (BEMResponse, error)
RequestMulti(context.Context, byte, []byte, time.Duration, func([]BEMResponse) (bool, error)) ([]BEMResponse, error)
}
Requester is the envelope-independent BEM request seam. Session implements it for local BST-A1/A0 traffic; the public package supplies a PGN-126720 implementation for remote devices.
type RxPGNEnableList ¶ added in v1.2.0
type RxPGNEnableList struct {
TransferID uint8
Entries []RxPGNListEntry
Proprietary ProprietaryPGNList
ProprietaryPresent bool
}
type RxPGNEnableListF1 ¶ added in v1.4.0
type RxPGNEnableListF1 struct {
PartsReceived int
Entries []RxPGNListF1Entry
}
PartsReceived identifies which fields of a partial F1 result are populated.
type RxPGNListEntry ¶ added in v1.2.0
type RxPGNListF1Entry ¶ added in v1.4.0
type RxPGNState ¶ added in v1.2.0
type RxPGNState struct {
PGN uint32
Flag PGNEnableFlag
Mask uint32
}
func DecodeRxPGNState ¶ added in v1.2.0
func DecodeRxPGNState(response BEMResponse) (RxPGNState, error)
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session serializes one Actisense connection epoch. It owns the sole wire writer and a bounded BEM correlation table with at most one request per response/BEM key.
func NewSession ¶
func NewSession(config SessionConfig) *Session
func (*Session) Close ¶
Close marks the session terminal and releases pending requests. The owner of the underlying transport remains responsible for closing it to unblock Run.
func (*Session) GetOperatingMode ¶
func (s *Session) GetOperatingMode(ctx context.Context) (OperatingMode, error)
func (*Session) Metrics ¶ added in v1.2.0
func (s *Session) Metrics() SessionMetrics
Metrics returns a concurrency-safe point-in-time snapshot.
func (*Session) Request ¶
Request sends one local BEM command and waits for its A0 response. The correlation key intentionally excludes the response sequence byte: gateway firmware uses the response BST group, BEM verb, and origin, and local A1/A0 sessions permit one in-flight request per verb.
func (*Session) RequestMulti ¶ added in v1.2.0
func (s *Session) RequestMulti(ctx context.Context, command byte, data []byte, inactivity time.Duration, complete func([]BEMResponse) (bool, error)) ([]BEMResponse, error)
RequestMulti sends one local BEM command and collects a bounded response train. complete is evaluated in wire order after every response and must return true for the final response. inactivity bounds the gap between responses; the caller context remains the overall deadline.
func (*Session) SetOperatingMode ¶
func (s *Session) SetOperatingMode(ctx context.Context, mode OperatingMode) error
type SessionConfig ¶
type SessionConfig struct {
// Write must stop physical I/O when ctx ends. A partial failed write must
// invalidate the connection so a later frame cannot append to its prefix.
Write func(context.Context, []byte) error
OnDatagram func(Datagram)
// OnResponse runs before correlation releases a caller. It must not block
// or issue requests through this session.
OnResponse func(BEMResponse)
OnDiagnostic func(Diagnostic)
OnDecodeError func(DecodeError)
OnWireBytes func(WireDirection, time.Time, []byte)
OnUnframed func([]byte)
}
type SessionMetrics ¶ added in v1.2.0
type SessionMetrics struct {
TransportReadCalls uint64
TransportReadBytes uint64
TransportReadErrors uint64
TransportWriteCalls uint64
TransportWriteBytes uint64
TransportWriteErrors uint64
Datagrams uint64
UnframedBytes uint64
FramingErrors uint64
ChecksumErrors uint64
LengthErrors uint64
OversizeErrors uint64
BSTFrames map[byte]uint64
BEMRequests uint64
BEMResponses uint64
BEMCompleted uint64
BEMCorrelationMisses uint64
BEMDuplicateRequests uint64
BEMTimeouts uint64
BEMDeviceErrors uint64
BEMNegativeAcks uint64
BEMResponseTrainOverflows uint64
BEMInFlight uint64
BEMMaxInFlight uint64
BEMLatencyMinimum time.Duration
BEMLatencyAverage time.Duration
BEMLatencyMaximum time.Duration
}
SessionMetrics is a point-in-time snapshot of one Actisense protocol session. BSTFrames is copied and safe for the caller to mutate.
type StartupStatus ¶
type SupportedPGN ¶ added in v1.2.0
type SupportedPGNList ¶ added in v1.2.0
type SupportedPGNList struct {
TransferID uint8
DatabaseVersion uint16
Entries []SupportedPGN
}
type SystemStatus ¶
type SystemStatus struct {
Individual []IndividualBufferStatus
Unified []UnifiedBufferStatus
CAN *CANStatus
OperatingMode *OperatingMode
}
type TxPGNEnableList ¶ added in v1.2.0
type TxPGNEnableList struct {
TransferID uint8
Entries []TxPGNListEntry
Proprietary ProprietaryPGNList
ProprietaryPresent bool
}
type TxPGNEnableListF1 ¶ added in v1.4.0
type TxPGNEnableListF1 struct {
PartsReceived int
Entries []TxPGNListF1Entry
}
type TxPGNListEntry ¶ added in v1.2.0
type TxPGNListF1Entry ¶ added in v1.4.0
type TxPGNState ¶
TxPGNState is the complete 14-byte Tx PGN enable response.
func DecodeTxPGNState ¶
func DecodeTxPGNState(response BEMResponse) (TxPGNState, error)
type UnifiedBufferStatus ¶
type WireDirection ¶ added in v1.2.0
type WireDirection uint8
const ( WireReceived WireDirection = iota WireTransmitted )