All Projects → einride → can-go

einride / can-go

Licence: MIT license
Controller Area Network (CAN) SDK for Go.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to can-go

can-prog
Command-line tool to flashing devices by CAN-BUS
Stars: ✭ 66 (-41.59%)
Mutual labels:  can, canbus, socketcan
JavaCAN
A simple JNI wrapper for the socketcan API provided by the Linux kernel. As it is wrapping a Linux Kernel API, it is intended for use on Linux only.
Stars: ✭ 23 (-79.65%)
Mutual labels:  can, socketcan
pcan cantact
🤖 XCAN firmware for CANtact ( CANable ) or any other similar boards.
Stars: ✭ 192 (+69.91%)
Mutual labels:  can, socketcan
pyuavcan
Python implementation of the Cyphal protocol stack.
Stars: ✭ 91 (-19.47%)
Mutual labels:  can, socketcan
openHCAN
Hausautomatisierungsloesung auf CAN-Bus Basis.
Stars: ✭ 16 (-85.84%)
Mutual labels:  can, socketcan
can2mqtt
Bidirectional CAN-Bus to MQTT-Bridge
Stars: ✭ 39 (-65.49%)
Mutual labels:  can, socketcan
awesome-automotive-can-id
🚜 unpretentious attempt to collect CAN IDs and payloads for various car brands/models in one place.
Stars: ✭ 104 (-7.96%)
Mutual labels:  can, canbus
ecu-simulator
OBD-II ECU Simulator
Stars: ✭ 24 (-78.76%)
Mutual labels:  can, socketcan
NodeMCU-BlackBox
ESP8266 based CAN-Bus Diagnostic Tool
Stars: ✭ 28 (-75.22%)
Mutual labels:  can, canbus
TC1791 CAN BSL
CAN Bootstrap Loader (BSL) for Tricore AudoMAX (TC1791 and friends), including arbitrary read/write as well as compressed read functionality.
Stars: ✭ 25 (-77.88%)
Mutual labels:  can
cpp-can-isotp
C++ implementation of CAN ISO 15765-2 also known as CAN ISO transport protocol. CPP CAN isotp.
Stars: ✭ 14 (-87.61%)
Mutual labels:  can
evDash
EV dashboard - software for small dev boards connected to the car via obd2 BLE4 or CAN bus.
Stars: ✭ 83 (-26.55%)
Mutual labels:  can
TeslondaServer
The back-end, server app for the Teslonda Dashboard on Raspberry Pi.
Stars: ✭ 20 (-82.3%)
Mutual labels:  can
talking-with-cars
CAN analysis - Use your car as a gamepad!
Stars: ✭ 95 (-15.93%)
Mutual labels:  can
PYCAN
Control ZLG-USBCAN with Python
Stars: ✭ 32 (-71.68%)
Mutual labels:  can
datalinkengineeringcanopen
CANopen SDK (API) for Windows developers. Supported adapters: Kvaser, Ixxat, CANUSB, CAN232, Peak PCAN, Copley Controls, USBTIN and more.
Stars: ✭ 26 (-76.99%)
Mutual labels:  can
107-Arduino-MCP2515
Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames.
Stars: ✭ 35 (-69.03%)
Mutual labels:  can
PSAVanCanBridge
VAN - CAN protocol bridge (V2C) for cars made by PSA Group (Peugeot, Citroen)
Stars: ✭ 67 (-40.71%)
Mutual labels:  can
ACSC
Automatic Calibration for Non-repetitive Scanning Solid-State LiDAR and Camera Systems
Stars: ✭ 210 (+85.84%)
Mutual labels:  autonomous-vehicles
CANopen-monitor
An NCurses-based TUI application for tracking activity over the CAN bus and decoding messages with provided EDS/OD files.
Stars: ✭ 15 (-86.73%)
Mutual labels:  can

🔌 CAN Go

PkgGoDev GoReportCard Codecov

CAN toolkit for Go programmers.

can-go makes use of the Linux SocketCAN abstraction for CAN communication. (See the SocketCAN documentation for more details).

Examples

Setting up a CAN interface

func main() {
	// Error handling omitted to keep example simple
	d, _ := candevice.New("can0")
	_ := d.SetBitrate(250000)
	_ := d.SetUp()
	defer d.SetDown()
}

Receiving CAN frames

Receiving CAN frames from a socketcan interface.

func main() {
	// Error handling omitted to keep example simple
	conn, _ := socketcan.DialContext(context.Background(), "can", "can0")

	recv := socketcan.NewReceiver(conn)
	for recv.Receive() {
		frame := recv.Frame()
		fmt.Println(frame.String())
	}
}

Sending CAN frames/messages

Sending CAN frames to a socketcan interface.

func main() {
	// Error handling omitted to keep example simple

	conn, _ := socketcan.DialContext(context.Background(), "can", "can0")

	frame := can.Frame{}
	tx := socketcan.NewTransmitter(conn)
	_ = tx.TransmitFrame(context.Background(), frame)
}

Generating Go code from a DBC file

It is possible to generate Go code from a .dbc file.

$ go run go.einride.tech/can/cmd/cantool generate <dbc file root folder> <output folder>

In order to generate Go code that makes sense, we currently perform some validations when parsing the DBC file so there may need to be some changes on the DBC file to make it work

After generating Go code we can marshal a message to a frame:

// import etruckcan "github.com/myproject/myrepo/gen"

auxMsg := etruckcan.NewAuxiliary().SetHeadLights(etruckcan.Auxiliary_HeadLights_LowBeam)
frame := auxMsg.Frame()

Or unmarshal a frame to a message:

// import etruckcan "github.com/myproject/myrepo/gen"

// Error handling omitted for simplicity
_ := recv.Receive()
frame := recv.Frame()

var auxMsg *etruckcan.Auxiliary
_ = auxMsg.UnmarshalFrame(frame)

Running integration tests

Building the tests:

$ make build-integration-tests

Built tests are placed in build/tests.

The candevice test requires access to physical HW, so run it using sudo. Example:

$ sudo ./build/tests/candevice.test
> PASS
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].