Skip to content

Commit

Permalink
feat(plc4py): UMAS write support (#1854)
Browse files Browse the repository at this point in the history
* feat(plc4py/umas): Add Write Support

* fix(plc4py/umas): Start testing all the data types.

* feat(plc4py/umas): Update documentation, test and look at random datatypes

* fix(plc4py/modbus): Update trailing white space in modebus tests

* fix(plc4py): Switch integration tests to include pyproject.toml

* fix(plc4py): Switch integration tests to include pyproject.toml

* fix(plc4py): Switch integration tests to include pyproject.toml

* fix(plc4py): Clean up config files
  • Loading branch information
hutcheb authored Oct 29, 2024
1 parent c936cf2 commit faa2c68
Show file tree
Hide file tree
Showing 83 changed files with 1,546 additions and 1,316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public String getPlcValueTypeForTypeReference(TypeReference typeReference) {
case BYTE:
// Byte values are represented as signed integers in PLC4Py
emitRequiredImport("from plc4py.spi.values.PlcValues import PlcSINT");
return "PlcSINT";
return "PlcBYTE";
case UINT:
IntegerTypeReference unsignedIntegerTypeReference = (IntegerTypeReference) simpleTypeReference;
if (unsignedIntegerTypeReference.getSizeInBits() <= 4) {
Expand Down Expand Up @@ -807,10 +807,10 @@ public String getReadBufferReadMethodCall(String logicalName, SimpleTypeReferenc
switch (simpleTypeReference.getBaseType()) {
case BIT:
String bitType = "bit";
return "read_buffer.read_" + bitType + "(\"" + logicalName + "\")";
return "read_buffer.read_" + bitType + "(\"" + logicalName + "\"";
case BYTE:
String byteType = "byte";
return "read_buffer.read_" + byteType + "(\"" + logicalName + "\")";
return "read_buffer.read_" + byteType + "(\"" + logicalName + "\"";
case UINT:
String unsignedIntegerType;
IntegerTypeReference unsignedIntegerTypeReference = (IntegerTypeReference) simpleTypeReference;
Expand All @@ -825,7 +825,7 @@ public String getReadBufferReadMethodCall(String logicalName, SimpleTypeReferenc
} else {
unsignedIntegerType = "unsigned_long";
}
return "read_buffer.read_" + unsignedIntegerType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\")";
return "read_buffer.read_" + unsignedIntegerType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\"";
case INT:
String integerType;
if (simpleTypeReference.getSizeInBits() <= 8) {
Expand All @@ -839,10 +839,10 @@ public String getReadBufferReadMethodCall(String logicalName, SimpleTypeReferenc
} else {
integerType = "long";
}
return "read_buffer.read_" + integerType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\")";
return "read_buffer.read_" + integerType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\"";
case FLOAT:
String floatType = (simpleTypeReference.getSizeInBits() <= 32) ? "float" : "double";
return "read_buffer.read_" + floatType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\")";
return "read_buffer.read_" + floatType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\"";
case STRING:
case VSTRING:
String stringType = "str";
Expand All @@ -856,7 +856,7 @@ public String getReadBufferReadMethodCall(String logicalName, SimpleTypeReferenc
VstringTypeReference vstringTypeReference = (VstringTypeReference) simpleTypeReference;
length = toParseExpression(field, INT_TYPE_REFERENCE, vstringTypeReference.getLengthExpression(), null);
}
return "read_buffer.read_" + stringType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\", encoding=" + "\"\")";
return "read_buffer.read_" + stringType + "(" + simpleTypeReference.getSizeInBits() + ", logical_name=\"" + logicalName + "\"";

default:
return "";
Expand Down Expand Up @@ -895,7 +895,8 @@ public String getWriteBufferWriteMethodCall(String logicalName, SimpleTypeRefere
case BIT:
return "write_buffer.write_bit(" + fieldName + ", \"" + logicalName + "\"" + writerArgsString + ")";
case BYTE:
return "write_buffer.write_byte(" + fieldName + ", \"" + logicalName + "\"" + writerArgsString + ")";
ByteTypeReference byteTypeReference = (ByteTypeReference) simpleTypeReference;
return "write_buffer.write_byte(" + fieldName + ", " + byteTypeReference.getSizeInBits() + ", \"" + logicalName + "\"" + writerArgsString + ")";
case UINT:
IntegerTypeReference unsignedIntegerTypeReference = (IntegerTypeReference) simpleTypeReference;
if (unsignedIntegerTypeReference.getSizeInBits() <= 8) {
Expand Down Expand Up @@ -945,7 +946,7 @@ public String getWriteBufferWriteMethodCall(String logicalName, SimpleTypeRefere
.orElseThrow(() -> new FreemarkerException("Encoding must be a quoted string value")).getValue();
String length = Integer.toString(simpleTypeReference.getSizeInBits());
return "write_buffer.write_str(" + fieldName + ", " + length + ", \"" +
encoding + "\", \"" + logicalName + "\"" + writerArgsString + ")";
logicalName + "\", \"" + encoding + "\"" + writerArgsString + ")";
}
case VSTRING: {
VstringTypeReference vstringTypeReference = (VstringTypeReference) simpleTypeReference;
Expand All @@ -957,7 +958,7 @@ public String getWriteBufferWriteMethodCall(String logicalName, SimpleTypeRefere
String lengthExpression = toExpression(field, null, vstringTypeReference.getLengthExpression(), null, Collections.singletonList(new DefaultArgument("stringLength", new DefaultIntegerTypeReference(SimpleTypeReference.SimpleBaseType.INT, 32))), true, false);
String length = Integer.toString(simpleTypeReference.getSizeInBits());
return "write_buffer.write_str(" + fieldName + ", " + lengthExpression + ", \"" +
encoding + "\", \"" + logicalName + "\"" + writerArgsString + ")";
logicalName + "\", \"" + encoding + "\"" + writerArgsString + ")";
}
case DATE:
case TIME:
Expand Down Expand Up @@ -1511,7 +1512,7 @@ else if ((variableLiteral.getChild().isPresent()) && ((ComplexTypeDefinition) th
} else if ((serializerArguments != null) && serializerArguments.stream()
.anyMatch(argument -> argument.getName().equals(variableLiteralName))) {
tracer = tracer.dive("serialization argument");
return tracer + "self." + camelCaseToSnakeCase(variableLiteralName) +
return tracer + camelCaseToSnakeCase(variableLiteralName) +
variableLiteral.getChild()
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, serialize, suppressPointerAccess, true)))
.orElse("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ class ${type.name}<#if type.isDiscriminatedParentTypeDefinition()></#if>(<#if ty
<#if parserArgument.type.isEnumTypeReference()>
${helper.camelCaseToSnakeCase(parserArgument.name)} = ${helper.getLanguageTypeNameForTypeReference(parserArgument.type, false)}[${helper.camelCaseToSnakeCase(parserArgument.name)}]
<#elseif helper.getLanguageTypeNameForTypeReference(parserArgument.type, false) = "bool">
<@emitImport import="from distutils.util import strtobool" />
<@emitImport import="from plc4py.utils.ConnectionStringHandling import strtobool" />
${helper.camelCaseToSnakeCase(parserArgument.name)} = bool(strtobool(${helper.camelCaseToSnakeCase(parserArgument.name)}))
<#else>
${helper.camelCaseToSnakeCase(parserArgument.name)} = ${helper.getLanguageTypeNameForTypeReference(parserArgument.type, false)}(${helper.camelCaseToSnakeCase(parserArgument.name)})
Expand Down
Loading

0 comments on commit faa2c68

Please sign in to comment.