Giter VIP home page Giter VIP logo

can-go's People

Contributors

alethenorio avatar anajavi avatar andersastrom avatar ardrabczyk avatar csholmq avatar d4l3k avatar dependabot[bot] avatar edholm avatar ezhik452 avatar jassob avatar maxekman avatar odsod avatar saimanwong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

can-go's Issues

Generate code only for specific message

Great lib!
Is there a way to pass some kind of list of messages to the generate command to filter code generation only for specific messages?
Would be very useful to shrink down file size for large .dbc when only some of the messages are actually required

Marshall DBC frame for sending

Hi,

Is there possibility with this library to create something similar like in python cantools:

db = cantools.database.load_file(my.dbc)
msg = db.get_message_by_name('My_SuperMessage')
data = msg.encode({'Sig1': int(1), 'Sig2': int(2)})
message = can.Message(is_extended_id=False, arbitration_id=msg.frame_id, data=data)
can_bus.send(message)

I found parsing method only for dbc but not encode or similar. Thanks.

question on DBC file parsing

Hi,
I was looking for a go package that could parse DBC files and I stumbled upon this package.
In the docs I can see that it's possible to generate some go code from a DBC file, which sounds great but I am looking for a way for parsing some can data & converting it via a DBC to a human readable format.
The purpose of this would be to create a telegraf plugin to parse raw can data and converting it for visualizations & logging.

It seems that the parsed DBC data is inside a []Defs slice, ideally it would be great to have some sort of map for directly converting CAN IDs, I don't know if this is possible in this implementation ?

Thanks a lot !

TransmitFrame hanging sometimes

This is probably a problem with Linux Socketcan (running on a Pi 4), but I thought I would note it in case anyone knew an easy answer. It's not a huge problem, but one I've found in testing. Essentially, on occasion, TransmitFrame doesn't return UNTIL I receive a frame on the bus. It's hard to replicate. But, in any case, when bus traffic is empty, then the TransmitFrame will, only sometimes, fail to return. When incoming traffic returns to the bus, TransmitFrame will finally complete.

discussions and searchability

Please

  • consider enabling discussions so questions could be asked without creating issue
  • consider adding "canbus" etc topic to library description (Edit repository details). I was searching go library for canbus and remembered seeing couple of months ago https://youtu.be/IbggJHJUv0U but could not find it from github when searching with "canbus". Newbies like me probably are more likely to search "canbus" than "can" from "go golang can autonomous-vehicles dbc socketcan"

generating dbc file for obd2 fails

I'm trying to generate code for this dbc file: https://canlogger1000.csselectronics.com/files/guides/mdf-intro/OBD2-DBC-MDF4.zip (CSS-Electronics-OBD2-Extended-v1.4.dbc) but if fails first with:

go run go.einride.tech/can/cmd/cantool generate `pwd` `pwd` > out.txt
cantool: error: failed to parse DBC source file: /home/marek/CSS-Electronics-OBD2-Extended-v1.4.dbc:190:28: invalid multiplexer value (parse), try --help
exit status 1

which point to the line:

SG_ ParameterID_Service01 m1M : 23|8@0+ (1,0) [0|255] "" Vector__XXX

by replacing m1M to m1 only it seems to generate code but generation fails with go generated output and at the end:

: 4:12: expected ';', found '-', try --help
exit status 1

I really have no clue what is going on there ;). Any ideas? Thanks.

generate from dbc err

### first step:
i use Canmatrix convert arxml to dbc

canconvert ./Clea_Mode_Year23_VCU_V25.62.0.arxml ./ttest.dbc
ldf is not supported
INFO - convert - Importing ./Clea_Mode_Year23_VCU_V25.62.0.arxml ...
INFO - convert - done

INFO - convert - Exporting ./ttest.dbc ...
INFO - convert - ICB
INFO - convert - 709 Frames found
WARNING - dbc - Frame Access_Mode_EasyEntry_Seat_Customization name exceeds 32 characters, consider updating the frame name within character limit(Max 32 characters)
WARNING - dbc - Frame Access_Mode_EasyEntry_Seat_Customization_Request_VCU_source name exceeds 32 characters, consider updating the frame name within character limit(Max 32 characters)
WARNING - dbc - Frame Active_Safety_Customization_Info_1 name exceeds 32 characters, consider updating the frame name within character limit(Max 32 characters)
WARNING - dbc - Frame Active_Safety_Customization_Info_2 name exceeds 32 characters, consider updating the frame name within character limit(Max 32 characters)
WARNING - dbc - Frame Active_Safety_Customization_Info_3 name exceeds 32 characters, consider updating the frame name within character limit(Max 32 characters)
WARNING - dbc - Frame Active_Safety_Customization_Info_4 name exceeds 32 characters, consider updating the frame name within character limit(Max 32 characters)
WARNING - dbc - Signal Active_Safety_Customization_Info::ITrfcLgtStpLnCntrlCustCrntStngVal name exceeds 32 characters, consider updating the signal name within the character limit(Max 32 characters)

second step:

i run CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build cmd/cantool/main.go to generate main

third: i use main to generate from dbc

./main generate /Users/wulili/Desktop/pythonProject/ /Users/wulili/Desktop/pythonProject/cango
main: error: failed to parse DBC source file: /Users/wulili/Desktop/pythonProject/ttest_ICB.dbc:6597:13: invalid identifier 'NWM-Knoten': invalid char: '45' (parse), try --help
can you tell me how to deal with this.

Add support for CAN FD

From the history of issues, this library does support CAN FD, but I couldn't find any related API provided in the latest documentation. I'm not sure if it's my oversight or there is indeed no CAN FD support? Thanks!!!

Not understanding the SetBit operations for Big Endian

Hi,

I'm looking to create a Frame with uint16 values converted to big endian, e.g., the value of 256 represented in the CAN data as (hex): 01 00.

I've looked at doing this via:

tx := socketcan.NewTransmitter(canCon)
a_uint16_var := 256
frame2.ID = 0xd0
frame2.Length = 2
frame2.Data.SetUnsignedBitsBigEndian(0, 16, uint64(a_uint16_var))
_ = tx.TransmitFrame(context.Background(), frame2)

Incorrect Result: vcan0 0D0 [2] 00 02

The documentation for Data looks like this is the correct format, and it's working when using SetUnsignedBitsLittleEndian (with byte order properly reversed).

However, the results I get passing the uint16 value come back with strange values in frame.Data.

Right now I can work around this by creating my own byte array, converting, then copying into frame.Data:

a_uint16_var := 256
tx := socketcan.NewTransmitter(canCon)
frame2.ID = 0xd0
frame2.Length = 2
buf := make([]byte, 2)
binary.BigEndian.PutUint16(buf, speed)
copy(frame2.Data[:], buf)
_ = tx.TransmitFrame(context.Background(), frame2)

Correct Result: vcan0 0D0 [2] 01 00

This works for some straight forward applications, but I saw all the error checking you've included in the Data type functions I'd to take advantage of. I looked for some more expanded examples, but didn't find anything to help me better understand the content of creating and sending frames from data in a big endian way.

bool mux types handling: cannot use 0 (type untyped int) as type bool

Ran into a bug with mux types

BO_ 123 a: 8 Vector__XXX
 SG_ b m0 : 58|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ c m0 : 57|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ d m0 : 56|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ e m0 : 55|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ f m0 : 48|7@1+ (1,0) [0|0] "%" Vector__XXX
 SG_ g m0 : 47|1@1+ (1,0) [0|0] "" Vector__XXX
 SG_ h m0 : 40|7@1+ (1,0) [0|0] "%" Vector__XXX
 SG_ i m1 : 32|16@1+ (1,0) [0|0] "" Vector__XXX
 SG_ j m0 : 24|16@1+ (1,0) [0|0] "MB" Vector__XXX
 SG_ k m1 : 8|24@1+ (1,0) [0|0] "" Vector__XXX
 SG_ l m0 : 8|16@1+ (1,0) [0|0] "MB" Vector__XXX
 SG_ mux M : 0|1@1+ (1,0) [0|0] "" Vector__XXX

VAL_ 123 mux 0 "0" 1 "1" ;

generates some invalid code since bools can't be compared to 0/1

// a_mux models the mux signal of the a message.
type a_mux bool

// Value descriptions for the mux signal of the a message.
const (
	a_mux_0 a_mux = false
	a_mux_1 a_mux = true
)

func (v a_mux) String() string {
	switch bool(v) {
	case false:
		return "0"
	case true:
		return "1"
	}
	return fmt.Sprintf("a_mux(%t)", v)
}

// Frame returns a CAN frame representing the message.
func (m *a) Frame() can.Frame {
	md := Messages().a
	f := can.Frame{ID: md.ID, IsExtended: md.IsExtended, Length: md.Length}
	md.mux.MarshalBool(&f.Data, bool(m.xxx_mux))
	if m.xxx_mux == 0 {
		md.l.MarshalUnsigned(&f.Data, uint64(m.xxx_l))
	}
	if m.xxx_mux == 1 {
		md.k.MarshalUnsigned(&f.Data, uint64(m.xxx_k))
	}
	if m.xxx_mux == 0 {
		md.j.MarshalUnsigned(&f.Data, uint64(m.xxx_j))
	}
	if m.xxx_mux == 1 {
		md.i.MarshalUnsigned(&f.Data, uint64(m.xxx_i))
	}
	if m.xxx_mux == 0 {
		md.h.MarshalUnsigned(&f.Data, uint64(m.xxx_h))
	}
	if m.xxx_mux == 0 {
		md.g.MarshalBool(&f.Data, bool(m.xxx_g))
	}
	if m.xxx_mux == 0 {
		md.f.MarshalUnsigned(&f.Data, uint64(m.xxx_f))
	}
	if m.xxx_mux == 0 {
		md.e.MarshalBool(&f.Data, bool(m.xxx_e))
	}
	if m.xxx_mux == 0 {
		md.d.MarshalBool(&f.Data, bool(m.xxx_d))
	}
	if m.xxx_mux == 0 {
		md.c.MarshalBool(&f.Data, bool(m.xxx_c))
	}
	if m.xxx_mux == 0 {
		md.b.MarshalBool(&f.Data, bool(m.xxx_b))
	}
	return f
}
<file>:<line>: cannot use 0 (type untyped int) as type bool

missing signals handling for large dbc files. j1939

We conducted tests on the sample example.dbc but it appears we're not adequately handling larger dbc files. I'm keen on contributing to the resolution of this issue. However, I would greatly appreciate some guidance in navigating this process.

root@d4018fb3a9c4:/app# go run go.einride.tech/can/cmd/cantool generate ./input ./output
wrote: output/example.dbc.go
cantool: error: failed to compile: no declared signal (&{input/j1939.dbc:10765:1 SigType SG_ 3221225472 TrailerWeight 0 0 Range}), try --help
exit status 1

values with spaces generate invalid code

I'm trying to generate Go code for the following dbc file:

https://github.com/joshwardell/model3dbc/blob/master/Model3CAN.dbc#L4745

This line

VAL_ 280 DI_tractionControlMode 6 "Offroad Assist" 5 "Dyno Mode" 4 "Rolls Mode" 3 "Dev2" 2 "Dev1" 1 "Slip Start" 0 "Standard" ;

generates Go code like:

type ID118DriveSystemStatus_DI_tractionControlMode uint8

// Value descriptions for the DI_tractionControlMode signal of the ID118DriveSystemStatus message.
const (
ID118DriveSystemStatus_DI_tractionControlMode_Standard ID118DriveSystemStatus_DI_tractionControlMode = 0
ID118DriveSystemStatus_DI_tractionControlMode_Slip Start ID118DriveSystemStatus_DI_tractionControlMode = 1
ID118DriveSystemStatus_DI_tractionControlMode_Dev1 ID118DriveSystemStatus_DI_tractionControlMode = 2
ID118DriveSystemStatus_DI_tractionControlMode_Dev2 ID118DriveSystemStatus_DI_tractionControlMode = 3
ID118DriveSystemStatus_DI_tractionControlMode_Rolls Mode ID118DriveSystemStatus_DI_tractionControlMode = 4
ID118DriveSystemStatus_DI_tractionControlMode_Dyno Mode ID118DriveSystemStatus_DI_tractionControlMode = 5
ID118DriveSystemStatus_DI_tractionControlMode_Offroad Assist ID118DriveSystemStatus_DI_tractionControlMode = 6
)

which is invalid due to the spaces

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.