diff --git a/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/C_Structures.cs b/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/C_Structures.cs index e4c5cfb7..50f6784a 100644 --- a/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/C_Structures.cs +++ b/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/C_Structures.cs @@ -696,7 +696,124 @@ namespace ModelGenerator.C_Structures } } + public class C_SMVControlBlockStructure + { + public SMVControl SMVControl; + public SclSMV SclSMV; + public string lnPrefix; + public string parent; + public string rptId; + public string externName; + public int reportNumber = -1; + public string index; + public bool hasOwner = false; + public string sibling = "NULL"; + public string phyComAddrName = "NULL"; + private string smvString = ""; + private string min = "-1"; + private string max = "-1"; + + public C_SMVControlBlockStructure() + { + } + public string ExternNameToString() + { + return "extern SMVControlBlock " + externName + ";"; + } + + private void LoadPhyComAddrName() + { + if (SclSMV != null) + { + if (SclSMV.SclAddress != null) + { + phyComAddrName = lnPrefix + "_smv" + reportNumber + "_address"; + + smvString += "\nstatic PhyComAddress " + phyComAddrName + " = {\n"; + smvString += " " + SclSMV.SclAddress.AppId + ",\n"; + smvString += " " + SclSMV.SclAddress.VlanPriority + ",\n"; + smvString += " " + SclSMV.SclAddress.VlanId + ",\n"; + smvString += " {"; + + for (int i = 0; i < 6; i++) + { + smvString += "0x" + (SclSMV.SclAddress.MacAddress[i]).ToString("x1"); + if (i == 5) + smvString += "}\n"; + else + smvString += ", "; + } + + smvString += "};\n\n"; + } + } + } + + public override string ToString() + { + LoadPhyComAddrName(); + + string cText = smvString; + cText += "SMVControlBlock " + externName + " = {\n"; + cText += " &" + parent + ",\n"; + cText += " \"" + SMVControl.Name + index + "\",\n"; + + if (SMVControl.SclSMVControl.Desc!= null) + cText += " \"" + SclSMV.SclAddress.AppId + "\",\n"; + else + cText += " NULL,\n"; + + + if (SMVControl.SclSMVControl.DataSet != null) + cText += " \"" + SMVControl.SclSMVControl.DataSet + "\",\n"; + else + cText += " NULL,\n"; + + if(SMVControl.SclSMVControl.ConfRev != -1) + cText += " " + SMVControl.SclSMVControl.ConfRev + ",\n"; + if(SMVControl.SclSMVControl.SmvID != null) + cText += " " + SMVControl.SclSMVControl.SmvID + ",\n"; + cText += " " + SMVControl.SclSMVControl.Multicast.ToString() + ",\n"; + if(SMVControl.SclSMVControl.SmpRate != -1) + cText += " " + SMVControl.SclSMVControl.SmpRate + ",\n"; + if(SMVControl.SclSMVControl.NofASDU != -1) + cText += " " + SMVControl.SclSMVControl.NofASDU + ",\n"; + if(SMVControl.SclSMVControl.SmpMod != null) + cText += " " + SMVControl.SclSMVControl.SmpMod + ",\n"; + if(SMVControl.SclSMVControl.SecurityEnabled != null) + cText += " " + SMVControl.SclSMVControl.SecurityEnabled + ",\n"; + + if(SMVControl.SclSMVControl.SclSmvOpts != null) + { + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.RefreshTime + ",\n"; + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.SampleRate + ",\n"; + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.DataSet + ",\n"; + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.Security + ",\n"; + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.SynchSourceId + ",\n"; + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.DataRef + ",\n"; + cText += " " + SMVControl.SclSMVControl.SclSmvOpts.SampleSynchronized + ",\n"; + } + + if (phyComAddrName == "NULL") + cText += " " + phyComAddrName + ",\n"; + else + cText += " &" + phyComAddrName + ",\n"; + + //cText += " " + min + ",\n"; + //cText += " " + max + ",\n"; + + + //if (sibling == "NULL") + // cText += " " + sibling + "\n"; + //else + // cText += " &" + sibling + "\n"; + + cText += "};"; + + return cText; + } + } public class C_ReportControlBlockStructure { public ReportControl ReportControl; diff --git a/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/StaticModelGenerator.cs b/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/StaticModelGenerator.cs index 53e3f03c..65c300e8 100644 --- a/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/StaticModelGenerator.cs +++ b/tools/model_generator_dotnet/ModelGenerator/ModelGenerator/src/StaticModelGenerator.cs @@ -25,6 +25,7 @@ namespace ModelGenerator List c_LogicalDeviceStructures = new List(); List c_ReportContorlBlockStructures = new List(); List c_GSEControlBlockStructures = new List(); + List c_SMVControlBlockStructures = new List(); C_SettingGroupStructure c_SettingGroupControlStructure = null; List c_LogControlBlockStructures = new List(); List c_LogStructures = new List(); @@ -246,6 +247,20 @@ namespace ModelGenerator cOut.WriteLine(); + foreach (C_SMVControlBlockStructure c_SMVContorlBlockStructure in c_SMVControlBlockStructures) + { + cOut.WriteLine(c_SMVContorlBlockStructure.ExternNameToString()); + } + + cOut.WriteLine(); + + foreach (C_SMVControlBlockStructure c_SMVContorlBlockStructure in c_SMVControlBlockStructures) + { + cOut.WriteLine(c_SMVContorlBlockStructure.ToString()); + } + + cOut.WriteLine(); + foreach (C_LogControlBlockStructure c_LogControlBlockStructure in c_LogControlBlockStructures) { cOut.WriteLine(c_LogControlBlockStructure.ExternNameToString()); @@ -774,6 +789,19 @@ namespace ModelGenerator c_GSEControlBlockStructures.Add(c_GSEContorlBlockStructure); } + private void addSMVControlBlockInstance(string lnPrefix, SMVControl smvControl, SclSMV sclSMV, int smvNumber) + { + C_SMVControlBlockStructure c_SMVContorlBlockStructure = new C_SMVControlBlockStructure(); + c_SMVContorlBlockStructure.SMVControl = smvControl; + c_SMVContorlBlockStructure.externName = lnPrefix + "_smv" + smvNumber.ToString(); + c_SMVContorlBlockStructure.parent = lnPrefix; + c_SMVContorlBlockStructure.reportNumber = smvNumber; + c_SMVContorlBlockStructure.hasOwner = hasOwner; + c_SMVContorlBlockStructure.lnPrefix = lnPrefix; + c_SMVContorlBlockStructure.SclSMV = sclSMV; + + c_SMVControlBlockStructures.Add(c_SMVContorlBlockStructure); + } private void addSettingGroulBlockInstance(string lnPrefix, SclSettingControl settingControl) { c_SettingGroupControlStructure = new C_SettingGroupStructure(); @@ -862,6 +890,41 @@ namespace ModelGenerator c_IEDModelStructure.gseCBs = c_GSEControlBlockStructures.First().externName; } + + int smvNumber = 0; + foreach (SMVControl sMVControl in logicalNode.SMVControls) + { + SclSMV sclSMV = connectedAP.SMVs.Find(x => x.CbName == sMVControl.Name); + + if (sclSMV != null) + { + addSMVControlBlockInstance(c_LogicalNodeStructure.objRef, sMVControl, sclSMV, smvNumber); + + gseNumber++; + + } + else + { + Console.WriteLine("GSE not found for GoCB " + sMVControl.Name); + } + } + + int smvIndex = 0; + + if (c_SMVControlBlockStructures.Count > 0) + { + foreach (C_SMVControlBlockStructure c_SMVContorlBlockStructure in c_SMVControlBlockStructures) + { + if (c_SMVContorlBlockStructure != c_SMVControlBlockStructures.Last()) + { + c_SMVContorlBlockStructure.sibling = c_SMVControlBlockStructures[gseIndex + 1].externName; + } + + smvIndex++; + } + + c_IEDModelStructure.svCBs = c_SMVControlBlockStructures.First().externName; + } } int lcbNumber = 0;