- added java based modelviewer tool

This commit is contained in:
Michael Zillgith 2015-12-25 18:33:24 +01:00
parent daa0a1e958
commit 9e626d58b8
12 changed files with 324 additions and 25 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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 */

View file

@ -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

View file

@ -0,0 +1,2 @@
Manifest-Version: 1.0
Main-Class: com.libiec61850.tools.ModelViewer

View file

@ -62,28 +62,47 @@ public class SclParser {
private List<IED> 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;
}

View file

@ -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));

View file

@ -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;

View file

@ -68,5 +68,11 @@ public class TypeDeclarations {
return null;
}
public List<SclType> getTypeDeclarations() {
return typeDeclarations;
}
}

View file

@ -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.");

View file

@ -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<LogicalDevice> devices = server.getLogicalDevices();
for (LogicalDevice device : devices) {
output.println(device.getInst());
List<LogicalNode> 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<LogicalDevice> devices = server.getLogicalDevices();
for (LogicalDevice device : devices) {
String devPrefix = ied.getName() + device.getInst() + "/";
List<LogicalNode> 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 <SCL file> [-ied <ied-name>] [-ap <access-point-name>] [-t] [-s] [-a] [<output filename>]");
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());
}
}
}

View file

@ -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.");