gokbus

package module
v0.0.0-...-bbd8d50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2021 License: MIT Imports: 4 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go KBUS

Go KBus is a golang module designed to interface with the BMW I/K Bus. This protocol is similar to CAN, and controls the non-essential components in the car.

This module can be used to read, write, and interpret BMW serial commands. It's loosely based on ezeakeal's excellent pyBus (and my subsequent fork).

Overview

  • USB serial interface can be acquired from Reslers.de. Other USB interfaces should work just as well, although are untested.
  • Communicates on the I-BUS to send and receive diagnostics, running status, button presses, vehicle info, etc.

Install

go get github.com/qcasey/gokbus

Example module usage

package main

import (
	"log"

	"github.com/qcasey/gokbus"
)

func main() {
	kbus, err := gokbus.New("/dev/ttyUSB0", 9600)
	if err != nil {
		panic(err)
	}
	defer kbus.Port.Close()

	// Start the read and write channels
	// This isn't required - we can ReadPacket() / WritePacket() separately without channels,
	// but timing will be less precise and many packets will be dropped.
	go kbus.Start()

	// Read 5 packets
	for i := 0; i < 5; i++ {
		select {
		case newPacket := <-kbus.ReadChannel:
			log.Print(newPacket.Pretty())
		}
	}

	// Prepare a write packet, this one opens the trunk
	openTrunkPacket := gokbus.Packet{
		Source:      0x3F,
		Destination: 0x00,
		Data:        []byte{0x0C, 0x02, 0x01},
	}
	
	// alternatively, a list of known packets are provided in /pkg/prepackets
	// flashLowBeamsPacket := prepackets.FlashLowBeams

	// Block until packet is written to the bus
	kbus.WriteChannel <- openTrunkPacket

	// Read another 5 packets
	for i := 0; i < 5; i++ {
		select {
		case newPacket := <-kbus.ReadChannel:
			log.Print(newPacket.Pretty())
		}
	}

}

Missing write confirmation that pyBus offers

http://web.archive.org/web/20041204074622/www.openbmw.org/bus/
https://web.archive.org/web/20190210133920/http://web.comhem.se/bengt-olof.swing/ibusdevicesandoperations.htm
https://web.archive.org/web/20180511152050/http://www.online-rubin.de/BMW/I-Bus/I-BUS%20Codes%20e46.htm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KBUS

type KBUS struct {
	Path string
	Baud int

	ReadChannel  chan Packet
	WriteChannel chan Packet
	ErrorChannel chan error
	Port         *serial.Port
}

KBUS is the main interface to communicate with the BMW I/K-Bus

func New

func New(devicePath string, baudrate int) (*KBUS, error)

New returns a new KBUS device interface

func (*KBUS) Close

func (kbus *KBUS) Close()

Close the KBUS port

func (*KBUS) ReadPacket

func (kbus *KBUS) ReadPacket() (Packet, error)

ReadPacket will block until the next Packet is recieved or times out because of an empty bus

func (*KBUS) Start

func (kbus *KBUS) Start()

Start will begin reading and writing packets to the KBus with the provided channels

func (*KBUS) WritePacket

func (kbus *KBUS) WritePacket(p Packet) (int, error)

WritePacket will attempt to write a packet to the kbus

type Packet

type Packet struct {
	Source byte

	Destination byte
	Data        []byte
	// contains filtered or unexported fields
}

Packet is a group of bytes read from the bus

func (*Packet) Flatten

func (p *Packet) Flatten() []byte

Flatten returns the packet represented as a byte array

func (*Packet) IsValid

func (p *Packet) IsValid() bool

IsValid checks a recieved Packet's checksum to ensure it was transmitted correctly This will fail on our own generated packets, since those haven't been given a Checksum or Length yet

func (*Packet) Pretty

func (p *Packet) Pretty() string

Pretty returns a well formatted string of the packet, with ECU locations resolved. Format: SOURCE -> DEST (LEN) DATA [CHECKSUM]

Directories

Path Synopsis
cmd
gokbus command
pkg
ecu
prepackets
Package prepackets are a collection of KBus packets prepared for a 2005 BMW Vert, they may or may not work for your model car
Package prepackets are a collection of KBus packets prepared for a 2005 BMW Vert, they may or may not work for your model car

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址