• Stars
    star
    169
  • Rank 218,257 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Controller Area Network (CAN) SDK for Go.

🔌 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

More Repositories

1

aip-go

Go SDK for implementing resource-oriented gRPC APIs.
Go
150
star
2

pid-go

PID controllers for Go.
Go
74
star
3

backstage-go

Backstage SDK for Go
Go
50
star
4

cloudrunner-go

☁️🏃 Get up and running with Go on Google Cloud.
Go
44
star
5

protobuf-bigquery-go

Seamlessly save and load protocol buffers to and from BigQuery using Go.
Go
43
star
6

protoc-gen-typescript-http

Generate types and service clients from protobuf definitions annotated with http rules.
Go
40
star
7

sage

🌿 A Make-like build tool for Go projects
Go
30
star
8

gh-dependabot

GitHub CLI extension for reviewing Dependabot PRs.
Go
29
star
9

iam-go

An opinionated Open Source implementation of the google.iam APIs on top of Cloud Spanner.
Go
27
star
10

protobuf-avro-go

Converts protocol buffers to Avro.
Go
26
star
11

ui

Reusable React components that adhere to Einride's design system.
TypeScript
23
star
12

supervisor-go

A service that starts and supervises other services and restarts them in case of failure.
Go
21
star
13

aip-cli-go

Generate command line interfaces to your gRPC services.
Go
21
star
14

balena-go

The unofficial SDK to make balena powered Go applications.
Go
11
star
15

monta-go

Go SDK for accessing the Monta Partner API
Go
9
star
16

spanner-aip-go

Go SDK for implementing Spanner persistance for resource-oriented APIs.
Go
7
star
17

protoc-gen-typescript-aip

Generates Typescript for gRPC APIs conforming to AIP https://aip.dev
Go
7
star
18

protoc-gen-go-aip-test

Go
6
star
19

lcm-go

Native Go SDK for LCM (Lightweight Communications and Marshaling)
Go
6
star
20

unit-go

Go SDK for modeling physical units and conversion between them
Go
5
star
21

vlp16-go

Go SDK for Velodyne VLP-16 LiDAR sensors.
Go
5
star
22

grpc-service-config-go

gRPC service config without service discovery.
Go
4
star
23

here-go

Go SDK for the HERE Maps API.
Go
4
star
24

protocrate-rs

Generate Rust crate for protobuf schemas and gRPC APIs.
Rust
4
star
25

protobuf-sensitive

A sensitive annotation for redacting sensitive information from protocol buffers
Go
3
star
26

clock-go

Go SDK with interfaces for clocks and time keeping
Go
3
star
27

xsens-go

Go SDK for Xsens MTi Inertial Measurement Units (IMUs).
Go
3
star
28

protoc-gen-go-aip-dataloader

Generate GraphQL Go dataloaders for AIP BatchGet gRPC methods.
Go
3
star
29

nobil-go

Go SDK for the NOBIL.no public charger API.
Go
3
star
30

extend

Open APIs and developer tools for Einride's Saga platform.
Go
3
star
31

dataloader-go

Generic dataloaders for Go
Go
3
star
32

hooks

Reusable React hooks
TypeScript
2
star
33

terraform-provider-iam-go

A Terraform Provider for https://github.com/einride/iam-go
Go
2
star
34

ghcomment

A simple CLI tool for commenting on GitHub PRs
Go
1
star
35

yamlfmt

A tool to format yaml files
Go
1
star
36

protoc-gen-messageintegrity

Code for the thesis "Implicit Message Integrity in Heterogeneous Systems".
Go
1
star
37

bigquery-importer-github

Data export from GitHub to BigQuery
Go
1
star
38

bigquery-importer-slack

Go service for importing Slack workspace data into BigQuery
Go
1
star
39

goreview

Einride-specific Go static analysis rules.
Go
1
star
40

tsconfig

Einride's default TSconfig
JavaScript
1
star
41

prettier-config

Einride's default Prettier config
JavaScript
1
star
42

protobuf-netlify-cms

Manage protobuf resources using Netlify CMS.
Go
1
star
43

aplicom-go

Go SDK for Aplicom telematics devices.
Go
1
star
44

spanner-backup-service

Go service for implementing scheduled backup for Cloud Spanner databases.
Go
1
star
45

google-cloud-proto-scrubber

Scrub unsupported annotations from Google Cloud gRPC API descriptors.
Go
1
star