Skip to content

Commit

Permalink
feat: Added support for all missing S7 64bit types (L-Types) as well …
Browse files Browse the repository at this point in the history
…as Duration/Time/Date types

chore: Ported the Java template for data-io to use the same techniques as the other templates used (We hadn't finished refactoring at the time we did the big template-refactoring.

fix: Fixed an issue with serial transports, not forwarding any configuration to the transport channel.

---------

Co-authored-by: Sebastian Rühl <sruehl@apache.org>
  • Loading branch information
chrisdutz and sruehl committed Feb 6, 2024
1 parent 2b64eb5 commit a7310e3
Show file tree
Hide file tree
Showing 118 changed files with 21,418 additions and 21,489 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Expand Up @@ -211,7 +211,10 @@ DartConfiguration.tcl
/plc4j/tools/ui/frontend/project/node_modules/
/plc4j/tools/ui/frontend/project/dist/
/plc4j/tools/ui/frontend/project/.vite/**
/storage/**
/derby.log
/plc4j/tools/ui/frontend/frontend/.idea/vcs.xml
/plc4j/tools/ui/frontend/frontend/.idea/workspace.xml
/storage/**
/derby.log
/plc4c/.idea/codeStyles/codeStyleConfig.xml
/plc4c/.idea/codeStyles/Project.xml
/plc4c/.idea/.name
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -88,7 +88,7 @@ the language of choice.

### Java

NOTE: Currently the Java version which supports building of all parts of Apache PLC4X is at least Java 11 (Currently with Java 21 the Apache Kafka integration module is excluded from the build as the plugins it requires are incompatible with this version)
NOTE: Currently the Java version which supports building of all parts of Apache PLC4X is at least Java 19 (We have tested all versions up to Java 21), however it's only the Java Tool UI, that requires this right now. All other modules need at least Java 11.

See the PLC4J user guide on the website to start using PLC4X in your Java application:
[https://plc4x.apache.org/users/getting-started/plc4j.html](https://plc4x.apache.org/users/getting-started/plc4j.html)
Expand Down
Expand Up @@ -168,6 +168,9 @@ public String getLanguageTypeNameForTypeReference(TypeReference typeReference, b
}

public String getPlcValueTypeForTypeReference(TypeReference typeReference) {
if(typeReference.isArrayTypeReference() && typeReference.asArrayTypeReference().orElseThrow().getElementTypeReference().isByteBased()) {
return "PlcRawByteArray";
}
if (!(typeReference instanceof SimpleTypeReference)) {
return "PlcStruct";
}
Expand Down Expand Up @@ -588,6 +591,79 @@ public String getWriteBufferWriteMethodCall(String logicalName, SimpleTypeRefere
throw new FreemarkerException("Unmapped basetype" + simpleTypeReference.getBaseType());
}

public boolean isRawByteArray(DiscriminatedComplexTypeDefinition currentCase) {
Optional<Field> valueFieldOptional = currentCase.getFields().stream().filter(field -> field.isNamedField() && field.asNamedField().orElseThrow().getName().equals("value")).findFirst();
if(valueFieldOptional.isPresent()) {
Field valueField = valueFieldOptional.get();
if(valueField.isTypedField()) {
TypedField typedField = valueField.asTypedField().orElseThrow();
return typedField.getType().isArrayTypeReference() && typedField.getType().asArrayTypeReference().orElseThrow().getElementTypeReference().isByteBased();
}
}
return false;
}

public String getDataIoPropertyValue(PropertyField propertyField) {
TypeReference propertyFieldType = propertyField.getType();
if(propertyFieldType.isSimpleTypeReference()) {
SimpleTypeReference simpleTypeReference = propertyFieldType.asSimpleTypeReference().orElseThrow();
switch (propertyField.getName()) {
case "value":
return "_value.get" + getLanguageTypeNameForTypeReference(simpleTypeReference) + "()";
case "year":
return "_value.getDate().getYear()";
case "month":
return "_value.getDate().getMonthValue()";
case "day":
case "dayOfMonth":
return "_value.getDate().getDayOfMonth()";
case "dayOfWeek":
return "_value.getDate().getDayOfWeek().getValue()";
case "hour":
return "_value.getTime().getHour()";
case "minutes":
return "_value.getTime().getMinute()";
case "seconds":
return "_value.getTime().getSecond()";
case "secondsSinceEpoch":
return "_value.getDateTime().toEpochSecond(ZoneOffset.UTC)";
case "milliseconds":
return "_value.getDuration().toMillis()";
case "millisecondsOfSecond":
return "_value.getTime().get(ChronoField.MILLI_OF_SECOND)";
case "millisecondsSinceMidnight":
if(simpleTypeReference.getSizeInBits() <= 63) {
return "_value.getTime().getLong(ChronoField.MILLI_OF_DAY)";
} else {
return "BigInteger.valueOf(_value.getTime().getLong(ChronoField.MILLI_OF_DAY))";
}
case "nanoseconds":
if(simpleTypeReference.getSizeInBits() <= 63) {
return "_value.getDuration().toNanos()";
} else {
return "BigInteger.valueOf(_value.getDuration().toNanos())";
}
case "nanosecondsSinceMidnight":
if(simpleTypeReference.getSizeInBits() <= 63) {
return "_value.getTime().getLong(ChronoField.NANO_OF_DAY)";
} else {
return "BigInteger.valueOf(_value.getTime().getLong(ChronoField.NANO_OF_DAY))";
}
case "nannosecondsOfSecond":
if(simpleTypeReference.getSizeInBits() <= 63) {
return "_value.getTime().getLong(ChronoField.NANO_OF_SECOND)";
} else {
return "BigInteger.valueOf(_value.getTime().getLong(ChronoField.NANO_OF_SECOND))";
}
case "nanosecondsSinceEpoch":
return "BigInteger.valueOf(_value.getDateTime().toEpochSecond(ZoneOffset.UTC)).multiply(BigInteger.valueOf(1000000000)).add(BigInteger.valueOf(_value.getDateTime().getNano()))";
default:
throw new UnsupportedOperationException(String.format("Unsupported field name %s.", propertyField.getName()));
}
}
throw new UnsupportedOperationException("Non Simple types not yet supported.");
}

public String getReservedValue(ReservedField reservedField) {
final String languageTypeName = getLanguageTypeNameForTypeReference(reservedField.getType(), true);
if ("BigInteger".equals(languageTypeName)) {
Expand Down

0 comments on commit a7310e3

Please sign in to comment.