Documentation
¶
Index ¶
- Constants
- Variables
- func MarshalRawMessage(raw RawMessage) []byte
- type Assembler
- type CanBusHeader
- type EnumValue
- type FastPacketAssembler
- type FieldValue
- type FieldValues
- type Message
- type MessageDecoder
- type PGN
- type RawData
- func (d *RawData) AsHex() string
- func (d *RawData) DecodeBytes(bitOffset uint16, bitLength uint16, isVariableSize bool) ([]byte, uint16, error)
- func (d *RawData) DecodeDate(bitOffset uint16, bitLength uint16) (time.Time, error)
- func (d *RawData) DecodeDecimal(bitOffset uint16, bitLength uint16) (uint64, error)
- func (d *RawData) DecodeFloat(bitOffset uint16, bitLength uint16) (float64, error)
- func (d *RawData) DecodeStringFix(bitOffset uint16, bitLength uint16) (string, error)
- func (d *RawData) DecodeStringLAU(bitOffset uint16) (string, uint16, error)
- func (d *RawData) DecodeStringLZ(bitOffset uint16, bitLength uint16) (string, uint16, error)
- func (d *RawData) DecodeTime(bitOffset uint16, bitLength uint16, resolution float64) (time.Duration, error)
- func (d *RawData) DecodeVariableInt(bitOffset uint16, bitLength uint16) (int64, error)
- func (d *RawData) DecodeVariableUint(bitOffset uint16, bitLength uint16) (uint64, error)
- type RawFrame
- type RawMessage
- type RawMessageReader
- type RawMessageReaderWriter
- type RawMessageWriter
Constants ¶
const ( PGNISORequest = PGN(59904) // 0xEA00 PGNISOAddressClaim = PGN(60928) // 0xEE00 PGNProductInfo = PGN(126996) // 0x1F014 PGNConfigurationInformation = PGN(126998) // 0x1F016 PGNPGNList = PGN(126464) // 0x1EE00 // AddressGlobal is broadcast address used to send messages for all nodes on the n2k bus. AddressGlobal = uint8(255) // AddressNull is used for nodes that have not or can not claim address in bus. Used with "Cannot claim ISO address" response. AddressNull = uint8(254) )
const FastRawPacketMaxSize = 223
FastRawPacketMaxSize is maximum size of fast packet multiple packets total length
NMEA200 frame is 8 bytes and to send longer payloads `Fast packet` protocol could be used. In case of fast packet nmea message consist of multiple frames where: * first frame of message has 2 first bytes reserved and up to 6 following bytes for actual payload
- first byte (data[0]) identifies message counter (first 3 bits) and frame counter (5 bits) for that PGN. Message counter is to distinguish simultaneously sent message frames. Frame counter is always 0 for first frame.
- second byte (data[1]) indicates message total size in bytes
* second and consecutive frames reserve 1 byte for message counter and frame counter and up to 7 bytes for payload Fast packet maximum payload size 223 comes from the fact that first packet can have only 6 bytes of data and following frames 7 bytes. As frame counter is 5 bits (0-31 dec) we get maximum by 6 + 31 * 7 = 223 bytes.
const ISOTPDataMaxSize = 1785
Variables ¶
var ( // ErrValueNoData indicates that field has no data (for example 8bits uint8=>0xFF, int8=>0x7F) ErrValueNoData = errors.New("field value has no data") // ErrValueOutOfRange indicates that field value is out of valid range (for example 8bits uint8=>0xFE, int8=>0x7E) ErrValueOutOfRange = errors.New("field value out of range") // ErrValueReserved indicates that field is reserved (for example 8bits uint8=>0xFD, int8=>0x7D) ErrValueReserved = errors.New("field value is reserved") )
https://www.nmea.org/Assets/2000-explained-white-paper.pdf Page 14 Refers 3 special values "no data", "out of range" and "reserved" https://www.maretron.com/support/manuals/EMS100UM_1.1.html from `EMS100 Engine Monitoring System User's Manual` `Appendix A 'NMEA 2000' Interfacing` Quote "Note: For integer values, the most positive three values are reserved; e.g., for 8-bit unsigned integers, the values 0xFD, 0xFE, 0xFF are reserved, and for 8-bit signed integers, the values 0x7D, 0x7E, 0x7F are reserved. The most positive value (0xFF and 0x7F, respectively, for the 8-bit examples) represents Data Not Available."
Functions ¶
func MarshalRawMessage ¶
func MarshalRawMessage(raw RawMessage) []byte
Types ¶
type Assembler ¶
type Assembler interface {
Assemble(frame RawFrame, to *RawMessage) bool
}
type CanBusHeader ¶
type CanBusHeader struct { PGN uint32 `json:"pgn"` Priority uint8 `json:"priority"` Source uint8 `json:"source"` Destination uint8 `json:"destination"` }
func ParseCANID ¶
func ParseCANID(canID uint32) CanBusHeader
ParseCANID parses can bus header fields from CANID (29 bits of 32 bit).
func (CanBusHeader) Uint32 ¶
func (h CanBusHeader) Uint32() uint32
type FastPacketAssembler ¶
type FastPacketAssembler struct {
// contains filtered or unexported fields
}
func NewFastPacketAssembler ¶
func NewFastPacketAssembler(fpPGNs []uint32) *FastPacketAssembler
func (*FastPacketAssembler) Assemble ¶
func (a *FastPacketAssembler) Assemble(frame RawFrame, to *RawMessage) bool
type FieldValue ¶
type FieldValue struct { ID string `json:"id"` // normalized to: // * string, // * float64, // * int64, // * uint64, // * []byte, // * time.Duration, // * time.Time, // * nmea.EnumValue, // * [][]nmea.EnumValue <-- for repeating fieldsets/groups Value interface{} `json:"value"` }
FieldValue hold extracted and processed value for PGN field
func (FieldValue) AsFloat64 ¶
func (f FieldValue) AsFloat64() (float64, bool)
AsFloat64 converts value to float64 if it is possible.
type FieldValues ¶
type FieldValues []FieldValue
FieldValues is slice of FieldValue
func (FieldValues) FindByID ¶
func (fvs FieldValues) FindByID(ID string) (FieldValue, bool)
type Message ¶
type Message struct { // NodeNAME is unique identifier (ISO Address Claim) for Node in NMEA bus. // // Helps to identify which physical/logical device/node was author/source of that message. CanBusHeader.Source is // not reliable to identify who/what sent the message as source is "randomly" assigned/claimed with ISO address // claim process // // Value `0` means that Node NAME was unknown. For example AddressMapper may have not yet been able to process NAME // for that source. For small/fixed NMEA networks this is perfectly fine as you always know what was the actual source // for this Message (PGN). NodeNAME uint64 `json:"node_name"` Header CanBusHeader `json:"header"` Fields FieldValues `json:"fields"` }
Message is parsed value of PGN packet(s). Message could be assembled from multiple RawMessage instances.
type MessageDecoder ¶
type MessageDecoder interface {
Decode(raw RawMessage) (Message, error)
}
type RawData ¶
type RawData []byte
func (*RawData) DecodeBytes ¶
func (*RawData) DecodeDate ¶
func (*RawData) DecodeDecimal ¶
func (*RawData) DecodeFloat ¶
func (*RawData) DecodeStringFix ¶
func (*RawData) DecodeStringLAU ¶
func (*RawData) DecodeStringLZ ¶
func (*RawData) DecodeTime ¶
func (*RawData) DecodeVariableInt ¶
type RawFrame ¶
type RawFrame struct { // Time is when frame was read from NMEA bus. Filled by this library. Time time.Time Header CanBusHeader Length uint8 // 1-8 Data [8]byte }
type RawMessage ¶
type RawMessage struct { // Time is when message was read from NMEA bus. Filled by this library. Time time.Time Header CanBusHeader Data RawData // usually 8 bytes but fast-packets can be up to 223 bytes, assembled multi-packets (ISO-TP) up to 1785 bytes }
RawMessage is complete message that is created from single or multiple raw frames assembled together. RawMessage could be assembled from multiple nmea/canbus frames thus data length can vary up to 1785 bytes.
type RawMessageReader ¶
type RawMessageReaderWriter ¶
type RawMessageReaderWriter interface { RawMessageReader RawMessageWriter }
type RawMessageWriter ¶
type RawMessageWriter interface { WriteRawMessage(ctx context.Context, msg RawMessage) error Close() error }