- Java SCL parser: added support for "Val" elements for Octet64 types

This commit is contained in:
Michael Zillgith 2017-09-05 12:09:03 +02:00
parent 0651b94be5
commit fe8deb9a0a
3 changed files with 40 additions and 0 deletions

Binary file not shown.

View File

@ -23,6 +23,8 @@ package com.libiec61850.scl.model;
* See COPYING file for the complete license text.
*/
import java.util.Base64;
import com.libiec61850.scl.types.EnumerationType;
import com.libiec61850.scl.types.IllegalValueException;
import com.libiec61850.scl.types.SclType;
@ -128,6 +130,15 @@ public class DataModelValue {
case UNICODE_STRING_255:
this.value = value;
break;
case OCTET_STRING_64:
try {
this.value = Base64.getDecoder().decode(value);
}
catch (IllegalArgumentException e) {
throw new IllegalValueException("Val element for Octet64 type does not contain a valid base64 encoded string");
}
break;
case VISIBLE_STRING_32:
case VISIBLE_STRING_64:

View File

@ -727,6 +727,20 @@ public class StaticModelGenerator {
}
}
private void appendHexArrayString(StringBuffer buffer, byte[] byteArray) {
buffer.append("{");
for (int i = 0; i < byteArray.length; i++) {
if (i == 0)
buffer.append(String.format("0x%02X", byteArray[i]));
else
buffer.append(String.format(", 0x%02X", byteArray[i]));
}
buffer.append("}");
}
private void printValue(String daName, DataAttribute dataAttribute, DataModelValue value) {
@ -759,6 +773,21 @@ public class StaticModelGenerator {
case BOOLEAN:
buffer.append("MmsValue_newBoolean(" + value.getValue() + ");");
break;
case OCTET_STRING_64:
{
String daValName = daName + "__val";
buffer.append("MmsValue_newOctetString(0, 64);\n");
buffer.append("uint8_t " + daValName + "[] = ");
appendHexArrayString(buffer, (byte[]) value.getValue());
buffer.append(";\n");
buffer.append("MmsValue_setOctetString(");
buffer.append(daName);
buffer.append(".mmsValue, " + daValName + ", " + ((byte[])value.getValue()).length + ");\n");
}
break;
case UNICODE_STRING_255:
buffer.append("MmsValue_newMmsString(\"" + value.getValue() + "\");");
break;