acmelib

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

acmelib

Go Reference Go Report Card

A Golang package for modelling complex CAN networks.

The package documentation can be found here.

Getting started

Prerequisites

Golang 1.22

Installation

Run the following Go command to install the acmelib package:

go get -u github.com/FerroO2000/acmelib

TODOs

  • Adding examples
  • Adding JSON/Yaml and Protobuf parsing of the model
  • Improving test coverage

Documentation

Overview

Package acmelib contains structures and methods for creating complex CAN (Controlled Area Network) networks.

Index

Constants

This section is empty.

Variables

View Source
var ErrIntersect = errors.New("is intersecting")

ErrIntersect is returned when two entities are intersecting.

View Source
var ErrInvalidType = errors.New("invalid type")

ErrInvalidType is returned when an invalid type is used.

View Source
var ErrIsDuplicated = errors.New("is duplicated")

ErrIsDuplicated is returned when an entity is duplicated.

View Source
var ErrIsNegative = errors.New("is negative")

ErrIsNegative is returned when a value is negative.

View Source
var ErrIsNil = errors.New("is nil")

ErrIsNil is returned when a value or entity is nil.

View Source
var ErrIsZero = errors.New("is zero")

ErrIsZero is returned when a value is zero.

View Source
var ErrNoSpaceLeft = errors.New("not enough space left")

ErrNoSpaceLeft is returned when there is not enough space left.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when an entity is not found.

View Source
var ErrOutOfBounds = errors.New("out of bounds")

ErrOutOfBounds is returned when a value is out of bounds.

Functions

func ExportBus added in v0.5.0

func ExportBus(w io.Writer, bus *Bus)

ExportBus exports the given Bus to DBC. It writes the content of the result DBC file into the io.Writer.

func ExportNetwork added in v0.5.0

func ExportNetwork(network *Network, basePath string) error

ExportNetwork exports the given Network to DBC. It will create a directory with the given base path and network name. Into the directory, it will create a DBC file for each Bus of the network.

Types

type AddEntityError added in v0.5.0

type AddEntityError struct {
	EntityID EntityID
	Name     string
	Err      error
}

AddEntityError is returned when an entity cannot be added. The EntityID field is the ID of the entity and the Name field is the name, and the Err field is the cause.

func (*AddEntityError) Error added in v0.5.0

func (e *AddEntityError) Error() string

func (*AddEntityError) Unwrap added in v0.5.0

func (e *AddEntityError) Unwrap() error

type AppendSignalError added in v0.5.0

type AppendSignalError struct {
	EntityID EntityID
	Name     string
	Err      error
}

AppendSignalError is returned when a signal cannot be appended. The EntityID field is the ID of the signal, the Name field is the name, and the Err field is the cause.

func (*AppendSignalError) Error added in v0.5.0

func (e *AppendSignalError) Error() string

func (*AppendSignalError) Unwrap added in v0.5.0

func (e *AppendSignalError) Unwrap() error

type ArgumentError added in v0.5.0

type ArgumentError struct {
	Name string
	Err  error
}

ArgumentError is returned when an argument is invalid. The Name field is the name of the argument and the Err field is the cause.

func (*ArgumentError) Error added in v0.5.0

func (e *ArgumentError) Error() string

func (*ArgumentError) Unwrap added in v0.5.0

func (e *ArgumentError) Unwrap() error

type Attribute

type Attribute interface {
	// EntityID returns the entity id of an attribute.
	EntityID() EntityID
	// Name returns the name of an attribute.
	Name() string
	// Desc returns the description of an attribute.
	Desc() string
	// CreateTime returns the time of creation of an attribute.
	CreateTime() time.Time

	// Kind returns the kind of an attribute.
	Kind() AttributeKind

	// References returns a slice of references of an attribute.
	References() []*AttributeRef

	String() string

	// ToString converts the attribute to a string attribute.
	ToString() (*StringAttribute, error)
	// ToInteger converts the attribute to a integer attribute.
	ToInteger() (*IntegerAttribute, error)
	// ToFloat converts the attribute to a float attribute.
	ToFloat() (*FloatAttribute, error)
	// ToEnum converts the attribute to a enum attribute.
	ToEnum() (*EnumAttribute, error)
	// contains filtered or unexported methods
}

Attribute interface specifies all common methods of StringAttribute, IntegerAttribute, FloatAttribute, and EnumAttribute.

type AttributeKind

type AttributeKind string

AttributeKind defines the kind of an Attribute.

const (
	// AttributeKindString defines a string attribute.
	AttributeKindString AttributeKind = "attribute-string"
	// AttributeKindInteger defines an integer attribute.
	AttributeKindInteger AttributeKind = "attribute-integer"
	// AttributeKindFloat defines a float attribute.
	AttributeKindFloat AttributeKind = "attribute-float"
	// AttributeKindEnum defines an enum attribute.
	AttributeKindEnum AttributeKind = "attribute-enum"
)

type AttributeRef

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

AttributeRef connects an Attribute to an entity and the value the latter has associated to the former. It is useful to connect an attribute to the entities that are using it.

func (*AttributeRef) EntityID

func (af *AttributeRef) EntityID() EntityID

EntityID returns the entity id of the AttributeRef

func (*AttributeRef) Kind

func (af *AttributeRef) Kind() AttributeRefKind

Kind returns the kind of the AttributeRef

func (*AttributeRef) Value

func (af *AttributeRef) Value() any

Value returns the value of the AttributeRef

type AttributeRefKind

type AttributeRefKind string

AttributeRefKind defines the kind of an AttributeRef.

const (
	// AttributeRefKindBus defines a bus reference.
	AttributeRefKindBus AttributeRefKind = "attribute_ref-bus"
	// AttributeRefKindNode defines a node reference.
	AttributeRefKindNode AttributeRefKind = "attribute_ref-node"
	// AttributeRefKindMessage defines a message reference.
	AttributeRefKindMessage AttributeRefKind = "attribute_ref-message"
	// AttributeRefKindSignal defines a signal reference.
	AttributeRefKindSignal AttributeRefKind = "attribute_ref-signal"
)

type AttributeValue

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

AttributeValue connects a general Attribute to the value associated by an entity.

func (*AttributeValue) Attribute

func (av *AttributeValue) Attribute() Attribute

Attribute returns the Attribute of the AttributeValue.

func (*AttributeValue) Value

func (av *AttributeValue) Value() any

Value returns the value of the AttributeValue.

type Bus

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

Bus is the virtual representation of physical CAN bus cable. It holds a list of nodes that are connected to it.

func ImportDBCFile added in v0.5.0

func ImportDBCFile(filename string, r io.Reader) (*Bus, error)

ImportDBCFile imports a DBC file passed as io.Reader and converts it to a Bus. The given filename will be used as the name of the bus.

func NewBus

func NewBus(name string) *Bus

NewBus creates a new Bus with the given name and description.

func (Bus) AddAttributeValue

func (ae Bus) AddAttributeValue(attribute Attribute, value any) error

AddAttributeValue adds an Attribute to the entity and it assign the given value to it. It may return an error if the given value is not valid for the given Attribute.

func (*Bus) AddNode

func (b *Bus) AddNode(node *Node) error

AddNode adds the given Node to the Bus. It may return an error if the node name or the node id is already used by the bus.

func (Bus) AttributeValues

func (ae Bus) AttributeValues() []*AttributeValue

AttributeValues returns slice of all the attributes of the entity.

func (*Bus) Baudrate

func (b *Bus) Baudrate() uint

Baudrate returns the baudrate of the Bus.

func (Bus) GetAttributeValue

func (ae Bus) GetAttributeValue(attributeEntityID EntityID) (*AttributeValue, error)

GetAttributeValue returns the Attribute with the given entity id from the entity. It may return an error if the attribute with the given entity id does not exist in the entity.

func (*Bus) GetNodeByName added in v0.4.0

func (b *Bus) GetNodeByName(nodeName string) (*Node, error)

GetNodeByName returns the Node with the given name from the Bus. It may return an error if the node with the given name is not part of the bus.

func (*Bus) Nodes

func (b *Bus) Nodes() []*Node

Nodes returns a slice of all nodes in the Bus sorted by node id.

func (*Bus) ParentNetwork

func (b *Bus) ParentNetwork() *Network

ParentNetwork returns the Network that the Bus is part of. If the Bus is not part of a Network, it returns nil.

func (Bus) RemoveAllAttributeValues

func (ae Bus) RemoveAllAttributeValues()

RemoveAllAttributeValues removes all [Attributes] from the entity.

func (*Bus) RemoveAllNodes

func (b *Bus) RemoveAllNodes()

RemoveAllNodes removes all nodes from the Bus.

func (Bus) RemoveAttributeValue

func (ae Bus) RemoveAttributeValue(attributeEntityID EntityID) error

RemoveAttributeValue removes an Attribute with the given entity id from the entity. It also removes the reference to the entity from the attribute. It may return an error if the attribute with the given entity id does not exist in the entity.

func (*Bus) RemoveNode

func (b *Bus) RemoveNode(nodeEntityID EntityID) error

RemoveNode removes a Node that matches the given entity id from the Bus. It may return an error if the node with the given entity id is not part of the bus.

func (*Bus) SetBaudrate

func (b *Bus) SetBaudrate(baudrate uint)

SetBaudrate sets the baudrate of the Bus.

func (*Bus) String added in v0.2.0

func (b *Bus) String() string

func (*Bus) UpdateName

func (b *Bus) UpdateName(newName string) error

UpdateName updates the name of the Bus. It may return an error if the new name is already in use within a network.

type ConversionError added in v0.5.1

type ConversionError struct {
	From string
	To   string
}

ConversionError is returned when a signal cannot be converted.

func (*ConversionError) Error added in v0.5.1

func (e *ConversionError) Error() string

type EntityError added in v0.5.0

type EntityError struct {
	Kind     EntityKind
	EntityID EntityID
	Name     string
	Err      error
}

EntityError is returned when a method of an entity fails. The Kind field is the entity kind, the EntityID field is the ID, the Name field is the name, and the Err field is the cause.

func (*EntityError) Error added in v0.5.0

func (e *EntityError) Error() string

func (*EntityError) Unwrap added in v0.5.0

func (e *EntityError) Unwrap() error

type EntityID

type EntityID string

EntityID is the unique identifier of an entity. Entities are:

  • networks
  • buses
  • nodes
  • messages
  • signals
  • signal types
  • signal enums
  • signal enum values
  • signal units
  • attributes

func (EntityID) String

func (id EntityID) String() string

type EntityKind added in v0.5.0

type EntityKind string

EntityKind is the kind of an entity.

const (
	// EntityKindNetwork represents a [Network] entity.
	EntityKindNetwork EntityKind = "network"
	// EntityKindBus represents a [Bus] entity.
	EntityKindBus EntityKind = "bus"
	// EntityKindNode represents a [Node] entity.
	EntityKindNode EntityKind = "node"
	// EntityKindMessage represents a [Message] entity.
	EntityKindMessage EntityKind = "message"
	// EntityKindSignal represents a [Signal] entity.
	EntityKindSignal EntityKind = "signal"
	// EntityKindSignalType represents a [SignalType] entity.
	EntityKindSignalType EntityKind = "signal_type"
	// EntityKindSignalEnum represents a [SignalEnum] entity.
	EntityKindSignalEnum EntityKind = "signal_enum"
	// EntityKindSignalEnumValue represents a [SignalEnumValue] entity.
	EntityKindSignalEnumValue EntityKind = "signal_enum_value"
	// EntityKindSignalUnit represents a [SignalUnit] entity.
	EntityKindSignalUnit EntityKind = "signal_unit"
	// EntityKindAttribute represents a [Attribute] entity.
	EntityKindAttribute EntityKind = "attribute"
)

func (EntityKind) String added in v0.5.0

func (k EntityKind) String() string

type EnumAttribute

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

EnumAttribute is an Attribute that holds an enum as value.

func NewEnumAttribute

func NewEnumAttribute(name string, values ...string) (*EnumAttribute, error)

NewEnumAttribute creates a new EnumAttribute with the given name and values. The first value is always selected as the default one. It may return an error if no values are passed.

func (*EnumAttribute) DefValue

func (ea *EnumAttribute) DefValue() string

DefValue returns the default value of the EnumAttribute.

func (*EnumAttribute) GetValueAtIndex

func (ea *EnumAttribute) GetValueAtIndex(valueIndex int) (string, error)

GetValueAtIndex returns the value at the given index. The index refers to the order of the values in the factory method. It may return an error if the index is out of range.

func (EnumAttribute) Kind

func (a EnumAttribute) Kind() AttributeKind

func (EnumAttribute) References

func (a EnumAttribute) References() []*AttributeRef

func (*EnumAttribute) String added in v0.3.0

func (ea *EnumAttribute) String() string

func (*EnumAttribute) ToEnum

func (ea *EnumAttribute) ToEnum() (*EnumAttribute, error)

ToEnum returns the EnumAttribute itself.

func (*EnumAttribute) ToFloat

func (ea *EnumAttribute) ToFloat() (*FloatAttribute, error)

ToFloat always returns an error.

func (*EnumAttribute) ToInteger

func (ea *EnumAttribute) ToInteger() (*IntegerAttribute, error)

ToInteger always returns an error.

func (*EnumAttribute) ToString

func (ea *EnumAttribute) ToString() (*StringAttribute, error)

ToString always returns an error.

func (*EnumAttribute) Values

func (ea *EnumAttribute) Values() []string

Values returns the values of the EnumAttribute in the order specified in the factory method.

type EnumSignal

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

EnumSignal is a signal that holds a SignalEnum.

func NewEnumSignal

func NewEnumSignal(name string, enum *SignalEnum) (*EnumSignal, error)

NewEnumSignal creates a new EnumSignal with the given name and SignalEnum. It may return an error if the given SignalEnum is nil.

func (EnumSignal) ByteOrder added in v0.5.0

func (s EnumSignal) ByteOrder() SignalByteOrder

func (*EnumSignal) Enum

func (es *EnumSignal) Enum() *SignalEnum

Enum returns the SignalEnum of the EnumSignal.

func (*EnumSignal) GetSize

func (es *EnumSignal) GetSize() int

GetSize returns the size of the EnumSignal.

func (EnumSignal) GetStartBit

func (s EnumSignal) GetStartBit() int

func (EnumSignal) Kind

func (s EnumSignal) Kind() SignalKind

func (EnumSignal) ParentMessage added in v0.5.0

func (s EnumSignal) ParentMessage() *Message

func (EnumSignal) ParentMultiplexerSignal added in v0.5.0

func (s EnumSignal) ParentMultiplexerSignal() *MultiplexerSignal

func (EnumSignal) SendType added in v0.5.0

func (s EnumSignal) SendType() SignalSendType

func (EnumSignal) SetByteOrder added in v0.5.0

func (s EnumSignal) SetByteOrder(byteOrder SignalByteOrder)

func (*EnumSignal) SetEnum

func (es *EnumSignal) SetEnum(enum *SignalEnum) error

SetEnum sets the SignalEnum of the EnumSignal to the given one. It may return an error if the given SignalEnum is nil, or if the new enum size cannot fit in the message payload.

func (EnumSignal) SetSendType added in v0.5.0

func (s EnumSignal) SetSendType(sendType SignalSendType)

func (*EnumSignal) String

func (es *EnumSignal) String() string

func (*EnumSignal) ToEnum

func (es *EnumSignal) ToEnum() (*EnumSignal, error)

ToEnum returns the EnumSignal itself.

func (*EnumSignal) ToMultiplexer

func (es *EnumSignal) ToMultiplexer() (*MultiplexerSignal, error)

ToMultiplexer always returns an error, because an EnumSignal cannot be converted to a MultiplexerSignal.

func (*EnumSignal) ToStandard

func (es *EnumSignal) ToStandard() (*StandardSignal, error)

ToStandard always returns an error, because an EnumSignal cannot be converted to a StandardSignal.

func (EnumSignal) UpdateName

func (s EnumSignal) UpdateName(newName string) error

type ErrGreaterThen added in v0.5.0

type ErrGreaterThen struct {
	Target string
}

ErrGreaterThen is returned when a value is greater than a target. The Target field is the target.

func (*ErrGreaterThen) Error added in v0.5.0

func (e *ErrGreaterThen) Error() string

type ErrIsRequired added in v0.5.0

type ErrIsRequired struct {
	Thing string
}

ErrIsRequired is returned when something is required. The Thing field is what is required.

func (*ErrIsRequired) Error added in v0.5.0

func (e *ErrIsRequired) Error() string

type ErrLowerThen added in v0.5.0

type ErrLowerThen struct {
	Target string
}

ErrLowerThen is returned when a value is lower than a target. The Target field is the target.

func (*ErrLowerThen) Error added in v0.5.0

func (e *ErrLowerThen) Error() string

type FloatAttribute

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

FloatAttribute is an Attribute that holds a float value.

func NewFloatAttribute

func NewFloatAttribute(name string, defValue, min, max float64) (*FloatAttribute, error)

NewFloatAttribute creates a new FloatAttribute with the given name, default value, min, and max. It may return an error if the default value is out of the min/max range, or if the min value is greater then the max value.

func (*FloatAttribute) DefValue

func (fa *FloatAttribute) DefValue() float64

DefValue returns the default value of the FloatAttribute.

func (FloatAttribute) Kind

func (a FloatAttribute) Kind() AttributeKind

func (*FloatAttribute) Max

func (fa *FloatAttribute) Max() float64

Max returns the max value of the FloatAttribute.

func (*FloatAttribute) Min

func (fa *FloatAttribute) Min() float64

Min returns the min value of the FloatAttribute.

func (FloatAttribute) References

func (a FloatAttribute) References() []*AttributeRef

func (*FloatAttribute) String added in v0.3.0

func (fa *FloatAttribute) String() string

func (*FloatAttribute) ToEnum

func (fa *FloatAttribute) ToEnum() (*EnumAttribute, error)

ToEnum always returns an error.

func (*FloatAttribute) ToFloat

func (fa *FloatAttribute) ToFloat() (*FloatAttribute, error)

ToFloat returns the FloatAttribute itself.

func (*FloatAttribute) ToInteger

func (fa *FloatAttribute) ToInteger() (*IntegerAttribute, error)

ToInteger always returns an error.

func (*FloatAttribute) ToString

func (fa *FloatAttribute) ToString() (*StringAttribute, error)

ToString always returns an error.

type GetEntityError added in v0.5.0

type GetEntityError struct {
	EntityID EntityID
	Err      error
}

GetEntityError is returned when an entity cannot be retrieved. The EntityID field is the ID of the entity and the Err field is the cause.

func (*GetEntityError) Error added in v0.5.0

func (e *GetEntityError) Error() string

func (*GetEntityError) Unwrap added in v0.5.0

func (e *GetEntityError) Unwrap() error

type GroupIDError added in v0.5.0

type GroupIDError struct {
	GroupID int
	Err     error
}

GroupIDError is returned when a group ID is invalid. The GroupID field is the group ID and the Err field is the cause.

func (*GroupIDError) Error added in v0.5.0

func (e *GroupIDError) Error() string

func (*GroupIDError) Unwrap added in v0.5.0

func (e *GroupIDError) Unwrap() error

type InsertSignalError added in v0.5.0

type InsertSignalError struct {
	EntityID EntityID
	Name     string
	StartBit int
	Err      error
}

InsertSignalError is returned when a signal cannot be inserted. The EntityID field is the ID of the signal, the Name field is the name, the StartBit field is the start bit, and the Err field is the cause.

func (*InsertSignalError) Error added in v0.5.0

func (e *InsertSignalError) Error() string

func (*InsertSignalError) Unwrap added in v0.5.0

func (e *InsertSignalError) Unwrap() error

type IntegerAttribute

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

IntegerAttribute is an Attribute that holds an integer value.

func NewIntegerAttribute

func NewIntegerAttribute(name string, defValue, min, max int) (*IntegerAttribute, error)

NewIntegerAttribute creates a new IntegerAttribute with the given name, default value, min, and max. It may return an error if the default value is out of the min/max range, or if the min value is greater then the max value.

func (*IntegerAttribute) DefValue

func (ia *IntegerAttribute) DefValue() int

DefValue returns the default value of the IntegerAttribute.

func (*IntegerAttribute) IsHexFormat

func (ia *IntegerAttribute) IsHexFormat() bool

IsHexFormat reports whether the IntegerAttribute is in hex format.

func (IntegerAttribute) Kind

func (a IntegerAttribute) Kind() AttributeKind

func (*IntegerAttribute) Max

func (ia *IntegerAttribute) Max() int

Max returns the max value of the IntegerAttribute.

func (*IntegerAttribute) Min

func (ia *IntegerAttribute) Min() int

Min returns the min value of the IntegerAttribute.

func (IntegerAttribute) References

func (a IntegerAttribute) References() []*AttributeRef

func (*IntegerAttribute) SetFormatHex

func (ia *IntegerAttribute) SetFormatHex()

SetFormatHex sets the format of the IntegerAttribute to hex.

func (*IntegerAttribute) String added in v0.3.0

func (ia *IntegerAttribute) String() string

func (*IntegerAttribute) ToEnum

func (ia *IntegerAttribute) ToEnum() (*EnumAttribute, error)

ToEnum always returns an error.

func (*IntegerAttribute) ToFloat

func (ia *IntegerAttribute) ToFloat() (*FloatAttribute, error)

ToFloat always returns an error.

func (*IntegerAttribute) ToInteger

func (ia *IntegerAttribute) ToInteger() (*IntegerAttribute, error)

ToInteger returns the IntegerAttribute itself.

func (*IntegerAttribute) ToString

func (ia *IntegerAttribute) ToString() (*StringAttribute, error)

ToString always returns an error.

type Message

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

Message is the representation of data sent by a node thought the bus. It holds a list of signals that are contained in the message payload.

func NewMessage

func NewMessage(name string, sizeByte int) *Message

NewMessage creates a new Message with the given name and size in bytes. By default a MessagePriority of MessagePriorityVeryHigh is used.

func (Message) AddAttributeValue

func (ae Message) AddAttributeValue(attribute Attribute, value any) error

AddAttributeValue adds an Attribute to the entity and it assign the given value to it. It may return an error if the given value is not valid for the given Attribute.

func (*Message) AddReceiver

func (m *Message) AddReceiver(receiver *Node)

AddReceiver adds a receiver Node to the Message.

func (*Message) AppendSignal

func (m *Message) AppendSignal(signal Signal) error

AppendSignal appends a Signal to the last position of the Message payload. It may return an error if the signal name is already used within the message, or if the signal cannot fit in the available space left at the end of the message payload.

func (Message) AttributeValues

func (ae Message) AttributeValues() []*AttributeValue

AttributeValues returns slice of all the attributes of the entity.

func (*Message) CANID added in v0.5.0

func (m *Message) CANID() MessageCANID

CANID returns the message CAN id.

func (*Message) CompactSignals

func (m *Message) CompactSignals()

CompactSignals compacts the Message payload.

func (*Message) CycleTime

func (m *Message) CycleTime() int

CycleTime returns the message cycle time.

func (*Message) DelayTime added in v0.4.0

func (m *Message) DelayTime() int

DelayTime returns the message delay time.

func (Message) GetAttributeValue

func (ae Message) GetAttributeValue(attributeEntityID EntityID) (*AttributeValue, error)

GetAttributeValue returns the Attribute with the given entity id from the entity. It may return an error if the attribute with the given entity id does not exist in the entity.

func (*Message) GetSignal

func (m *Message) GetSignal(signalEntityID EntityID) (Signal, error)

GetSignal returns the Signal that matches the given entity id.

func (*Message) InsertSignal

func (m *Message) InsertSignal(signal Signal, startBit int) error

InsertSignal inserts a Signal at the given position of the Message payload. The start bit defines the index of the message payload where the signal will start. It may return an error if the signal name is already used within the message, or if the signal cannot fit in the available space left at the start bit.

func (*Message) Priority

func (m *Message) Priority() MessagePriority

Priority returns the message priority.

func (*Message) Receivers

func (m *Message) Receivers() []*Node

Receivers returns a slice of all receiver nodes of the Message.

func (Message) RemoveAllAttributeValues

func (ae Message) RemoveAllAttributeValues()

RemoveAllAttributeValues removes all [Attributes] from the entity.

func (*Message) RemoveAllSignals

func (m *Message) RemoveAllSignals()

RemoveAllSignals removes all signals from the Message.

func (Message) RemoveAttributeValue

func (ae Message) RemoveAttributeValue(attributeEntityID EntityID) error

RemoveAttributeValue removes an Attribute with the given entity id from the entity. It also removes the reference to the entity from the attribute. It may return an error if the attribute with the given entity id does not exist in the entity.

func (*Message) RemoveReceiver

func (m *Message) RemoveReceiver(receiverEntityID EntityID)

RemoveReceiver removes a receiver Node of the Message.

func (*Message) RemoveSignal

func (m *Message) RemoveSignal(signalEntityID EntityID) error

RemoveSignal removes a Signal that matches the given entity id from the Message. It may return an error if the signal with the given entity id is not part of the message payload.

func (*Message) SendType added in v0.4.0

func (m *Message) SendType() MessageSendType

SendType returns the message send type.

func (*Message) SenderNode added in v0.3.0

func (m *Message) SenderNode() *Node

SenderNode returns the Node that sends the Message. It returns nil if the message is not added to a node.

func (*Message) SetCANID added in v0.5.0

func (m *Message) SetCANID(messageCANID MessageCANID)

SetCANID sets the message CAN id. When the id is set in this way, the id generator function is not used anymore.

func (*Message) SetCANIDGeneratorFn added in v0.5.0

func (m *Message) SetCANIDGeneratorFn(canIDGeneratorFn MessageCANIDGeneratorFn)

SetCANIDGeneratorFn sets the message CAN id generator function.

func (*Message) SetCycleTime

func (m *Message) SetCycleTime(cycleTime int)

SetCycleTime sets the message cycle time.

func (*Message) SetDelayTime added in v0.4.0

func (m *Message) SetDelayTime(delayTime int)

SetDelayTime sets the delay time of the Message.

func (*Message) SetPriority

func (m *Message) SetPriority(priority MessagePriority)

SetPriority sets the message priority.

func (*Message) SetSendType added in v0.4.0

func (m *Message) SetSendType(sendType MessageSendType)

SetSendType sets the send type of the Message.

func (*Message) SetStartDelayTime added in v0.4.0

func (m *Message) SetStartDelayTime(startDelayTime int)

SetStartDelayTime sets the start delay time of the Message.

func (*Message) ShiftSignalLeft

func (m *Message) ShiftSignalLeft(signalEntityID EntityID, amount int) int

ShiftSignalLeft shifts the signal with the given entity id left by the given amount. It returns the amount of bits shifted.

func (*Message) ShiftSignalRight

func (m *Message) ShiftSignalRight(signalEntityID EntityID, amount int) int

ShiftSignalRight shifts the signal with the given entity id right by the given amount. It returns the amount of bits shifted.

func (*Message) SignalNames

func (m *Message) SignalNames() []string

SignalNames returns a slice of all signal names in the Message.

func (*Message) Signals

func (m *Message) Signals() []Signal

Signals returns a slice of all signals in the Message.

func (*Message) SizeByte

func (m *Message) SizeByte() int

SizeByte returns the size of the Message in bytes.

func (*Message) StartDelayTime added in v0.4.0

func (m *Message) StartDelayTime() int

StartDelayTime returns the message start delay time.

func (*Message) String

func (m *Message) String() string

func (*Message) UpdateName

func (m *Message) UpdateName(newName string) error

UpdateName updates the name of the Message. It may return an error if the new name is already used within a node.

type MessageCANID added in v0.5.0

type MessageCANID uint32

MessageCANID is the bus unique identifier of a Message. By default 11 bits ids are used.

func (MessageCANID) String added in v0.5.0

func (id MessageCANID) String() string

type MessageCANIDGeneratorFn added in v0.5.0

type MessageCANIDGeneratorFn func(priority MessagePriority, messageID int, nodeID NodeID) (messageCANID MessageCANID)

MessageCANIDGeneratorFn is callback used for generating automatically the MessageCANID of a Message. It is triggered when a Message is added to a Node or when the former is removed. It takes as prameters the priority of the message, the number of messages sended by the node, and the node id, then it returns the computed message id. By default the messages calculate their 11 bit ids by putting the node id in the 4 lsb, the message id (the nth message sent by the node) from bit 4 to 9, and the priority in the 2 msb.

type MessageIDError added in v0.5.0

type MessageIDError struct {
	MessageID MessageCANID
	Err       error
}

MessageIDError is returned when a MessageCANID is invalid. The MessageID field is the message ID and the Err field is the cause.

func (*MessageIDError) Error added in v0.5.0

func (e *MessageIDError) Error() string

func (*MessageIDError) Unwrap added in v0.5.0

func (e *MessageIDError) Unwrap() error

type MessagePriority

type MessagePriority uint

MessagePriority rappresents the priority of a Message. The priorities are very high, high, medium, and low. The higher priority has the value 0 and the lower has 3.

const (
	// MessagePriorityVeryHigh defines a very high priority.
	MessagePriorityVeryHigh MessagePriority = iota
	// MessagePriorityHigh defines an high priority.
	MessagePriorityHigh
	// MessagePriorityMedium defines a medium priority.
	MessagePriorityMedium
	// MessagePriorityLow defines a low priority.
	MessagePriorityLow
)

type MessageSendType added in v0.4.0

type MessageSendType string

MessageSendType rappresents the transition type of a Message.

const (
	// MessageSendTypeUnset defines an unset transmission type.
	MessageSendTypeUnset MessageSendType = "NoMsgSendType"
	// MessageSendTypeCyclic defines a cyclic transmission type.
	MessageSendTypeCyclic MessageSendType = "Cyclic"
	// MessageSendTypeCyclicIfActive defines a cyclic if active transmission type.
	MessageSendTypeCyclicIfActive MessageSendType = "CyclicIfActive"
	// MessageSendTypeCyclicAndTriggered defines a cyclic and triggered transmission type.
	MessageSendTypeCyclicAndTriggered MessageSendType = "CyclicAndTriggered"
	// MessageSendTypeCyclicIfActiveAndTriggered defines a cyclic if active and triggered transmission type.
	MessageSendTypeCyclicIfActiveAndTriggered MessageSendType = "CyclicIfActiveAndTriggered"
)

type MultiplexerSignal

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

MultiplexerSignal is a signal that holds groups of other signals that are selected/multiplexed by the value of the group id. It can multiplex all the kinds of signals (StandardSignal, EnumSignal, MultiplexerSignal), so it is possible to create multiple levels of multiplexing.

func NewMultiplexerSignal

func NewMultiplexerSignal(name string, groupCount, groupSize int) (*MultiplexerSignal, error)

NewMultiplexerSignal creates a new MultiplexerSignal with the given name, group count and group size. The group count defines the number of groups that the signal will hold and the group size defines the dimension in bits of each group.

It will return an ArgumentError if group count or group size is invalid.

func (MultiplexerSignal) ByteOrder added in v0.5.0

func (s MultiplexerSignal) ByteOrder() SignalByteOrder

func (*MultiplexerSignal) ClearAllSignalGroups added in v0.5.0

func (ms *MultiplexerSignal) ClearAllSignalGroups()

ClearAllSignalGroups removes all signals from all groups.

func (*MultiplexerSignal) ClearSignalGroup added in v0.5.0

func (ms *MultiplexerSignal) ClearSignalGroup(groupID int) error

ClearSignalGroup removes all signals from a group with the given group ID.

It will return a GroupIDError if the given group ID is invalid.

func (*MultiplexerSignal) GetGroupCountSize added in v0.5.0

func (ms *MultiplexerSignal) GetGroupCountSize() int

GetGroupCountSize returns the number of bits needed to select the right group.

func (*MultiplexerSignal) GetSignalGroup added in v0.5.0

func (ms *MultiplexerSignal) GetSignalGroup(groupID int) []Signal

GetSignalGroup returns a slice of signals present in the group selected by the given group ID. The signals are sorted by their start bit.

func (*MultiplexerSignal) GetSignalGroups added in v0.5.0

func (ms *MultiplexerSignal) GetSignalGroups() [][]Signal

GetSignalGroups returns a slice of groups sorted by their group ID. Each group contains a slice of signals sorted by their start bit.

func (*MultiplexerSignal) GetSize

func (ms *MultiplexerSignal) GetSize() int

GetSize returns the total size of the MultiplexerSignal. The returned value is the sum of the size of the groups and the number of bits needed to select the right group. e.g. with group count = 8 and group size = 16, the total size will be 3 + 16 = 19 bits, since 8 groups can be selected by 3 bits.

func (MultiplexerSignal) GetStartBit

func (s MultiplexerSignal) GetStartBit() int

func (*MultiplexerSignal) GroupCount added in v0.5.0

func (ms *MultiplexerSignal) GroupCount() int

GroupCount returns the number of groups.

func (*MultiplexerSignal) GroupSize added in v0.5.0

func (ms *MultiplexerSignal) GroupSize() int

GroupSize returns the size of a group.

func (*MultiplexerSignal) InsertSignal added in v0.5.0

func (ms *MultiplexerSignal) InsertSignal(signal Signal, startBit int, groupIDs ...int) error

InsertSignal inserts a Signal at the given start bit. If no group IDs are given, the signal will be considered as fixed and it will be inserted into all groups. If group IDs are given, the signal will be inserted into the given groups.

It will return an InsertSignalError if the signal cannot be inserted at the given start bit into the given group. This error can wrap:

func (MultiplexerSignal) Kind

func (s MultiplexerSignal) Kind() SignalKind

func (MultiplexerSignal) ParentMessage added in v0.5.0

func (s MultiplexerSignal) ParentMessage() *Message

func (MultiplexerSignal) ParentMultiplexerSignal added in v0.5.0

func (s MultiplexerSignal) ParentMultiplexerSignal() *MultiplexerSignal

func (*MultiplexerSignal) RemoveSignal added in v0.5.0

func (ms *MultiplexerSignal) RemoveSignal(signalEntityID EntityID) error

RemoveSignal removes the Signal with the given entity ID.

It will return an RemoveEntityError if the signal cannot be removed.

func (MultiplexerSignal) SendType added in v0.5.0

func (s MultiplexerSignal) SendType() SignalSendType

func (MultiplexerSignal) SetByteOrder added in v0.5.0

func (s MultiplexerSignal) SetByteOrder(byteOrder SignalByteOrder)

func (MultiplexerSignal) SetSendType added in v0.5.0

func (s MultiplexerSignal) SetSendType(sendType SignalSendType)

func (*MultiplexerSignal) ShiftSignalLeft added in v0.5.0

func (ms *MultiplexerSignal) ShiftSignalLeft(signalEntityID EntityID, amount int) int

ShiftSignalLeft shifts the Signal with the given entity ID left by the given amount and it returns the number of bits shifted. It will not shift signals that are fixed or assigned to more then one group.

func (*MultiplexerSignal) ShiftSignalRight added in v0.5.0

func (ms *MultiplexerSignal) ShiftSignalRight(signalEntityID EntityID, amount int) int

ShiftSignalRight shifts the Signal with the given entity ID right by the given amount and it returns the number of bits shifted. It will not shift signals that are fixed or assigned to more then one group.

func (*MultiplexerSignal) String

func (ms *MultiplexerSignal) String() string

func (*MultiplexerSignal) ToEnum

func (ms *MultiplexerSignal) ToEnum() (*EnumSignal, error)

ToEnum always returns a ConversionError, since MultiplexerSignal cannot be converted to EnumSignal.

func (*MultiplexerSignal) ToMultiplexer

func (ms *MultiplexerSignal) ToMultiplexer() (*MultiplexerSignal, error)

ToMultiplexer always returns the MultiplexerSignal itself.

func (*MultiplexerSignal) ToStandard

func (ms *MultiplexerSignal) ToStandard() (*StandardSignal, error)

ToStandard always returns a ConversionError, since MultiplexerSignal cannot be converted to StandardSignal.

func (MultiplexerSignal) UpdateName

func (s MultiplexerSignal) UpdateName(newName string) error

type NameError added in v0.5.0

type NameError struct {
	Name string
	Err  error
}

NameError is returned when a name is invalid. The Name field is the name and the Err field is the cause.

func (*NameError) Error added in v0.5.0

func (e *NameError) Error() string

func (*NameError) Unwrap added in v0.5.0

func (e *NameError) Unwrap() error

type Network

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

Network is the highest level entity in the package. Its main purpose is to hold all buses belonging to the same network. For example, a car can be seen as a network with multiple buses that are serving different areas or ECUs in the vehicle.

func NewNetwork

func NewNetwork(name string) *Network

NewNetwork returns a new Network with the given name.

func (*Network) AddBus

func (n *Network) AddBus(bus *Bus) error

AddBus adds a Bus to the Network. It may return an error if the bus name is already taken.

func (*Network) Buses

func (n *Network) Buses() []*Bus

Buses returns a slice of all [Bus]es in the Network sorted by name.

func (Network) CreateTime

func (e Network) CreateTime() time.Time

CreateTime returns the time when the entity was created.

func (Network) Desc

func (e Network) Desc() string

Desc returns the description of the entity.

func (Network) EntityID

func (e Network) EntityID() EntityID

EntityID returns the unique identifier of the entity.

func (Network) Name

func (e Network) Name() string

Name returns the name of the entity.

func (*Network) RemoveAllBuses

func (n *Network) RemoveAllBuses()

RemoveAllBuses removes all [Bus]es from the Network.

func (*Network) RemoveBus

func (n *Network) RemoveBus(busEntityID EntityID) error

RemoveBus removes a Bus that matches the given entity id from the Network. It may return an error if the bus with the given entity id is not part of the network.

func (Network) SetDesc added in v0.3.0

func (e Network) SetDesc(desc string)

SetDesc sets the description of the entity.

func (*Network) String added in v0.2.0

func (n *Network) String() string

func (*Network) UpdateName

func (n *Network) UpdateName(newName string)

UpdateName updates the name of the Network.

type Node

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

Node is the representation of an ECU. It holds a list of messages which are sent to other nodes thought the bus. A node can be assigned to more then 1 bus.

func NewNode

func NewNode(name string, id NodeID) *Node

NewNode creates a new Node with the given name and id. The id must be unique among all nodes within a bus.

func (Node) AddAttributeValue

func (ae Node) AddAttributeValue(attribute Attribute, value any) error

AddAttributeValue adds an Attribute to the entity and it assign the given value to it. It may return an error if the given value is not valid for the given Attribute.

func (*Node) AddMessage

func (n *Node) AddMessage(message *Message) error

AddMessage adds a Message to the Node. This means that the given message will be sent by the node. It may return an error if the message name or the message id is already used by the node.

func (Node) AttributeValues

func (ae Node) AttributeValues() []*AttributeValue

AttributeValues returns slice of all the attributes of the entity.

func (Node) GetAttributeValue

func (ae Node) GetAttributeValue(attributeEntityID EntityID) (*AttributeValue, error)

GetAttributeValue returns the Attribute with the given entity id from the entity. It may return an error if the attribute with the given entity id does not exist in the entity.

func (*Node) ID

func (n *Node) ID() NodeID

ID returns the node id.

func (*Node) Messages

func (n *Node) Messages() []*Message

Messages returns a slice of messages that the Node sends sorted by message id.

func (*Node) ParentBuses

func (n *Node) ParentBuses() []*Bus

ParentBuses returns a slice of [Bus]es that the Node is part of.

func (Node) RemoveAllAttributeValues

func (ae Node) RemoveAllAttributeValues()

RemoveAllAttributeValues removes all [Attributes] from the entity.

func (*Node) RemoveAllMessages

func (n *Node) RemoveAllMessages()

RemoveAllMessages removes all messages from the Node.

func (Node) RemoveAttributeValue

func (ae Node) RemoveAttributeValue(attributeEntityID EntityID) error

RemoveAttributeValue removes an Attribute with the given entity id from the entity. It also removes the reference to the entity from the attribute. It may return an error if the attribute with the given entity id does not exist in the entity.

func (*Node) RemoveMessage

func (n *Node) RemoveMessage(messageEntityID EntityID) error

RemoveMessage removes a Message that matches the given entity id from the Node. It may return an error if the message with the given entity id is not sent by the node.

func (*Node) String added in v0.2.0

func (n *Node) String() string

func (*Node) UpdateName

func (n *Node) UpdateName(newName string) error

UpdateName updates the name of the Node. It may return an error if the new name is already in use within a bus.

type NodeID

type NodeID uint32

NodeID is a unique identifier for a node. It must be manually assigned by the user.

func (NodeID) String added in v0.2.0

func (nid NodeID) String() string

type NodeIDError added in v0.5.0

type NodeIDError struct {
	NodeID NodeID
	Err    error
}

NodeIDError is returned when a NodeID is invalid. The NodeID field is the node ID and the Err field is the cause.

func (*NodeIDError) Error added in v0.5.0

func (e *NodeIDError) Error() string

func (*NodeIDError) Unwrap added in v0.5.0

func (e *NodeIDError) Unwrap() error

type RemoveEntityError added in v0.5.0

type RemoveEntityError struct {
	EntityID EntityID
	Err      error
}

RemoveEntityError is returned when an entity cannot be removed. The EntityID field is the ID of the entity and the Err field is the cause.

func (*RemoveEntityError) Error added in v0.5.0

func (e *RemoveEntityError) Error() string

func (*RemoveEntityError) Unwrap added in v0.5.0

func (e *RemoveEntityError) Unwrap() error

type Signal

type Signal interface {
	// EntityID returns the entity id of the signal.
	EntityID() EntityID
	// Name returns the name of the signal.
	Name() string
	// SetDesc stes the description of the signal.
	SetDesc(desc string)
	// Desc returns the description of the signal.
	Desc() string
	// CreateTime returns the creation time of the signal.
	CreateTime() time.Time

	// AddAttributeValue adds to the signal an attribute and its value.
	AddAttributeValue(attribute Attribute, value any) error
	// RemoveAttributeValue removes from the signal an attribute and its value.
	RemoveAttributeValue(attributeEntityID EntityID) error
	// RemoveAllAttributeValues removes all attribute and their values from the signal.
	RemoveAllAttributeValues()
	// AttributeValues returns all attribute and their values from the signal.
	AttributeValues() []*AttributeValue
	// GetAttributeValue returns the value of an attribute and its value from the signal.
	GetAttributeValue(attributeEntityID EntityID) (*AttributeValue, error)

	String() string

	// Kind returns the kind of the signal.
	Kind() SignalKind

	// ParentMessage returns the parent message of the signal or nil if not set.
	ParentMessage() *Message
	// ParentMultiplexerSignal returns the parent multiplexer signal of the signal
	// or nil if not set.
	ParentMultiplexerSignal() *MultiplexerSignal

	// SetByteOrder sets the byte order of the signal.
	// By default it is set to little endian.
	SetByteOrder(byteOrder SignalByteOrder)
	// ByteOrder returns the byte order of the signal.
	ByteOrder() SignalByteOrder

	// SetSendType sets the send type of the signal.
	SetSendType(sendType SignalSendType)
	// SendType returns the send type of the signal.
	SendType() SignalSendType

	// GetStartBit returns the start bit of the signal.
	GetStartBit() int

	// GetSize returns the size of the signal.
	GetSize() int

	// ToStandard returns the signal as a standard signal.
	ToStandard() (*StandardSignal, error)
	// ToEnum returns the signal as a enum signal.
	ToEnum() (*EnumSignal, error)
	// ToMultiplexer returns the signal as a multiplexer signal.
	ToMultiplexer() (*MultiplexerSignal, error)
	// contains filtered or unexported methods
}

Signal interface specifies all common methods of StandardSignal, EnumSignal, and [MultiplexerSignal1].

type SignalByteOrder added in v0.5.0

type SignalByteOrder string

SignalByteOrder represents the byte order of a Signal.

const (
	// SignalByteOrderLittleEndian defines a little endian byte order.
	SignalByteOrderLittleEndian SignalByteOrder = "signal_byte_order-little_endian"
	// SignalByteOrderBigEndian defines a big endian byte order.
	SignalByteOrderBigEndian SignalByteOrder = "signal_byte_order-big_endian"
)

type SignalEnum

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

SignalEnum is the representation of an enum that can be assigned to a signal.

func NewSignalEnum

func NewSignalEnum(name string) *SignalEnum

NewSignalEnum creates a new SignalEnum with the given name.

func (*SignalEnum) AddValue

func (se *SignalEnum) AddValue(value *SignalEnumValue) error

AddValue adds the given SignalEnumValue to the SignalEnum. It may return an error if the value name is already in use within the signal enum, or if it has an invalid index.

func (SignalEnum) CreateTime

func (e SignalEnum) CreateTime() time.Time

CreateTime returns the time when the entity was created.

func (SignalEnum) Desc

func (e SignalEnum) Desc() string

Desc returns the description of the entity.

func (SignalEnum) EntityID

func (e SignalEnum) EntityID() EntityID

EntityID returns the unique identifier of the entity.

func (*SignalEnum) GetSize

func (se *SignalEnum) GetSize() int

GetSize returns the size of the SignalEnum in bits.

func (*SignalEnum) MaxIndex

func (se *SignalEnum) MaxIndex() int

MaxIndex returns the highest index of the enum values of the SignalEnum.

func (*SignalEnum) MinSize added in v0.3.0

func (se *SignalEnum) MinSize() int

MinSize return the minimum size of the SignalEnum in bits.

func (SignalEnum) Name

func (e SignalEnum) Name() string

Name returns the name of the entity.

func (*SignalEnum) RemoveAllValues

func (se *SignalEnum) RemoveAllValues()

RemoveAllValues removes all enum values from the SignalEnum.

func (*SignalEnum) RemoveValue

func (se *SignalEnum) RemoveValue(valueEntityID EntityID) error

RemoveValue removes the SignalEnumValue with the given entity id from the SignalEnum. It may return an error if the value with the given entity id is not found.

func (SignalEnum) SetDesc added in v0.3.0

func (e SignalEnum) SetDesc(desc string)

SetDesc sets the description of the entity.

func (*SignalEnum) SetMinSize added in v0.3.0

func (se *SignalEnum) SetMinSize(minSize int)

SetMinSize sets the minimum size in bit of the SignalEnum. By defaul it is set to 1.

func (*SignalEnum) String added in v0.2.0

func (se *SignalEnum) String() string

func (*SignalEnum) UpdateName

func (se *SignalEnum) UpdateName(newName string)

UpdateName updates the name of the SignalEnum to the given new one.

func (*SignalEnum) Values added in v0.2.0

func (se *SignalEnum) Values() []*SignalEnumValue

Values returns a slice of all the enum values of the SignalEnum.

type SignalEnumValue

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

SignalEnumValue holds the key (name) and the value (index) of a signal enum entry.

func NewSignalEnumValue

func NewSignalEnumValue(name string, index int) *SignalEnumValue

NewSignalEnumValue creates a new SignalEnumValue with the given name and index.

func (SignalEnumValue) CreateTime

func (e SignalEnumValue) CreateTime() time.Time

CreateTime returns the time when the entity was created.

func (SignalEnumValue) Desc

func (e SignalEnumValue) Desc() string

Desc returns the description of the entity.

func (SignalEnumValue) EntityID

func (e SignalEnumValue) EntityID() EntityID

EntityID returns the unique identifier of the entity.

func (*SignalEnumValue) Index

func (sev *SignalEnumValue) Index() int

Index returns the index of the SignalEnumValue.

func (SignalEnumValue) Name

func (e SignalEnumValue) Name() string

Name returns the name of the entity.

func (*SignalEnumValue) ParentEnum

func (sev *SignalEnumValue) ParentEnum() *SignalEnum

ParentEnum returns the parent SignalEnum of the SignalEnumValue, or nil if not set.

func (SignalEnumValue) SetDesc added in v0.3.0

func (e SignalEnumValue) SetDesc(desc string)

SetDesc sets the description of the entity.

func (*SignalEnumValue) String added in v0.2.0

func (sev *SignalEnumValue) String() string

func (*SignalEnumValue) UpdateIndex

func (sev *SignalEnumValue) UpdateIndex(newIndex int) error

UpdateIndex updates the index of the SignalEnumValue to the given new one. It may return an error if the new index is invalid.

func (*SignalEnumValue) UpdateName

func (sev *SignalEnumValue) UpdateName(newName string) error

UpdateName updates the name of the SignalEnumValue to the given new one. It may return an error if the new name is already in use within the parent enum.

type SignalKind

type SignalKind string

SignalKind rappresents the kind of a Signal. It can be standard, enum, or multiplexer

const (
	// SignalKindStandard defines a standard signal.
	SignalKindStandard SignalKind = "signal-standard"
	// SignalKindEnum defines a enum signal.
	SignalKindEnum SignalKind = "signal-enum"
	// SignalKindMultiplexer defines a multiplexer signal.
	SignalKindMultiplexer SignalKind = "signal-multiplexer"
)

type SignalSendType added in v0.5.0

type SignalSendType string

SignalSendType rappresents the send type of a Signal.

const (
	// SignalSendTypeUnset defines an unset transmission type.
	SignalSendTypeUnset SignalSendType = "NoSigSendType"
	// SignalSendTypeCyclic defines a cyclic transmission type.
	SignalSendTypeCyclic SignalSendType = "Cyclic"
	// SignalSendTypeOnWrite defines an on write transmission type.
	SignalSendTypeOnWrite SignalSendType = "OnWrite"
	// SignalSendTypeOnWriteWithRepetition defines an on write with repetition transmission type.
	SignalSendTypeOnWriteWithRepetition SignalSendType = "OnWriteWithRepetition"
	// SignalSendTypeOnChange defines an on change transmission type.
	SignalSendTypeOnChange SignalSendType = "OnChange"
	// SignalSendTypeOnChangeWithRepetition defines an on change with repetition transmission type.
	SignalSendTypeOnChangeWithRepetition SignalSendType = "OnChangeWithRepetition"
	// SignalSendTypeIfActive defines an if active transmission type.
	SignalSendTypeIfActive SignalSendType = "IfActive"
	// SignalSendTypeIfActiveWithRepetition defines an if active with repetition transmission type.
	SignalSendTypeIfActiveWithRepetition SignalSendType = "IfActiveWithRepetition"
)

type SignalSizeError added in v0.5.0

type SignalSizeError struct {
	Size int
	Err  error
}

SignalSizeError is returned when a signal size is invalid. The Size field is the size and the Err field is the cause.

func (*SignalSizeError) Error added in v0.5.0

func (e *SignalSizeError) Error() string

func (*SignalSizeError) Unwrap added in v0.5.0

func (e *SignalSizeError) Unwrap() error

type SignalType

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

SignalType is the representation of a signal type.

func NewCustomSignalType

func NewCustomSignalType(name string, size int, signed bool, min, max float64) (*SignalType, error)

NewCustomSignalType creates a new SignalType of kind SignalTypeKindCustom with the given name, size, signed, order, and min/max values. It may return an error if the size is negative.

func NewFlagSignalType

func NewFlagSignalType(name string) *SignalType

NewFlagSignalType creates a new SignalType of kind SignalTypeKindFlag with the given name. The order is set to little endian.

func NewFloatSignalType

func NewFloatSignalType(name string, size int) (*SignalType, error)

NewFloatSignalType creates a new SignalType of kind SignalTypeKindFloat with the given name and size. The order is set to little endian. It may return an error if the size is negative.

func NewIntegerSignalType

func NewIntegerSignalType(name string, size int, signed bool) (*SignalType, error)

NewIntegerSignalType creates a new SignalType of kind SignalTypeKindInteger with the given name, size, and signed. The order is set to little endian. It may return an error if the size is negative.

func (SignalType) CreateTime

func (e SignalType) CreateTime() time.Time

CreateTime returns the time when the entity was created.

func (SignalType) Desc

func (e SignalType) Desc() string

Desc returns the description of the entity.

func (SignalType) EntityID

func (e SignalType) EntityID() EntityID

EntityID returns the unique identifier of the entity.

func (*SignalType) Kind

func (st *SignalType) Kind() SignalTypeKind

Kind returns the kind of the SignalType.

func (*SignalType) Max

func (st *SignalType) Max() float64

Max returns the maximum value of the SignalType.

func (*SignalType) Min

func (st *SignalType) Min() float64

Min returns the minimum value of the SignalType.

func (SignalType) Name

func (e SignalType) Name() string

Name returns the name of the entity.

func (SignalType) SetDesc added in v0.3.0

func (e SignalType) SetDesc(desc string)

SetDesc sets the description of the entity.

func (*SignalType) Signed

func (st *SignalType) Signed() bool

Signed returns whether the SignalType is signed.

func (*SignalType) Size

func (st *SignalType) Size() int

Size returns the size of the SignalType.

func (*SignalType) String added in v0.2.0

func (st *SignalType) String() string

type SignalTypeKind

type SignalTypeKind string

SignalTypeKind represents the kind of a SignalType.

const (
	// SignalTypeKindCustom defines a signal of type custom.
	SignalTypeKindCustom SignalTypeKind = "signal_type-custom"
	// SignalTypeKindFlag defines a signal of type flag (1 bit).
	SignalTypeKindFlag SignalTypeKind = "signal_type-flag"
	// SignalTypeKindInteger defines a signal of type integer.
	SignalTypeKindInteger SignalTypeKind = "signal_type-integer"
	// SignalTypeKindFloat defines a signal of type float.
	SignalTypeKindFloat SignalTypeKind = "signal_type-float"
)

type SignalUnit

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

SignalUnit is an entity that defines the physical unit of a Signal.

func NewSignalUnit

func NewSignalUnit(name string, kind SignalUnitKind, symbol string) *SignalUnit

NewSignalUnit creates a new SignalUnit with the given name, kind, and symbol.

func (SignalUnit) CreateTime

func (e SignalUnit) CreateTime() time.Time

CreateTime returns the time when the entity was created.

func (SignalUnit) Desc

func (e SignalUnit) Desc() string

Desc returns the description of the entity.

func (SignalUnit) EntityID

func (e SignalUnit) EntityID() EntityID

EntityID returns the unique identifier of the entity.

func (*SignalUnit) Kind

func (su *SignalUnit) Kind() SignalUnitKind

Kind returns the kind of the SignalUnit.

func (SignalUnit) Name

func (e SignalUnit) Name() string

Name returns the name of the entity.

func (SignalUnit) SetDesc added in v0.3.0

func (e SignalUnit) SetDesc(desc string)

SetDesc sets the description of the entity.

func (*SignalUnit) String added in v0.2.0

func (su *SignalUnit) String() string

func (*SignalUnit) Symbol

func (su *SignalUnit) Symbol() string

Symbol returns the symbol of the SignalUnit.

type SignalUnitKind

type SignalUnitKind string

SignalUnitKind defines the kind of a SignalUnit.

const (
	// SignalUnitKindCustom defines a custom unit.
	SignalUnitKindCustom SignalUnitKind = "signal_unit-custom"
	// SignalUnitKindTemperature defines a temperature unit.
	SignalUnitKindTemperature SignalUnitKind = "signal_unit-temperature"
	// SignalUnitKindElectrical defines an electrical unit.
	SignalUnitKindElectrical SignalUnitKind = "signal_unit-electrical"
	// SignalUnitKindPower defines a power unit.
	SignalUnitKindPower SignalUnitKind = "signal_unit-power"
)

type StandardSignal

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

StandardSignal is the representation of a normal signal that has a SignalType, a min, a max, an offset, a scale, and can have a SignalUnit.

func NewStandardSignal

func NewStandardSignal(name string, typ *SignalType) (*StandardSignal, error)

NewStandardSignal creates a new StandardSignal with the given name and SignalType. It may return an error if the given SignalType is nil.

func (StandardSignal) ByteOrder added in v0.5.0

func (s StandardSignal) ByteOrder() SignalByteOrder

func (*StandardSignal) GetSize

func (ss *StandardSignal) GetSize() int

GetSize returns the size of the StandardSignal.

func (StandardSignal) GetStartBit

func (s StandardSignal) GetStartBit() int

func (StandardSignal) Kind

func (s StandardSignal) Kind() SignalKind

func (*StandardSignal) Max

func (ss *StandardSignal) Max() float64

Max returns the maximum value of the StandardSignal. It may differ from the maximum value of the signal type associated with the StandardSignal.

func (*StandardSignal) Min

func (ss *StandardSignal) Min() float64

Min returns the minimum value of the StandardSignal. It may differ from the minimum value of the signal type associated with the StandardSignal.

func (*StandardSignal) Offset

func (ss *StandardSignal) Offset() float64

Offset returns the offset of the StandardSignal.

func (StandardSignal) ParentMessage added in v0.5.0

func (s StandardSignal) ParentMessage() *Message

func (StandardSignal) ParentMultiplexerSignal added in v0.5.0

func (s StandardSignal) ParentMultiplexerSignal() *MultiplexerSignal

func (*StandardSignal) Scale

func (ss *StandardSignal) Scale() float64

Scale returns the scale of the StandardSignal.

func (StandardSignal) SendType added in v0.5.0

func (s StandardSignal) SendType() SignalSendType

func (StandardSignal) SetByteOrder added in v0.5.0

func (s StandardSignal) SetByteOrder(byteOrder SignalByteOrder)

func (*StandardSignal) SetPhysicalValues added in v0.3.0

func (ss *StandardSignal) SetPhysicalValues(min, max, offset, scale float64) error

SetPhysicalValues sets the physical min, max, offset, and scale of the StandardSignal. It returns an error if the scale is equal to 0.

func (StandardSignal) SetSendType added in v0.5.0

func (s StandardSignal) SetSendType(sendType SignalSendType)

func (*StandardSignal) SetType

func (ss *StandardSignal) SetType(typ *SignalType) error

SetType sets the SignalType of the StandardSignal. It resets the physical values. It may return an error if the given SignalType is nil, or if the new signal type size cannot fit in the message payload.

func (*StandardSignal) SetUnit

func (ss *StandardSignal) SetUnit(unit *SignalUnit)

SetUnit sets the SignalUnit of the StandardSignal to the given one.

func (*StandardSignal) String

func (ss *StandardSignal) String() string

func (*StandardSignal) ToEnum

func (ss *StandardSignal) ToEnum() (*EnumSignal, error)

ToEnum always returns an error, because a StandardSignal cannot be converted to an EnumSignal.

func (*StandardSignal) ToMultiplexer

func (ss *StandardSignal) ToMultiplexer() (*MultiplexerSignal, error)

ToMultiplexer always returns an error, because a [StandardSigna] cannot be converted to a MultiplexerSignal.

func (*StandardSignal) ToStandard

func (ss *StandardSignal) ToStandard() (*StandardSignal, error)

ToStandard returns the StandardSignal itself.

func (*StandardSignal) Type

func (ss *StandardSignal) Type() *SignalType

Type returns the SignalType of the StandardSignal.

func (*StandardSignal) Unit

func (ss *StandardSignal) Unit() *SignalUnit

Unit returns the SignalUnit of the StandardSignal.

func (StandardSignal) UpdateName

func (s StandardSignal) UpdateName(newName string) error

type StartBitError added in v0.5.0

type StartBitError struct {
	StartBit int
	Err      error
}

StartBitError is returned when a start bit is invalid. The StartBit field is the start bit and the Err field is the cause.

func (*StartBitError) Error added in v0.5.0

func (e *StartBitError) Error() string

func (*StartBitError) Unwrap added in v0.5.0

func (e *StartBitError) Unwrap() error

type StringAttribute

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

StringAttribute is an Attribute that holds a string value.

func NewStringAttribute

func NewStringAttribute(name, defValue string) *StringAttribute

NewStringAttribute creates a new StringAttribute with the given name, and default value.

func (*StringAttribute) DefValue

func (sa *StringAttribute) DefValue() string

DefValue returns the default value of the StringAttribute.

func (StringAttribute) Kind

func (a StringAttribute) Kind() AttributeKind

func (StringAttribute) References

func (a StringAttribute) References() []*AttributeRef

func (*StringAttribute) String added in v0.3.0

func (sa *StringAttribute) String() string

func (*StringAttribute) ToEnum

func (sa *StringAttribute) ToEnum() (*EnumAttribute, error)

ToEnum always returns an error.

func (*StringAttribute) ToFloat

func (sa *StringAttribute) ToFloat() (*FloatAttribute, error)

ToFloat always returns an error.

func (*StringAttribute) ToInteger

func (sa *StringAttribute) ToInteger() (*IntegerAttribute, error)

ToInteger always returns an error.

func (*StringAttribute) ToString

func (sa *StringAttribute) ToString() (*StringAttribute, error)

ToString returns the StringAttribute itself.

type UpdateIndexError added in v0.5.0

type UpdateIndexError struct {
	Err error
}

UpdateIndexError is returned when an index cannot be updated. The Err field is the cause.

func (*UpdateIndexError) Error added in v0.5.0

func (e *UpdateIndexError) Error() string

func (*UpdateIndexError) Unwrap added in v0.5.0

func (e *UpdateIndexError) Unwrap() error

type UpdateNameError added in v0.5.0

type UpdateNameError struct {
	Err error
}

UpdateNameError is returned when a name cannot be updated.

func (*UpdateNameError) Error added in v0.5.0

func (e *UpdateNameError) Error() string

func (*UpdateNameError) Unwrap added in v0.5.0

func (e *UpdateNameError) Unwrap() error

type ValueIndexError added in v0.5.0

type ValueIndexError struct {
	Index int
	Err   error
}

ValueIndexError is returned when a value index is invalid. The Index field is the index and the Err field is the cause.

func (*ValueIndexError) Error added in v0.5.0

func (e *ValueIndexError) Error() string

func (*ValueIndexError) Unwrap added in v0.5.0

func (e *ValueIndexError) Unwrap() error

Directories

Path Synopsis
Package dbc provides a [parser] and a [writer] for DBC files.
Package dbc provides a [parser] and a [writer] for DBC files.
examples
dm1

Jump to

Keyboard shortcuts

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