Skip to content

Commit a7310e3

Browse files
chrisdutzsruehl
andauthored
feat: Added support for all missing S7 64bit types (L-Types) as well 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 <[email protected]>
1 parent 2b64eb5 commit a7310e3

File tree

118 files changed

+21418
-21489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+21418
-21489
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ DartConfiguration.tcl
211211
/plc4j/tools/ui/frontend/project/node_modules/
212212
/plc4j/tools/ui/frontend/project/dist/
213213
/plc4j/tools/ui/frontend/project/.vite/**
214-
/storage/**
215-
/derby.log
216214
/plc4j/tools/ui/frontend/frontend/.idea/vcs.xml
217215
/plc4j/tools/ui/frontend/frontend/.idea/workspace.xml
216+
/storage/**
217+
/derby.log
218+
/plc4c/.idea/codeStyles/codeStyleConfig.xml
219+
/plc4c/.idea/codeStyles/Project.xml
220+
/plc4c/.idea/.name

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ the language of choice.
8888

8989
### Java
9090

91-
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)
91+
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.
9292

9393
See the PLC4J user guide on the website to start using PLC4X in your Java application:
9494
[https://plc4x.apache.org/users/getting-started/plc4j.html](https://plc4x.apache.org/users/getting-started/plc4j.html)

code-generation/language-java/src/main/java/org/apache/plc4x/language/java/JavaLanguageTemplateHelper.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public String getLanguageTypeNameForTypeReference(TypeReference typeReference, b
168168
}
169169

170170
public String getPlcValueTypeForTypeReference(TypeReference typeReference) {
171+
if(typeReference.isArrayTypeReference() && typeReference.asArrayTypeReference().orElseThrow().getElementTypeReference().isByteBased()) {
172+
return "PlcRawByteArray";
173+
}
171174
if (!(typeReference instanceof SimpleTypeReference)) {
172175
return "PlcStruct";
173176
}
@@ -588,6 +591,79 @@ public String getWriteBufferWriteMethodCall(String logicalName, SimpleTypeRefere
588591
throw new FreemarkerException("Unmapped basetype" + simpleTypeReference.getBaseType());
589592
}
590593

594+
public boolean isRawByteArray(DiscriminatedComplexTypeDefinition currentCase) {
595+
Optional<Field> valueFieldOptional = currentCase.getFields().stream().filter(field -> field.isNamedField() && field.asNamedField().orElseThrow().getName().equals("value")).findFirst();
596+
if(valueFieldOptional.isPresent()) {
597+
Field valueField = valueFieldOptional.get();
598+
if(valueField.isTypedField()) {
599+
TypedField typedField = valueField.asTypedField().orElseThrow();
600+
return typedField.getType().isArrayTypeReference() && typedField.getType().asArrayTypeReference().orElseThrow().getElementTypeReference().isByteBased();
601+
}
602+
}
603+
return false;
604+
}
605+
606+
public String getDataIoPropertyValue(PropertyField propertyField) {
607+
TypeReference propertyFieldType = propertyField.getType();
608+
if(propertyFieldType.isSimpleTypeReference()) {
609+
SimpleTypeReference simpleTypeReference = propertyFieldType.asSimpleTypeReference().orElseThrow();
610+
switch (propertyField.getName()) {
611+
case "value":
612+
return "_value.get" + getLanguageTypeNameForTypeReference(simpleTypeReference) + "()";
613+
case "year":
614+
return "_value.getDate().getYear()";
615+
case "month":
616+
return "_value.getDate().getMonthValue()";
617+
case "day":
618+
case "dayOfMonth":
619+
return "_value.getDate().getDayOfMonth()";
620+
case "dayOfWeek":
621+
return "_value.getDate().getDayOfWeek().getValue()";
622+
case "hour":
623+
return "_value.getTime().getHour()";
624+
case "minutes":
625+
return "_value.getTime().getMinute()";
626+
case "seconds":
627+
return "_value.getTime().getSecond()";
628+
case "secondsSinceEpoch":
629+
return "_value.getDateTime().toEpochSecond(ZoneOffset.UTC)";
630+
case "milliseconds":
631+
return "_value.getDuration().toMillis()";
632+
case "millisecondsOfSecond":
633+
return "_value.getTime().get(ChronoField.MILLI_OF_SECOND)";
634+
case "millisecondsSinceMidnight":
635+
if(simpleTypeReference.getSizeInBits() <= 63) {
636+
return "_value.getTime().getLong(ChronoField.MILLI_OF_DAY)";
637+
} else {
638+
return "BigInteger.valueOf(_value.getTime().getLong(ChronoField.MILLI_OF_DAY))";
639+
}
640+
case "nanoseconds":
641+
if(simpleTypeReference.getSizeInBits() <= 63) {
642+
return "_value.getDuration().toNanos()";
643+
} else {
644+
return "BigInteger.valueOf(_value.getDuration().toNanos())";
645+
}
646+
case "nanosecondsSinceMidnight":
647+
if(simpleTypeReference.getSizeInBits() <= 63) {
648+
return "_value.getTime().getLong(ChronoField.NANO_OF_DAY)";
649+
} else {
650+
return "BigInteger.valueOf(_value.getTime().getLong(ChronoField.NANO_OF_DAY))";
651+
}
652+
case "nannosecondsOfSecond":
653+
if(simpleTypeReference.getSizeInBits() <= 63) {
654+
return "_value.getTime().getLong(ChronoField.NANO_OF_SECOND)";
655+
} else {
656+
return "BigInteger.valueOf(_value.getTime().getLong(ChronoField.NANO_OF_SECOND))";
657+
}
658+
case "nanosecondsSinceEpoch":
659+
return "BigInteger.valueOf(_value.getDateTime().toEpochSecond(ZoneOffset.UTC)).multiply(BigInteger.valueOf(1000000000)).add(BigInteger.valueOf(_value.getDateTime().getNano()))";
660+
default:
661+
throw new UnsupportedOperationException(String.format("Unsupported field name %s.", propertyField.getName()));
662+
}
663+
}
664+
throw new UnsupportedOperationException("Non Simple types not yet supported.");
665+
}
666+
591667
public String getReservedValue(ReservedField reservedField) {
592668
final String languageTypeName = getLanguageTypeNameForTypeReference(reservedField.getType(), true);
593669
if ("BigInteger".equals(languageTypeName)) {

0 commit comments

Comments
 (0)