Documentation
¶
Index ¶
- Variables
- func FormatBitrate(b uint32) string
- func RegisterDriver(drv Driver)
- func VerifyDataLenFD(n int) (next int, needsFD bool, err error)
- type BitTimingConfig
- type Config
- type DataBufPool
- type DataBuffer
- type Device
- type DeviceInfo
- type Driver
- type Env
- type Error
- type Flags
- type Msg
- type MsgFilter
- type Option
- type Optional
- type PlainData
- type Time
- type Unversioned
Constants ¶
This section is empty.
Variables ¶
var ErrFDNotSupported = Error("FD mode not supported")
var ErrInvalidMsgLen = errors.New("invalid message length")
var ErrMsgCapExceeded = errors.New("message capacity too small")
var ErrTxQueueFull = Error("tx queue full")
ErrTxQueueFull is returned when a Msg could not be added to the devices' transmit queue. On Linux, it is returned in case of ENOBUFS. Normally this error is caused by a wiring problem, or if no CAN node is present on the bus.
var ValidFDSizes = []int{12, 16, 20, 24, 36, 48, 64}
Functions ¶
func FormatBitrate ¶ added in v0.3.0
func RegisterDriver ¶
func RegisterDriver(drv Driver)
Types ¶
type BitTimingConfig ¶ added in v0.3.0
type BitTimingConfig struct {
Bitrate uint32
SamplePoint timing.SamplePoint
timing.BitTiming
Tq time.Duration
}
func (*BitTimingConfig) Resolve ¶ added in v0.3.0
func (btc *BitTimingConfig) Resolve(dest *BitTimingConfig, clock uint32, cstr *timing.Constraints) error
Resolve interprets a BitTimingConfig.
If a bitrate and (optionally) a sample point are specified, it calculates a timing.BitTiming, taking fOsc and dev into account.
If, instead, the BitTiming field is provided, it validates and, if necessary, fills in the Tq or Prescaler fields.
The result is stored into dest if dest is non-nil; otherwise, the receiver btc is modified in-place.
func (*BitTimingConfig) String ¶ added in v0.3.0
func (c *BitTimingConfig) String() string
type Config ¶ added in v0.3.0
type Config struct {
Nominal BitTimingConfig
Data Optional[BitTimingConfig]
Termination Optional[bool]
FDMode Optional[bool]
MsgFilter []MsgFilter
}
func ParseConfig ¶ added in v0.3.0
ParseConfSpecs parses CAN adapter configuration specifications. The strings may contain space separated parameter settings.
The syntax of configuration strings has been designed with Plan 9's _ctl_ file commands in mind (see https://plan9.io/magic/man2html/3/uart for an example). The basic structure is:
key ":" value
The colon may be omitted; in this case, the start of the value will be the position of the first decimal digit.
A value may be a plain integer, a bool or a more complex string.
Boolean values are represented by integer values 1 and 0, which map to true and false. In case of true, the value may be omitted -- the key used alone stands for the value being "true".
If a parameter is omitted altogether, the default settings of adapters will be used, if not otherwise specified.
Defined parameters:
b - nominal bit timing, optionally with a sample point, and SJW A value can be a bit timing expression: bit-timing-expr = ( bitrate | bittiming ) [[ ":" ] sjw] bitrate = number [ "k" | "M" ] [ "@" sample-point ] bittiming = ( "*" tq | "/" prescaler ) ":" seg-expr seg-expr = prop-seg "-" ps1 "-" ps2 sjw = "s" [ number | "." fraction ] sample-point = "." fraction Examples: 500k@.875, b1M@.75 refering to 500 kbit/s or 1 Mbit/s, with sample points at 87.5% resp. 75%. In case of nominal bitrates, as an exception, the "b" key may be omitted. So, stating "500k" will be recognized as b:500k. db - data bit timing, optionally with a sample point, and SJW A data bit timing value is a bit timing expr. See the definition of "b" (nominal bit timing) for details. fd - CAN FD mode A boolean parameter deciding whether the CAN adapter should be run in CAN 2.0 mode or FD mode. f - CAN message filter A value has the form: id ":" mask, where id and mask either consist of three characters (standard frame) or up to eight characters (extended frame), as in: f:123:7ff or f:123_4567:1fff_ffff A short form can be used where only the id is specified and ":" mask part is omitted. Within the id part, "-" may be used for a nibble that may contain any value from 0 to 0xF, as in: f:67- This would enable the receipt of messages with standard frame CAN IDs from 0x670 to 0x67F. Multiple filters may be specified. The effect of a filter may be inverted by using a prefix "!" in front of the id part, like in "f!12-" (the example would avoid the reception of standard frames in the range 120 to 12F). T - enable/disable termination resistor This is a boolean parameter.
func (*Config) ResolveBitTiming ¶ added in v0.3.0
func (conf *Config) ResolveBitTiming(ctl *timing.Controller) error
ResolveBittiming calls Resolve on the nominal and, if requested and supported, the data BitTimingConfig fields, updating the Config in-place. The function returns any error received from any of the Resolve calls.
func (*Config) ResolveFDMode ¶ added in v0.3.0
ResolveFDMode determines whether a Config requests FD mode, factoring in the hardware's FD capability. It does not modify the Config.
FD mode is requested if either the FDMode option is enabled or data bit timing is specified. If the request is "soft" (FDMode.Soft or Data.Soft is true) and fdCapable is false, the function returns isFD==false without an error. If the request is strict and fdCapable is false, it returns ErrFDNotSupported.
type DataBufPool ¶ added in v0.3.0
type DataBufPool interface {
Get(minSize int) DataBuffer
}
type DataBuffer ¶ added in v0.3.0
type DataBuffer interface {
// Data returns a byte slice with len set to the current data
// portion, and cap set to the size of the underlying buffer.
Data() []byte
// Set updates the length of the current data if the underlying
// buffer is the same. Otherwise it will use copy() to import
// the specified bytes.
Set([]byte)
// Put returns the buffer back to its internally referenced pool.
// Depending on whether a pool is associated, this may be a no-op.
Put()
// Reset sets the current slice to an empty slice.
Reset()
}
type Device ¶
type Device interface {
Read([]Msg) (n int, err error)
// Writes a message into the driver transmit buffer.
// The ownership of the message will not be taken.
WriteMsg(*Msg) error
// As an alternative to WriteMsg, Write can be used
// if more than one message should be handed over
// to the driver at once (if the driver is able to do that).
Write([]Msg) (n int, err error)
ID() string
Info() *DeviceInfo
Close() error
}
The Device interface gives access to a CAN Device. Read and Write calls will block if no messages are available to be read or if the transmit buffer of the driver is full.
func Open ¶
Open tries to open a CAN device matching the device specification. The deviceSpec has the syntax
[ driverName [ ":" deviceName ] { "," ctlString } ]
The syntax suggests that "" is a valid input: It will try to open any available CAN adapter with driver dependent default settings. The comma separated ctl strings will be processed by ParseConfig. On success, a Device instance will be returned, else an error.
type DeviceInfo ¶ added in v0.3.0
type DeviceInfo struct {
ID string
Model string
Device string
Driver string
SystemDriver string
SystemDriverVersion string
APIVersion string
Firmware string
SerialNum string
}
func Scan ¶
func Scan() (list []DeviceInfo)
func (*DeviceInfo) Format ¶ added in v0.3.0
func (di *DeviceInfo) Format(idSep, itemSep, end string) string
func (*DeviceInfo) String ¶ added in v0.3.0
func (di *DeviceInfo) String() string
type Driver ¶
type Driver interface {
Name() string
// Version() string
Open(env *Env, name string, conf *Config) (Device, error)
Scan() []DeviceInfo
}
var UnsupportedDriver Driver = unsupported{}
type Env ¶ added in v0.3.0
type Env struct {
BufPool DataBufPool
}
type Flags ¶
type Flags int
Message Flags.
func (Flags) ExtFrame ¶
Reports whether the message contains an 29 bit wide, extended indentifier, or a standard 11 bit wide identifier.
type Msg ¶
type Msg struct {
Id uint32 // The CAN message identifier
Flags
Rx struct {
Time Time // Timestamp
}
// contains filtered or unexported fields
}
Definition of a CAN Message.
func (*Msg) Attach ¶ added in v0.3.0
func (m *Msg) Attach(b DataBuffer)
Attach is similar to SetData, but instead of a byte slice, a DataBuffer must be provided. This helps to avoid an internal allocation in case the data contains more than eight bytes.
func (*Msg) Data ¶
Data returns the current Payload of the message. If no payload buffer has been set by calling SetData before, Data returns a byte slice with the standard payload length 8.
func (*Msg) FromExpr ¶ added in v0.3.0
FromExpr parses a CAN message expression string and stores the result into m, which may be a pre-initialized value. The format is similar to the format used by cansend from can-utils.
CAN ID and data, separated by '#' or ':', must be specified in hexadecimal format. An FD frame can be forced using a double separator, followed by a CAN flags hex nibble; supported FD flags: BRS = 0b0001.
The string may not contain white-space, but '.' can be used to separate data bytes.
func (*Msg) Import ¶ added in v0.3.0
func (m *Msg) Import(b []byte, pool DataBufPool) error
Import copies b into the message's backing store, either the standard payload array (if ≤ 8 bytes), or a user provided buffer previously set using SetData, if available. Else it will try to get a sufficient buffer from the pool, link it to the message, and copy the contents of b there. If the pool argument is nil, ErrMsgCapExceeded will be replied.
type MsgFilter ¶ added in v0.3.0
func (*MsgFilter) Range ¶ added in v0.3.0
Range returns two values defining a range that corresponds a single region defined by ID and IDMask fields. In this case ok will be set to true. If ID and IDMask would create multiple / many regions, ok is set to false. Range may be useful for drivers that implement filtering based on ID ranges.
type Unversioned ¶
type Unversioned struct{}
func (Unversioned) Info ¶ added in v0.3.0
func (Unversioned) Info() *DeviceInfo
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
module
|
|
|
A helper package for the various CAN driver interface packages.
|
A helper package for the various CAN driver interface packages. |
|
all
Convenience package that registers all known drivers.
|
Convenience package that registers all known drivers. |
|
canrpc
Package canrpc implements net/rpc client and server objects.
|
Package canrpc implements net/rpc client and server objects. |
|
socketcan
module
|
|