dbc

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dbc provides primitives for parsing, formatting and linting DBC files.

The implementation adheres to the "DBC File Format Documentation Version 01/2007" unless specified otherwise.

Index

Constants

View Source
const (
	// IndependentSignalsMessageName is the message name used by the special independent signals message.
	IndependentSignalsMessageName Identifier = "VECTOR__INDEPENDENT_SIG_MSG"
	// IndependentSignalsMessageName is the message ID used by the special independent signals message.
	IndependentSignalsMessageID MessageID = 0xc0000000
	// IndependentSignalsMessageSize is the size used by the special independent signals message.
	IndependentSignalsMessageSize = 0
)

Independent signals constants.

DBC files may contain a special message with the following message name and message ID.

This message will have size 0 and may contain duplicate signal names.

Variables

This section is empty.

Functions

func IsIndependentSignalsMessage

func IsIndependentSignalsMessage(m *MessageDef) bool

IsIndependentSignalsMessage returns true if m is the special independent signals message.

Types

type AccessType

type AccessType string

AccessType represents the access type of an environment variable.

const (
	AccessTypeUnrestricted AccessType = "DUMMY_NODE_VECTOR0"
	AccessTypeRead         AccessType = "DUMMY_NODE_VECTOR1"
	AccessTypeWrite        AccessType = "DUMMY_NODE_VECTOR2"
	AccessTypeReadWrite    AccessType = "DUMMY_NODE_VECTOR3"
)

func (AccessType) Validate

func (a AccessType) Validate() error

Validate returns an error for invalid access types.

type AttributeDef

type AttributeDef struct {
	Pos          scanner.Position
	ObjectType   ObjectType
	Name         Identifier
	Type         AttributeValueType
	MinimumInt   int64
	MaximumInt   int64
	MinimumFloat float64
	MaximumFloat float64
	EnumValues   []string
}

AttributeDef defines a user-defined attribute.

User-defined attributes are a means to extend the object properties of the DBC file.

These additional attributes have to be defined using an attribute definition with an attribute default value.

For each object having a value defined for the attribute, an attribute value entry has to be defined.

If no attribute value entry is defined for an object, the value of the object's attribute is the attribute's default.

func (*AttributeDef) Position

func (d *AttributeDef) Position() scanner.Position

Position returns the position of the definition.

type AttributeDefaultValueDef

type AttributeDefaultValueDef struct {
	Pos                scanner.Position
	AttributeName      Identifier
	DefaultIntValue    int64
	DefaultFloatValue  float64
	DefaultStringValue string
}

AttributeDefaultValueDef defines the default value for an attribute.

func (*AttributeDefaultValueDef) Position

Position returns the position of the definition.

type AttributeValueForObjectDef

type AttributeValueForObjectDef struct {
	Pos                     scanner.Position
	AttributeName           Identifier
	ObjectType              ObjectType
	MessageID               MessageID
	SignalName              Identifier
	NodeName                Identifier
	EnvironmentVariableName Identifier
	IntValue                int64
	FloatValue              float64
	StringValue             string
}

AttributeValueForObjectDef defines a value for an attribute and an object.

func (*AttributeValueForObjectDef) Position

Position returns the position of the definition.

type AttributeValueType

type AttributeValueType string

AttributeValueType represents an attribute value type.

const (
	AttributeValueTypeInt    AttributeValueType = "INT"
	AttributeValueTypeHex    AttributeValueType = "HEX"
	AttributeValueTypeFloat  AttributeValueType = "FLOAT"
	AttributeValueTypeString AttributeValueType = "STRING"
	AttributeValueTypeEnum   AttributeValueType = "ENUM"
)

func (AttributeValueType) Validate

func (a AttributeValueType) Validate() error

Validate returns an error for invalid attribute value types.

type BitTimingDef

type BitTimingDef struct {
	Pos      scanner.Position
	BaudRate uint64
	BTR1     uint64
	BTR2     uint64
}

BitTimingDef defines the baud rate and the settings of the BTR registers of a CAN network.

This definition is obsolete and not used anymore.

func (*BitTimingDef) Position

func (d *BitTimingDef) Position() scanner.Position

Position returns the position of the definition.

type CommentDef

type CommentDef struct {
	Pos                     scanner.Position
	ObjectType              ObjectType
	NodeName                Identifier
	MessageID               MessageID
	SignalName              Identifier
	EnvironmentVariableName Identifier
	Comment                 string
}

CommentDef defines a comment.

func (*CommentDef) Position

func (d *CommentDef) Position() scanner.Position

Position returns the position of the definition.

type Def

type Def interface {
	// Position of the definition.
	Position() scanner.Position
	// contains filtered or unexported methods
}

Def represents a single definition within a DBC file.

type EnvironmentVariableDataDef

type EnvironmentVariableDataDef struct {
	Pos scanner.Position
	// EnvironmentVariableName is the name of the environment variable.
	EnvironmentVariableName Identifier
	// DataSize is the size of the environment variable data in bytes.
	DataSize uint64
}

EnvironmentVariableDataDef defines an environment variable as being of type "data".

Environment variables of this type can store an arbitrary binary data of the given length. The length is given in bytes.

func (*EnvironmentVariableDataDef) Position

Position returns the position of the definition.

type EnvironmentVariableDef

type EnvironmentVariableDef struct {
	Pos          scanner.Position
	Name         Identifier
	Type         EnvironmentVariableType
	Minimum      float64
	Maximum      float64
	Unit         string
	InitialValue float64
	ID           uint64
	AccessType   AccessType
	AccessNodes  []Identifier
}

EnvironmentVariableDef defines an environment variable.

DBC files that describe the CAN communication and don't define any additional data for system or remaining bus simulations don't include environment variables.

func (*EnvironmentVariableDef) Position

func (d *EnvironmentVariableDef) Position() scanner.Position

Position returns the position of the definition.

type EnvironmentVariableType

type EnvironmentVariableType uint64

EnvironmentVariableType represents the type of an environment variable.

const (
	EnvironmentVariableTypeInteger EnvironmentVariableType = 0
	EnvironmentVariableTypeFloat   EnvironmentVariableType = 1
	EnvironmentVariableTypeString  EnvironmentVariableType = 2
)

func (EnvironmentVariableType) Validate

func (e EnvironmentVariableType) Validate() error

Validate returns an error for invalid environment variable types.

type Error

type Error interface {
	error

	// Position of the error in the DBC file.
	Position() scanner.Position

	// Reason for the error.
	Reason() string
}

Error represents an error in a DBC file.

type File

type File struct {
	// Name of the file.
	Name string
	// Data contains the raw file data.
	Data []byte
	// Defs in the file.
	Defs []Def
}

File is a parsed DBC source file.

type Identifier

type Identifier string

Identifier represents a DBC identifier.

const NodePlaceholder Identifier = "Vector__XXX"

NodePlaceholder is the placeholder node name used when no actual node is specified.

func (Identifier) Validate

func (id Identifier) Validate() (err error)

Validate returns an error for invalid DBC identifiers.

type Keyword

type Keyword string

Keyword represents a DBC keyword.

const (
	KeywordAttribute               Keyword = "BA_DEF_"
	KeywordAttributeDefault        Keyword = "BA_DEF_DEF_"
	KeywordAttributeValue          Keyword = "BA_"
	KeywordBitTiming               Keyword = "BS_"
	KeywordComment                 Keyword = "CM_"
	KeywordEnvironmentVariable     Keyword = "EV_"
	KeywordEnvironmentVariableData Keyword = "ENVVAR_DATA_"
	KeywordMessage                 Keyword = "BO_"
	KeywordMessageTransmitters     Keyword = "BO_TX_BU_"
	KeywordNewSymbols              Keyword = "NS_"
	KeywordNodes                   Keyword = "BU_"
	KeywordSignal                  Keyword = "SG_"
	KeywordSignalGroup             Keyword = "SIG_GROUP_"
	KeywordSignalType              Keyword = "SGTYPE_"
	KeywordSignalValueType         Keyword = "SIG_VALTYPE_"
	KeywordValueDescriptions       Keyword = "VAL_"
	KeywordValueTable              Keyword = "VAL_TABLE_"
	KeywordVersion                 Keyword = "VERSION"
)

type MessageDef

type MessageDef struct {
	// Pos is the position of the message definition.
	Pos scanner.Position

	// MessageID contains the message CAN ID.
	//
	// The CAN ID has to be unique within the DBC file.
	//
	// If the most significant bit of the message ID is set, the ID is an extended CAN ID. The extended CAN ID can be
	// determined by masking out the most significant bit with the mask 0xCFFFFFFF.
	MessageID MessageID

	// Name is the name of the message.
	//
	// The message name has to be unique within the DBC file.
	Name Identifier

	// Size specifies the size of the message in bytes.
	Size uint64

	// Transmitter specifies the name of the node transmitting the message.
	//
	// The transmitter has to be defined in the set of node names in the nodes definition.
	//
	// If the message has no transmitter, the string 'Vector__XXX' has to be given here.
	Transmitter Identifier

	// Signals specifies the signals of the message.
	Signals []SignalDef
}

MessageDef defines a frame in the network.

The definition includes the name of a frame as well as its properties and the signals transferred.

func (*MessageDef) Position

func (d *MessageDef) Position() scanner.Position

Position returns the position of the definition.

type MessageID

type MessageID uint32

MessageID represents a message ID.

func (MessageID) IsExtended

func (m MessageID) IsExtended() bool

IsExtended returns true if the message ID is an extended CAN ID.

func (MessageID) ToCAN

func (m MessageID) ToCAN() uint32

ToCAN returns the CAN id value of the message ID (i.e. with bit flags removed).

func (MessageID) Validate

func (m MessageID) Validate() error

Validate returns an error for invalid message IDs.

type MessageTransmittersDef

type MessageTransmittersDef struct {
	Pos          scanner.Position
	MessageID    MessageID
	Transmitters []Identifier
}

MessageTransmittersDef defines multiple transmitter nodes of a single message.

This definition is used to describe communication data for higher layer protocols.

This is not used to define CAN layer-2 communication.

func (*MessageTransmittersDef) Position

func (d *MessageTransmittersDef) Position() scanner.Position

Position returns the position of the definition.

type NewSymbolsDef

type NewSymbolsDef struct {
	Pos     scanner.Position
	Symbols []Keyword
}

NewSymbolsDef defines new symbol entries in a DBC file.

func (*NewSymbolsDef) Position

func (d *NewSymbolsDef) Position() scanner.Position

Position returns the position of the definition.

type NodesDef

type NodesDef struct {
	Pos       scanner.Position
	NodeNames []Identifier
}

NodesDef defines the names of all nodes participating in the network.

This definition is required in every DBC file.

All node names must be unique.

func (*NodesDef) Position

func (d *NodesDef) Position() scanner.Position

Position returns the position of the definition.

type ObjectType

type ObjectType string

ObjectType identifies the type of a DBC object.

const (
	ObjectTypeUnspecified         ObjectType = ""
	ObjectTypeNetworkNode         ObjectType = "BU_"
	ObjectTypeMessage             ObjectType = "BO_"
	ObjectTypeSignal              ObjectType = "SG_"
	ObjectTypeEnvironmentVariable ObjectType = "EV_"
)

func (ObjectType) Validate

func (o ObjectType) Validate() error

Validate returns an error for invalid object types.

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(filename string, data []byte) *Parser

func (*Parser) Defs

func (p *Parser) Defs() []Def

func (*Parser) File

func (p *Parser) File() *File

func (*Parser) Parse

func (p *Parser) Parse() (err Error)

type SignalDef

type SignalDef struct {
	// Pos is the position of the definition.
	Pos scanner.Position

	// Name of the signal.
	//
	// Has to be unique for all signals within the same message.
	Name Identifier

	// StartBit specifies the position of the signal within the data field of the frame.
	//
	// For signals with byte order Intel (little-endian) the position of the least-significant bit is given.
	//
	// For signals with byte order Motorola (big-endian) the position of the most significant bit is given.
	//
	// The bits are counted in a saw-tooth manner.
	//
	// The start bit has to be in the range of [0 ,8*message_size-1].
	StartBit uint64

	// Size specifies the size of the signal in bits.
	Size uint64

	// IsBigEndian is true if the signal's byte order is Motorola (big-endian).
	IsBigEndian bool

	// IsSigned is true if the signal is signed.
	IsSigned bool

	// IsMultiplexerSwitch is true if the signal is a multiplexer switch.
	//
	// A multiplexer indicator of 'M' defines the signal as the multiplexer switch.
	// Only one signal within a single message can be the multiplexer switch.
	IsMultiplexerSwitch bool

	// IsMultiplexed is true if the signal is multiplexed by the message's multiplexer switch.
	IsMultiplexed bool

	// MultiplexerSwitch is the multiplexer switch value of the signal.
	//
	// The multiplexed signal is transferred in the message if the switch value of the multiplexer signal is equal to
	// its multiplexer switch value.
	MultiplexerSwitch uint64

	// Offset is the signals physical value offset.
	//
	// Together with the factor, the offset defines the linear conversion rule to convert the signal's raw value into
	// the signal's physical value and vice versa.
	//
	//  physical_value = raw_value * factor + offset
	//  raw_value      = (physical_value - offset) / factor
	Offset float64

	// Factor is the signal's physical value factor.
	//
	// See: Offset.
	Factor float64

	// Minimum defines the signal's minimum physical value.
	Minimum float64

	// Maximum defines the signal's maximum physical value.
	Maximum float64

	// Unit defines the unit of the signal's physical value.
	Unit string

	// Receivers specifies the nodes receiving the signal.
	//
	// If the signal has no receiver, the string 'Vector__XXX' has to be given here.
	Receivers []Identifier
}

SignalDef defines a signal within a message.

func (*SignalDef) Position

func (d *SignalDef) Position() scanner.Position

Position returns the position of the definition.

type SignalValueType

type SignalValueType uint64

SignalValueType represents an extended signal value type.

const (
	SignalValueTypeInt     SignalValueType = 0
	SignalValueTypeFloat32 SignalValueType = 1
	SignalValueTypeFloat64 SignalValueType = 2
)

func (SignalValueType) Validate

func (s SignalValueType) Validate() error

Validate returns an error for invalid signal value types.

type SignalValueTypeDef

type SignalValueTypeDef struct {
	Pos             scanner.Position
	MessageID       MessageID
	SignalName      Identifier
	SignalValueType SignalValueType
}

SignalValueTypeDef defines an extended type definition for a signal.

func (*SignalValueTypeDef) Position

func (d *SignalValueTypeDef) Position() scanner.Position

Position returns the position of the definition.

type UnknownDef

type UnknownDef struct {
	Pos     scanner.Position
	Keyword Keyword
}

UnknownDef represents an unknown or unsupported DBC definition.

func (*UnknownDef) Position

func (d *UnknownDef) Position() scanner.Position

Position returns the position of the definition.

type ValueDescriptionDef

type ValueDescriptionDef struct {
	Pos         scanner.Position
	Value       float64
	Description string
}

ValueDescriptionDef defines a textual description for a single signal value.

The value may either be a signal raw value transferred on the bus or the value of an environment variable in a remaining bus simulation.

func (*ValueDescriptionDef) Position

func (d *ValueDescriptionDef) Position() scanner.Position

Position returns the position of the definition.

type ValueDescriptionsDef

type ValueDescriptionsDef struct {
	Pos                     scanner.Position
	ObjectType              ObjectType
	MessageID               MessageID
	SignalName              Identifier
	EnvironmentVariableName Identifier
	ValueDescriptions       []ValueDescriptionDef
}

ValueDescriptionsDef defines inline descriptions for specific raw signal values.

func (*ValueDescriptionsDef) Position

func (d *ValueDescriptionsDef) Position() scanner.Position

Position returns the position of the definition.

type ValueTableDef

type ValueTableDef struct {
	Pos               scanner.Position
	TableName         Identifier
	ValueDescriptions []ValueDescriptionDef
}

ValueTableDef defines a global value table.

The value descriptions in value tables define value encodings for signal raw values.

In commonly used DBC files, the global value tables aren't used, but the value descriptions are defined for each signal independently.

func (*ValueTableDef) Position

func (d *ValueTableDef) Position() scanner.Position

Position returns the position of the definition.

type VersionDef

type VersionDef struct {
	Pos     scanner.Position
	Version string
}

VersionDef defines the version of a DBC file.

func (*VersionDef) Position

func (d *VersionDef) Position() scanner.Position

Position returns the position of the definition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL