Documentation ¶
Overview ¶
Package can is a GO implementation of several Controller Area Network (CAN) utilities that facilitate the interaction with CAN messages and networks.
It contains functions, structs, and utilities that assist with the capture, processing, generation, and sending of CAN messages that were captured either by the functions in this library, or with other common capture methods such as SocketCan's userspace utilities
Index ¶
- Constants
- func CaptureCan(canInterface InterfaceDescriptor, canChannel chan<- *Frame, ...)
- func ChannelMultiplex(input <-chan *Frame, output ...chan<- *Frame)
- func CloseCanInterface(canInterface InterfaceDescriptor) error
- func CompareFrames(frameOne *Frame, frameTwo *Frame) bool
- func CompareFramesSimple(frameOne *Frame, frameTwo *Frame) bool
- func FrameInSlice(frame *Frame, frameSlice []*Frame) bool
- func FrameInSliceSimple(frame *Frame, frameSlice []*Frame) bool
- func ReceiveNFrames(canInterface InterfaceDescriptor, n int, canChannel chan<- *Frame, ...)
- func SendConcurrent(canInterface InterfaceDescriptor, canChannel <-chan *Frame, ...)
- func SendFrame(canInterface InterfaceDescriptor, message *Frame) error
- func TimestampToSeconds(timestamp int64) float64
- type Frame
- type InterfaceDescriptor
- type ProcessedFrame
- type Router
Constants ¶
const ALLIDs = 0xFFFFFFFF
Variables ¶
This section is empty.
Functions ¶
func CaptureCan ¶
func CaptureCan(canInterface InterfaceDescriptor, canChannel chan<- *Frame, errorChannel chan<- error)
CaptureCan will listen to the provided SocketCAN interface and add any messages seen to the provided channel TODO remove?
func ChannelMultiplex ¶
ChannelMultiplex will take a Frame sent into the input channel and relay it to all output channels
func CloseCanInterface ¶
func CloseCanInterface(canInterface InterfaceDescriptor) error
CloseCanInterface closes the passed interface
func CompareFrames ¶
CompareFrames takes two Raw Can Frames and returns true if they are the same frame and false otherwise
This comparison is done on all fields and flags except anything time based. Since a Raw Can Frame's OID contains the masked ID and Flags, it is used for comparison to save a bit of computation. Because of this OID comparison, this function is not compatible with Frame structs that are built with SocketCan's candump output is not supported. Instead use CompareFramesSimple instead.
func CompareFramesSimple ¶
CompareFramesSimple takes two Frames and returns true if they are the same frame and false otherwise
This comparison is only performed on the ID, Data Length, and Data Contents. It does not support checking flasgs or masks in order to support Frames that are built from SocketCan's candump output.
func FrameInSlice ¶
FrameInSlice takes a Raw Can Frame and looks to see if it exists within a slice of Raw Can Frames
Because this function makes use of CompareFrames, it is not compatible with Frames that are built from SocketCan's candump output. Instead, use FrameInSliceSimple.
func FrameInSliceSimple ¶
FrameInSliceSimple takes a Frame and looks to see if it exists within a slice of Frames using the simple method
Because this function makes use of CompareFramesSimple, it is compatible with Frames that are built from SocketCan's candump output.
func ReceiveNFrames ¶
func ReceiveNFrames(canInterface InterfaceDescriptor, n int, canChannel chan<- *Frame, errorChannel chan<- error)
ReceiveNFrames reads N frames from the provided interface
func SendConcurrent ¶
func SendConcurrent(canInterface InterfaceDescriptor, canChannel <-chan *Frame, errorChannel chan<- error)
SendConcurrent will utilize a channel to send CAN messages on the given CAN interface
func SendFrame ¶
func SendFrame(canInterface InterfaceDescriptor, message *Frame) error
SendFrame will send the provided CAN message on the given CAN interface
func TimestampToSeconds ¶
TimestampToSeconds converts the int64 timestamp into a float unix timestamp
Types ¶
type Frame ¶
type Frame struct { OID uint32 // 32-bit CAN_ID including masks Data []byte // Message Payload Timestamp int64 // Time message was captured as Unix Timestamp in nanoseconds }
Frame represents the data contained in a CAN packet
func CreateFrame ¶
CreateFrame will take an ID, Data, and Flags to generate a valid Frame
func CreateFrameFromByte ¶
CreateFrameFromByte will take an byte array and tries to create a can Frame
func ReceiveFrame ¶
func ReceiveFrame(canInterface InterfaceDescriptor) (*Frame, error)
ReceiveFrame reads a frame from the provided interface
type InterfaceDescriptor ¶
type InterfaceDescriptor int
InterfaceDescriptor is a can device handler that must be passed to functions using the can bus. Create one with SetupCanInterface.
func SetupCanInterface ¶
func SetupCanInterface(canInterface string) (InterfaceDescriptor, error)
SetupCanInterface will set up a CAN file descriptor to be used with sending and receiving CAN message. The function takes a string that specifies the interface to open.
type ProcessedFrame ¶
type ProcessedFrame struct { Packet Frame // CAN packet PacketHash string // md5 hash of the Packet's ID and Data fields AlphaNumData string // Any Alpha-numeric data within the can payload }
ProcessedFrame represents a CAN packet and additional data about the packet
func (ProcessedFrame) ToString ¶
func (frame ProcessedFrame) ToString(delimiter string) string
ToString takes a ProcessedFrame and formats it based on several parameters
This function is designed to be used to prepare a Frame for multiple output formats including stdout, csv, and other custom delimited formats.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func NewRouter ¶
func NewRouter(canFD InterfaceDescriptor) Router
NewRouter creates a new router and starts it
func (*Router) Stop ¶
func (r *Router) Stop()
Stop will stop the router and drains all of its channels
func (*Router) Unsubscribe ¶
Unsubscribe removes ch from the subscriber list for id