diff --git a/cmd/version.go b/cmd/version.go index a6b8ae8..18529a7 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -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{ diff --git a/examples/multiplexed_signal.dbc b/examples/multiplexed_signal.dbc index b70c28a..edd68a6 100644 --- a/examples/multiplexed_signal.dbc +++ b/examples/multiplexed_signal.dbc @@ -1,6 +1,6 @@ VERSION "1.0" -NS_ : +NS_ : NS_DESC_ CM_ BA_DEF_ @@ -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; diff --git a/examples/simple.dbc b/examples/simple.dbc index 42f82b8..c878821 100644 --- a/examples/simple.dbc +++ b/examples/simple.dbc @@ -38,8 +38,6 @@ 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"; @@ -47,15 +45,22 @@ 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"; diff --git a/pkg/dbc_writer.go b/pkg/dbc_writer.go index e564d36..5103175 100644 --- a/pkg/dbc_writer.go +++ b/pkg/dbc_writer.go @@ -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() @@ -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 } @@ -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+";")