diff --git a/src/iec61850/server/model/config_file_parser.c b/src/iec61850/server/model/config_file_parser.c index 98240366..b6e4b5b0 100644 --- a/src/iec61850/server/model/config_file_parser.c +++ b/src/iec61850/server/model/config_file_parser.c @@ -434,10 +434,36 @@ ConfigFileParser_createModelFromConfigFile(FileHandle fileHandle) } } else if (StringUtils_startsWith((char*) lineBuffer, "DE")) { - sscanf((char*) lineBuffer, "DE(%s)", nameString); - terminateString(nameString, ')'); + char* start = strchr(lineBuffer, '('); + + if (start) { + start++; + strncpy(nameString, start, 129); + terminateString(nameString, ')'); + + int indexVal = -1; + char* componentVal = NULL; + + /* check for index */ + char* sep = strchr(nameString, ' '); + + if (sep) { + char* indexStr = sep + 1; + *sep = 0; + + /* check for component */ + char* sep = strchr(indexStr, ' '); - DataSetEntry_create(currentDataSet, nameString, -1, NULL); + if (sep) { + componentVal = sep + 1; + *sep = 0; + } + + indexVal = atoi(indexStr); + } + + DataSetEntry_create(currentDataSet, nameString, indexVal, componentVal); + } } else if (StringUtils_startsWith((char*) lineBuffer, "PA")) { uint32_t vlanPrio; diff --git a/tools/model_generator/genconfig.jar b/tools/model_generator/genconfig.jar index 915ca964..6da279bb 100644 Binary files a/tools/model_generator/genconfig.jar and b/tools/model_generator/genconfig.jar differ diff --git a/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java b/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java index fdbdb40a..b1e04201 100644 --- a/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java +++ b/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java @@ -96,7 +96,7 @@ public class DynamicModelGenerator { output.println("}"); } - private void exportLogicalNodes(PrintStream output, LogicalDevice logicalDevice) { + private void exportLogicalNodes(PrintStream output, LogicalDevice logicalDevice) throws SclParserException { for (LogicalNode logicalNode : logicalDevice.getLogicalNodes()) { output.print("LN(" + logicalNode.getName() + "){\n"); @@ -110,7 +110,7 @@ public class DynamicModelGenerator { return iecString.replace('.', '$'); } - private void exportLogicalNode(PrintStream output, LogicalNode logicalNode, LogicalDevice logicalDevice) { + private void exportLogicalNode(PrintStream output, LogicalNode logicalNode, LogicalDevice logicalDevice) throws SclParserException { for (SettingControl sgcb : logicalNode.getSettingGroupControlBlocks()) { output.print("SG(" + sgcb.getActSG() + " " + sgcb.getNumOfSGs() + ")\n"); @@ -271,7 +271,7 @@ public class DynamicModelGenerator { output.println(");"); } - private void exportDataSet(PrintStream output, DataSet dataSet, LogicalNode logicalNode) { + private void exportDataSet(PrintStream output, DataSet dataSet, LogicalNode logicalNode) throws SclParserException { output.print("DS(" + dataSet.getName() + "){\n"); for (FunctionalConstraintData fcda : dataSet.getFcda()) { String mmsVariableName = ""; @@ -291,6 +291,40 @@ public class DynamicModelGenerator { if (fcda.getDaName() != null) mmsVariableName += "$" + toMmsString(fcda.getDaName()); + /* check for array index and component */ + + int arrayStart = mmsVariableName.indexOf('('); + + String variableName = mmsVariableName; + int arrayIndex = -1; + String componentName = null; + + if (arrayStart != -1) { + variableName = mmsVariableName.substring(0, arrayStart); + + int arrayEnd = mmsVariableName.indexOf(')'); + + String arrayIndexStr = mmsVariableName.substring(arrayStart + 1, arrayEnd); + arrayIndex = Integer.parseInt(arrayIndexStr); + + if (arrayIndex < 0) { + throw new SclParserException("Array index out of range in data set entry definition"); + } + + String componentNamePart = mmsVariableName.substring(arrayEnd + 1); + + if ((componentNamePart != null) && (componentNamePart.length() > 0)) { + if (componentNamePart.charAt(0) == '$') { + componentNamePart = componentNamePart.substring(1); + } + + if ((componentNamePart != null) && (componentNamePart.length() > 0)) + componentName = componentNamePart; + } + } + + /* check for LD name */ + String logicalDeviceName = null; if (fcda.getLdInstance() != null) { @@ -300,12 +334,18 @@ public class DynamicModelGenerator { } } + if (logicalDeviceName != null) + variableName = logicalDeviceName + "/" + variableName; - if (logicalDeviceName != null) - output.print("DE(" + logicalDeviceName + "/" + mmsVariableName + ");\n"); - else - output.print("DE(" + mmsVariableName + ");\n"); - + if (variableName != null && arrayIndex != -1 && componentName != null) { + output.print("DE(" + variableName + " " + arrayIndex + " " + componentName + ");\n"); + } + else if (variableName != null && arrayIndex != -1) { + output.print("DE(" + variableName + " " + arrayIndex + ");\n"); + } + else if (variableName != null) { + output.print("DE(" + variableName + ");\n"); + } } output.println("}"); } diff --git a/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java b/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java index 6198bb76..18460784 100644 --- a/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java +++ b/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java @@ -1566,6 +1566,8 @@ public class StaticModelGenerator { if (fcda.getDaName() != null) mmsVariableName += "$" + toMmsString(fcda.getDaName()); + /* check for array index and component */ + int arrayStart = mmsVariableName.indexOf('('); String variableName = mmsVariableName;