• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created about 5 years ago
  • Updated 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
165
star
2

pid-go

PID controllers for Go.
Go
83
star
3

backstage-go

Backstage SDK for Go
Go
56
star
4

protobuf-bigquery-go

Seamlessly save and load protocol buffers to and from BigQuery using Go.
Go
49
star
5

cloudrunner-go

β˜οΈπŸƒ Get up and running with Go on Google Cloud.
Go
45
star
6

protoc-gen-typescript-http

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

sage

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

gh-dependabot

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

protobuf-avro-go

Converts protocol buffers to Avro.
Go
30
star
10

iam-go

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

ui

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

aip-cli-go

Generate command line interfaces to your gRPC services.
Go
24
star
13

supervisor-go

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

balena-go

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

monta-go

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

protoc-gen-go-aip-test

Go
8
star
17

spanner-aip-go

Go SDK for implementing Spanner persistance for resource-oriented APIs.
Go
8
star
18

protoc-gen-typescript-aip

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

grpc-service-config-go

gRPC service config without service discovery.
Go
6
star
20

protobuf-sensitive

A sensitive annotation for redacting sensitive information from protocol buffers
Go
6
star
21

lcm-go

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

vlp16-go

Go SDK for Velodyne VLP-16 LiDAR sensors.
Go
6
star
23

unit-go

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

here-go

Go SDK for the HERE Maps API.
Go
5
star
25

protocrate-rs

Generate Rust crate for protobuf schemas and gRPC APIs.
Rust
5
star
26

xsens-go

Go SDK for Xsens MTi Inertial Measurement Units (IMUs).
Go
4
star
27

clock-go

Go SDK with interfaces for clocks and time keeping
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

csp-evaluator-cli

A command line tool to validate Content-Security-Policy rules
JavaScript
1
star
36

yamlfmt

A tool to format yaml files
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

protoc-gen-messageintegrity

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

goreview

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

tsconfig

Einride's default TSconfig
JavaScript
1
star
42

prettier-config

Einride's default Prettier config
JavaScript
1
star
43

protobuf-decap-cms

Manage protobuf resources using Decap CMS.
Go
1
star
44

aplicom-go

Go SDK for Aplicom telematics devices.
Go
1
star
45

spanner-backup-service

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

google-cloud-proto-scrubber

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