Skip to content

Commit

Permalink
feat(plc4py/umas): UMAS implementation (#1339)
Browse files Browse the repository at this point in the history
* fix(plc4py/umas): Why not start implementing umas while I have some interest

* Fix dirs

* fix(plc4py/umas): Got rid of old files

* fix(plc4py/umas): First successful umas message

* fix(plc4py/umas): First successful message parsed

* fix(plc4py/umas): Fixed alignment on return packet

* fix(plc4py/umas): Failed Attempt to pass the function key as a parameter

Realized that I need to get the unit identifier before I can lookup the umas request function code

* fix(plc4py/umas): Can now pass ADU and PDU separately

* fix(plc4py/umas): Initialize Comms message is now sent and ident message update

* fix(plc4py/umas): PLC Status Message and Project CRC can now be received

* fix(plc4py/umas): Add Read Memory Block, need to implement little endian reading/writing

* fix(plc4py/umas): Switched to using little endian for umas stuff

* fix(plc4py/umas): Mucked up the bit/byte order need to fix

* fix(plc4py/umas): Success reading list of variables

* fix(plc4py/umas): Should be able to read a variable if I get endianess correct

* fix(plc4py/umas): Start tidying up the read request.

Next order the variables and work out the max number of variables we can read.

* fix(plc4py/umas): Can now sort the list of tags by memory address

* fix(plc4py/umas): Support for manual fields in data item and string variables

* fix(plc4py/umas): Fix issue reading STRINGS

* fix(plc4py/umas): Started to implement custom data type reads

* fix(plc4py/umas): Finally got the UDT tag structure built out.

* fix(plc4py/umas): UDT and Array member reads now work. Time to clean.

* fix(plc4py/umas): re-generated code

* fix(plc4py/umas): Add support for Browsing.
  • Loading branch information
hutcheb committed Feb 10, 2024
1 parent 6cc7d4b commit 780a104
Show file tree
Hide file tree
Showing 124 changed files with 8,413 additions and 400 deletions.
33 changes: 33 additions & 0 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ else if (thisType.isComplexTypeDefinition()
tracer = tracer.dive("optional fields");
OptionalField optionalField = thisType.asComplexTypeDefinition().orElseThrow().getPropertyFieldByName(variableLiteralName).orElseThrow().asOptionalField().orElseThrow();
return tracer + "(" + (suppressPointerAccess || optionalField.getType().isComplexTypeReference() ? "" : "*") + "self." + camelCaseToSnakeCase(variableLiteral.getName()) + ")" +
variableLiteral.getChild().map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true))).orElse("");
variableLiteral.getChild().map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, serialize, suppressPointerAccess, true))).orElse("");
}
// If we are accessing implicit fields, we need to rely on local variable instead.
//else if (isVariableLiteralImplicitField(vl)) {
Expand Down Expand Up @@ -1046,22 +1046,22 @@ else if ((variableLiteral.getChild().isPresent()) && ((ComplexTypeDefinition) th
tracer = tracer.dive("serialization argument");
return tracer + camelCaseToSnakeCase(variableLiteralName) +
variableLiteral.getChild()
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true)))
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, serialize, suppressPointerAccess, true)))
.orElse("");
} else if ((serializerArguments != null) && serializerArguments.stream()
.anyMatch(argument -> argument.getName().equals(variableLiteralName))) {
tracer = tracer.dive("serialization argument");
return tracer + "self." + camelCaseToSnakeCase(variableLiteralName) +
variableLiteral.getChild()
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true)))
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, serialize, suppressPointerAccess, true)))
.orElse("");
}
if ((parserArguments != null) && parserArguments.stream()
.anyMatch(argument -> argument.getName().equals(variableLiteralName))) {
tracer = tracer.dive("parser argument");
return tracer + camelCaseToSnakeCase(variableLiteralName) +
variableLiteral.getChild()
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true)))
.map(child -> "." + camelCaseToSnakeCase(toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, serialize, suppressPointerAccess, true)))
.orElse("");
}
String indexCall = "";
Expand Down Expand Up @@ -1199,6 +1199,7 @@ private String toStaticCallVariableExpression(Field field, TypeReference typeRef
VariableLiteral va = (VariableLiteral) arg;
// "io" is the default name of the reader argument which is always available.
boolean isParserArg = "readBuffer".equals(va.getName()) || "writeBuffer".equals(va.getName()) || ((thisType instanceof DataIoTypeDefinition) && "_value".equals(va.getName()));
boolean isBufferArg = "readBuffer".equals(va.getName()) || "writeBuffer".equals(va.getName());
boolean isTypeArg = "_type".equals(va.getName());
if (!isParserArg && !isTypeArg && parserArguments != null) {
for (Argument parserArgument : parserArguments) {
Expand All @@ -1208,13 +1209,15 @@ private String toStaticCallVariableExpression(Field field, TypeReference typeRef
}
}
}
if (isParserArg) {
if (isBufferArg) {
sb.append(toVariableExpression(field, typeReference, va, parserArguments, serializerArguments, false, suppressPointerAccess));
} else if (isParserArg) {
tracer = tracer.dive("isParserArg");
if (va.getName().equals("_value")) {
tracer = tracer.dive("is _value");
sb.append(va.getName().substring(1)).append(va.getChild().map(child -> "." + toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, true)).orElse(""));
sb.append(va.getName().substring(1)).append(va.getChild().map(child -> "." + toVariableExpression(field, typeReference, child, parserArguments, serializerArguments, false, suppressPointerAccess, false)).orElse(""));
} else {
sb.append(va.getName()).append((va.getChild().isPresent()) ?
sb.append(camelCaseToSnakeCase(va.getName())).append((va.getChild().isPresent()) ?
".get_" + camelCaseToSnakeCase(toVariableExpression(field, typeReference, va.getChild().orElseThrow(IllegalStateException::new), parserArguments, serializerArguments, false, suppressPointerAccess)) + "()" : "");
}
}
Expand Down Expand Up @@ -1318,7 +1321,7 @@ private String toValueVariableExpression(Field field, TypeReference typeReferenc
final Tracer tracer2 = tracer.dive("_value");
return variableLiteral.getChild()
.map(child -> tracer2.dive("withChild") + "self." + toUppercaseVariableExpression(field, typeReference, child, parserArguments, serializerArguments, serialize, suppressPointerAccess, tracer2))
.orElse(tracer2 + "m");
.orElse(tracer2 + "value");
}

private String toLengthInBitsVariableExpression(TypeReference typeReference, boolean serialize, Tracer tracer) {
Expand Down
Loading

0 comments on commit 780a104

Please sign in to comment.