Skip to content

Commit 4e93a88

Browse files
jshivJason ShiverickNaveen Venkatesannaveenv92
authored
Support canfd (#1)
* 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>
1 parent 85971b3 commit 4e93a88

File tree

14 files changed

+1077
-93
lines changed

14 files changed

+1077
-93
lines changed

data_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,17 @@ func BenchmarkData_PackLittleEndian(b *testing.B) {
331331
_ = data.PackLittleEndian()
332332
}
333333
}
334+
335+
func BenchmarkData_UnsignedBitsBigEndian(b *testing.B) {
336+
var data Data
337+
for i := 0; i < b.N; i++ {
338+
_ = data.UnsignedBitsBigEndian(0, 16)
339+
}
340+
}
341+
342+
func BenchmarkData_UnsignedBitsLittleEndian(b *testing.B) {
343+
var data Data
344+
for i := 0; i < b.N; i++ {
345+
_ = data.UnsignedBitsLittleEndian(0, 16)
346+
}
347+
}

frame.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Frame struct {
2626
// ID is the CAN ID
2727
ID uint32
2828
// Length is the number of bytes of data in the frame.
29-
Length uint8
29+
Length uint16
3030
// Data is the frame data.
3131
Data Data
3232
// IsRemote is true for remote frames.
@@ -114,7 +114,7 @@ func (f *Frame) UnmarshalString(s string) error {
114114
if err != nil {
115115
return fmt.Errorf("invalid remote length: %v: %w", s, err)
116116
}
117-
frame.Length = uint8(dataLength)
117+
frame.Length = uint16(dataLength)
118118
}
119119
*f = frame
120120
return nil
@@ -123,7 +123,7 @@ func (f *Frame) UnmarshalString(s string) error {
123123
if len(dataPart) > 16 || len(dataPart)%2 != 0 {
124124
return fmt.Errorf("invalid data length: %v", s)
125125
}
126-
frame.Length = uint8(len(dataPart) / 2)
126+
frame.Length = uint16(len(dataPart) / 2)
127127
// Parse: Data
128128
decodedData, err := hex.DecodeString(dataPart)
129129
if err != nil {

frame_json.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type jsonFrame struct {
1111
ID uint32 `json:"id"`
1212
Data *string `json:"data"`
13-
Length *uint8 `json:"length"`
13+
Length *uint16 `json:"length"`
1414
Extended *bool `json:"extended"`
1515
Remote *bool `json:"remote"`
1616
}
@@ -69,7 +69,7 @@ func (f *Frame) UnmarshalJSON(jsonData []byte) error {
6969
}
7070
f.Data = Data{}
7171
copy(f.Data[:], data)
72-
f.Length = uint8(len(data))
72+
f.Length = uint16(len(data))
7373
} else {
7474
f.Data = Data{}
7575
f.Length = 0

frame_json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (Frame) Generate(rand *rand.Rand, size int) reflect.Value {
102102
} else {
103103
f.ID = rand.Uint32() & MaxID
104104
}
105-
f.Length = uint8(rand.Intn(9))
105+
f.Length = uint16(rand.Intn(9))
106106
if !f.IsRemote {
107107
_, _ = rand.Read(f.Data[:f.Length])
108108
}

internal/generate/compile.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *compiler) collectDescriptors() {
6262
Name: string(def.Name),
6363
ID: def.MessageID.ToCAN(),
6464
IsExtended: def.MessageID.IsExtended(),
65-
Length: uint8(def.Size),
65+
Length: uint16(def.Size),
6666
SenderNode: string(def.Transmitter),
6767
}
6868
for _, signalDef := range def.Signals {
@@ -73,8 +73,8 @@ func (c *compiler) collectDescriptors() {
7373
IsMultiplexer: signalDef.IsMultiplexerSwitch,
7474
IsMultiplexed: signalDef.IsMultiplexed,
7575
MultiplexerValue: uint(signalDef.MultiplexerSwitch),
76-
Start: uint8(signalDef.StartBit),
77-
Length: uint8(signalDef.Size),
76+
Start: uint16(signalDef.StartBit),
77+
Length: uint16(signalDef.Size),
7878
Scale: signalDef.Factor,
7979
Offset: signalDef.Offset,
8080
Min: signalDef.Minimum,

0 commit comments

Comments
 (0)