Skip to content

Commit

Permalink
(fix) compatibility with candb++
Browse files Browse the repository at this point in the history
  • Loading branch information
FerroO2000 committed Jul 4, 2023
1 parent 3b23dc7 commit 31402f6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra"
)

const version = "v0.3.2"
const version = "v0.3.3"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Expand Down
28 changes: 18 additions & 10 deletions examples/multiplexed_signal.dbc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
VERSION "1.0"

NS_ :
NS_ :
NS_DESC_
CM_
BA_DEF_
Expand Down Expand Up @@ -28,29 +28,37 @@ NS_ :
BU_SG_REL_
BU_EV_REL_
BU_BO_REL_
SG_MUL_VAL_

BS_ :

BU_ : Node1

BO_ 2024 OBD2: 8 Node1
SG_ Service M : 11|4@1+ (1,0) [0|15] "" Vector__XXX
SG_ ExtendedMuxSignalName m1M : 23|8@1+ (1,0) [0|255] "" Vector__XXX
SG_ MultiplexedSignalName m2 : 23|8@1+ (1,0) [0|255] "" Vector__XXX
SG_ VehicleSpeed m13 : 31|8@1+ (1,0) [0|255] "km/h" Vector__XXX
SG_ ThrottlePosition m17 : 31|8@1+ (0.39216,0) [0|100] "%" Vector__XXX
SG_ ExtendedMuxSignalName m1M : 23|8@1+ (1,0) [0|255] "" Vector__XXX
SG_ Service M : 11|4@1+ (1,0) [0|15] "" Vector__XXX


SG_MUL_VAL_ 2024 MultiplexedSignalName Service 2-2;
SG_MUL_VAL_ 2024 VehicleSpeed ExtendedMuxSignalName 13-13;
SG_MUL_VAL_ 2024 ThrottlePosition ExtendedMuxSignalName 17-17;
SG_MUL_VAL_ 2024 ExtendedMuxSignalName Service 1-1;

CM_ BU_ Node1 "Node1 desc";
CM_ BO_ 2024 "desc OBD2";
CM_ SG_ 2024 Service "desc Service";
CM_ SG_ 2024 MultiplexedSignalName "desc S2";
CM_ SG_ 2024 ExtendedMuxSignalName "desc S1";
CM_ SG_ 2024 VehicleSpeed "desc VehicleSpeed";
CM_ SG_ 2024 ThrottlePosition "desc ThrottlePosition";
CM_ SG_ 2024 VehicleSpeed "desc VehicleSpeed";

BA_DEF_ BO_ "MsgPeriodMS" INT 0 65535;
BA_DEF_ SG_ "TestFloatAtt" FLOAT 0 25.75;
BA_DEF_ SG_ "SPN" INT 0 524287;
BA_DEF_DEF_ "MsgPeriodMS" 0;
BA_DEF_DEF_ "SPN" 0;
BA_DEF_DEF_ "TestFloatAtt" 1.5;
BA_ "TestFloatAtt" SG_ 2024 VehicleSpeed 10.5;
BA_ "SPN" SG_ 2024 VehicleSpeed 190;

SG_MUL_VAL_ 2024 MultiplexedSignalName Service 2-2;
SG_MUL_VAL_ 2024 VehicleSpeed ExtendedMuxSignalName 13-13;
SG_MUL_VAL_ 2024 ThrottlePosition ExtendedMuxSignalName 17-17;
SG_MUL_VAL_ 2024 ExtendedMuxSignalName Service 1-1;
13 changes: 9 additions & 4 deletions examples/simple.dbc
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,29 @@ BO_ 2364540158 EEC1: 8 Vector__XXX
SG_ Engine_Status : 0|2@1+ (0,0) [0|2] "status" Vector__XXX
SG_ Engine_Speed : 24|16@0+ (0.125,0) [0|8031.875] "rpm" Node1,Node2

VAL_ 2364540158 Engine_Status 0 "Off" 1 "Idle" 2 "Running";


CM_ BU_ Node1 "Node1 desc";
CM_ BU_ Node2 "Node2 desc";
CM_ BO_ 2364540158 "desc 0 (period: 100 ms)";
CM_ SG_ 2364540158 Engine_Speed "desc 1";
CM_ SG_ 2364540158 Engine_Status "desc 2";

BA_DEF_ "FloatAtt" FLOAT 0 25.75;
BA_DEF_ BU_ "TestString" STRING ;
BA_DEF_ BO_ "VFrameFormat" ENUM "StandardCAN","ExtendedCAN","reserved","J1939PG";
BA_DEF_ BO_ "MsgPeriodMS" INT 0 65535;
BA_DEF_ SG_ "SPN" INT 0 524287;
BA_DEF_ SG_ "TestFloatAtt" FLOAT 0 25.75;
BA_DEF_DEF_ "FloatAtt" 1.5;
BA_DEF_DEF_ "TestString" "";
BA_DEF_DEF_ "VFrameFormat" 3;
BA_DEF_DEF_ "VFrameFormat" "J1939PG";
BA_DEF_DEF_ "MsgPeriodMS" 0;
BA_DEF_DEF_ "SPN" 0;
BA_DEF_DEF_ "TestFloatAtt" 1.5;
BA_ "TestString" BU_ Node2 "test";
BA_ "VFrameFormat" BO_ 2364540158 0;
BA_ "MsgPeriodMS" BO_ 2364540158 100;
BA_ "VFrameFormat" BO_ 2364540158 0;
BA_ "SPN" SG_ 2364540158 Engine_Speed 190;
BA_ "TestFloatAtt" SG_ 2364540158 Engine_Speed 10.5;

VAL_ 2364540158 Engine_Status 0 "Off" 1 "Idle" 2 "Running";
13 changes: 6 additions & 7 deletions pkg/dbc_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ func (w *DBCWriter) Write(file *os.File, canModel *CanModel) error {
w.writeMessage(f, msg)
}

w.writeBitmaps(f, canModel)
f.newLine()

w.writeMuxGroup(f, canModel.Messages)
f.newLine()

w.writeComments(f, canModel)
f.newLine()

Expand All @@ -80,6 +74,11 @@ func (w *DBCWriter) Write(file *os.File, canModel *CanModel) error {
w.writeMessageAttributeAssignments(f, canModel.getMessageAttributes())
w.writeSignalAttributeAssignments(f, canModel.getSignalAttributes())

f.newLine()
w.writeBitmaps(f, canModel)

w.writeMuxGroup(f, canModel.Messages)

return nil
}

Expand Down Expand Up @@ -296,7 +295,7 @@ func (w *DBCWriter) writeAttributeDefaultValue(f *file, att *Attribute) {
case attributeTypeFloat:
defValue = formatFloat(att.Float.Default)
case attributeTypeEnum:
defValue = formatInt(att.Enum.defaultIdx)
defValue = formatString(att.Enum.Default)
}

f.print(sym.DBCAttDefaultVal, formatString(att.attributeName), defValue+";")
Expand Down

0 comments on commit 31402f6

Please sign in to comment.