diff --git a/examples/server_example_dynamic/server_example_dynamic.c b/examples/server_example_dynamic/server_example_dynamic.c index 1d01c40..2bab1f0 100644 --- a/examples/server_example_dynamic/server_example_dynamic.c +++ b/examples/server_example_dynamic/server_example_dynamic.c @@ -83,9 +83,8 @@ int main(int argc, char** argv) { while (running) { IedServer_lockDataModel(iedServer); - MmsValue_setFloat(temperatureValue->mmsValue, val); - MmsValue_setUtcTimeMs(temperatureTimestamp->mmsValue, Hal_getTimeInMs()); - IedServer_updateAttributeValue(iedServer, temperatureValue, temperatureValue->mmsValue); + IedServer_updateUTCTimeAttributeValue(iedServer, temperatureTimestamp, Hal_getTimeInMs()) + IedServer_updateFloatAttributeValue(iedServer, temperatureValue, val); IedServer_unlockDataModel(iedServer); diff --git a/src/iec61850/server/mms_mapping/reporting.c b/src/iec61850/server/mms_mapping/reporting.c index ee60618..2ce1a3f 100644 --- a/src/iec61850/server/mms_mapping/reporting.c +++ b/src/iec61850/server/mms_mapping/reporting.c @@ -57,7 +57,7 @@ ReportBuffer_create(void) self->memoryBlockSize = CONFIG_REPORTING_DEFAULT_REPORT_BUFFER_SIZE; self->memoryBlock = (uint8_t*) GLOBAL_MALLOC(self->memoryBlockSize); self->reportsCount = 0; - self->isOverflow = false; + self->isOverflow = true; return self; } @@ -1266,8 +1266,10 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme if (rc->buffered) { - if (rc->isResync == false) + if (rc->isResync == false) { rc->reportBuffer->nextToTransmit = rc->reportBuffer->oldestReport; + rc->reportBuffer->isOverflow = true; + } rc->isResync = false; } @@ -1308,6 +1310,7 @@ Reporting_RCBWriteAccessHandler(MmsMapping* self, ReportControl* rc, char* eleme if (rc->buffered) { rc->reportBuffer->isOverflow = true; + rc->isResync = false; } else { GLOBAL_FREEMEM(rc->inclusionFlags); diff --git a/src/mms/iso_mms/server/mms_file_service.c b/src/mms/iso_mms/server/mms_file_service.c index 74c60d5..75ee505 100644 --- a/src/mms/iso_mms/server/mms_file_service.c +++ b/src/mms/iso_mms/server/mms_file_service.c @@ -517,9 +517,9 @@ addFileEntriesToResponse(uint8_t* buffer, int bufPos, int maxBufSize, char* dire } static void -createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, char* directoryName, char* continueAfterFileName) +createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, int maxPduSize, char* directoryName, char* continueAfterFileName) { - int maxSize = response->maxSize - 3; /* reserve space for moreFollows */ + int maxSize = maxPduSize - 3; /* reserve space for moreFollows */ uint8_t* buffer = response->buffer; bool moreFollows = false; @@ -533,6 +533,8 @@ createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, char* direc continueAfterFileName = NULL; } + printf("createFileDirectoryResponse: maxSize:%i\n", maxSize); + tempCurPos = addFileEntriesToResponse(buffer, tempCurPos, maxSize, directoryName, continueAfterFileName, &moreFollows); if (tempCurPos < 0) { @@ -584,6 +586,8 @@ createFileDirectoryResponse(uint32_t invokeId, ByteBuffer* response, char* direc bufPos = BerEncoder_encodeBoolean(0x81, moreFollows, buffer, bufPos); response->size = bufPos; + + printf("createFileDirectoryResponse: maxSize:%i response->isze:%i\n", maxSize, response->size); } void @@ -708,7 +712,9 @@ mmsServer_handleFileDirectoryRequest( } - createFileDirectoryResponse(invokeId, response, filename, continueAfter); + int maxPduSize = connection->maxPduSize; + + createFileDirectoryResponse(invokeId, response, maxPduSize, filename, continueAfter); } #endif /* MMS_FILE_SERVICE == 1 */ diff --git a/tools/model_generator/build-modelviewer.sh b/tools/model_generator/build-modelviewer.sh new file mode 100755 index 0000000..42d27fb --- /dev/null +++ b/tools/model_generator/build-modelviewer.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +mkdir build + +find src/ -name "*.java" > listFile.tmp + +javac -target 1.6 -source 1.6 -d build @listFile.tmp + +jar cfm modelviewer.jar manifest-modelviewer.mf -C build/ com/ + +rm listFile.tmp +rm -r build diff --git a/tools/model_generator/manifest-modelviewer.mf b/tools/model_generator/manifest-modelviewer.mf new file mode 100644 index 0000000..dd837e7 --- /dev/null +++ b/tools/model_generator/manifest-modelviewer.mf @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +Main-Class: com.libiec61850.tools.ModelViewer diff --git a/tools/model_generator/src/com/libiec61850/scl/SclParser.java b/tools/model_generator/src/com/libiec61850/scl/SclParser.java index 8ed6b2c..4ed22e5 100644 --- a/tools/model_generator/src/com/libiec61850/scl/SclParser.java +++ b/tools/model_generator/src/com/libiec61850/scl/SclParser.java @@ -62,28 +62,47 @@ public class SclParser { private List ieds; private Communication communication; private TypeDeclarations typeDeclarations; - private Node scl; + + public static boolean withOutput = true; + + public TypeDeclarations getTypeDeclarations() { + return typeDeclarations; + } - public SclParser(InputStream stream) throws SclParserException { + private Node scl; + + public SclParser(InputStream stream, boolean withOutput) throws SclParserException { + this.withOutput = withOutput; + Document doc = parseXmlDocument(stream); scl = getRootNode(doc); - System.out.println("parse data type templates ..."); + if (withOutput) + System.out.println("parse data type templates ..."); + typeDeclarations = parseTypeDeclarations(); - System.out.println("parse IED section ..."); + if (withOutput) + System.out.println("parse IED section ..."); parseIedSections(); - System.out.println("parse communication section ..."); + if (withOutput) + System.out.println("parse communication section ..."); + communication = parseCommunicationSection(); if (communication == null) - System.out.println("WARNING: No communication section found!"); + if (withOutput) + System.out.println("WARNING: No communication section found!"); } - public IED getIedByteName(String iedName) { + public SclParser(InputStream stream) throws SclParserException { + this(stream, true); + } + + public IED getIedByName(String iedName) { for (IED ied : ieds) { if (ied.getName().equals(iedName)) return ied; @@ -280,7 +299,8 @@ public class SclParser { if (connectedAP.getApName().equals(accessPointName)) { - System.out.println("Found connectedAP " + accessPointName + " for IED " + ied.getName()); + if (withOutput) + System.out.println("Found connectedAP " + accessPointName + " for IED " + ied.getName()); return connectedAP; } diff --git a/tools/model_generator/src/com/libiec61850/scl/model/DataObject.java b/tools/model_generator/src/com/libiec61850/scl/model/DataObject.java index 7a86176..818bfad 100644 --- a/tools/model_generator/src/com/libiec61850/scl/model/DataObject.java +++ b/tools/model_generator/src/com/libiec61850/scl/model/DataObject.java @@ -82,12 +82,9 @@ public class DataObject implements DataModelNode { for (DataAttributeDefinition daDefinition : daDefinitions) { - if (daDefinition.getFc() == FunctionalConstraint.SE) { - - System.out.println("Add SG DA for corresponding SE DA: "); - this.dataAttributes.add(new DataAttribute(daDefinition, typeDeclarations, FunctionalConstraint.SG, this)); - } - + if (daDefinition.getFc() == FunctionalConstraint.SE) + this.dataAttributes.add(new DataAttribute(daDefinition, typeDeclarations, FunctionalConstraint.SG, this)); + this.dataAttributes.add(new DataAttribute(daDefinition, typeDeclarations, null, this)); diff --git a/tools/model_generator/src/com/libiec61850/scl/types/SclType.java b/tools/model_generator/src/com/libiec61850/scl/types/SclType.java index 04c9e45..f6edac4 100644 --- a/tools/model_generator/src/com/libiec61850/scl/types/SclType.java +++ b/tools/model_generator/src/com/libiec61850/scl/types/SclType.java @@ -26,7 +26,7 @@ import org.w3c.dom.Node; import com.libiec61850.scl.ParserUtils; import com.libiec61850.scl.SclParserException; -public class SclType { +public abstract class SclType { private String id = null; private String description; diff --git a/tools/model_generator/src/com/libiec61850/scl/types/TypeDeclarations.java b/tools/model_generator/src/com/libiec61850/scl/types/TypeDeclarations.java index 4d9999a..2931ce1 100644 --- a/tools/model_generator/src/com/libiec61850/scl/types/TypeDeclarations.java +++ b/tools/model_generator/src/com/libiec61850/scl/types/TypeDeclarations.java @@ -68,5 +68,11 @@ public class TypeDeclarations { return null; } + + public List getTypeDeclarations() { + return typeDeclarations; + } + + } diff --git a/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java b/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java index 1297c62..a7fd660 100644 --- a/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java +++ b/tools/model_generator/src/com/libiec61850/tools/DynamicModelGenerator.java @@ -62,7 +62,7 @@ public class DynamicModelGenerator { if (iedName == null) ied = sclParser.getFirstIed(); else - ied = sclParser.getIedByteName(iedName); + ied = sclParser.getIedByName(iedName); if (ied == null) throw new SclParserException("No data model present in SCL file! Exit."); diff --git a/tools/model_generator/src/com/libiec61850/tools/ModelViewer.java b/tools/model_generator/src/com/libiec61850/tools/ModelViewer.java new file mode 100644 index 0000000..d364959 --- /dev/null +++ b/tools/model_generator/src/com/libiec61850/tools/ModelViewer.java @@ -0,0 +1,254 @@ +package com.libiec61850.tools; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.List; + +import com.libiec61850.scl.SclParser; +import com.libiec61850.scl.SclParserException; +import com.libiec61850.scl.model.AccessPoint; +import com.libiec61850.scl.model.DataAttribute; +import com.libiec61850.scl.model.DataObject; +import com.libiec61850.scl.model.IED; +import com.libiec61850.scl.model.LogicalDevice; +import com.libiec61850.scl.model.LogicalNode; +import com.libiec61850.scl.model.Server; +import com.libiec61850.scl.types.DataAttributeType; +import com.libiec61850.scl.types.DataObjectType; +import com.libiec61850.scl.types.EnumerationType; +import com.libiec61850.scl.types.LogicalNodeType; +import com.libiec61850.scl.types.SclType; +import com.libiec61850.scl.types.TypeDeclarations; + +public class ModelViewer { + + private static void showTypes(InputStream stream, String icdFile, PrintStream output, String iedName, String accessPointName) + throws SclParserException { + + SclParser sclParser = new SclParser(stream, false); + + TypeDeclarations typeDecl = sclParser.getTypeDeclarations(); + + for (SclType type : typeDecl.getTypeDeclarations()) { + output.print(type.getId()); + + if (type.getClass() == LogicalNodeType.class) + output.print(" : LogicalNode"); + else if (type.getClass() == DataObjectType.class) + output.print(" : DataObject"); + else if (type.getClass() == DataAttributeType.class) + output.print(" : DataAttribute"); + else if (type.getClass() == EnumerationType.class) + output.print(" : Enumeration"); + + output.println(); + } + } + + private static void printSubAttributes(DataAttribute attribute, PrintStream output, String indent, String add) { + + if (attribute.getSubDataAttributes() != null) { + + for (DataAttribute attr : attribute.getSubDataAttributes()) { + output.println(indent + add + attr.getName()); + + printSubAttributes(attr, output, indent + add, add); + } + } + } + + private static void printModelStructure(InputStream stream, String icdFile, PrintStream output, String iedName, String accessPointName) + throws SclParserException { + + SclParser sclParser = new SclParser(stream, false); + + IED ied = null; + + if (iedName == null) + ied = sclParser.getFirstIed(); + else + ied = sclParser.getIedByName(iedName); + + AccessPoint ap = ied.getFirstAccessPoint(); + + Server server = ap.getServer(); + + List devices = server.getLogicalDevices(); + + for (LogicalDevice device : devices) { + output.println(device.getInst()); + + List lNodes = device.getLogicalNodes(); + + for (LogicalNode lNode : lNodes) { + output.println(" " + lNode.getName()); + + for (DataObject dObject : lNode.getDataObjects()) { + output.println(" " + dObject.getName()); + + for (DataAttribute dAttribute : dObject.getDataAttributes()) { + output.println(" " + dAttribute.getName() + " [" + dAttribute.getFc().toString() + "]"); + + printSubAttributes(dAttribute, output, " ", " "); + } + + } + } + } + + } + + + private static void printSubAttributeList(DataAttribute attribute, PrintStream output, String prefix) { + + if (attribute.getSubDataAttributes() != null) { + + for (DataAttribute attr : attribute.getSubDataAttributes()) { + + String nextPrefix = prefix + "." + attr.getName(); + + output.println(nextPrefix + " [" + attr.getFc() + "]"); + + printSubAttributeList(attr, output, nextPrefix); + } + } + } + + + private static void printAttributeList(InputStream stream, String icdFile, PrintStream output, String iedName, String accessPointName) + throws SclParserException { + + SclParser sclParser = new SclParser(stream, false); + + IED ied = null; + + if (iedName == null) + ied = sclParser.getFirstIed(); + else + ied = sclParser.getIedByName(iedName); + + AccessPoint ap = ied.getFirstAccessPoint(); + + Server server = ap.getServer(); + + List devices = server.getLogicalDevices(); + + + + for (LogicalDevice device : devices) { + + String devPrefix = ied.getName() + device.getInst() + "/"; + + List lNodes = device.getLogicalNodes(); + + for (LogicalNode lNode : lNodes) { + String lNodePrefix = devPrefix + lNode.getName(); + + for (DataObject dObject : lNode.getDataObjects()) { + + String dOPrefix = lNodePrefix + "." + dObject.getName(); + + for (DataAttribute dAttribute : dObject.getDataAttributes()) { + + String daPrefix = dOPrefix + "." + dAttribute.getName(); + + output.println(daPrefix + " [" + dAttribute.getFc().toString() + "]"); + + printSubAttributeList(dAttribute, output, daPrefix); + } + + } + } + } + + } + + public static void main(String[] args) throws FileNotFoundException { + + if (args.length < 1) { + System.out.println("SCL model viewer"); + System.out.println("Usage: scltool [-ied ] [-ap ] [-t] [-s] [-a] []"); + System.out.println(" -ied select IED"); + System.out.println(" -ap select AP"); + System.out.println(" -t print type list"); + System.out.println(" -s print IED device model structure"); + System.out.println(" -a print list of data attributes (object references)"); + System.exit(1); + } + + String icdFile = args[0]; + + PrintStream outputStream = System.out; + + String accessPointName = null; + String iedName = null; + + boolean printTypeList = false; + boolean printModelStructure = false; + boolean printDataAttribtues = false; + + if (args.length > 1) { + for (int i = 1; i < args.length; i++) { + if (args[i].equals("-ap")) { + accessPointName = args[i+1]; + + System.out.println("Select access point " + accessPointName); + + i++; + } + else if (args[i].equals("-ied")) { + iedName = args[i+1]; + + System.out.println("Select IED " + iedName); + + i++; + + } + else if (args[i].equals("-t")) { + printTypeList = true; + + i++; + + } + else if (args[i].equals("-s")) { + printModelStructure = true; + + i++; + + } + else if (args[i].equals("-a")) { + printDataAttribtues = true; + + i++; + + } + else { + outputStream = new PrintStream(new FileOutputStream(new File(args[i]))); + } + } + + } + + InputStream stream = new FileInputStream(icdFile); + + try { + if (printTypeList) + showTypes(stream, icdFile, outputStream, iedName, accessPointName); + + if (printModelStructure) + printModelStructure(stream, icdFile, outputStream, iedName, accessPointName); + + if (printDataAttribtues) + printAttributeList(stream, icdFile, outputStream, iedName, accessPointName); + + + } catch (SclParserException e) { + System.err.println("ERROR: " + e.getMessage()); + } + } + +} diff --git a/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java b/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java index cad7d5e..a0b1ea6 100644 --- a/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java +++ b/tools/model_generator/src/com/libiec61850/tools/StaticModelGenerator.java @@ -129,7 +129,7 @@ public class StaticModelGenerator { if (iedName == null) ied = sclParser.getFirstIed(); else - ied = sclParser.getIedByteName(iedName); + ied = sclParser.getIedByName(iedName); if (ied == null) System.out.println("IED model not found in SCL file! Exit.");