From a3134236840493344665d34cb48a3d8f15cbb7c8 Mon Sep 17 00:00:00 2001 From: FerroO2000 Date: Sat, 16 Mar 2024 15:33:54 +0100 Subject: [PATCH] fix indentation for global signal enums --- cmd/version.go | 2 +- examples/simple_enum_ref.dbc | 12 ++++++------ pkg/can_model.go | 16 +++++++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cmd/version.go b/cmd/version.go index badafb2..2820a5a 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v0.5.0" +const version = "v0.5.1" // versionCmd represents the version command var versionCmd = &cobra.Command{ diff --git a/examples/simple_enum_ref.dbc b/examples/simple_enum_ref.dbc index c53ea72..4e00c82 100644 --- a/examples/simple_enum_ref.dbc +++ b/examples/simple_enum_ref.dbc @@ -52,26 +52,26 @@ BA_DEF_ BO_ "VFrameFormat" ENUM "StandardCAN","ExtendedCAN","reserved","J1939PG" BA_DEF_ BO_ "MsgPeriodMS" INT 0 65535; BA_DEF_ BO_ "GenMsgCycleTime" INT 0 1000; BA_DEF_ BO_ "GenMsgSendType" ENUM "NoMsgSendType","Cyclic","IfActive","cyclicIfActive","NotUsed"; -BA_DEF_ SG_ "SPN" INT 0 524287; BA_DEF_ SG_ "TestFloatAtt" FLOAT 0 25.75; BA_DEF_ SG_ "GenSigSendType" ENUM "NoSigSendType","Cyclic","OnWrite","OnWriteWithRepetition","OnChange","OnChangeWithRepetition","IfActive","IfActiveWithRepetition","NotUsed"; -BA_DEF_DEF_ "FloatAtt" 1.5; +BA_DEF_ SG_ "SPN" INT 0 524287; BA_DEF_DEF_ "Baudrate" 1000000; +BA_DEF_DEF_ "FloatAtt" 1.5; BA_DEF_DEF_ "TestString" ""; -BA_DEF_DEF_ "VFrameFormat" "J1939PG"; -BA_DEF_DEF_ "MsgPeriodMS" 0; BA_DEF_DEF_ "GenMsgCycleTime" 0; BA_DEF_DEF_ "GenMsgSendType" "NoMsgSendType"; +BA_DEF_DEF_ "VFrameFormat" "J1939PG"; +BA_DEF_DEF_ "MsgPeriodMS" 0; BA_DEF_DEF_ "SPN" 0; BA_DEF_DEF_ "TestFloatAtt" 1.5; BA_DEF_DEF_ "GenSigSendType" "NoSigSendType"; BA_ "TestString" BU_ Node2 "test"; +BA_ "GenMsgSendType" BO_ 2364540158 2; BA_ "VFrameFormat" BO_ 2364540158 0; BA_ "MsgPeriodMS" BO_ 2364540158 100; BA_ "GenMsgCycleTime" BO_ 2364540158 10; -BA_ "GenMsgSendType" BO_ 2364540158 2; BA_ "SPN" SG_ 2364540158 Engine_Speed 190; BA_ "TestFloatAtt" SG_ 2364540158 Engine_Speed 10.5; BA_ "GenSigSendType" SG_ 2364540158 Engine_Status 1; -VAL_ 2364540158 Engine_Status 1 "Idle" 2 "Running" 0 "Off"; +VAL_ 2364540158 Engine_Status 0 "Off" 1 "Idle" 2 "Running"; diff --git a/pkg/can_model.go b/pkg/can_model.go index c839769..872124b 100644 --- a/pkg/can_model.go +++ b/pkg/can_model.go @@ -116,6 +116,7 @@ func (c *CanModel) Init() { } } } + for _, msg := range c.Messages { for attName := range msg.Attributes { if msgAtt, ok := c.MessageAttributes[attName]; ok { @@ -129,13 +130,14 @@ func (c *CanModel) Init() { sigAtt.assignSignal(msg.ID, sig) } - // check if signal has an enum_ref, if so, attach the global signal_enum - if len(sig.Enum) == 0 && len(sig.EnumRef) > 0 { - if enum, ok := c.SignalEnums[sig.EnumRef]; ok { - sig.Enum = enum - } else { - fmt.Printf("WARNING: signal '%s' -> enum_ref '%s' is not defined in global signal enums -> SKIPPED\n", sig.signalName, sig.EnumRef) - } + } + + // check if signal has an enum_ref, if so, attach the global signal_enum + if len(sig.Enum) == 0 && len(sig.EnumRef) > 0 { + if enum, ok := c.SignalEnums[sig.EnumRef]; ok { + sig.Enum = enum + } else { + fmt.Printf("WARNING: signal '%s' -> enum_ref '%s' is not defined in global signal enums -> SKIPPED\n", sig.signalName, sig.EnumRef) } } }