Documentation ¶
Index ¶
- Variables
- func MarshalRawMessage(v nmea.RawMessage) ([]byte, error)
- func UnmarshalString(raw string) (nmea.RawMessage, error)
- type BitEnum
- type BitEnumValue
- type CanboatSchema
- type Decoder
- type DecoderConfig
- type Device
- type Enum
- type EnumBitValue
- type EnumValue
- type Field
- type FieldType
- type IndirectEnum
- type IndirectEnumValue
- type LookupBitEnumerations
- type LookupEnumerations
- type LookupIndirectEnumerations
- type PGN
- type PGNs
- type PacketType
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownEnumType = errors.New("unknown enum type given") ErrUnknownEnumValue = errors.New("unknown enum value given") )
var (
ErrDecodeUnknownPGN = errors.New("decode failed, unknown PGN seen")
)
var (
ErrUnsupportedFieldType = errors.New("unsupported field type")
)
Functions ¶
func MarshalRawMessage ¶
func UnmarshalString ¶
Types ¶
type BitEnum ¶
type BitEnum struct { Name string `json:"Name"` Values []BitEnumValue `json:"EnumBitValues"` }
type BitEnumValue ¶
type CanboatSchema ¶
type CanboatSchema struct { Comment string `json:"Comment"` CreatorCode string `json:"CreatorCode"` License string `json:"License"` Version string `json:"Version"` PGNs PGNs `json:"PGNs"` Enums LookupEnumerations `json:"LookupEnumerations"` IndirectEnums LookupIndirectEnumerations `json:"LookupIndirectEnumerations"` BitEnums LookupBitEnumerations `json:"LookupBitEnumerations"` }
CanboatSchema is root element for Canboat Json schema
func LoadCANBoatSchema ¶
func LoadCANBoatSchema(filesystem fs.FS, path string) (CanboatSchema, error)
LoadCANBoatSchema loads CANBoat PGN schema from JSON file
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoder(schema CanboatSchema) *Decoder
NewDecoder creates new instance of Canboat PGN decoder
func NewDecoderWithConfig ¶
func NewDecoderWithConfig(schema CanboatSchema, config DecoderConfig) *Decoder
NewDecoderWithConfig creates new instance of Canboat PGN decoder with given config
type DecoderConfig ¶
type DecoderConfig struct { // DecodeReservedFields instructs Decoder to include reserved type fields in output DecodeReservedFields bool // DecodeSpareFields instructs Decoder to include spare type fields in output DecodeSpareFields bool // DecodeLookupsToEnumType instructs Decoder to convert lookup number to actual enum text+value pair DecodeLookupsToEnumType bool }
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
func NewCanBoatReader ¶
func (*Device) Initialize ¶
func (*Device) ReadRawMessage ¶
type EnumBitValue ¶
EnumBitValue is Enum type for Canbus schema.
func (*EnumBitValue) UnmarshalJSON ¶
func (bv *EnumBitValue) UnmarshalJSON(b []byte) error
UnmarshalJSON custom unmarshalling function for EnumBitValue.
type Field ¶
type Field struct { ID string `json:"Id"` Order int8 `json:"Order"` Name string `json:"Name"` Description string `json:"Description"` Condition string `json:"Condition"` Match int32 `json:"Match"` Unit string `json:"Unit"` Format string `json:"Format"` PhysicalQuantity string `json:"PhysicalQuantity"` BitLength uint16 `json:"BitLength"` BitOffset uint16 `json:"BitOffset"` BitLengthVariable bool `json:"BitLengthVariable"` Signed bool `json:"Signed"` Offset int32 `json:"Offset"` Resolution float64 `json:"Resolution"` // scale factor for parsed value. result = Offset + (parsedValue * Resolution) RangeMin float64 `json:"RangeMin"` RangeMax float64 `json:"RangeMax"` FieldType FieldType `json:"FieldType"` LookupEnumeration string `json:"LookupEnumeration"` LookupBitEnumeration string `json:"LookupBitEnumeration"` LookupIndirectEnumeration string `json:"LookupIndirectEnumeration"` LookupIndirectEnumerationFieldOrder int8 `json:"LookupIndirectEnumerationFieldOrder"` }
Field is (possibly) one of many values packed into PGN packet data
type FieldType ¶
type FieldType string
FieldType is type Canboat type field values
const ( // FieldTypeNumber - Binary numbers are little endian. Number fields that use two or three bits use one special // encoding, for the maximum value. When present, this means that the field is not present. Number fields that // use four bits or more use two special encodings. The maximum positive value means that the field is not present. // The maximum positive value minus 1 means that the field has an error. For instance, a broken sensor. // For signed numbers the maximum values are the maximum positive value and that minus 1, not the all-ones bit // encoding which is the maximum negative value. https://en.wikipedia.org/wiki/Binary_number FieldTypeNumber FieldType = "NUMBER" // FieldTypeFloat - 32 bit IEEE-754 floating point number. https://en.wikipedia.org/wiki/IEEE_754 FieldTypeFloat FieldType = "FLOAT" // FieldTypeDecimal - A unsigned numeric value represented with 2 decimal digits per. Each byte represent 2 digits, // so 1234 is represented by 2 bytes containing 0x12 and 0x34. A number with an odd number of digits will have 0 // as the first digit in the first byte. https://en.wikipedia.org/wiki/Binary-coded_decimal FieldTypeDecimal FieldType = "DECIMAL" // FieldTypeLookup - Number value where each value encodes for a distinct meaning. Each lookup has a // LookupEnumeration defining what the possible values mean FieldTypeLookup FieldType = "LOOKUP" // FieldTypeIndirectLookup - Number value where each value encodes for a distinct meaning but the meaning also // depends on the value in another field. Each lookup has a LookupIndirectEnumeration defining what the possible values mean. FieldTypeIndirectLookup FieldType = "INDIRECT_LOOKUP" // FieldTypeBitLookup - Number value where each bit value encodes for a distinct meaning. Each LookupBit has a // LookupBitEnumeration defining what the possible values mean. A bitfield can have any combination of bits set. FieldTypeBitLookup FieldType = "BITLOOKUP" // FieldTypeTime - time https://en.wikipedia.org/wiki/Time FieldTypeTime FieldType = "TIME" // FieldTypeDate - The date, in days since 1 January 1970. https://en.wikipedia.org/wiki/Calendar_date FieldTypeDate FieldType = "DATE" // FieldTypeStringFix - A fixed length string containing single byte codepoints. The length of the string is // determined by the PGN field definition. Trailing bytes have been observed as '@', ' ', 0x0 or 0xff. FieldTypeStringFix FieldType = "STRING_FIX" // FieldTypeStringLz - A varying length string containing single byte codepoints encoded with a length byte and // terminating zero. The length of the string is determined by a starting length byte. It also contains a // terminating zero byte. The length byte includes the zero byte but not itself. FieldTypeStringLz FieldType = "STRING_LZ" // FieldTypeStringLAU - A varying length string containing double or single byte codepoints encoded with a length // byte and terminating zero. The length of the string is determined by a starting length byte. The 2nd byte // contains 0 for UNICODE or 1 for ASCII. FieldTypeStringLAU FieldType = "STRING_LAU" // FieldTypeBinary - Unspecified content consisting of any number of bits. FieldTypeBinary FieldType = "BINARY" // FieldTypeReserved - Reserved field. All reserved bits shall be 1 FieldTypeReserved FieldType = "RESERVED" // FieldTypeSpare - Spare field. All spare bits shall be 0 FieldTypeSpare FieldType = "SPARE" // FieldTypeMMSI - The MMSI is encoded as a 32 bit number, but is always printed as a 9 digit number and // should be considered as a string. The first three or four digits are special, see the USCG link for a detailed // explanation. FieldTypeMMSI FieldType = "MMSI" // FieldTypeVariable - Variable. The definition of the field is that of the reference PGN and reference field, // this is totally variable. FieldTypeVariable FieldType = "VARIABLE" )
func (*FieldType) UnmarshalJSON ¶
UnmarshalJSON custom unmarshalling function for FieldType.
type IndirectEnum ¶
type IndirectEnum struct { Name string `json:"Name"` Values []IndirectEnumValue `json:"EnumValues"` }
type IndirectEnumValue ¶
type LookupBitEnumerations ¶
type LookupBitEnumerations []BitEnum
func (LookupBitEnumerations) Exists ¶
func (le LookupBitEnumerations) Exists(enum string) bool
func (LookupBitEnumerations) FindValue ¶
func (le LookupBitEnumerations) FindValue(enum string, value uint32) ([]BitEnumValue, error)
type LookupEnumerations ¶
type LookupEnumerations []Enum
func (LookupEnumerations) Exists ¶
func (le LookupEnumerations) Exists(enum string) bool
type LookupIndirectEnumerations ¶
type LookupIndirectEnumerations []IndirectEnum
func (LookupIndirectEnumerations) Exists ¶
func (le LookupIndirectEnumerations) Exists(enum string) bool
func (LookupIndirectEnumerations) FindValue ¶
func (le LookupIndirectEnumerations) FindValue(enum string, value uint32, indirectValue uint32) (IndirectEnumValue, error)
type PGN ¶
type PGN struct { // Note: PGN is not unique. Some PGNs have multiple different packets (field sets). pgn+first-field-value is sometimes unique PGN uint32 `json:"PGN"` ID string `json:"Id"` Description string `json:"Description"` Explanation string `json:"Explanation"` URL string `json:"URL"` Type PacketType `json:"Type"` // ISO, Fast, Single Complete bool `json:"Complete"` // false if Canboat schema is incomplete FieldCount int16 `json:"FieldCount"` MinLength int16 `json:"MinLength"` Length int16 `json:"Length"` MissingAttribute []string `json:"Missing"` // Fields, FieldLengths, Precision, Lookups, SampleData // RepeatingFields is number of fields that may or may not exist at the end of fields list. RepeatingFieldSet1Size int8 `json:"RepeatingFieldSet1Size"` RepeatingFieldSet1StartField int8 `json:"RepeatingFieldSet1StartField"` RepeatingFieldSet1CountField int8 `json:"RepeatingFieldSet1CountField"` RepeatingFieldSet2Size int8 `json:"RepeatingFieldSet2Size"` RepeatingFieldSet2StartField int8 `json:"RepeatingFieldSet2StartField"` RepeatingFieldSet2CountField int8 `json:"RepeatingFieldSet2CountField"` TransmissionInterval int16 `json:"TransmissionInterval"` TransmissionIrregular bool `json:"TransmissionIrregular"` Fields []Field `json:"Fields"` // IsMatchable denotes that PGNs contains Fields that are matchable. IsMatchable bool }
PGN is Parameter Group Number. A PGN identifies a message's function and how its data is structured.
func (*PGN) UnmarshalJSON ¶
UnmarshalJSON custom unmarshalling function for Field.
type PGNs ¶
type PGNs []PGN
PGNs is list of PNG instances
func (*PGNs) FastPacketPGNs ¶
func (*PGNs) FilterByPGN ¶
FilterByPGN returns list of matching PGN objects that match by PGN value
type PacketType ¶
type PacketType string
const ( PacketTypeISO PacketType = "ISO" // including multi-packet messages send with ISO 11783-3 Transport Protocol PacketTypeFast PacketType = "Fast" // can have up to 223 bytes of payload data PacketTypeSingle PacketType = "Single" )
func (*PacketType) UnmarshalJSON ¶
func (pt *PacketType) UnmarshalJSON(b []byte) error
UnmarshalJSON custom unmarshalling function for PacketType.