Skip to content

Commit

Permalink
Support canfd (#1)
Browse files Browse the repository at this point in the history
* Updated Message.Length to uint16 to support message lengths up to 65,535 bytes

* Updated Signal.Lenght and Signal.Size to uint16 for payloads larger than 8 bytes

* Added payload.go and payload_tests.go

* Updated Big and Little Endian encoding methods

* Added benchmarks

* Added methods and tests to decode signed/unsigned signals in big/little endian

* Added benchmarks for UnsignedBitsLittleEndian

* Added hex string methods for Payload

* Added UnmarshalPhysicalPayload and updated bit-level methods for Payload struct

* Added UnmarshalValueDescriptionPayload and associated methods for Payload data struct

* Added decode_tests.go

* Updated decode test

* Added asserts to decode_test.go

* Added comparitive unit tests for can.Data and benchmarks for decoding

* Updated PackLittleEndian and PackBigEndian to return new big.Int and reference pointer to payload in decode methods

* Fixed units in VDM_Disconnect test

Co-authored-by: Jason Shiverick <jshiverick@rivian.coml>
Co-authored-by: Naveen Venkatesan <nvenkatesan@rivian.com>
Co-authored-by: Naveen Venkatesan <naveen.venkatesan@gmail.com>
  • Loading branch information
4 people authored Mar 1, 2021
1 parent 85971b3 commit 4e93a88
Show file tree
Hide file tree
Showing 14 changed files with 1,077 additions and 93 deletions.
14 changes: 14 additions & 0 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,17 @@ func BenchmarkData_PackLittleEndian(b *testing.B) {
_ = data.PackLittleEndian()
}
}

func BenchmarkData_UnsignedBitsBigEndian(b *testing.B) {
var data Data
for i := 0; i < b.N; i++ {
_ = data.UnsignedBitsBigEndian(0, 16)
}
}

func BenchmarkData_UnsignedBitsLittleEndian(b *testing.B) {
var data Data
for i := 0; i < b.N; i++ {
_ = data.UnsignedBitsLittleEndian(0, 16)
}
}
6 changes: 3 additions & 3 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Frame struct {
// ID is the CAN ID
ID uint32
// Length is the number of bytes of data in the frame.
Length uint8
Length uint16
// Data is the frame data.
Data Data
// IsRemote is true for remote frames.
Expand Down Expand Up @@ -114,7 +114,7 @@ func (f *Frame) UnmarshalString(s string) error {
if err != nil {
return fmt.Errorf("invalid remote length: %v: %w", s, err)
}
frame.Length = uint8(dataLength)
frame.Length = uint16(dataLength)
}
*f = frame
return nil
Expand All @@ -123,7 +123,7 @@ func (f *Frame) UnmarshalString(s string) error {
if len(dataPart) > 16 || len(dataPart)%2 != 0 {
return fmt.Errorf("invalid data length: %v", s)
}
frame.Length = uint8(len(dataPart) / 2)
frame.Length = uint16(len(dataPart) / 2)
// Parse: Data
decodedData, err := hex.DecodeString(dataPart)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions frame_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type jsonFrame struct {
ID uint32 `json:"id"`
Data *string `json:"data"`
Length *uint8 `json:"length"`
Length *uint16 `json:"length"`
Extended *bool `json:"extended"`
Remote *bool `json:"remote"`
}
Expand Down Expand Up @@ -69,7 +69,7 @@ func (f *Frame) UnmarshalJSON(jsonData []byte) error {
}
f.Data = Data{}
copy(f.Data[:], data)
f.Length = uint8(len(data))
f.Length = uint16(len(data))
} else {
f.Data = Data{}
f.Length = 0
Expand Down
2 changes: 1 addition & 1 deletion frame_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (Frame) Generate(rand *rand.Rand, size int) reflect.Value {
} else {
f.ID = rand.Uint32() & MaxID
}
f.Length = uint8(rand.Intn(9))
f.Length = uint16(rand.Intn(9))
if !f.IsRemote {
_, _ = rand.Read(f.Data[:f.Length])
}
Expand Down
6 changes: 3 additions & 3 deletions internal/generate/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *compiler) collectDescriptors() {
Name: string(def.Name),
ID: def.MessageID.ToCAN(),
IsExtended: def.MessageID.IsExtended(),
Length: uint8(def.Size),
Length: uint16(def.Size),
SenderNode: string(def.Transmitter),
}
for _, signalDef := range def.Signals {
Expand All @@ -73,8 +73,8 @@ func (c *compiler) collectDescriptors() {
IsMultiplexer: signalDef.IsMultiplexerSwitch,
IsMultiplexed: signalDef.IsMultiplexed,
MultiplexerValue: uint(signalDef.MultiplexerSwitch),
Start: uint8(signalDef.StartBit),
Length: uint8(signalDef.Size),
Start: uint16(signalDef.StartBit),
Length: uint16(signalDef.Size),
Scale: signalDef.Factor,
Offset: signalDef.Offset,
Min: signalDef.Minimum,
Expand Down
Loading

0 comments on commit 4e93a88

Please sign in to comment.