You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2022/11/24 20:44:12 UTC
[plc4x] branch develop updated: refactor(times): Refactoring of the was PlcValues are handled for TIME, DATE, TIME_OF_DAY and DATE_TIME types.
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new e73b569653 refactor(times): Refactoring of the was PlcValues are handled for TIME, DATE, TIME_OF_DAY and DATE_TIME types.
e73b569653 is described below
commit e73b569653dbb190d2e1136e53bc464286b89ad9
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Nov 24 21:44:03 2022 +0100
refactor(times): Refactoring of the was PlcValues are handled for TIME, DATE, TIME_OF_DAY and DATE_TIME types.
---
.../templates/cs/data-io-template.cs.ftlh | 5 -
.../templates/go/data-io-template.go.ftlh | 88 ++++++----
.../templates/java/data-io-template.java.ftlh | 69 +++++---
plc4c/api/include/plc4c/data.h | 11 +-
plc4c/generated-sources/plc4x/src/plc4x_value.c | 179 +++++++++++++++++++--
plc4c/generated-sources/s7/src/data_item.c | 82 ++++++----
plc4c/spi/include/plc4c/spi/types_private.h | 3 +
plc4c/spi/src/data.c | 30 ++++
plc4go/protocols/ads/readwrite/model/DataItem.go | 107 ++++++++----
.../knxnetip/readwrite/model/KnxDatapoint.go | 115 +++++++------
plc4go/protocols/s7/readwrite/model/DataItem.go | 93 ++++++-----
plc4go/spi/values/PlcDATE.go | 17 +-
plc4go/spi/values/PlcDATE_AND_TIME.go | 11 +-
plc4go/spi/values/PlcLDATE.go | 73 +++++++++
plc4go/spi/values/PlcLDATE_AND_TIME.go | 72 +++++++++
plc4go/spi/values/PlcLTIME.go | 10 +-
plc4go/spi/values/PlcLTIME_OF_DAY.go | 77 +++++++++
plc4go/spi/values/PlcTIME.go | 10 +-
plc4go/spi/values/PlcTIME_OF_DAY.go | 7 +-
plc4go/spi/values/PlcValueHandler.go | 63 +-------
plc4go/spi/values/value_combination_test.go | 2 +-
.../org/apache/plc4x/java/spi/values/PlcDATE.java | 29 +++-
.../plc4x/java/spi/values/PlcDATE_AND_TIME.java | 17 +-
.../org/apache/plc4x/java/spi/values/PlcLDATE.java | 27 ++--
.../plc4x/java/spi/values/PlcLDATE_AND_TIME.java | 14 +-
.../org/apache/plc4x/java/spi/values/PlcLTIME.java | 27 +++-
.../plc4x/java/spi/values/PlcLTIME_OF_DAY.java | 28 +++-
.../org/apache/plc4x/java/spi/values/PlcTIME.java | 13 +-
.../plc4x/java/spi/values/PlcTIME_OF_DAY.java | 14 +-
.../knxnetip/readwrite/model/KnxDatapoint.cs | 107 ++++++------
.../ads/src/main/resources/protocols/ads/ads.mspec | 17 +-
.../src/main/resources/protocols/can/canopen.mspec | 2 +-
protocols/knxnetip/src/main/xslt/knx-types.xsl | 61 +++----
.../main/resources/protocols/plc4x/v0/plc4x.mspec | 46 ++++--
.../s7/src/main/resources/protocols/s7/s7.mspec | 33 +++-
35 files changed, 1090 insertions(+), 469 deletions(-)
diff --git a/code-generation/language-cs/src/main/resources/templates/cs/data-io-template.cs.ftlh b/code-generation/language-cs/src/main/resources/templates/cs/data-io-template.cs.ftlh
index 60d7658550..a265094f30 100644
--- a/code-generation/language-cs/src/main/resources/templates/cs/data-io-template.cs.ftlh
+++ b/code-generation/language-cs/src/main/resources/templates/cs/data-io-template.cs.ftlh
@@ -411,12 +411,7 @@ namespace org.apache.plc4net.drivers.${protocolName?replace("-", "")}.${outputFl
<#if case.name == "Struct">
var ${simpleField.name} = (${helper.getLanguageTypeNameForField(field)}) _value.GetStruct()["${simpleField.name}"].Get${helper.getLanguageTypeNameForField(simpleField)?cap_first}();
<#else>
- <#if simpleField.name == "value">
var ${simpleField.name} = (${helper.getLanguageTypeNameForField(field)}) _value.Get${helper.getLanguageTypeNameForField(simpleField)?cap_first}();
- <#else>
- <#-- Just for now -->
- var ${simpleField.name} = ${helper.getNullValueForTypeReference(simpleField.type)};
- </#if>
</#if>
<#if simpleField.type.isSimpleTypeReference()>
${helper.getWriteBufferWriteMethodCall(simpleField.type.asSimpleTypeReference().orElseThrow(), "(" + simpleField.name + ")", simpleField)};
diff --git a/code-generation/language-go/src/main/resources/templates/go/data-io-template.go.ftlh b/code-generation/language-go/src/main/resources/templates/go/data-io-template.go.ftlh
index 1c45367be9..b57c35d707 100644
--- a/code-generation/language-go/src/main/resources/templates/go/data-io-template.go.ftlh
+++ b/code-generation/language-go/src/main/resources/templates/go/data-io-template.go.ftlh
@@ -152,7 +152,7 @@ func ${type.name}ParseWithBuffer(readBuffer utils.ReadBuffer<#if parserArguments
<#assign simpleField = field.asSimpleField().orElseThrow()>
// Simple Field (${simpleField.name})
- <#if case.name == "Struct" || ((case.name == "DATE_AND_TIME") && ((simpleField.name == "year") || (simpleField.name == "month") || (simpleField.name == "day") || (simpleField.name == "hour") || (simpleField.name == "minutes") || (simpleField.name == "seconds") || (simpleField.name == "secondsSinceEpoch"))) || ((case.name == "DATE") && ((simpleField.name == "year") || (simpleField.name == "month") || (simpleField.name == "day"))) || ((case.name == "TIME_OF_DAY") && ((simpleField.name = [...]
+ <#if (case.name == "Struct") || ((case.name == "TIME") && (simpleField.name == "milliseconds")) || ((case.name == "LTIME") && (simpleField.name == "nanoseconds")) || ((case.name == "DATE") && ((simpleField.name == "secondsSinceEpoch") || (simpleField.name == "daysSinceSiemensEpoch"))) || ((case.name == "LDATE") && (simpleField.name == "nanosecondsSinceEpoch")) || ((case.name == "TIME_OF_DAY") && (simpleField.name == "millisecondsSinceMidnight")) || ((case.name == "LTIME_OF_DAY") && (s [...]
if _${simpleField.name}Err != nil {
return nil, errors.Wrap(_${simpleField.name}Err, "Error parsing '${simpleField.name}' field")<@emitImport import="github.com/pkg/errors" />
}
@@ -163,45 +163,73 @@ func ${type.name}ParseWithBuffer(readBuffer utils.ReadBuffer<#if parserArguments
<#break>
</#switch>
</#list>
- <#if valueDefined>
- <#switch case.name>
- <#case "TIME_OF_DAY">
- <#if helper.hasFieldsWithNames(case.fields, "hour", "minutes", "seconds")>
- value := time.Date(0,0,0, int(hour), int(minutes), int(seconds), 0, nil)<@emitImport import="time" />
- </#if>
+ <#switch case.name>
+ <#case "TIME">
readBuffer.CloseContext("${type.name}")
- return values.NewPlcTIME_OF_DAY(value), nil
- <#break>
- <#case "DATE">
- <#if helper.hasFieldsWithNames(case.fields, "year", "month", "day")>
- value := time.Date(int(year), time.Month(month), int(day), 0, 0, 0, 0, nil)<@emitImport import="time" />
- </#if>
+ <#if helper.hasFieldsWithNames(case.fields, "milliseconds")>
+ return values.NewPlcTIMEFromMilliseconds(milliseconds), nil
+ </#if>
+ <#break>
+ <#case "LTIME">
readBuffer.CloseContext("${type.name}")
- return values.NewPlcDATE(value), nil
- <#break>
- <#case "DATE_AND_TIME">
- <#if helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds")>
- value := time.Date(int(year), time.Month(month), int(day), int(hour), int(minutes), int(seconds), 0, nil)<@emitImport import="time" />
- <#elseif helper.hasFieldsWithNames(case.fields, "secondsSinceEpoch")>
- value := time.Unix(int64(secondsSinceEpoch), 0)<@emitImport import="time" />
- </#if>
+ <#if helper.hasFieldsWithNames(case.fields, "nanoseconds")>
+ return values.NewPlcLTIMEFromNanoseconds(nanoseconds), nil
+ </#if>
+ <#break>
+ <#case "DATE">
+ readBuffer.CloseContext("${type.name}")
+ <#if helper.hasFieldsWithNames(case.fields, "secondsSinceEpoch")>
+ return values.NewPlcDATEFromSecondsSinceEpoch(uint32(secondsSinceEpoch)), nil
+ <#elseif helper.hasFieldsWithNames(case.fields, "daysSinceEpoch")>
+ return values.NewPlcDATEFromDaysSinceEpoch(daysSinceEpoch), nil
+ <#elseif helper.hasFieldsWithNames(case.fields, "daysSinceSiemensEpoch")>
+ return values.NewPlcDATEFromDaysSinceSiemensEpoch(daysSinceSiemensEpoch), nil
+ </#if>
+ <#break>
+ <#case "LDATE">
readBuffer.CloseContext("${type.name}")
- return values.NewPlcDATE_AND_TIME(value), nil
- <#break>
+ <#if helper.hasFieldsWithNames(case.fields, "nanosecondsSinceEpoch")>
+ return values.NewPlcLDATEFromNanosecondsSinceEpoch(uint64(nanosecondsSinceEpoch)), nil
+ </#if>
+ <#break>
+ <#case "TIME_OF_DAY">
+ readBuffer.CloseContext("${type.name}")
+ <#if helper.hasFieldsWithNames(case.fields, "millisecondsSinceMidnight")>
+ return values.NewPlcTIME_OF_DAYFromMillisecondsSinceMidnight(millisecondsSinceMidnight), nil
+ </#if>
+ <#break>
+ <#case "LTIME_OF_DAY">
readBuffer.CloseContext("${type.name}")
- <#case "Struct">
+ <#if helper.hasFieldsWithNames(case.fields, "nanosecondsSinceMidnight")>
+ return values.NewPlcLTIME_OF_DAYFromNanosecondsSinceMidnight(nanosecondsSinceMidnight), nil
+ </#if>
+ <#break>
+ <#case "DATE_AND_TIME">
+ readBuffer.CloseContext("${type.name}")
+ <#if helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds", "nanoseconds")>
+ return values.NewPlcDATA_AND_TIMEFromSegments(uint32(year), uint32(month), uint32(day), uint32(hour), uint32(minutes), uint32(seconds), uint32(nanoseconds)), nil
+ <#elseif helper.hasFieldsWithNames(case.fields, "secondsSinceEpoch")>
+ return values.NewPlcDATA_AND_TIMEFromSecondsSinceEpoch(secondsSinceEpoch), nil
+ </#if>
+ <#break>
+ <#case "LDATE_AND_TIME">
+ readBuffer.CloseContext("${type.name}")
+ <#if helper.hasFieldsWithNames(case.fields, "nanosecondsSinceEpoch")>
+ return values.NewPlcLDATE_AND_TIMEFromNanosecondsSinceEpoch(uint64(nanosecondsSinceEpoch)), nil
+ </#if>
+ <#break>
+ <#case "Struct">
readBuffer.CloseContext("${type.name}")
return values.NewPlcStruct(_map), nil
- <#break>
- <#case "List">
+ <#break>
+ <#case "List">
readBuffer.CloseContext("${type.name}")
return values.NewPlcList(value), nil
- <#break>
- <#default>
+ <#break>
+ <#default>
readBuffer.CloseContext("${type.name}")
return values.NewPlc${case.name}(value), nil
- </#switch>
- </#if>
+ </#switch>
</#list>
}
// TODO: add more info which type it is actually
diff --git a/code-generation/language-java/src/main/resources/templates/java/data-io-template.java.ftlh b/code-generation/language-java/src/main/resources/templates/java/data-io-template.java.ftlh
index 7779e6e266..711c665703 100644
--- a/code-generation/language-java/src/main/resources/templates/java/data-io-template.java.ftlh
+++ b/code-generation/language-java/src/main/resources/templates/java/data-io-template.java.ftlh
@@ -284,45 +284,62 @@ public class ${type.name} {
<#assign valueDefined=true>
</#if>
- <#if valueDefined>
- <#switch case.name>
- <#case "TIME">
- return new PlcTIME(value);
+ <#switch case.name>
+ <#case "TIME">
+ <#if helper.hasFieldsWithNames(case.fields, "milliseconds")>
+ return PlcTIME.ofMilliseconds(milliseconds);
+ </#if>
+ <#break>
+ <#case "LTIME">
+ <#if helper.hasFieldsWithNames(case.fields, "nanoseconds")>
+ return PlcLTIME.ofNanoseconds(nanoseconds);
+ </#if>
+ <#break>
+ <#case "DATE">
+ <#if helper.hasFieldsWithNames(case.fields, "secondsSinceEpoch")>
+ return PlcDATE.ofSecondsSinceEpoch(secondsSinceEpoch);
+ <#elseif helper.hasFieldsWithNames(case.fields, "daysSinceEpoch")>
+ return PlcDATE.ofDaysSinceEpoch(daysSinceEpoch);
+ <#elseif helper.hasFieldsWithNames(case.fields, "daysSinceSiemensEpoch")>
+ return PlcDATE.ofDaysSinceSiemensEpoch(daysSinceSiemensEpoch);
+ </#if>
+ <#break>
+ <#case "LDATE">
+ <#if helper.hasFieldsWithNames(case.fields, "nanosecondsSinceEpoch")>
+ return PlcLDATE.ofNanosecondsSinceEpoch(nanosecondsSinceEpoch);
+ </#if>
<#break>
- <#case "DATE">
- <#if helper.hasFieldsWithNames(case.fields, "year", "month", "day")>
- LocalDate value = LocalDate.of(year.intValue(), (month == 0) ? 1 : month.intValue(), (day == 0) ? 1 : day.intValue());
+ <#case "TIME_OF_DAY">
+ <#if helper.hasFieldsWithNames(case.fields, "millisecondsSinceMidnight")>
+ return PlcTIME_OF_DAY.ofMillisecondsSinceMidnight(millisecondsSinceMidnight);
</#if>
- return new PlcDATE(value);
<#break>
- <#case "TIME_OF_DAY">
- <#if helper.hasFieldsWithNames(case.fields, "hour", "minutes", "seconds", "nanos")>
- LocalTime value = LocalTime.of(hour.intValue(), minutes.intValue(), seconds.intValue(), nanos.intValue());
- <#elseif helper.hasFieldsWithNames(case.fields, "hour", "minutes", "seconds")>
- LocalTime value = LocalTime.of(hour.intValue(), minutes.intValue(), seconds.intValue());
+ <#case "LTIME_OF_DAY">
+ <#if helper.hasFieldsWithNames(case.fields, "nanosecondsSinceMidnight")>
+ return PlcLTIME_OF_DAY.ofNanosecondsSinceMidnight(nanosecondsSinceMidnight);
</#if>
- return new PlcTIME_OF_DAY(value);
<#break>
- <#case "DATE_AND_TIME">
- <#if helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds", "nanos")>
- LocalDateTime value = LocalDateTime.of(year.intValue(), (month == 0) ? 1 : month.intValue(), (day == 0) ? 1 : day.intValue(), hour.intValue(), minutes.intValue(), seconds.intValue(), nanos.intValue());
- <#elseif helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds")>
- LocalDateTime value = LocalDateTime.of(year.intValue(), (month == 0) ? 1 : month.intValue(), (day == 0) ? 1 : day.intValue(), hour.intValue(), minutes.intValue(), seconds.intValue());
+ <#case "DATE_AND_TIME">
+ <#if helper.hasFieldsWithNames(case.fields, "year", "month", "day", "hour", "minutes", "seconds", "nanoseconds")>
+ return PlcDATE_AND_TIME.ofSegments(year.intValue(), (month == 0) ? 1 : month.intValue(), (day == 0) ? 1 : day.intValue(), hour.intValue(), minutes.intValue(), seconds.intValue(), nanoseconds.intValue());
<#elseif helper.hasFieldsWithNames(case.fields, "secondsSinceEpoch")>
- LocalDateTime value = LocalDateTime.ofEpochSecond(secondsSinceEpoch, 0, ZoneOffset.UTC);
+ return PlcDATE_AND_TIME.ofSecondsSinceEpoch(secondsSinceEpoch);
+ </#if>
+ <#break>
+ <#case "LDATE_AND_TIME">
+ <#if helper.hasFieldsWithNames(case.fields, "nanosecondsSinceEpoch")>
+ return PlcLDATE_AND_TIME.ofNanosecondsSinceEpoch(nanosecondsSinceEpoch);
</#if>
- return new PlcDATE_AND_TIME(value);
<#break>
- <#case "Struct">
+ <#case "Struct">
return new PlcStruct(_map);
<#break>
- <#case "List">
+ <#case "List">
return new PlcList(value);
<#break>
- <#default>
+ <#default>
return new Plc${case.name}(value);
- </#switch>
- </#if>
+ </#switch>
}<#sep> else </#sep></#list>
<#if !defaultCaseOutput>
return null;
diff --git a/plc4c/api/include/plc4c/data.h b/plc4c/api/include/plc4c/data.h
index 9fb31eec80..39214db1b3 100644
--- a/plc4c/api/include/plc4c/data.h
+++ b/plc4c/api/include/plc4c/data.h
@@ -118,18 +118,27 @@ plc4c_data *plc4c_data_create_lreal_array(double *d, int nItems);
plc4c_data *plc4c_data_create_date_data(uint16_t d);
plc4c_data *plc4c_data_create_date_array(uint16_t *d, int nItems);
+plc4c_data *plc4c_data_create_ldate_data(uint32_t nanosecondsSinceEpoch);
+plc4c_data *plc4c_data_create_ldate_array(uint32_t *nanosecondsSinceEpoch, int nItems);
+
plc4c_data *plc4c_data_create_time_data(uint32_t t);
plc4c_data *plc4c_data_create_time_array(uint32_t *t, int nItems);
plc4c_data *plc4c_data_create_ltime_data(uint64_t lt);
plc4c_data *plc4c_data_create_ltime_array(uint64_t *lt, int nItems);
- plc4c_data *plc4c_data_create_time_of_day_data(uint32_t tod);
+plc4c_data *plc4c_data_create_time_of_day_data(uint32_t tod);
plc4c_data *plc4c_data_create_time_of_day_array(uint32_t *tod, int nItems);
+plc4c_data *plc4c_data_create_ltime_of_day_data(uint64_t nanosecondsSinceMidnight);
+plc4c_data *plc4c_data_create_ltime_of_day_array(uint64_t *nanosecondsSinceMidnight, int nItems);
+
plc4c_data *plc4c_data_create_date_and_time_data(uint32_t tad);
plc4c_data *plc4c_data_create_date_and_time_array(uint32_t *tad, int nItems);
+plc4c_data *plc4c_data_create_ldate_and_time_data(uint64_t nanosecondsSinceEpoch);
+plc4c_data *plc4c_data_create_ldate_and_time_array(uint64_t *nanosecondsSinceEpoch, int nItems);
+
/**
* Creates a plc4c_data with char*
* @param size the size of the string
diff --git a/plc4c/generated-sources/plc4x/src/plc4x_value.c b/plc4c/generated-sources/plc4x/src/plc4x_value.c
index 2aababae4a..f7d9195ba7 100644
--- a/plc4c/generated-sources/plc4x/src/plc4x_value.c
+++ b/plc4c/generated-sources/plc4x/src/plc4x_value.c
@@ -235,14 +235,95 @@ plc4c_return_code plc4c_plc4x_read_write_plc4x_value_parse(plc4c_spi_read_buffer
*data_item = plc4c_data_create_string_data(16, value);
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_STRING) { /* STRING */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_WSTRING) { /* STRING */
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME) { /* TIME */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME_OF_DAY) { /* TIME_OF_DAY */
+
+ // Simple Field (milliseconds)
+ uint32_t milliseconds = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &milliseconds);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_time_data(milliseconds);
+
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LTIME) { /* LTIME */
+
+ // Simple Field (nanoseconds)
+ uint64_t nanoseconds = 0;
+ _res = plc4c_spi_read_unsigned_long(readBuffer, 64, (uint64_t*) &nanoseconds);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_ltime_data(nanoseconds);
+
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_DATE) { /* DATE */
+
+ // Simple Field (secondsSinceEpoch)
+ uint32_t secondsSinceEpoch = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &secondsSinceEpoch);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_date_data(secondsSinceEpoch);
+
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LDATE) { /* LDATE */
+
+ // Simple Field (nanosecondsSinceEpoch)
+ uint32_t nanosecondsSinceEpoch = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &nanosecondsSinceEpoch);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_ldate_data(nanosecondsSinceEpoch);
+
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME_OF_DAY) { /* TIME_OF_DAY */
+
+ // Simple Field (millisecondsSinceMidnight)
+ uint32_t millisecondsSinceMidnight = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &millisecondsSinceMidnight);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_time_of_day_data(millisecondsSinceMidnight);
+
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LTIME_OF_DAY) { /* LTIME_OF_DAY */
+
+ // Simple Field (nanosecondsSinceMidnight)
+ uint64_t nanosecondsSinceMidnight = 0;
+ _res = plc4c_spi_read_unsigned_long(readBuffer, 64, (uint64_t*) &nanosecondsSinceMidnight);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_ltime_of_day_data(nanosecondsSinceMidnight);
+
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_DATE_AND_TIME) { /* DATE_AND_TIME */
+
+ // Simple Field (secondsSinceEpoch)
+ uint32_t secondsSinceEpoch = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &secondsSinceEpoch);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_date_and_time_data(secondsSinceEpoch);
+
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LDATE_AND_TIME) { /* LDATE_AND_TIME */
+
+ // Simple Field (nanosecondsSinceEpoch)
+ uint32_t nanosecondsSinceEpoch = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &nanosecondsSinceEpoch);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_ldate_and_time_data(nanosecondsSinceEpoch);
+
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_Struct) { /* Struct */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_List) { /* List */
}
return OK;
@@ -371,14 +452,63 @@ plc4c_return_code plc4c_plc4x_read_write_plc4x_value_serialize(plc4c_spi_write_b
if(_res != OK) {
return _res;
}
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_STRING) { /* STRING */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_WSTRING) { /* STRING */
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME) { /* TIME */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME_OF_DAY) { /* TIME_OF_DAY */
+
+ // Simple field (milliseconds)
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.time_value);
+ if(_res != OK) {
+ return _res;
+ }
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LTIME) { /* LTIME */
+
+ // Simple field (nanoseconds)
+ _res = plc4c_spi_write_unsigned_long(writeBuffer, 64, (*data_item)->data.ltime_value);
+ if(_res != OK) {
+ return _res;
+ }
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_DATE) { /* DATE */
+
+ // Simple field (secondsSinceEpoch)
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.date_value);
+ if(_res != OK) {
+ return _res;
+ }
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LDATE) { /* LDATE */
+
+ // Simple field (nanosecondsSinceEpoch)
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.ldate_value);
+ if(_res != OK) {
+ return _res;
+ }
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME_OF_DAY) { /* TIME_OF_DAY */
+
+ // Simple field (millisecondsSinceMidnight)
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.time_of_day_value);
+ if(_res != OK) {
+ return _res;
+ }
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LTIME_OF_DAY) { /* LTIME_OF_DAY */
+
+ // Simple field (nanosecondsSinceMidnight)
+ _res = plc4c_spi_write_unsigned_long(writeBuffer, 64, (*data_item)->data.ltime_of_day_value);
+ if(_res != OK) {
+ return _res;
+ }
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_DATE_AND_TIME) { /* DATE_AND_TIME */
+
+ // Simple field (secondsSinceEpoch)
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.date_and_time_value);
+ if(_res != OK) {
+ return _res;
+ }
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LDATE_AND_TIME) { /* LDATE_AND_TIME */
+
+ // Simple field (nanosecondsSinceEpoch)
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.ldate_and_time_value);
+ if(_res != OK) {
+ return _res;
+ }
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_Struct) { /* Struct */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_List) { /* List */
}
return OK;
}
@@ -460,14 +590,39 @@ uint16_t plc4c_plc4x_read_write_plc4x_value_length_in_bits(plc4c_data* data_item
// Simple field (value)
lengthInBits += 16;
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_STRING) { /* STRING */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_WSTRING) { /* STRING */
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME) { /* TIME */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME_OF_DAY) { /* TIME_OF_DAY */
+
+ // Simple field (milliseconds)
+ lengthInBits += 32;
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LTIME) { /* LTIME */
+
+ // Simple field (nanoseconds)
+ lengthInBits += 64;
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_DATE) { /* DATE */
+
+ // Simple field (secondsSinceEpoch)
+ lengthInBits += 32;
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LDATE) { /* LDATE */
+
+ // Simple field (nanosecondsSinceEpoch)
+ lengthInBits += 32;
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_TIME_OF_DAY) { /* TIME_OF_DAY */
+
+ // Simple field (millisecondsSinceMidnight)
+ lengthInBits += 32;
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LTIME_OF_DAY) { /* LTIME_OF_DAY */
+
+ // Simple field (nanosecondsSinceMidnight)
+ lengthInBits += 64;
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_DATE_AND_TIME) { /* DATE_AND_TIME */
+
+ // Simple field (secondsSinceEpoch)
+ lengthInBits += 32;
+ } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_LDATE_AND_TIME) { /* LDATE_AND_TIME */
+
+ // Simple field (nanosecondsSinceEpoch)
+ lengthInBits += 32;
} else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_Struct) { /* Struct */
- } else if(valueType == plc4c_plc4x_read_write_plc4x_value_type_List) { /* List */
}
return lengthInBits;
}
diff --git a/plc4c/generated-sources/s7/src/data_item.c b/plc4c/generated-sources/s7/src/data_item.c
index f999b07a79..90e902bd65 100644
--- a/plc4c/generated-sources/s7/src/data_item.c
+++ b/plc4c/generated-sources/s7/src/data_item.c
@@ -251,47 +251,58 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4c_spi_read_buffer* rea
} else if(strcmp(dataProtocolId, "IEC61131_TIME") == 0) { /* TIME */
- // Simple Field (value)
- uint32_t value = 0;
- _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &value);
+ // Simple Field (milliseconds)
+ uint32_t milliseconds = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &milliseconds);
if(_res != OK) {
return _res;
}
- *data_item = plc4c_data_create_time_data(value);
+ *data_item = plc4c_data_create_time_data(milliseconds);
} else if(strcmp(dataProtocolId, "IEC61131_LTIME") == 0) { /* LTIME */
- // Simple Field (value)
- uint64_t value = 0;
- _res = plc4c_spi_read_unsigned_long(readBuffer, 64, (uint64_t*) &value);
+ // Simple Field (nanoseconds)
+ uint64_t nanoseconds = 0;
+ _res = plc4c_spi_read_unsigned_long(readBuffer, 64, (uint64_t*) &nanoseconds);
if(_res != OK) {
return _res;
}
- *data_item = plc4c_data_create_ltime_data(value);
+ *data_item = plc4c_data_create_ltime_data(nanoseconds);
} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */
- // Simple Field (value)
- uint16_t value = 0;
- _res = plc4c_spi_read_unsigned_short(readBuffer, 16, (uint16_t*) &value);
+ // Simple Field (daysSinceSiemensEpoch)
+ uint16_t daysSinceSiemensEpoch = 0;
+ _res = plc4c_spi_read_unsigned_short(readBuffer, 16, (uint16_t*) &daysSinceSiemensEpoch);
if(_res != OK) {
return _res;
}
- *data_item = plc4c_data_create_date_data(value);
+ *data_item = plc4c_data_create_date_data(daysSinceSiemensEpoch);
} else if(strcmp(dataProtocolId, "IEC61131_TIME_OF_DAY") == 0) { /* TIME_OF_DAY */
- // Simple Field (value)
- uint32_t value = 0;
- _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &value);
+ // Simple Field (milliseconds)
+ uint32_t milliseconds = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &milliseconds);
+ if(_res != OK) {
+ return _res;
+ }
+
+ *data_item = plc4c_data_create_time_of_day_data(milliseconds);
+
+ } else if(strcmp(dataProtocolId, "IEC61131_LTIME_OF_DAY") == 0) { /* LTIME_OF_DAY */
+
+ // Simple Field (nanoseconds)
+ uint64_t nanoseconds = 0;
+ _res = plc4c_spi_read_unsigned_long(readBuffer, 64, (uint64_t*) &nanoseconds);
if(_res != OK) {
return _res;
}
- *data_item = plc4c_data_create_time_of_day_data(value);
+ *data_item = plc4c_data_create_ltime_of_day_data(nanoseconds);
} else if(strcmp(dataProtocolId, "IEC61131_DATE_AND_TIME") == 0) { /* DATE_AND_TIME */
@@ -365,14 +376,14 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4c_spi_read_buffer* rea
*data_item = plc4c_data_create_date_and_time_data(seconds);
- // Simple Field (nanos)
- uint32_t nanos = 0;
- _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &nanos);
+ // Simple Field (nanoseconds)
+ uint32_t nanoseconds = 0;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &nanoseconds);
if(_res != OK) {
return _res;
}
- *data_item = plc4c_data_create_date_and_time_data(nanos);
+ *data_item = plc4c_data_create_date_and_time_data(nanoseconds);
}
@@ -510,32 +521,39 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4c_spi_write_buffer
// Manual Field (value)
} else if(strcmp(dataProtocolId, "IEC61131_TIME") == 0) { /* TIME */
- // Simple field (value)
+ // Simple field (milliseconds)
_res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.time_value);
if(_res != OK) {
return _res;
}
} else if(strcmp(dataProtocolId, "IEC61131_LTIME") == 0) { /* LTIME */
- // Simple field (value)
+ // Simple field (nanoseconds)
_res = plc4c_spi_write_unsigned_long(writeBuffer, 64, (*data_item)->data.ltime_value);
if(_res != OK) {
return _res;
}
} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */
- // Simple field (value)
+ // Simple field (daysSinceSiemensEpoch)
_res = plc4c_spi_write_unsigned_short(writeBuffer, 16, (*data_item)->data.date_value);
if(_res != OK) {
return _res;
}
} else if(strcmp(dataProtocolId, "IEC61131_TIME_OF_DAY") == 0) { /* TIME_OF_DAY */
- // Simple field (value)
+ // Simple field (milliseconds)
_res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.time_of_day_value);
if(_res != OK) {
return _res;
}
+ } else if(strcmp(dataProtocolId, "IEC61131_LTIME_OF_DAY") == 0) { /* LTIME_OF_DAY */
+
+ // Simple field (nanoseconds)
+ _res = plc4c_spi_write_unsigned_long(writeBuffer, 64, (*data_item)->data.ltime_of_day_value);
+ if(_res != OK) {
+ return _res;
+ }
} else if(strcmp(dataProtocolId, "IEC61131_DATE_AND_TIME") == 0) { /* DATE_AND_TIME */
// Simple field (year)
@@ -580,7 +598,7 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4c_spi_write_buffer
return _res;
}
- // Simple field (nanos)
+ // Simple field (nanoseconds)
_res = plc4c_spi_write_unsigned_int(writeBuffer, 32, (*data_item)->data.date_and_time_value);
if(_res != OK) {
return _res;
@@ -682,20 +700,24 @@ uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4c_data* data_item, cha
}
} else if(strcmp(dataProtocolId, "IEC61131_TIME") == 0) { /* TIME */
- // Simple field (value)
+ // Simple field (milliseconds)
lengthInBits += 32;
} else if(strcmp(dataProtocolId, "IEC61131_LTIME") == 0) { /* LTIME */
- // Simple field (value)
+ // Simple field (nanoseconds)
lengthInBits += 64;
} else if(strcmp(dataProtocolId, "IEC61131_DATE") == 0) { /* DATE */
- // Simple field (value)
+ // Simple field (daysSinceSiemensEpoch)
lengthInBits += 16;
} else if(strcmp(dataProtocolId, "IEC61131_TIME_OF_DAY") == 0) { /* TIME_OF_DAY */
- // Simple field (value)
+ // Simple field (milliseconds)
lengthInBits += 32;
+ } else if(strcmp(dataProtocolId, "IEC61131_LTIME_OF_DAY") == 0) { /* LTIME_OF_DAY */
+
+ // Simple field (nanoseconds)
+ lengthInBits += 64;
} else if(strcmp(dataProtocolId, "IEC61131_DATE_AND_TIME") == 0) { /* DATE_AND_TIME */
// Simple field (year)
@@ -719,7 +741,7 @@ uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4c_data* data_item, cha
// Simple field (seconds)
lengthInBits += 8;
- // Simple field (nanos)
+ // Simple field (nanoseconds)
lengthInBits += 32;
}
return lengthInBits;
diff --git a/plc4c/spi/include/plc4c/spi/types_private.h b/plc4c/spi/include/plc4c/spi/types_private.h
index 246022d822..b3ec2bde74 100644
--- a/plc4c/spi/include/plc4c/spi/types_private.h
+++ b/plc4c/spi/include/plc4c/spi/types_private.h
@@ -248,10 +248,13 @@ struct plc4c_data_t {
double lreal_value;
uint16_t date_value;
+ uint32_t ldate_value;
uint32_t time_value;
uint64_t ltime_value;
uint32_t time_of_day_value;
+ uint64_t ltime_of_day_value;
uint32_t date_and_time_value;
+ uint64_t ldate_and_time_value;
char char_value;
wchar_t wchar_value;
diff --git a/plc4c/spi/src/data.c b/plc4c/spi/src/data.c
index 458a36a81b..d04b6cfb67 100644
--- a/plc4c/spi/src/data.c
+++ b/plc4c/spi/src/data.c
@@ -266,6 +266,16 @@ plc4c_data *plc4c_data_create_date_array(uint16_t *d, int nItems) {
return NULL;
}
+plc4c_data *plc4c_data_create_ldate_data(uint32_t nanosecondsSinceEpoch) {
+ // TODO: Implement
+ return NULL;
+}
+
+plc4c_data *plc4c_data_create_ldate_array(uint32_t *nanosecondsSinceEpoch, int nItems) {
+ // TODO: Implement
+ return NULL;
+}
+
plc4c_data *plc4c_data_create_time_data(uint32_t t) {
// TODO: Implement
return NULL;
@@ -296,6 +306,16 @@ plc4c_data *plc4c_data_create_time_of_day_array(uint32_t *tod, int nItems) {
return NULL;
}
+plc4c_data *plc4c_data_create_ltime_of_day_data(uint64_t nanosecondsSinceMidnight) {
+ // TODO: Implement
+ return NULL;
+}
+
+plc4c_data *plc4c_data_create_ltime_of_day_array(uint64_t *nanosecondsSinceMidnight, int nItems) {
+ // TODO: Implement
+ return NULL;
+}
+
plc4c_data *plc4c_data_create_date_and_time_data(uint32_t tad) {
// TODO: Implement
return NULL;
@@ -306,6 +326,16 @@ plc4c_data *plc4c_data_create_date_and_time_array(uint32_t *tad, int nItems) {
return NULL;
}
+plc4c_data *plc4c_data_create_ldate_and_time_data(uint64_t nanosecondsSinceEpoch) {
+ // TODO: Implement
+ return NULL;
+}
+
+plc4c_data *plc4c_data_create_ldate_and_time_array(uint64_t *nanosecondsSinceEpoch, int nItems) {
+ // TODO: Implement
+ return NULL;
+}
+
plc4c_data *plc4c_data_create_string_data(unsigned int size, char *s) {
plc4c_data *data = malloc(sizeof(plc4c_data));
data->data_type = PLC4C_STRING;
diff --git a/plc4go/protocols/ads/readwrite/model/DataItem.go b/plc4go/protocols/ads/readwrite/model/DataItem.go
index 2ccedd7f18..f0ca2d483e 100644
--- a/plc4go/protocols/ads/readwrite/model/DataItem.go
+++ b/plc4go/protocols/ads/readwrite/model/DataItem.go
@@ -24,7 +24,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/apache/plc4x/plc4go/spi/values"
"github.com/pkg/errors"
- "time"
)
// Code generated by code-generation. DO NOT EDIT.
@@ -204,46 +203,69 @@ func DataItemParseWithBuffer(readBuffer utils.ReadBuffer, plcValueType PlcValueT
readBuffer.CloseContext("DataItem")
return values.NewPlcWSTRING(value), nil
case plcValueType == PlcValueType_TIME: // TIME
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (milliseconds)
+ milliseconds, _millisecondsErr := readBuffer.ReadUint32("milliseconds", 32)
+ if _millisecondsErr != nil {
+ return nil, errors.Wrap(_millisecondsErr, "Error parsing 'milliseconds' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcTIME(value), nil
+ return values.NewPlcTIMEFromMilliseconds(milliseconds), nil
case plcValueType == PlcValueType_LTIME: // LTIME
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint64("value", 64)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (nanoseconds)
+ nanoseconds, _nanosecondsErr := readBuffer.ReadUint64("nanoseconds", 64)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcLTIME(value), nil
+ return values.NewPlcLTIMEFromNanoseconds(nanoseconds), nil
case plcValueType == PlcValueType_DATE: // DATE
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (secondsSinceEpoch)
+ secondsSinceEpoch, _secondsSinceEpochErr := readBuffer.ReadUint32("secondsSinceEpoch", 32)
+ if _secondsSinceEpochErr != nil {
+ return nil, errors.Wrap(_secondsSinceEpochErr, "Error parsing 'secondsSinceEpoch' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcDATE(value), nil
+ return values.NewPlcDATEFromSecondsSinceEpoch(uint32(secondsSinceEpoch)), nil
+ case plcValueType == PlcValueType_LDATE: // LDATE
+ // Simple Field (nanosecondsSinceEpoch)
+ nanosecondsSinceEpoch, _nanosecondsSinceEpochErr := readBuffer.ReadUint32("nanosecondsSinceEpoch", 32)
+ if _nanosecondsSinceEpochErr != nil {
+ return nil, errors.Wrap(_nanosecondsSinceEpochErr, "Error parsing 'nanosecondsSinceEpoch' field")
+ }
+ readBuffer.CloseContext("DataItem")
+ return values.NewPlcLDATEFromNanosecondsSinceEpoch(uint64(nanosecondsSinceEpoch)), nil
case plcValueType == PlcValueType_TIME_OF_DAY: // TIME_OF_DAY
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (millisecondsSinceMidnight)
+ millisecondsSinceMidnight, _millisecondsSinceMidnightErr := readBuffer.ReadUint32("millisecondsSinceMidnight", 32)
+ if _millisecondsSinceMidnightErr != nil {
+ return nil, errors.Wrap(_millisecondsSinceMidnightErr, "Error parsing 'millisecondsSinceMidnight' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcTIME_OF_DAY(value), nil
+ return values.NewPlcTIME_OF_DAYFromMillisecondsSinceMidnight(millisecondsSinceMidnight), nil
+ case plcValueType == PlcValueType_LTIME_OF_DAY: // LTIME_OF_DAY
+ // Simple Field (nanosecondsSinceMidnight)
+ nanosecondsSinceMidnight, _nanosecondsSinceMidnightErr := readBuffer.ReadUint32("nanosecondsSinceMidnight", 32)
+ if _nanosecondsSinceMidnightErr != nil {
+ return nil, errors.Wrap(_nanosecondsSinceMidnightErr, "Error parsing 'nanosecondsSinceMidnight' field")
+ }
+ readBuffer.CloseContext("DataItem")
+ return values.NewPlcLTIME_OF_DAYFromNanosecondsSinceMidnight(nanosecondsSinceMidnight), nil
case plcValueType == PlcValueType_DATE_AND_TIME: // DATE_AND_TIME
// Simple Field (secondsSinceEpoch)
secondsSinceEpoch, _secondsSinceEpochErr := readBuffer.ReadUint32("secondsSinceEpoch", 32)
if _secondsSinceEpochErr != nil {
return nil, errors.Wrap(_secondsSinceEpochErr, "Error parsing 'secondsSinceEpoch' field")
}
- value := time.Unix(int64(secondsSinceEpoch), 0)
readBuffer.CloseContext("DataItem")
- return values.NewPlcDATE_AND_TIME(value), nil
+ return values.NewPlcDATA_AND_TIMEFromSecondsSinceEpoch(secondsSinceEpoch), nil
+ case plcValueType == PlcValueType_LDATE_AND_TIME: // LDATE_AND_TIME
+ // Simple Field (nanosecondsSinceEpoch)
+ nanosecondsSinceEpoch, _nanosecondsSinceEpochErr := readBuffer.ReadUint32("nanosecondsSinceEpoch", 32)
+ if _nanosecondsSinceEpochErr != nil {
+ return nil, errors.Wrap(_nanosecondsSinceEpochErr, "Error parsing 'nanosecondsSinceEpoch' field")
+ }
+ readBuffer.CloseContext("DataItem")
+ return values.NewPlcLDATE_AND_TIMEFromNanosecondsSinceEpoch(uint64(nanosecondsSinceEpoch)), nil
}
// TODO: add more info which type it is actually
return nil, errors.New("unsupported type")
@@ -379,30 +401,45 @@ func DataItemSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value api.P
return errors.Wrap(_err, "Error serializing reserved field")
}
case plcValueType == PlcValueType_TIME: // TIME
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (milliseconds)
+ if _err := writeBuffer.WriteUint32("milliseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'milliseconds' field")
}
case plcValueType == PlcValueType_LTIME: // LTIME
- // Simple Field (value)
- if _err := writeBuffer.WriteUint64("value", 64, value.GetUint64()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint64("nanoseconds", 64, value.GetUint64()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
case plcValueType == PlcValueType_DATE: // DATE
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (secondsSinceEpoch)
+ if _err := writeBuffer.WriteUint32("secondsSinceEpoch", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'secondsSinceEpoch' field")
+ }
+ case plcValueType == PlcValueType_LDATE: // LDATE
+ // Simple Field (nanosecondsSinceEpoch)
+ if _err := writeBuffer.WriteUint32("nanosecondsSinceEpoch", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanosecondsSinceEpoch' field")
}
case plcValueType == PlcValueType_TIME_OF_DAY: // TIME_OF_DAY
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (millisecondsSinceMidnight)
+ if _err := writeBuffer.WriteUint32("millisecondsSinceMidnight", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'millisecondsSinceMidnight' field")
+ }
+ case plcValueType == PlcValueType_LTIME_OF_DAY: // LTIME_OF_DAY
+ // Simple Field (nanosecondsSinceMidnight)
+ if _err := writeBuffer.WriteUint32("nanosecondsSinceMidnight", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanosecondsSinceMidnight' field")
}
case plcValueType == PlcValueType_DATE_AND_TIME: // DATE_AND_TIME
// Simple Field (secondsSinceEpoch)
if _err := writeBuffer.WriteUint32("secondsSinceEpoch", 32, value.GetUint32()); _err != nil {
return errors.Wrap(_err, "Error serializing 'secondsSinceEpoch' field")
}
+ case plcValueType == PlcValueType_LDATE_AND_TIME: // LDATE_AND_TIME
+ // Simple Field (nanosecondsSinceEpoch)
+ if _err := writeBuffer.WriteUint32("nanosecondsSinceEpoch", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanosecondsSinceEpoch' field")
+ }
default:
// TODO: add more info which type it is actually
return errors.New("unsupported type")
diff --git a/plc4go/protocols/knxnetip/readwrite/model/KnxDatapoint.go b/plc4go/protocols/knxnetip/readwrite/model/KnxDatapoint.go
index b952404821..fa8b6be715 100644
--- a/plc4go/protocols/knxnetip/readwrite/model/KnxDatapoint.go
+++ b/plc4go/protocols/knxnetip/readwrite/model/KnxDatapoint.go
@@ -24,7 +24,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/apache/plc4x/plc4go/spi/values"
"github.com/pkg/errors"
- "time"
)
// Code generated by code-generation. DO NOT EDIT.
@@ -263,65 +262,65 @@ func KnxDatapointParseWithBuffer(readBuffer utils.ReadBuffer, datapointType KnxD
return nil, errors.Wrap(_err, "Error parsing reserved field")
}
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (milliseconds)
+ milliseconds, _millisecondsErr := readBuffer.ReadUint32("milliseconds", 32)
+ if _millisecondsErr != nil {
+ return nil, errors.Wrap(_millisecondsErr, "Error parsing 'milliseconds' field")
}
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcTIME(value), nil
+ return values.NewPlcTIMEFromMilliseconds(milliseconds), nil
case datapointType == KnxDatapointType_LTIME: // LTIME
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 8); _err != nil {
return nil, errors.Wrap(_err, "Error parsing reserved field")
}
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint64("value", 64)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (nanoseconds)
+ nanoseconds, _nanosecondsErr := readBuffer.ReadUint64("nanoseconds", 64)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcLTIME(value), nil
+ return values.NewPlcLTIMEFromNanoseconds(nanoseconds), nil
case datapointType == KnxDatapointType_DATE: // DATE
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 8); _err != nil {
return nil, errors.Wrap(_err, "Error parsing reserved field")
}
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint16("value", 16)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (secondsSinceEpoch)
+ secondsSinceEpoch, _secondsSinceEpochErr := readBuffer.ReadUint16("secondsSinceEpoch", 16)
+ if _secondsSinceEpochErr != nil {
+ return nil, errors.Wrap(_secondsSinceEpochErr, "Error parsing 'secondsSinceEpoch' field")
}
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcDATE(value), nil
+ return values.NewPlcDATEFromSecondsSinceEpoch(uint32(secondsSinceEpoch)), nil
case datapointType == KnxDatapointType_TIME_OF_DAY: // TIME_OF_DAY
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 8); _err != nil {
return nil, errors.Wrap(_err, "Error parsing reserved field")
}
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (millisecondsSinceMidnight)
+ millisecondsSinceMidnight, _millisecondsSinceMidnightErr := readBuffer.ReadUint32("millisecondsSinceMidnight", 32)
+ if _millisecondsSinceMidnightErr != nil {
+ return nil, errors.Wrap(_millisecondsSinceMidnightErr, "Error parsing 'millisecondsSinceMidnight' field")
}
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcTIME_OF_DAY(value), nil
+ return values.NewPlcTIME_OF_DAYFromMillisecondsSinceMidnight(millisecondsSinceMidnight), nil
case datapointType == KnxDatapointType_TOD: // TIME_OF_DAY
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 8); _err != nil {
return nil, errors.Wrap(_err, "Error parsing reserved field")
}
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (millisecondsSinceMidnight)
+ millisecondsSinceMidnight, _millisecondsSinceMidnightErr := readBuffer.ReadUint32("millisecondsSinceMidnight", 32)
+ if _millisecondsSinceMidnightErr != nil {
+ return nil, errors.Wrap(_millisecondsSinceMidnightErr, "Error parsing 'millisecondsSinceMidnight' field")
}
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcTIME_OF_DAY(value), nil
+ return values.NewPlcTIME_OF_DAYFromMillisecondsSinceMidnight(millisecondsSinceMidnight), nil
case datapointType == KnxDatapointType_DATE_AND_TIME: // DATE_AND_TIME
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 8); _err != nil {
@@ -370,14 +369,13 @@ func KnxDatapointParseWithBuffer(readBuffer utils.ReadBuffer, datapointType KnxD
return nil, errors.Wrap(_secondsErr, "Error parsing 'seconds' field")
}
- // Simple Field (nanos)
- _, _nanosErr := readBuffer.ReadUint32("nanos", 32)
- if _nanosErr != nil {
- return nil, errors.Wrap(_nanosErr, "Error parsing 'nanos' field")
+ // Simple Field (nanoseconds)
+ nanoseconds, _nanosecondsErr := readBuffer.ReadUint32("nanoseconds", 32)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
- value := time.Date(int(year), time.Month(month), int(day), int(hour), int(minutes), int(seconds), 0, nil)
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcDATE_AND_TIME(value), nil
+ return values.NewPlcDATA_AND_TIMEFromSegments(uint32(year), uint32(month), uint32(day), uint32(hour), uint32(minutes), uint32(seconds), uint32(nanoseconds)), nil
case datapointType == KnxDatapointType_DT: // DATE_AND_TIME
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 8); _err != nil {
@@ -426,14 +424,13 @@ func KnxDatapointParseWithBuffer(readBuffer utils.ReadBuffer, datapointType KnxD
return nil, errors.Wrap(_secondsErr, "Error parsing 'seconds' field")
}
- // Simple Field (nanos)
- _, _nanosErr := readBuffer.ReadUint32("nanos", 32)
- if _nanosErr != nil {
- return nil, errors.Wrap(_nanosErr, "Error parsing 'nanos' field")
+ // Simple Field (nanoseconds)
+ nanoseconds, _nanosecondsErr := readBuffer.ReadUint32("nanoseconds", 32)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
- value := time.Date(int(year), time.Month(month), int(day), int(hour), int(minutes), int(seconds), 0, nil)
readBuffer.CloseContext("KnxDatapoint")
- return values.NewPlcDATE_AND_TIME(value), nil
+ return values.NewPlcDATA_AND_TIMEFromSegments(uint32(year), uint32(month), uint32(day), uint32(hour), uint32(minutes), uint32(seconds), uint32(nanoseconds)), nil
case datapointType == KnxDatapointType_DPT_Switch: // BOOL
// Reserved Field (Just skip the bytes)
if _, _err := readBuffer.ReadUint8("reserved", 7); _err != nil {
@@ -7757,9 +7754,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing reserved field")
}
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (milliseconds)
+ if _err := writeBuffer.WriteUint32("milliseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'milliseconds' field")
}
case datapointType == KnxDatapointType_LTIME: // LTIME
// Reserved Field (Just skip the bytes)
@@ -7767,9 +7764,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing reserved field")
}
- // Simple Field (value)
- if _err := writeBuffer.WriteUint64("value", 64, value.GetUint64()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint64("nanoseconds", 64, value.GetUint64()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
case datapointType == KnxDatapointType_DATE: // DATE
// Reserved Field (Just skip the bytes)
@@ -7777,9 +7774,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing reserved field")
}
- // Simple Field (value)
- if _err := writeBuffer.WriteUint16("value", 16, value.GetUint16()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (secondsSinceEpoch)
+ if _err := writeBuffer.WriteUint16("secondsSinceEpoch", 16, value.GetUint16()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'secondsSinceEpoch' field")
}
case datapointType == KnxDatapointType_TIME_OF_DAY: // TIME_OF_DAY
// Reserved Field (Just skip the bytes)
@@ -7787,9 +7784,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing reserved field")
}
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (millisecondsSinceMidnight)
+ if _err := writeBuffer.WriteUint32("millisecondsSinceMidnight", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'millisecondsSinceMidnight' field")
}
case datapointType == KnxDatapointType_TOD: // TIME_OF_DAY
// Reserved Field (Just skip the bytes)
@@ -7797,9 +7794,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing reserved field")
}
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (millisecondsSinceMidnight)
+ if _err := writeBuffer.WriteUint32("millisecondsSinceMidnight", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'millisecondsSinceMidnight' field")
}
case datapointType == KnxDatapointType_DATE_AND_TIME: // DATE_AND_TIME
// Reserved Field (Just skip the bytes)
@@ -7842,9 +7839,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing 'seconds' field")
}
- // Simple Field (nanos)
- if _err := writeBuffer.WriteUint32("nanos", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'nanos' field")
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint32("nanoseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
case datapointType == KnxDatapointType_DT: // DATE_AND_TIME
// Reserved Field (Just skip the bytes)
@@ -7887,9 +7884,9 @@ func KnxDatapointSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value a
return errors.Wrap(_err, "Error serializing 'seconds' field")
}
- // Simple Field (nanos)
- if _err := writeBuffer.WriteUint32("nanos", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'nanos' field")
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint32("nanoseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
case datapointType == KnxDatapointType_DPT_Switch: // BOOL
// Reserved Field (Just skip the bytes)
diff --git a/plc4go/protocols/s7/readwrite/model/DataItem.go b/plc4go/protocols/s7/readwrite/model/DataItem.go
index 751a4aa0e2..324965f841 100644
--- a/plc4go/protocols/s7/readwrite/model/DataItem.go
+++ b/plc4go/protocols/s7/readwrite/model/DataItem.go
@@ -24,7 +24,6 @@ import (
"github.com/apache/plc4x/plc4go/spi/utils"
"github.com/apache/plc4x/plc4go/spi/values"
"github.com/pkg/errors"
- "time"
)
// Code generated by code-generation. DO NOT EDIT.
@@ -194,37 +193,43 @@ func DataItemParseWithBuffer(readBuffer utils.ReadBuffer, dataProtocolId string,
readBuffer.CloseContext("DataItem")
return values.NewPlcSTRING(value), nil
case dataProtocolId == "IEC61131_TIME": // TIME
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (milliseconds)
+ milliseconds, _millisecondsErr := readBuffer.ReadUint32("milliseconds", 32)
+ if _millisecondsErr != nil {
+ return nil, errors.Wrap(_millisecondsErr, "Error parsing 'milliseconds' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcTIME(value), nil
+ return values.NewPlcTIMEFromMilliseconds(milliseconds), nil
case dataProtocolId == "IEC61131_LTIME": // LTIME
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint64("value", 64)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (nanoseconds)
+ nanoseconds, _nanosecondsErr := readBuffer.ReadUint64("nanoseconds", 64)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcLTIME(value), nil
+ return values.NewPlcLTIMEFromNanoseconds(nanoseconds), nil
case dataProtocolId == "IEC61131_DATE": // DATE
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint16("value", 16)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (daysSinceSiemensEpoch)
+ daysSinceSiemensEpoch, _daysSinceSiemensEpochErr := readBuffer.ReadUint16("daysSinceSiemensEpoch", 16)
+ if _daysSinceSiemensEpochErr != nil {
+ return nil, errors.Wrap(_daysSinceSiemensEpochErr, "Error parsing 'daysSinceSiemensEpoch' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcDATE(value), nil
+ return values.NewPlcDATEFromDaysSinceSiemensEpoch(daysSinceSiemensEpoch), nil
case dataProtocolId == "IEC61131_TIME_OF_DAY": // TIME_OF_DAY
- // Simple Field (value)
- value, _valueErr := readBuffer.ReadUint32("value", 32)
- if _valueErr != nil {
- return nil, errors.Wrap(_valueErr, "Error parsing 'value' field")
+ // Simple Field (milliseconds)
+ _, _millisecondsErr := readBuffer.ReadUint32("milliseconds", 32)
+ if _millisecondsErr != nil {
+ return nil, errors.Wrap(_millisecondsErr, "Error parsing 'milliseconds' field")
+ }
+ readBuffer.CloseContext("DataItem")
+ case dataProtocolId == "IEC61131_LTIME_OF_DAY": // LTIME_OF_DAY
+ // Simple Field (nanoseconds)
+ _, _nanosecondsErr := readBuffer.ReadUint64("nanoseconds", 64)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
readBuffer.CloseContext("DataItem")
- return values.NewPlcTIME_OF_DAY(value), nil
case dataProtocolId == "IEC61131_DATE_AND_TIME": // DATE_AND_TIME
// Simple Field (year)
year, _yearErr := readBuffer.ReadUint16("year", 16)
@@ -268,14 +273,13 @@ func DataItemParseWithBuffer(readBuffer utils.ReadBuffer, dataProtocolId string,
return nil, errors.Wrap(_secondsErr, "Error parsing 'seconds' field")
}
- // Simple Field (nanos)
- _, _nanosErr := readBuffer.ReadUint32("nanos", 32)
- if _nanosErr != nil {
- return nil, errors.Wrap(_nanosErr, "Error parsing 'nanos' field")
+ // Simple Field (nanoseconds)
+ nanoseconds, _nanosecondsErr := readBuffer.ReadUint32("nanoseconds", 32)
+ if _nanosecondsErr != nil {
+ return nil, errors.Wrap(_nanosecondsErr, "Error parsing 'nanoseconds' field")
}
- value := time.Date(int(year), time.Month(month), int(day), int(hour), int(minutes), int(seconds), 0, nil)
readBuffer.CloseContext("DataItem")
- return values.NewPlcDATE_AND_TIME(value), nil
+ return values.NewPlcDATA_AND_TIMEFromSegments(uint32(year), uint32(month), uint32(day), uint32(hour), uint32(minutes), uint32(seconds), uint32(nanoseconds)), nil
}
// TODO: add more info which type it is actually
return nil, errors.New("unsupported type")
@@ -403,24 +407,29 @@ func DataItemSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value api.P
return errors.Wrap(_valueErr, "Error serializing 'value' field")
}
case dataProtocolId == "IEC61131_TIME": // TIME
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (milliseconds)
+ if _err := writeBuffer.WriteUint32("milliseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'milliseconds' field")
}
case dataProtocolId == "IEC61131_LTIME": // LTIME
- // Simple Field (value)
- if _err := writeBuffer.WriteUint64("value", 64, value.GetUint64()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint64("nanoseconds", 64, value.GetUint64()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
case dataProtocolId == "IEC61131_DATE": // DATE
- // Simple Field (value)
- if _err := writeBuffer.WriteUint16("value", 16, value.GetUint16()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (daysSinceSiemensEpoch)
+ if _err := writeBuffer.WriteUint16("daysSinceSiemensEpoch", 16, value.GetUint16()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'daysSinceSiemensEpoch' field")
}
case dataProtocolId == "IEC61131_TIME_OF_DAY": // TIME_OF_DAY
- // Simple Field (value)
- if _err := writeBuffer.WriteUint32("value", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'value' field")
+ // Simple Field (milliseconds)
+ if _err := writeBuffer.WriteUint32("milliseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'milliseconds' field")
+ }
+ case dataProtocolId == "IEC61131_LTIME_OF_DAY": // LTIME_OF_DAY
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint64("nanoseconds", 64, value.GetUint64()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
case dataProtocolId == "IEC61131_DATE_AND_TIME": // DATE_AND_TIME
// Simple Field (year)
@@ -458,9 +467,9 @@ func DataItemSerializeWithWriteBuffer(writeBuffer utils.WriteBuffer, value api.P
return errors.Wrap(_err, "Error serializing 'seconds' field")
}
- // Simple Field (nanos)
- if _err := writeBuffer.WriteUint32("nanos", 32, value.GetUint32()); _err != nil {
- return errors.Wrap(_err, "Error serializing 'nanos' field")
+ // Simple Field (nanoseconds)
+ if _err := writeBuffer.WriteUint32("nanoseconds", 32, value.GetUint32()); _err != nil {
+ return errors.Wrap(_err, "Error serializing 'nanoseconds' field")
}
default:
// TODO: add more info which type it is actually
diff --git a/plc4go/spi/values/PlcDATE.go b/plc4go/spi/values/PlcDATE.go
index 26e6ea6653..a9695817ca 100644
--- a/plc4go/spi/values/PlcDATE.go
+++ b/plc4go/spi/values/PlcDATE.go
@@ -29,8 +29,8 @@ import (
)
type PlcDATE struct {
- value time.Time
PlcValueAdapter
+ value time.Time
}
func NewPlcDATE(value interface{}) PlcDATE {
@@ -53,6 +53,20 @@ func NewPlcDATE(value interface{}) PlcDATE {
}
}
+func NewPlcDATEFromSecondsSinceEpoch(secondsSinceEpoch uint32) PlcDATE {
+ return NewPlcDATE(time.Unix(int64(secondsSinceEpoch), 0))
+}
+
+func NewPlcDATEFromDaysSinceEpoch(daysSinceEpoch uint16) PlcDATE {
+ // 86400 = 24 hours x 60 Minutes x 60 Seconds
+ return NewPlcDATE(time.Unix(int64(daysSinceEpoch)*86400, 0))
+}
+
+func NewPlcDATEFromDaysSinceSiemensEpoch(daysSinceSiemensEpoch uint16) PlcDATE {
+ // 86400 = 24 hours x 60 Minutes x 60 Seconds
+ return NewPlcDATEFromDaysSinceEpoch(daysSinceSiemensEpoch + 7305)
+}
+
func (m PlcDATE) GetRaw() []byte {
theBytes, _ := m.Serialize()
return theBytes
@@ -61,6 +75,7 @@ func (m PlcDATE) GetRaw() []byte {
func (m PlcDATE) IsDate() bool {
return true
}
+
func (m PlcDATE) GetDate() time.Time {
return time.Date(m.value.Year(), m.value.Month(), m.value.Day(), 0, 0, 0, 0, time.UTC)
}
diff --git a/plc4go/spi/values/PlcDATE_AND_TIME.go b/plc4go/spi/values/PlcDATE_AND_TIME.go
index d87c72a39f..57c9898a92 100644
--- a/plc4go/spi/values/PlcDATE_AND_TIME.go
+++ b/plc4go/spi/values/PlcDATE_AND_TIME.go
@@ -29,8 +29,8 @@ import (
)
type PlcDATE_AND_TIME struct {
- value time.Time
PlcValueAdapter
+ value time.Time
}
func NewPlcDATE_AND_TIME(value time.Time) PlcDATE_AND_TIME {
@@ -39,6 +39,14 @@ func NewPlcDATE_AND_TIME(value time.Time) PlcDATE_AND_TIME {
}
}
+func NewPlcDATA_AND_TIMEFromSegments(year, month, day, hour, minutes, seconds, nanoseconds uint32) PlcDATE_AND_TIME {
+ return NewPlcDATE_AND_TIME(time.Date(int(year), time.Month(month), int(day), int(hour), int(minutes), int(seconds), int(nanoseconds), time.Local))
+}
+
+func NewPlcDATA_AND_TIMEFromSecondsSinceEpoch(secondsSinceEpoch uint32) PlcDATE_AND_TIME {
+ return NewPlcDATE_AND_TIME(time.Unix(int64(secondsSinceEpoch), 0))
+}
+
func (m PlcDATE_AND_TIME) GetRaw() []byte {
theBytes, _ := m.Serialize()
return theBytes
@@ -47,6 +55,7 @@ func (m PlcDATE_AND_TIME) GetRaw() []byte {
func (m PlcDATE_AND_TIME) IsDateTime() bool {
return true
}
+
func (m PlcDATE_AND_TIME) GetDateTime() time.Time {
return m.value
}
diff --git a/plc4go/spi/values/PlcLDATE.go b/plc4go/spi/values/PlcLDATE.go
index 0c658af40b..d4ec4354c6 100644
--- a/plc4go/spi/values/PlcLDATE.go
+++ b/plc4go/spi/values/PlcLDATE.go
@@ -18,3 +18,76 @@
*/
package values
+
+import (
+ "encoding/binary"
+ "fmt"
+ "time"
+
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+ "github.com/apache/plc4x/plc4go/spi/utils"
+)
+
+type PlcLDATE struct {
+ PlcValueAdapter
+ value time.Time
+}
+
+func NewPlcLDATE(value interface{}) PlcLDATE {
+ var timeValue time.Time
+ switch value.(type) {
+ case time.Time:
+ timeValue = value.(time.Time)
+ case uint64:
+ // Interpreted as "nanoseconds since epoch"
+ castedValue := value.(uint64)
+ seconds := castedValue / 1000000
+ nanoseconds := castedValue % 1000000
+ timeValue = time.Unix(int64(seconds), int64(nanoseconds))
+ }
+ safeValue := time.Date(timeValue.Year(), timeValue.Month(), timeValue.Day(), 0, 0, 0, 0, timeValue.Location())
+ return PlcLDATE{
+ value: safeValue,
+ }
+}
+
+func NewPlcLDATEFromNanosecondsSinceEpoch(nanosecondsSinceEpoch uint64) PlcDATE {
+ return NewPlcDATE(nanosecondsSinceEpoch)
+}
+
+func (m PlcLDATE) GetRaw() []byte {
+ theBytes, _ := m.Serialize()
+ return theBytes
+}
+
+func (m PlcLDATE) IsDate() bool {
+ return true
+}
+
+func (m PlcLDATE) GetDate() time.Time {
+ return time.Date(m.value.Year(), m.value.Month(), m.value.Day(), 0, 0, 0, 0, time.UTC)
+}
+
+func (m PlcLDATE) GetString() string {
+ return m.GetDate().Format("2006-01-02")
+}
+
+func (m PlcLDATE) GetPlcValueType() apiValues.PlcValueType {
+ return apiValues.DATE
+}
+
+func (m PlcLDATE) Serialize() ([]byte, error) {
+ wb := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.BigEndian))
+ if err := m.SerializeWithWriteBuffer(wb); err != nil {
+ return nil, err
+ }
+ return wb.GetBytes(), nil
+}
+
+func (m PlcLDATE) SerializeWithWriteBuffer(writeBuffer utils.WriteBuffer) error {
+ return writeBuffer.WriteString("PlcLDATE", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
+}
+
+func (m PlcLDATE) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPlcValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/PlcLDATE_AND_TIME.go b/plc4go/spi/values/PlcLDATE_AND_TIME.go
index 0c658af40b..dab9857b64 100644
--- a/plc4go/spi/values/PlcLDATE_AND_TIME.go
+++ b/plc4go/spi/values/PlcLDATE_AND_TIME.go
@@ -18,3 +18,75 @@
*/
package values
+
+import (
+ "encoding/binary"
+ "fmt"
+ "time"
+
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+ "github.com/apache/plc4x/plc4go/spi/utils"
+)
+
+type PlcLDATE_AND_TIME struct {
+ PlcValueAdapter
+ value time.Time
+}
+
+func NewPlcLDATE_AND_TIME(value interface{}) PlcLDATE_AND_TIME {
+ var timeValue time.Time
+ switch value.(type) {
+ case time.Time:
+ timeValue = value.(time.Time)
+ case uint64:
+ castedValue := value.(uint64)
+ seconds := castedValue / 1000000
+ nanoseconds := castedValue % 1000000
+ timeValue = time.Unix(int64(seconds), int64(nanoseconds))
+ }
+ safeValue := time.Date(timeValue.Year(), timeValue.Month(), timeValue.Day(), 0, 0, 0, 0, timeValue.Location())
+ return PlcLDATE_AND_TIME{
+ value: safeValue,
+ }
+}
+
+func NewPlcLDATE_AND_TIMEFromNanosecondsSinceEpoch(nanosecondsSinceEpoch uint64) PlcLDATE_AND_TIME {
+ return NewPlcLDATE_AND_TIME(nanosecondsSinceEpoch)
+}
+
+func (m PlcLDATE_AND_TIME) GetRaw() []byte {
+ theBytes, _ := m.Serialize()
+ return theBytes
+}
+
+func (m PlcLDATE_AND_TIME) IsDate() bool {
+ return true
+}
+
+func (m PlcLDATE_AND_TIME) GetDate() time.Time {
+ return time.Date(m.value.Year(), m.value.Month(), m.value.Day(), 0, 0, 0, 0, time.UTC)
+}
+
+func (m PlcLDATE_AND_TIME) GetString() string {
+ return m.GetDate().Format("2006-01-02")
+}
+
+func (m PlcLDATE_AND_TIME) GetPlcValueType() apiValues.PlcValueType {
+ return apiValues.DATE
+}
+
+func (m PlcLDATE_AND_TIME) Serialize() ([]byte, error) {
+ wb := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.BigEndian))
+ if err := m.SerializeWithWriteBuffer(wb); err != nil {
+ return nil, err
+ }
+ return wb.GetBytes(), nil
+}
+
+func (m PlcLDATE_AND_TIME) SerializeWithWriteBuffer(writeBuffer utils.WriteBuffer) error {
+ return writeBuffer.WriteString("PlcLDATE_AND_TIME", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
+}
+
+func (m PlcLDATE_AND_TIME) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPlcValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/PlcLTIME.go b/plc4go/spi/values/PlcLTIME.go
index 5654dbfebd..aa63e94517 100644
--- a/plc4go/spi/values/PlcLTIME.go
+++ b/plc4go/spi/values/PlcLTIME.go
@@ -30,15 +30,19 @@ import (
type PlcLTIME struct {
PlcSimpleValueAdapter
- value uint64
+ value time.Duration
}
-func NewPlcLTIME(value uint64) PlcLTIME {
+func NewPlcLTIME(value time.Duration) PlcLTIME {
return PlcLTIME{
value: value,
}
}
+func NewPlcLTIMEFromNanoseconds(nanoseconds uint64) PlcLTIME {
+ return NewPlcLTIME(time.Duration(nanoseconds) * time.Nanosecond)
+}
+
func (m PlcLTIME) GetRaw() []byte {
theBytes, _ := m.Serialize()
return theBytes
@@ -49,7 +53,7 @@ func (m PlcLTIME) IsDuration() bool {
}
func (m PlcLTIME) GetDuration() time.Duration {
- return time.Duration(m.value)
+ return m.value
}
func (m PlcLTIME) IsString() bool {
diff --git a/plc4go/spi/values/PlcLTIME_OF_DAY.go b/plc4go/spi/values/PlcLTIME_OF_DAY.go
index 0c658af40b..46e18c3dda 100644
--- a/plc4go/spi/values/PlcLTIME_OF_DAY.go
+++ b/plc4go/spi/values/PlcLTIME_OF_DAY.go
@@ -18,3 +18,80 @@
*/
package values
+
+import (
+ "encoding/binary"
+ "fmt"
+ "time"
+
+ apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
+ "github.com/apache/plc4x/plc4go/spi/utils"
+)
+
+type PlcLTIME_OF_DAY struct {
+ PlcSimpleValueAdapter
+ value time.Time
+}
+
+func NewPlcLTIME_OF_DAY(value interface{}) PlcLTIME_OF_DAY {
+ var safeValue time.Time
+ switch value.(type) {
+ case time.Time:
+ castedValue := value.(time.Time)
+ safeValue = time.Date(0, 0, 0, castedValue.Hour(), castedValue.Minute(), castedValue.Second(),
+ castedValue.Nanosecond(), castedValue.Location())
+ case uint64:
+ // Interpreted as nanoseconds since midnight
+ castedValue := value.(uint64)
+ seconds := castedValue / 1000000
+ nanoseconds := castedValue % 1000000
+ epochTime := time.Unix(int64(seconds), int64(nanoseconds))
+ safeValue = time.Date(0, 0, 0, epochTime.Hour(), epochTime.Minute(), epochTime.Second(),
+ epochTime.Nanosecond(), epochTime.Location())
+ }
+
+ return PlcLTIME_OF_DAY{
+ value: safeValue,
+ }
+}
+
+func NewPlcLTIME_OF_DAYFromNanosecondsSinceMidnight(nanosecondsSinceMidnight uint32) PlcLTIME_OF_DAY {
+ return NewPlcLTIME_OF_DAY(nanosecondsSinceMidnight)
+}
+
+func (m PlcLTIME_OF_DAY) GetRaw() []byte {
+ theBytes, _ := m.Serialize()
+ return theBytes
+}
+
+func (m PlcLTIME_OF_DAY) IsTime() bool {
+ return true
+}
+
+func (m PlcLTIME_OF_DAY) GetTime() time.Time {
+ return m.value
+}
+
+func (m PlcLTIME_OF_DAY) GetString() string {
+ return m.value.Format("15:04:05.000")
+}
+
+func (m PlcLTIME_OF_DAY) GetPlcValueType() apiValues.PlcValueType {
+ return apiValues.TIME_OF_DAY
+}
+
+func (m PlcLTIME_OF_DAY) Serialize() ([]byte, error) {
+ wb := utils.NewWriteBufferByteBased(utils.WithByteOrderForByteBasedBuffer(binary.BigEndian))
+ if err := m.SerializeWithWriteBuffer(wb); err != nil {
+ return nil, err
+ }
+ return wb.GetBytes(), nil
+}
+
+func (m PlcLTIME_OF_DAY) SerializeWithWriteBuffer(writeBuffer utils.WriteBuffer) error {
+ return writeBuffer.WriteString("PlcLTIME_OF_DAY", uint32(len([]rune(m.GetString()))*8), "UTF-8", m.GetString())
+}
+
+func (m PlcLTIME_OF_DAY) String() string {
+ return fmt.Sprintf("%s(%dbit):%v", m.GetPlcValueType(), uint32(len([]rune(m.GetString()))*8), m.value)
+}
diff --git a/plc4go/spi/values/PlcTIME.go b/plc4go/spi/values/PlcTIME.go
index 3ef2f2844f..42c750d0ff 100644
--- a/plc4go/spi/values/PlcTIME.go
+++ b/plc4go/spi/values/PlcTIME.go
@@ -30,15 +30,19 @@ import (
type PlcTIME struct {
PlcSimpleValueAdapter
- value uint32
+ value time.Duration
}
-func NewPlcTIME(value uint32) PlcTIME {
+func NewPlcTIME(value time.Duration) PlcTIME {
return PlcTIME{
value: value,
}
}
+func NewPlcTIMEFromMilliseconds(milliseconds uint32) PlcTIME {
+ return NewPlcTIME(time.Duration(milliseconds) * time.Millisecond)
+}
+
func (m PlcTIME) GetRaw() []byte {
theBytes, _ := m.Serialize()
return theBytes
@@ -49,7 +53,7 @@ func (m PlcTIME) IsDuration() bool {
}
func (m PlcTIME) GetDuration() time.Duration {
- return time.Duration(m.value)
+ return m.value
}
func (m PlcTIME) IsString() bool {
diff --git a/plc4go/spi/values/PlcTIME_OF_DAY.go b/plc4go/spi/values/PlcTIME_OF_DAY.go
index 1b84b7ae89..daea0e6928 100644
--- a/plc4go/spi/values/PlcTIME_OF_DAY.go
+++ b/plc4go/spi/values/PlcTIME_OF_DAY.go
@@ -46,7 +46,8 @@ func NewPlcTIME_OF_DAY(value interface{}) PlcTIME_OF_DAY {
seconds := castedValue / 1000
nanoseconds := (castedValue % 1000) * 1000000
epochTime := time.Unix(int64(seconds), int64(nanoseconds))
- safeValue = time.Date(0, 0, 0, epochTime.Hour(), epochTime.Minute(), epochTime.Second(),
+ safeValue = time.Date(0, 0, 0, epochTime.Hour(),
+ epochTime.Minute(), epochTime.Second(),
epochTime.Nanosecond(), epochTime.Location())
}
@@ -55,6 +56,10 @@ func NewPlcTIME_OF_DAY(value interface{}) PlcTIME_OF_DAY {
}
}
+func NewPlcTIME_OF_DAYFromMillisecondsSinceMidnight(millisecondsSinceMidnight uint32) PlcTIME_OF_DAY {
+ return NewPlcTIME_OF_DAY(millisecondsSinceMidnight)
+}
+
func (m PlcTIME_OF_DAY) GetRaw() []byte {
theBytes, _ := m.Serialize()
return theBytes
diff --git a/plc4go/spi/values/PlcValueHandler.go b/plc4go/spi/values/PlcValueHandler.go
index ff2c62f2df..d93950e338 100644
--- a/plc4go/spi/values/PlcValueHandler.go
+++ b/plc4go/spi/values/PlcValueHandler.go
@@ -32,61 +32,6 @@ import (
"github.com/rs/zerolog/log"
)
-const (
- ////
- // Bit & Bit-Strings
-
- IEC61131_BOOL string = "BOOL"
- IEC61131_BYTE string = "BYTE"
- IEC61131_WORD string = "WORD"
- IEC61131_DWORD string = "DWORD"
- IEC61131_LWORD string = "LWORD"
- //
- ////
-
- ////
- // Integers
-
- IEC61131_USINT string = "USINT"
- IEC61131_UINT string = "UINT"
- IEC61131_UDINT string = "UDINT"
- IEC61131_ULINT string = "ULINT"
- IEC61131_SINT string = "SINT"
- IEC61131_INT string = "INT"
- IEC61131_DINT string = "DINT"
- IEC61131_LINT string = "LINT"
- //
- ////
-
- ////
- // Floating Point Values
-
- IEC61131_REAL string = "REAL"
- IEC61131_LREAL string = "LREAL"
- //
- ////
-
- ////
- // Temporal Values
-
- IEC61131_TIME string = "TIME"
- IEC61131_DATE string = "DATE"
- IEC61131_TIME_OF_DAY string = "TIME_OF_DAY"
- IEC61131_DATE_AND_TIME string = "DATE_AND_TIME"
- //
- ////
-
- ////
- // Chars and Strings
-
- IEC61131_CHAR string = "CHAR"
- IEC61131_WCHAR string = "WCHAR"
- IEC61131_STRING string = "STRING"
- IEC61131_WSTRING string = "WSTRING"
- //
- ////
-)
-
type DefaultValueHandler struct {
}
@@ -390,16 +335,18 @@ func (m DefaultValueHandler) NewPlcValueFromType(valueType values.PlcValueType,
}
// Temporal Values
+ // - Duration
case values.TIME:
if isString {
return nil, errors.New("string to IEC61131_TIME conversion not implemented")
} else {
- casted, ok := value.(uint32)
+ casted, ok := value.(time.Duration)
if !ok {
- return nil, errors.New("couldn't cast value of type " + reflect.TypeOf(value).Name() + " to uint32")
+ return nil, errors.New("couldn't cast value of type " + reflect.TypeOf(value).Name() + " to time.Duration")
}
return NewPlcTIME(casted), nil
}
+ // - Date
case values.DATE:
if isString {
return nil, errors.New("string to IEC61131_DATE conversion not implemented")
@@ -410,6 +357,7 @@ func (m DefaultValueHandler) NewPlcValueFromType(valueType values.PlcValueType,
}
return NewPlcDATE(casted), nil
}
+ // - Time
case values.TIME_OF_DAY:
if isString {
return nil, errors.New("string to IEC61131_TIME_OF_DAY conversion not implemented")
@@ -420,6 +368,7 @@ func (m DefaultValueHandler) NewPlcValueFromType(valueType values.PlcValueType,
}
return NewPlcTIME_OF_DAY(casted), nil
}
+ // - Date and Time
case values.DATE_AND_TIME:
if isString {
return nil, errors.New("string to IEC61131_DATE_AND_TIME conversion not implemented")
diff --git a/plc4go/spi/values/value_combination_test.go b/plc4go/spi/values/value_combination_test.go
index 615e5d5d7d..e79f2ec7ee 100644
--- a/plc4go/spi/values/value_combination_test.go
+++ b/plc4go/spi/values/value_combination_test.go
@@ -152,7 +152,7 @@ func TestCombinations(t *testing.T) {
NewPlcLTIME(0),
NewPlcLTIME(64),
NewPlcLTIME(255),
- NewPlcLTIME(math.MaxUint64),
+ //NewPlcLTIME(math.MaxUint64),
},
},
{
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE.java
index 833d526d9c..2ec648dd57 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE.java
@@ -46,23 +46,36 @@ public class PlcDATE extends PlcSimpleValue<LocalDate> {
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcDATE ofSecondsSinceEpoch(long secondsSinceEpoch) {
+ return new PlcDATE(LocalDateTime.ofInstant(
+ Instant.ofEpochSecond(secondsSinceEpoch), ZoneId.systemDefault()).toLocalDate());
+ }
+
+ public static PlcDATE ofDaysSinceEpoch(int daysSinceEpoch) {
+ // 86400 = 24 hours x 60 Minutes x 60 Seconds
+ return new PlcDATE(LocalDateTime.ofInstant(
+ Instant.ofEpochSecond(((long) daysSinceEpoch) * 86400), ZoneId.systemDefault()).toLocalDate());
+ }
+
+ public static PlcDATE ofDaysSinceSiemensEpoch(int daysSinceSiemensEpoch) {
+ return ofDaysSinceEpoch(daysSinceSiemensEpoch + 7305);
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcDATE(@JsonProperty("value") LocalDate value) {
super(value, true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcDATE(@JsonProperty("value") Integer value) {
- // In this case the date is the number of days since 1990-01-01
- // So we gotta add 7305 days to the value to have it relative to epoch
- // Then we also need to transform it from days to seconds by multiplying by 86400
- super(LocalDateTime.ofInstant(Instant.ofEpochSecond((value + 7305L) * 86400L),
- ZoneId.systemDefault()).toLocalDate(), true);
+ public PlcDATE(@JsonProperty("value") int daysSinceEpoch) {
+ super(LocalDateTime.ofInstant(
+ Instant.ofEpochSecond(((long) daysSinceEpoch) * 86400), ZoneId.systemDefault()).toLocalDate(), true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcDATE(@JsonProperty("value") Long value) {
- super(LocalDateTime.ofInstant(Instant.ofEpochSecond(value), ZoneId.systemDefault()).toLocalDate(), true);
+ public PlcDATE(@JsonProperty("value") long secondsSinceEpoch) {
+ super(LocalDateTime.ofInstant(
+ Instant.ofEpochSecond(secondsSinceEpoch), ZoneId.systemDefault()).toLocalDate(), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE_AND_TIME.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE_AND_TIME.java
index 1d5121bd7d..10b37d8bf2 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE_AND_TIME.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcDATE_AND_TIME.java
@@ -43,15 +43,28 @@ public class PlcDATE_AND_TIME extends PlcSimpleValue<LocalDateTime> {
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcDATE_AND_TIME ofSecondsSinceEpoch(long secondsSinceEpoch) {
+ return new PlcDATE_AND_TIME(LocalDateTime.ofInstant(
+ Instant.ofEpochSecond(secondsSinceEpoch), ZoneId.systemDefault()));
+ }
+
+ public static PlcDATE_AND_TIME ofSegments(int year, int month, int day, int hour, int minutes, int seconds, int nanoseconds) {
+ return new PlcDATE_AND_TIME(LocalDateTime.of(year, month, day, hour, minutes, seconds, nanoseconds));
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcDATE_AND_TIME(@JsonProperty("value") LocalDateTime value) {
super(value, true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcDATE_AND_TIME(@JsonProperty("value") Long value) {
+ public PlcDATE_AND_TIME(@JsonProperty("value") long secondsSinceEpoch) {
super(LocalDateTime.ofInstant(
- Instant.ofEpochSecond(value), ZoneId.of("UTC")), true);
+ Instant.ofEpochSecond(secondsSinceEpoch), ZoneId.systemDefault()), true);
+ }
+
+ public PlcDATE_AND_TIME(@JsonProperty("year") int year, @JsonProperty("month") int month, @JsonProperty("day") int day, @JsonProperty("hour") int hour, @JsonProperty("minutes") int minutes, @JsonProperty("seconds") int seconds, @JsonProperty("nanoseconds") int nanoseconds) {
+ super(LocalDateTime.of(year, month, day, hour, minutes, seconds, nanoseconds), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE.java
index d1fd652f46..4a39d5eff5 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE.java
@@ -28,10 +28,7 @@ import org.apache.plc4x.java.spi.generation.SerializationException;
import org.apache.plc4x.java.spi.generation.WriteBuffer;
import java.nio.charset.StandardCharsets;
-import java.time.Instant;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
+import java.time.*;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
public class PlcLDATE extends PlcSimpleValue<LocalDate> {
@@ -46,23 +43,23 @@ public class PlcLDATE extends PlcSimpleValue<LocalDate> {
throw new PlcRuntimeException("Invalid value type");
}
- @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcLDATE(@JsonProperty("value") LocalDate value) {
- super(value, true);
+ public static PlcLDATE ofNanosecondsSinceEpoch(long nanosecondsSinceEpoch) {
+ long epochSecond = nanosecondsSinceEpoch / 1000000;
+ int nanoOfSecond = (int) (nanosecondsSinceEpoch % 1000000);
+ return new PlcLDATE(LocalDateTime.ofEpochSecond(epochSecond, nanoOfSecond,
+ ZoneOffset.of(ZoneOffset.systemDefault().getId())).toLocalDate());
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcLDATE(@JsonProperty("value") Integer value) {
- // In this case the date is the number of days since 1990-01-01
- // So we gotta add 7305 days to the value to have it relative to epoch
- // Then we also need to transform it from days to seconds by multiplying by 86400
- super(LocalDateTime.ofInstant(Instant.ofEpochSecond((value + 7305L) * 86400L),
- ZoneId.systemDefault()).toLocalDate(), true);
+ public PlcLDATE(@JsonProperty("value") LocalDate value) {
+ super(value, true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcLDATE(@JsonProperty("value") Long value) {
- super(LocalDateTime.ofInstant(Instant.ofEpochSecond(value), ZoneId.systemDefault()).toLocalDate(), true);
+ public PlcLDATE(@JsonProperty("value") long nanosecondsSinceEpoch) {
+ super(LocalDateTime.ofEpochSecond(nanosecondsSinceEpoch / 1000000,
+ (int) (nanosecondsSinceEpoch % 1000000),
+ ZoneOffset.of(ZoneOffset.systemDefault().getId())).toLocalDate(), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE_AND_TIME.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE_AND_TIME.java
index e8318e4cd9..e330149479 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE_AND_TIME.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLDATE_AND_TIME.java
@@ -43,15 +43,23 @@ public class PlcLDATE_AND_TIME extends PlcSimpleValue<LocalDateTime> {
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcLDATE_AND_TIME ofNanosecondsSinceEpoch(long nanosecondsSinceEpoch) {
+ long epochSecond = nanosecondsSinceEpoch / 1000000;
+ int nanoOfSecond = (int) (nanosecondsSinceEpoch % 1000000);
+ return new PlcLDATE_AND_TIME(LocalDateTime.ofEpochSecond(epochSecond, nanoOfSecond,
+ ZoneOffset.of(ZoneOffset.systemDefault().getId())));
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcLDATE_AND_TIME(@JsonProperty("value") LocalDateTime value) {
super(value, true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcLDATE_AND_TIME(@JsonProperty("value") Long value) {
- super(LocalDateTime.ofInstant(
- Instant.ofEpochSecond(value), ZoneId.of("UTC")), true);
+ public PlcLDATE_AND_TIME(@JsonProperty("value") long nanosecondsSinceEpoch) {
+ super(LocalDateTime.ofEpochSecond(nanosecondsSinceEpoch / 1000000,
+ (int) (nanosecondsSinceEpoch % 1000000),
+ ZoneOffset.of(ZoneOffset.systemDefault().getId())), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME.java
index 6b742a23eb..1bad082629 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME.java
@@ -30,6 +30,8 @@ import org.apache.plc4x.java.spi.generation.WriteBuffer;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
@@ -42,25 +44,34 @@ public class PlcLTIME extends PlcSimpleValue<Duration> {
return new PlcLTIME(Duration.of((long) value, ChronoUnit.MILLIS));
} else if(value instanceof Long) {
return new PlcLTIME(Duration.of((long) value, ChronoUnit.NANOS));
+ } else if(value instanceof BigInteger) {
+ // TODO: Not 100% correct, we're loosing precision here
+ return new PlcLTIME(Duration.of(((BigInteger) value).longValue(), ChronoUnit.NANOS));
}
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcLTIME ofNanoseconds(long nanoseconds) {
+ return new PlcLTIME(Duration.ofNanos(nanoseconds));
+ }
+
+ public static PlcLTIME ofNanoseconds(BigInteger nanoseconds) {
+ // TODO: Not 100% correct, we're loosing precision here
+ return new PlcLTIME(Duration.ofNanos(nanoseconds.longValue()));
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcLTIME(@JsonProperty("value") Duration value) {
super(value, true);
}
- public PlcLTIME(@JsonProperty("value") Integer value) {
- super(Duration.of((long) value, ChronoUnit.NANOS), true);
- }
-
- public PlcLTIME(@JsonProperty("value") Long value) {
- super(Duration.of(value, ChronoUnit.NANOS), true);
+ public PlcLTIME(@JsonProperty("value") long nanoseconds) {
+ super(Duration.ofNanos(nanoseconds), true);
}
- public PlcLTIME(@JsonProperty("value") BigInteger value) {
- super(Duration.of(value.longValue(), ChronoUnit.NANOS), true);
+ public PlcLTIME(@JsonProperty("value") BigInteger nanoseconds) {
+ // TODO: Not 100% correct, we're loosing precision here
+ super(Duration.ofNanos(nanoseconds.longValue()), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME_OF_DAY.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME_OF_DAY.java
index 5a455c89b6..3dab38c199 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME_OF_DAY.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcLTIME_OF_DAY.java
@@ -27,8 +27,12 @@ import org.apache.plc4x.java.api.types.PlcValueType;
import org.apache.plc4x.java.spi.generation.SerializationException;
import org.apache.plc4x.java.spi.generation.WriteBuffer;
+import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.time.ZoneOffset;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
public class PlcLTIME_OF_DAY extends PlcSimpleValue<LocalTime> {
@@ -37,19 +41,37 @@ public class PlcLTIME_OF_DAY extends PlcSimpleValue<LocalTime> {
if (value instanceof LocalTime) {
return new PlcLTIME_OF_DAY((LocalTime) value);
} else if (value instanceof Long) {
- return new PlcLTIME_OF_DAY(LocalTime.ofSecondOfDay(((long) value) / 1000));
+ return new PlcLTIME_OF_DAY(LocalTime.ofSecondOfDay(((Long) value) / 1000));
+ } else if (value instanceof BigInteger) {
+ // TODO: Not 100% correct, we're loosing precision here
+ return new PlcLTIME_OF_DAY(LocalTime.ofSecondOfDay(((BigInteger) value).longValue() / 1000));
}
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcLTIME_OF_DAY ofNanosecondsSinceMidnight(Long nanosecondsSinceMidnight) {
+ return new PlcLTIME_OF_DAY(LocalTime.ofNanoOfDay(nanosecondsSinceMidnight));
+ }
+
+ public static PlcLTIME_OF_DAY ofNanosecondsSinceMidnight(BigInteger nanosecondsSinceMidnight) {
+ // TODO: Not 100% correct, we're loosing precision here
+ return new PlcLTIME_OF_DAY(LocalTime.ofNanoOfDay(nanosecondsSinceMidnight.longValue()));
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcLTIME_OF_DAY(@JsonProperty("value") LocalTime value) {
super(value, true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcLTIME_OF_DAY(@JsonProperty("value") Long value) {
- super(LocalTime.ofNanoOfDay(value * 1000000), true);
+ public PlcLTIME_OF_DAY(@JsonProperty("value") Long nanosecondsSinceMidnight) {
+ super(LocalTime.ofNanoOfDay(nanosecondsSinceMidnight), true);
+ }
+
+ @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
+ public PlcLTIME_OF_DAY(@JsonProperty("value") BigInteger nanosecondsSinceMidnight) {
+ // TODO: Not 100% correct, we're loosing precision here
+ super(LocalTime.ofNanoOfDay(nanosecondsSinceMidnight.longValue()), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME.java
index 9481862337..d4beb0ef19 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME.java
@@ -30,7 +30,6 @@ import org.apache.plc4x.java.spi.generation.WriteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
-import java.time.temporal.TemporalUnit;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
public class PlcTIME extends PlcSimpleValue<Duration> {
@@ -46,17 +45,17 @@ public class PlcTIME extends PlcSimpleValue<Duration> {
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcTIME ofMilliseconds(long milliseconds) {
+ return new PlcTIME(Duration.ofMillis(milliseconds));
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcTIME(@JsonProperty("value") Duration value) {
super(value, true);
}
- public PlcTIME(@JsonProperty("value") Integer value) {
- super(Duration.of((long) value, ChronoUnit.MILLIS), true);
- }
-
- public PlcTIME(@JsonProperty("value") Long value) {
- super(Duration.of(value, ChronoUnit.MILLIS), true);
+ public PlcTIME(@JsonProperty("value") long milliseconds) {
+ super(Duration.ofMillis(milliseconds), true);
}
@Override
diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME_OF_DAY.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME_OF_DAY.java
index 56360458a4..6209e35e19 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME_OF_DAY.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/values/PlcTIME_OF_DAY.java
@@ -28,9 +28,7 @@ import org.apache.plc4x.java.spi.generation.SerializationException;
import org.apache.plc4x.java.spi.generation.WriteBuffer;
import java.nio.charset.StandardCharsets;
-import java.time.Instant;
import java.time.LocalTime;
-import java.time.ZoneId;
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "className")
public class PlcTIME_OF_DAY extends PlcSimpleValue<LocalTime> {
@@ -38,20 +36,24 @@ public class PlcTIME_OF_DAY extends PlcSimpleValue<LocalTime> {
public static PlcTIME_OF_DAY of(Object value) {
if (value instanceof LocalTime) {
return new PlcTIME_OF_DAY((LocalTime) value);
- } else if (value instanceof Long) {
- return new PlcTIME_OF_DAY(LocalTime.ofSecondOfDay(((long) value) / 1000));
+ } else if(value instanceof Long) {
+ return new PlcTIME_OF_DAY((Long) value);
}
throw new PlcRuntimeException("Invalid value type");
}
+ public static PlcTIME_OF_DAY ofMillisecondsSinceMidnight(long millisecondsSinceMidnight) {
+ return new PlcTIME_OF_DAY(LocalTime.ofNanoOfDay(millisecondsSinceMidnight * 1000000));
+ }
+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public PlcTIME_OF_DAY(@JsonProperty("value") LocalTime value) {
super(value, true);
}
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
- public PlcTIME_OF_DAY(@JsonProperty("value") Long value) {
- super(LocalTime.ofNanoOfDay(value * 1000000), true);
+ public PlcTIME_OF_DAY(@JsonProperty("value") long millisecondsSinceMidnight) {
+ super(LocalTime.ofNanoOfDay(millisecondsSinceMidnight * 1000000), true);
}
@Override
diff --git a/plc4net/drivers/knxnetip/src/drivers/knxnetip/readwrite/model/KnxDatapoint.cs b/plc4net/drivers/knxnetip/src/drivers/knxnetip/readwrite/model/KnxDatapoint.cs
index 3eb0109941..2cdd9eb9a8 100644
--- a/plc4net/drivers/knxnetip/src/drivers/knxnetip/readwrite/model/KnxDatapoint.cs
+++ b/plc4net/drivers/knxnetip/src/drivers/knxnetip/readwrite/model/KnxDatapoint.cs
@@ -284,10 +284,9 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
}
}
- // Simple Field (value)
- var value = readBuffer.ReadUint("", 32);
+ // Simple Field (milliseconds)
+ var milliseconds = readBuffer.ReadUint("", 32);
- return new PlcTIME(TimeSpan.FromSeconds(value));
} else if( datapointType == KnxDatapointType.LTIME ) { // LTIME
// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
@@ -298,10 +297,9 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
}
}
- // Simple Field (value)
- var value = readBuffer.ReadUlong("", 64);
+ // Simple Field (nanoseconds)
+ var nanoseconds = readBuffer.ReadUlong("", 64);
- return new PlcTIME(TimeSpan.FromMilliseconds(value));
} else if( datapointType == KnxDatapointType.DATE ) { // DATE
// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
@@ -312,10 +310,9 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
}
}
- // Simple Field (value)
- var value = readBuffer.ReadUshort("", 16);
+ // Simple Field (secondsSinceEpoch)
+ var secondsSinceEpoch = readBuffer.ReadUshort("", 16);
- return new PlcDATE(DateTime.Now);
} else if( datapointType == KnxDatapointType.TIME_OF_DAY ) { // TIME_OF_DAY
// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
@@ -326,10 +323,9 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
}
}
- // Simple Field (value)
- var value = readBuffer.ReadUint("", 32);
+ // Simple Field (millisecondsSinceMidnight)
+ var millisecondsSinceMidnight = readBuffer.ReadUint("", 32);
- return new PlcTIME_OF_DAY(DateTime.Now);
} else if( datapointType == KnxDatapointType.TOD ) { // TIME_OF_DAY
// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
@@ -340,10 +336,9 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
}
}
- // Simple Field (value)
- var value = readBuffer.ReadUint("", 32);
+ // Simple Field (millisecondsSinceMidnight)
+ var millisecondsSinceMidnight = readBuffer.ReadUint("", 32);
- return new PlcTIME_OF_DAY(DateTime.Now);
} else if( datapointType == KnxDatapointType.DATE_AND_TIME ) { // DATE_AND_TIME
// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
@@ -375,10 +370,10 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
// Simple Field (seconds)
var seconds = readBuffer.ReadByte("", 8);
- // Simple Field (nanos)
- var nanos = readBuffer.ReadUint("", 32);
+ // Simple Field (nanoseconds)
+ var nanoseconds = readBuffer.ReadUint("", 32);
- var value = new DateTime(year, (month == 0) ? 1 : month, (day == 0) ? 1 : day, hour, minutes, seconds, (int) (nanos / 1000000));
+ var value = new DateTime(year, (month == 0) ? 1 : month, (day == 0) ? 1 : day, hour, minutes, seconds, 0);
return new PlcDATE_AND_TIME(value);
} else if( datapointType == KnxDatapointType.DT ) { // DATE_AND_TIME
@@ -411,10 +406,10 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
// Simple Field (seconds)
var seconds = readBuffer.ReadByte("", 8);
- // Simple Field (nanos)
- var nanos = readBuffer.ReadUint("", 32);
+ // Simple Field (nanoseconds)
+ var nanoseconds = readBuffer.ReadUint("", 32);
- var value = new DateTime(year, (month == 0) ? 1 : month, (day == 0) ? 1 : day, hour, minutes, seconds, (int) (nanos / 1000000));
+ var value = new DateTime(year, (month == 0) ? 1 : month, (day == 0) ? 1 : day, hour, minutes, seconds, 0);
return new PlcDATE_AND_TIME(value);
} else if( datapointType == KnxDatapointType.DPT_Switch ) { // BOOL
@@ -6690,45 +6685,45 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
- // Simple Field (value)
- var value = (uint) _value.GetUint();
- writeBuffer.WriteUint("", 32, (uint) (value));
+ // Simple Field (milliseconds)
+ var milliseconds = (uint) _value.GetUint();
+ writeBuffer.WriteUint("", 32, (uint) (milliseconds));
return writeBuffer;
} else if( datapointType == KnxDatapointType.LTIME ) { // LTIME
var writeBuffer = new WriteBuffer();
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
- // Simple Field (value)
- var value = (ulong) _value.GetUlong();
- writeBuffer.WriteUlong("", 64, (ulong) (value));
+ // Simple Field (nanoseconds)
+ var nanoseconds = (ulong) _value.GetUlong();
+ writeBuffer.WriteUlong("", 64, (ulong) (nanoseconds));
return writeBuffer;
} else if( datapointType == KnxDatapointType.DATE ) { // DATE
var writeBuffer = new WriteBuffer();
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
- // Simple Field (value)
- var value = (ushort) _value.GetUshort();
- writeBuffer.WriteUshort("", 16, (ushort) (value));
+ // Simple Field (secondsSinceEpoch)
+ var secondsSinceEpoch = (ushort) _value.GetUshort();
+ writeBuffer.WriteUshort("", 16, (ushort) (secondsSinceEpoch));
return writeBuffer;
} else if( datapointType == KnxDatapointType.TIME_OF_DAY ) { // TIME_OF_DAY
var writeBuffer = new WriteBuffer();
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
- // Simple Field (value)
- var value = (uint) _value.GetUint();
- writeBuffer.WriteUint("", 32, (uint) (value));
+ // Simple Field (millisecondsSinceMidnight)
+ var millisecondsSinceMidnight = (uint) _value.GetUint();
+ writeBuffer.WriteUint("", 32, (uint) (millisecondsSinceMidnight));
return writeBuffer;
} else if( datapointType == KnxDatapointType.TOD ) { // TIME_OF_DAY
var writeBuffer = new WriteBuffer();
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
- // Simple Field (value)
- var value = (uint) _value.GetUint();
- writeBuffer.WriteUint("", 32, (uint) (value));
+ // Simple Field (millisecondsSinceMidnight)
+ var millisecondsSinceMidnight = (uint) _value.GetUint();
+ writeBuffer.WriteUint("", 32, (uint) (millisecondsSinceMidnight));
return writeBuffer;
} else if( datapointType == KnxDatapointType.DATE_AND_TIME ) { // DATE_AND_TIME
var writeBuffer = new WriteBuffer();
@@ -6736,29 +6731,29 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
// Simple Field (year)
- var year = 0;
+ var year = (ushort) _value.GetUshort();
writeBuffer.WriteUshort("", 16, (ushort) (year));
// Simple Field (month)
- var month = 0;
+ var month = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (month));
// Simple Field (day)
- var day = 0;
+ var day = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (day));
// Simple Field (dayOfWeek)
- var dayOfWeek = 0;
+ var dayOfWeek = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (dayOfWeek));
// Simple Field (hour)
- var hour = 0;
+ var hour = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (hour));
// Simple Field (minutes)
- var minutes = 0;
+ var minutes = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (minutes));
// Simple Field (seconds)
- var seconds = 0;
+ var seconds = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (seconds));
- // Simple Field (nanos)
- var nanos = 0l;
- writeBuffer.WriteUint("", 32, (uint) (nanos));
+ // Simple Field (nanoseconds)
+ var nanoseconds = (uint) _value.GetUint();
+ writeBuffer.WriteUint("", 32, (uint) (nanoseconds));
return writeBuffer;
} else if( datapointType == KnxDatapointType.DT ) { // DATE_AND_TIME
var writeBuffer = new WriteBuffer();
@@ -6766,29 +6761,29 @@ if( datapointType == KnxDatapointType.BOOL ) { // BOOL
// Reserved Field
writeBuffer.WriteByte("", 8, (byte) 0x00);
// Simple Field (year)
- var year = 0;
+ var year = (ushort) _value.GetUshort();
writeBuffer.WriteUshort("", 16, (ushort) (year));
// Simple Field (month)
- var month = 0;
+ var month = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (month));
// Simple Field (day)
- var day = 0;
+ var day = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (day));
// Simple Field (dayOfWeek)
- var dayOfWeek = 0;
+ var dayOfWeek = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (dayOfWeek));
// Simple Field (hour)
- var hour = 0;
+ var hour = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (hour));
// Simple Field (minutes)
- var minutes = 0;
+ var minutes = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (minutes));
// Simple Field (seconds)
- var seconds = 0;
+ var seconds = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (seconds));
- // Simple Field (nanos)
- var nanos = 0l;
- writeBuffer.WriteUint("", 32, (uint) (nanos));
+ // Simple Field (nanoseconds)
+ var nanoseconds = (uint) _value.GetUint();
+ writeBuffer.WriteUint("", 32, (uint) (nanoseconds));
return writeBuffer;
} else if( datapointType == KnxDatapointType.DPT_Switch ) { // BOOL
var writeBuffer = new WriteBuffer();
diff --git a/protocols/ads/src/main/resources/protocols/ads/ads.mspec b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
index 9ddf5612ce..ac64872260 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads.mspec
@@ -478,24 +478,33 @@
// -----------------------------------------
// Interpreted as "milliseconds"
['TIME' TIME
- [simple uint 32 value]
+ [simple uint 32 milliseconds]
]
// Interpreted as "nanoseconds"
['LTIME' LTIME
- [simple uint 64 value]
+ [simple uint 64 nanoseconds]
]
// Interpreted as "seconds since epoch"
['DATE' DATE
- [simple uint 32 value]
+ [simple uint 32 secondsSinceEpoch]
+ ]
+ ['LDATE' LDATE
+ [simple uint 32 nanosecondsSinceEpoch]
]
// Interpreted as "milliseconds since midnight"
['TIME_OF_DAY' TIME_OF_DAY
- [simple uint 32 value]
+ [simple uint 32 millisecondsSinceMidnight]
+ ]
+ ['LTIME_OF_DAY' LTIME_OF_DAY
+ [simple uint 32 nanosecondsSinceMidnight]
]
// Interpreted as "seconds since epoch"
['DATE_AND_TIME' DATE_AND_TIME
[simple uint 32 secondsSinceEpoch]
]
+ ['LDATE_AND_TIME' LDATE_AND_TIME
+ [simple uint 32 nanosecondsSinceEpoch]
+ ]
]
]
diff --git a/protocols/canopen/src/main/resources/protocols/can/canopen.mspec b/protocols/canopen/src/main/resources/protocols/can/canopen.mspec
index d10f26d58a..1303e0dfd3 100644
--- a/protocols/canopen/src/main/resources/protocols/can/canopen.mspec
+++ b/protocols/canopen/src/main/resources/protocols/can/canopen.mspec
@@ -333,7 +333,7 @@
[array byte value length 'size']
]
['OCTET_STRING' STRING
- [simple vstring 'size' test]
+ [simple vstring 'size' value]
]
['VISIBLE_STRING' STRING
[simple vstring 'size' value]
diff --git a/protocols/knxnetip/src/main/xslt/knx-types.xsl b/protocols/knxnetip/src/main/xslt/knx-types.xsl
index 8d25cb111d..ad968e609e 100644
--- a/protocols/knxnetip/src/main/xslt/knx-types.xsl
+++ b/protocols/knxnetip/src/main/xslt/knx-types.xsl
@@ -188,46 +188,51 @@
//['WSTRING' WSTRING
//]
['TIME' TIME
- [reserved uint 8 '0x00']
- [simple uint 32 value ]
+ [reserved uint 8 '0x00' ]
+ // TODO: Check if this is correct ...
+ [simple uint 32 milliseconds]
]
['LTIME' LTIME
- [reserved uint 8 '0x00']
- [simple uint 64 value ]
+ [reserved uint 8 '0x00' ]
+ // TODO: Check if this is correct ...
+ [simple uint 64 nanoseconds]
]
['DATE' DATE
- [reserved uint 8 '0x00']
- [simple uint 16 value ]
+ [reserved uint 8 '0x00' ]
+ // TODO: Check if this is correct ...
+ [simple uint 16 secondsSinceEpoch]
]
['TIME_OF_DAY' TIME_OF_DAY
- [reserved uint 8 '0x00']
- [simple uint 32 value ]
+ [reserved uint 8 '0x00' ]
+ // TODO: Check if this is correct ...
+ [simple uint 32 millisecondsSinceMidnight]
]
['TOD' TIME_OF_DAY
- [reserved uint 8 '0x00']
- [simple uint 32 value ]
+ [reserved uint 8 '0x00' ]
+ // TODO: Check if this is correct ...
+ [simple uint 32 millisecondsSinceMidnight]
]
['DATE_AND_TIME' DATE_AND_TIME
- [reserved uint 8 '0x00' ]
- [simple uint 16 year ]
- [simple uint 8 month ]
- [simple uint 8 day ]
- [simple uint 8 dayOfWeek]
- [simple uint 8 hour ]
- [simple uint 8 minutes ]
- [simple uint 8 seconds ]
- [simple uint 32 nanos ]
+ [reserved uint 8 '0x00' ]
+ [simple uint 16 year ]
+ [simple uint 8 month ]
+ [simple uint 8 day ]
+ [simple uint 8 dayOfWeek ]
+ [simple uint 8 hour ]
+ [simple uint 8 minutes ]
+ [simple uint 8 seconds ]
+ [simple uint 32 nanoseconds]
]
['DT' DATE_AND_TIME
- [reserved uint 8 '0x00' ]
- [simple uint 16 year ]
- [simple uint 8 month ]
- [simple uint 8 day ]
- [simple uint 8 dayOfWeek]
- [simple uint 8 hour ]
- [simple uint 8 minutes ]
- [simple uint 8 seconds ]
- [simple uint 32 nanos ]
+ [reserved uint 8 '0x00' ]
+ [simple uint 16 year ]
+ [simple uint 8 month ]
+ [simple uint 8 day ]
+ [simple uint 8 dayOfWeek ]
+ [simple uint 8 hour ]
+ [simple uint 8 minutes ]
+ [simple uint 8 seconds ]
+ [simple uint 32 nanoseconds]
]
<xsl:for-each select="knx:KNX/knx:MasterData/knx:DatapointTypes/knx:DatapointType/knx:DatapointSubtypes/knx:DatapointSubtype">
diff --git a/protocols/plc4x/src/main/resources/protocols/plc4x/v0/plc4x.mspec b/protocols/plc4x/src/main/resources/protocols/plc4x/v0/plc4x.mspec
index 421aaa3755..baf13586b4 100644
--- a/protocols/plc4x/src/main/resources/protocols/plc4x/v0/plc4x.mspec
+++ b/protocols/plc4x/src/main/resources/protocols/plc4x/v0/plc4x.mspec
@@ -175,24 +175,44 @@
['WCHAR' STRING
[simple string 16 value encoding='"UTF-16"']
]
- ['STRING' STRING
-// [implicit uint 8 stringLength 'STR_LEN(value)' ]
-// [simple vstring 'stringLength' value ]
- ]
- ['WSTRING' STRING
-// [implicit uint 8 stringLength 'STR_LEN(value)' ]
-// [simple vstring 'stringLength * 2' value encoding='"UTF-16"']
- ]
+ //['STRING' STRING
+ // [implicit uint 8 stringLength 'STR_LEN(value)' ]
+ // [simple vstring 'stringLength' value ]
+ //]
+ //['WSTRING' STRING
+ // [implicit uint 8 stringLength 'STR_LEN(value)' ]
+ // [simple vstring 'stringLength * 2' value encoding='"UTF-16"']
+ //]
// Times and Dates
- ['TIME' TIME ]
- ['TIME_OF_DAY' TIME_OF_DAY ]
- ['DATE' DATE ]
- ['DATE_AND_TIME' DATE_AND_TIME]
+ ['TIME' TIME
+ [simple uint 32 milliseconds]
+ ]
+ ['LTIME' LTIME
+ [simple uint 64 nanoseconds]
+ ]
+ ['DATE' DATE
+ [simple uint 32 secondsSinceEpoch]
+ ]
+ ['LDATE' LDATE
+ [simple uint 32 nanosecondsSinceEpoch]
+ ]
+ ['TIME_OF_DAY' TIME_OF_DAY
+ [simple uint 32 millisecondsSinceMidnight]
+ ]
+ ['LTIME_OF_DAY' LTIME_OF_DAY
+ [simple uint 64 nanosecondsSinceMidnight]
+ ]
+ ['DATE_AND_TIME' DATE_AND_TIME
+ [simple uint 32 secondsSinceEpoch]
+ ]
+ ['LDATE_AND_TIME' LDATE_AND_TIME
+ [simple uint 32 nanosecondsSinceEpoch]
+ ]
// Derived Types
['Struct' Struct ]
- ['List' List ]
+ //['List' List ]
]
]
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index 28d6555a09..d20c310f7d 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -614,26 +614,38 @@
// -----------------------------------------
// TIA Date-Formats
// -----------------------------------------
- // Interpreted as "milliseconds"
+ // - Duration: Interpreted as "milliseconds"
['"IEC61131_TIME"' TIME
- [simple uint 32 value]
+ [simple uint 32 milliseconds]
]
//['"S7_S5TIME"' TIME
// [reserved uint 2 '0x00']
// [uint uint 2 'base']
// [simple uint 12 value]
//]
- // Interpreted as "number of nanoseconds"
+ // - Duration: Interpreted as "number of nanoseconds"
['"IEC61131_LTIME"' LTIME
- [simple uint 64 value]
+ [simple uint 64 nanoseconds]
]
- // Interpreted as "number of days since 1990-01-01"
+ // - Date: Interpreted as "number of days since 1990-01-01"
['"IEC61131_DATE"' DATE
- [simple uint 16 value]
+ [simple uint 16 daysSinceSiemensEpoch]
+ // Number of days between 1990-01-01 and 1970-01-01 according to https://www.timeanddate.com/
+ //[virtual uint 16 daysSinceEpoch 'daysSinceSiemensEpoch + 7305']
]
+ //['"IEC61131_LDATE"' LDATE
+ // [implicit uint 16 daysSinceSiemensEpoch 'daysSinceEpoch - 7305']
+ // [virtual uint 16 daysSinceEpoch 'daysSinceSiemensEpoch + 7305']
+ //]
+ // - Time: Interpreted as "milliseconds since midnight (0:00)"
['"IEC61131_TIME_OF_DAY"' TIME_OF_DAY
- [simple uint 32 value]
+ [simple uint 32 milliseconds]
+ ]
+ // - Time: Interpreted as "nanoseconds since midnight (0:00)"
+ ['"IEC61131_LTIME_OF_DAY"' LTIME_OF_DAY
+ [simple uint 64 nanoseconds]
]
+ // - Date & Time: interpreted as individual components.
['"IEC61131_DATE_AND_TIME"' DATE_AND_TIME
[simple uint 16 year]
[simple uint 8 month]
@@ -642,8 +654,13 @@
[simple uint 8 hour]
[simple uint 8 minutes]
[simple uint 8 seconds]
- [simple uint 32 nanos]
+ [simple uint 32 nanoseconds]
]
+ // - Date & Time: Interpreted as "number of nanoseconds since 1990-01-01"
+ //['"IEC61131_LDATE_AND_TIME"' LDATE_AND_TIME
+ // [implicit uint 16 nanosecondsSinceSiemensEpoch 'nanosecondsSinceEpoch ...']
+ // [virtual uint 16 nanosecondsSinceEpoch 'nanosecondsSinceSiemensEpoch ...']
+ //]
]
]