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 2024/01/31 10:11:10 UTC
(plc4x) branch fix/DATE_AND_TIME_2 updated: refactor: Added a controller-type argument to the DataItems signature
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch fix/DATE_AND_TIME_2
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/fix/DATE_AND_TIME_2 by this push:
new 4387552778 refactor: Added a controller-type argument to the DataItems signature
4387552778 is described below
commit 43875527782b3c1caf6141868b5273d9868f7cf8
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Wed Jan 31 09:12:11 2024 +0100
refactor: Added a controller-type argument to the DataItems signature
---
.gitignore | 7 +-
plc4c/drivers/s7/src/driver_s7_sm_read.c | 6 +-
.../generated-sources/s7/include/controller_type.h | 63 +++++++
plc4c/generated-sources/s7/include/data_item.h | 9 +-
plc4c/generated-sources/s7/src/controller_type.c | 127 ++++++++++++++
plc4c/generated-sources/s7/src/data_item.c | 10 +-
plc4go/protocols/s7/readwrite/ParserHelper.go | 5 +-
plc4go/protocols/s7/readwrite/XmlParserHelper.go | 7 +-
.../protocols/s7/readwrite/model/ControllerType.go | 191 +++++++++++++++++++++
plc4go/protocols/s7/readwrite/model/DataItem.go | 14 +-
.../plc4x/java/s7/readwrite/ControllerType.java | 60 +++++++
.../apache/plc4x/java/s7/readwrite/DataItem.java | 26 ++-
.../java/s7/readwrite/context/S7DriverContext.java | 12 +-
.../s7/readwrite/protocol/S7ProtocolLogic.java | 34 ++--
.../java/s7/readwrite/types/S7ControllerType.java | 31 ----
.../src/generated/plc4j-tools-ui-frontend.ts | 2 +-
.../s7/src/main/resources/protocols/s7/s7.mspec | 13 +-
17 files changed, 530 insertions(+), 87 deletions(-)
diff --git a/.gitignore b/.gitignore
index 9e1ce6b2fb..2763b28276 100644
--- a/.gitignore
+++ b/.gitignore
@@ -211,7 +211,10 @@ DartConfiguration.tcl
/plc4j/tools/ui/frontend/project/node_modules/
/plc4j/tools/ui/frontend/project/dist/
/plc4j/tools/ui/frontend/project/.vite/**
-/storage/**
-/derby.log
/plc4j/tools/ui/frontend/frontend/.idea/vcs.xml
/plc4j/tools/ui/frontend/frontend/.idea/workspace.xml
+/storage/**
+/derby.log
+/plc4c/.idea/codeStyles/codeStyleConfig.xml
+/plc4c/.idea/codeStyles/Project.xml
+/plc4c/.idea/.name
diff --git a/plc4c/drivers/s7/src/driver_s7_sm_read.c b/plc4c/drivers/s7/src/driver_s7_sm_read.c
index abc8d59f64..192bd5690f 100644
--- a/plc4c/drivers/s7/src/driver_s7_sm_read.c
+++ b/plc4c/drivers/s7/src/driver_s7_sm_read.c
@@ -257,12 +257,14 @@ plc4c_return_code plc4c_driver_s7_parse_read_response(
all_data_item = plc4c_data_create_list_data(all_list);
free(all_list);
for (idx = 0; idx < num_elements ; idx++) {
- plc4c_s7_read_write_data_item_parse(plc4x_spi_context_background(), read_buffer, data_protocol_id, string_length, &data_item);
+ // TODO: Pass the plc-type along.
+ plc4c_s7_read_write_data_item_parse(plc4x_spi_context_background(), read_buffer, data_protocol_id, plc4c_s7_read_write_controller_type_ANY, string_length, &data_item);
plc4c_utils_list_insert_head_value(all_data_item->data.list_value, (void*)data_item);
}
data_item = all_data_item;
} else {
- plc4c_s7_read_write_data_item_parse(plc4x_spi_context_background(), read_buffer, data_protocol_id, string_length, &data_item);
+ // TODO: Pass the plc-type along.
+ plc4c_s7_read_write_data_item_parse(plc4x_spi_context_background(), read_buffer, data_protocol_id, plc4c_s7_read_write_controller_type_ANY, string_length, &data_item);
}
// Create a new response value-item
diff --git a/plc4c/generated-sources/s7/include/controller_type.h b/plc4c/generated-sources/s7/include/controller_type.h
new file mode 100644
index 0000000000..d366b8b245
--- /dev/null
+++ b/plc4c/generated-sources/s7/include/controller_type.h
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef PLC4C_S7_READ_WRITE_CONTROLLER_TYPE_H_
+#define PLC4C_S7_READ_WRITE_CONTROLLER_TYPE_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <plc4c/spi/context.h>
+#include <plc4c/spi/read_buffer.h>
+#include <plc4c/spi/write_buffer.h>
+
+// Code generated by code-generation. DO NOT EDIT.
+
+
+enum plc4c_s7_read_write_controller_type {
+ plc4c_s7_read_write_controller_type_ANY = 0,
+ plc4c_s7_read_write_controller_type_S7_200 = 1,
+ plc4c_s7_read_write_controller_type_S7_300 = 2,
+ plc4c_s7_read_write_controller_type_S7_400 = 3,
+ plc4c_s7_read_write_controller_type_S7_1200 = 4,
+ plc4c_s7_read_write_controller_type_S7_1500 = 5,
+ plc4c_s7_read_write_controller_type_LOGO = 6
+};
+typedef enum plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type;
+
+// Get an empty NULL-struct
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_null();
+
+plc4c_return_code plc4c_s7_read_write_controller_type_parse(plc4x_spi_context ctx, plc4c_spi_read_buffer* readBuffer, plc4c_s7_read_write_controller_type* message);
+
+plc4c_return_code plc4c_s7_read_write_controller_type_serialize(plc4x_spi_context ctx, plc4c_spi_write_buffer* writeBuffer, plc4c_s7_read_write_controller_type* message);
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_for_value(uint32_t value);
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_value_of(char* value_string);
+
+int plc4c_s7_read_write_controller_type_num_values();
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_value_for_index(int index);
+
+uint16_t plc4c_s7_read_write_controller_type_length_in_bytes(plc4x_spi_context ctx, plc4c_s7_read_write_controller_type* message);
+
+uint16_t plc4c_s7_read_write_controller_type_length_in_bits(plc4x_spi_context ctx, plc4c_s7_read_write_controller_type* message);
+
+
+#endif // PLC4C_S7_READ_WRITE_CONTROLLER_TYPE_H_
diff --git a/plc4c/generated-sources/s7/include/data_item.h b/plc4c/generated-sources/s7/include/data_item.h
index 32893bb96b..4cee4e23f8 100644
--- a/plc4c/generated-sources/s7/include/data_item.h
+++ b/plc4c/generated-sources/s7/include/data_item.h
@@ -25,15 +25,16 @@
#include <plc4c/spi/read_buffer.h>
#include <plc4c/spi/write_buffer.h>
#include <plc4c/utils/list.h>
+#include "controller_type.h"
// Code generated by code-generation. DO NOT EDIT.
-plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc4c_spi_read_buffer* readBuffer, char* dataProtocolId, int32_t stringLength, plc4c_data** data_item);
+plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc4c_spi_read_buffer* readBuffer, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength, plc4c_data** data_item);
-plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx, plc4c_spi_write_buffer* writeBuffer, char* dataProtocolId, int32_t stringLength, plc4c_data** data_item);
+plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx, plc4c_spi_write_buffer* writeBuffer, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength, plc4c_data** data_item);
-uint16_t plc4c_s7_read_write_data_item_length_in_bytes(plc4x_spi_context ctx, plc4c_data* data_item, char* dataProtocolId, int32_t stringLength);
+uint16_t plc4c_s7_read_write_data_item_length_in_bytes(plc4x_spi_context ctx, plc4c_data* data_item, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength);
-uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc4c_data* data_item, char* dataProtocolId, int32_t stringLength);
+uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc4c_data* data_item, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength);
#endif // PLC4C_S7_READ_WRITE_DATA_ITEM_H_
diff --git a/plc4c/generated-sources/s7/src/controller_type.c b/plc4c/generated-sources/s7/src/controller_type.c
new file mode 100644
index 0000000000..c581b51c9c
--- /dev/null
+++ b/plc4c/generated-sources/s7/src/controller_type.c
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include <plc4c/driver_s7_static.h>
+
+#include "controller_type.h"
+
+// Code generated by code-generation. DO NOT EDIT.
+
+
+// Create an empty NULL-struct
+static const plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_null_const;
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_null() {
+ return plc4c_s7_read_write_controller_type_null_const;
+}
+
+// Parse function.
+plc4c_return_code plc4c_s7_read_write_controller_type_parse(plc4x_spi_context ctx, plc4c_spi_read_buffer* readBuffer, plc4c_s7_read_write_controller_type* _message) {
+ plc4c_return_code _res = OK;
+
+ uint32_t value;
+ _res = plc4c_spi_read_unsigned_int(readBuffer, 32, (uint32_t*) &value);
+ *_message = plc4c_s7_read_write_controller_type_for_value(value);
+
+ return _res;
+}
+
+plc4c_return_code plc4c_s7_read_write_controller_type_serialize(plc4x_spi_context ctx, plc4c_spi_write_buffer* writeBuffer, plc4c_s7_read_write_controller_type* _message) {
+ plc4c_return_code _res = OK;
+
+ _res = plc4c_spi_write_unsigned_int(writeBuffer, 32, *_message);
+
+ return _res;
+}
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_for_value(uint32_t value) {
+ for(int i = 0; i < plc4c_s7_read_write_controller_type_num_values(); i++) {
+ if(plc4c_s7_read_write_controller_type_value_for_index(i) == value) {
+ return plc4c_s7_read_write_controller_type_value_for_index(i);
+ }
+ }
+ return -1;
+}
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_value_of(char* value_string) {
+ if(strcmp(value_string, "ANY") == 0) {
+ return plc4c_s7_read_write_controller_type_ANY;
+ }
+ if(strcmp(value_string, "S7_200") == 0) {
+ return plc4c_s7_read_write_controller_type_S7_200;
+ }
+ if(strcmp(value_string, "S7_300") == 0) {
+ return plc4c_s7_read_write_controller_type_S7_300;
+ }
+ if(strcmp(value_string, "S7_400") == 0) {
+ return plc4c_s7_read_write_controller_type_S7_400;
+ }
+ if(strcmp(value_string, "S7_1200") == 0) {
+ return plc4c_s7_read_write_controller_type_S7_1200;
+ }
+ if(strcmp(value_string, "S7_1500") == 0) {
+ return plc4c_s7_read_write_controller_type_S7_1500;
+ }
+ if(strcmp(value_string, "LOGO") == 0) {
+ return plc4c_s7_read_write_controller_type_LOGO;
+ }
+ return -1;
+}
+
+int plc4c_s7_read_write_controller_type_num_values() {
+ return 7;
+}
+
+plc4c_s7_read_write_controller_type plc4c_s7_read_write_controller_type_value_for_index(int index) {
+ switch(index) {
+ case 0: {
+ return plc4c_s7_read_write_controller_type_ANY;
+ }
+ case 1: {
+ return plc4c_s7_read_write_controller_type_S7_200;
+ }
+ case 2: {
+ return plc4c_s7_read_write_controller_type_S7_300;
+ }
+ case 3: {
+ return plc4c_s7_read_write_controller_type_S7_400;
+ }
+ case 4: {
+ return plc4c_s7_read_write_controller_type_S7_1200;
+ }
+ case 5: {
+ return plc4c_s7_read_write_controller_type_S7_1500;
+ }
+ case 6: {
+ return plc4c_s7_read_write_controller_type_LOGO;
+ }
+ default: {
+ return -1;
+ }
+ }
+}
+
+uint16_t plc4c_s7_read_write_controller_type_length_in_bytes(plc4x_spi_context ctx, plc4c_s7_read_write_controller_type* _message) {
+ return plc4c_s7_read_write_controller_type_length_in_bits(ctx, _message) / 8;
+}
+
+uint16_t plc4c_s7_read_write_controller_type_length_in_bits(plc4x_spi_context ctx, plc4c_s7_read_write_controller_type* _message) {
+ return 32;
+}
diff --git a/plc4c/generated-sources/s7/src/data_item.c b/plc4c/generated-sources/s7/src/data_item.c
index 52161f491a..4ba42e59bd 100644
--- a/plc4c/generated-sources/s7/src/data_item.c
+++ b/plc4c/generated-sources/s7/src/data_item.c
@@ -31,7 +31,7 @@
// Code generated by code-generation. DO NOT EDIT.
// Parse function.
-plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc4c_spi_read_buffer* readBuffer, char* dataProtocolId, int32_t stringLength, plc4c_data** data_item) {
+plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc4c_spi_read_buffer* readBuffer, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength, plc4c_data** data_item) {
uint16_t startPos = plc4c_spi_read_get_pos(readBuffer);
uint16_t curPos;
plc4c_return_code _res = OK;
@@ -393,7 +393,7 @@ plc4c_return_code plc4c_s7_read_write_data_item_parse(plc4x_spi_context ctx, plc
return OK;
}
-plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx, plc4c_spi_write_buffer* writeBuffer, char* dataProtocolId, int32_t stringLength, plc4c_data** data_item) {
+plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx, plc4c_spi_write_buffer* writeBuffer, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength, plc4c_data** data_item) {
plc4c_return_code _res = OK;
if(strcmp(dataProtocolId, "IEC61131_BOOL") == 0) { /* BOOL */
@@ -609,11 +609,11 @@ plc4c_return_code plc4c_s7_read_write_data_item_serialize(plc4x_spi_context ctx,
return OK;
}
-uint16_t plc4c_s7_read_write_data_item_length_in_bytes(plc4x_spi_context ctx, plc4c_data* data_item, char* data_protocol_id, int32_t string_length) {
- return plc4c_s7_read_write_data_item_length_in_bits(ctx, data_item, data_protocol_id, string_length) / 8;
+uint16_t plc4c_s7_read_write_data_item_length_in_bytes(plc4x_spi_context ctx, plc4c_data* data_item, char* data_protocol_id, plc4c_s7_read_write_controller_type controller_type, int32_t string_length) {
+ return plc4c_s7_read_write_data_item_length_in_bits(ctx, data_item, data_protocol_id, controller_type, string_length) / 8;
}
-uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc4c_data* data_item, char* dataProtocolId, int32_t stringLength) {
+uint16_t plc4c_s7_read_write_data_item_length_in_bits(plc4x_spi_context ctx, plc4c_data* data_item, char* dataProtocolId, plc4c_s7_read_write_controller_type controllerType, int32_t stringLength) {
uint16_t lengthInBits = 0;
if(strcmp(dataProtocolId, "IEC61131_BOOL") == 0) { /* BOOL */
diff --git a/plc4go/protocols/s7/readwrite/ParserHelper.go b/plc4go/protocols/s7/readwrite/ParserHelper.go
index 1043128f5f..b8ec3d0d54 100644
--- a/plc4go/protocols/s7/readwrite/ParserHelper.go
+++ b/plc4go/protocols/s7/readwrite/ParserHelper.go
@@ -84,11 +84,12 @@ func (m S7ParserHelper) Parse(typeName string, arguments []string, io utils.Read
if err != nil {
return nil, errors.Wrap(err, "Error parsing")
}
- stringLength, err := utils.StrToInt32(arguments[1])
+ controllerType, _ := model.ControllerTypeByName(arguments[1])
+ stringLength, err := utils.StrToInt32(arguments[2])
if err != nil {
return nil, errors.Wrap(err, "Error parsing")
}
- return model.DataItemParseWithBuffer(context.Background(), io, dataProtocolId, stringLength)
+ return model.DataItemParseWithBuffer(context.Background(), io, dataProtocolId, controllerType, stringLength)
case "SubItem":
return model.SubItemParseWithBuffer(context.Background(), io)
case "CycServiceItemType":
diff --git a/plc4go/protocols/s7/readwrite/XmlParserHelper.go b/plc4go/protocols/s7/readwrite/XmlParserHelper.go
index 4a599a0d30..ce9936274b 100644
--- a/plc4go/protocols/s7/readwrite/XmlParserHelper.go
+++ b/plc4go/protocols/s7/readwrite/XmlParserHelper.go
@@ -99,12 +99,13 @@ func (m S7XmlParserHelper) Parse(typeName string, xmlString string, parserArgume
case "DataItem":
// TODO: find a way to parse the sub types
var dataProtocolId string
- parsedInt1, err := strconv.ParseInt(parserArguments[1], 10, 32)
+ controllerType, _ := model.ControllerTypeByName(parserArguments[1])
+ parsedInt2, err := strconv.ParseInt(parserArguments[2], 10, 32)
if err != nil {
return nil, err
}
- stringLength := int32(parsedInt1)
- return model.DataItemParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)), dataProtocolId, stringLength)
+ stringLength := int32(parsedInt2)
+ return model.DataItemParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)), dataProtocolId, controllerType, stringLength)
case "SubItem":
return model.SubItemParseWithBuffer(context.Background(), utils.NewXmlReadBuffer(strings.NewReader(xmlString)))
case "CycServiceItemType":
diff --git a/plc4go/protocols/s7/readwrite/model/ControllerType.go b/plc4go/protocols/s7/readwrite/model/ControllerType.go
new file mode 100644
index 0000000000..6feb1d8b2f
--- /dev/null
+++ b/plc4go/protocols/s7/readwrite/model/ControllerType.go
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package model
+
+import (
+ "context"
+ "fmt"
+
+ "github.com/apache/plc4x/plc4go/spi/utils"
+
+ "github.com/pkg/errors"
+ "github.com/rs/zerolog"
+)
+
+// Code generated by code-generation. DO NOT EDIT.
+
+// ControllerType is an enum
+type ControllerType uint32
+
+type IControllerType interface {
+ fmt.Stringer
+ utils.LengthAware
+ utils.Serializable
+}
+
+const (
+ ControllerType_ANY ControllerType = 0
+ ControllerType_S7_200 ControllerType = 1
+ ControllerType_S7_300 ControllerType = 2
+ ControllerType_S7_400 ControllerType = 3
+ ControllerType_S7_1200 ControllerType = 4
+ ControllerType_S7_1500 ControllerType = 5
+ ControllerType_LOGO ControllerType = 6
+)
+
+var ControllerTypeValues []ControllerType
+
+func init() {
+ _ = errors.New
+ ControllerTypeValues = []ControllerType{
+ ControllerType_ANY,
+ ControllerType_S7_200,
+ ControllerType_S7_300,
+ ControllerType_S7_400,
+ ControllerType_S7_1200,
+ ControllerType_S7_1500,
+ ControllerType_LOGO,
+ }
+}
+
+func ControllerTypeByValue(value uint32) (enum ControllerType, ok bool) {
+ switch value {
+ case 0:
+ return ControllerType_ANY, true
+ case 1:
+ return ControllerType_S7_200, true
+ case 2:
+ return ControllerType_S7_300, true
+ case 3:
+ return ControllerType_S7_400, true
+ case 4:
+ return ControllerType_S7_1200, true
+ case 5:
+ return ControllerType_S7_1500, true
+ case 6:
+ return ControllerType_LOGO, true
+ }
+ return 0, false
+}
+
+func ControllerTypeByName(value string) (enum ControllerType, ok bool) {
+ switch value {
+ case "ANY":
+ return ControllerType_ANY, true
+ case "S7_200":
+ return ControllerType_S7_200, true
+ case "S7_300":
+ return ControllerType_S7_300, true
+ case "S7_400":
+ return ControllerType_S7_400, true
+ case "S7_1200":
+ return ControllerType_S7_1200, true
+ case "S7_1500":
+ return ControllerType_S7_1500, true
+ case "LOGO":
+ return ControllerType_LOGO, true
+ }
+ return 0, false
+}
+
+func ControllerTypeKnows(value uint32) bool {
+ for _, typeValue := range ControllerTypeValues {
+ if uint32(typeValue) == value {
+ return true
+ }
+ }
+ return false
+}
+
+func CastControllerType(structType any) ControllerType {
+ castFunc := func(typ any) ControllerType {
+ if sControllerType, ok := typ.(ControllerType); ok {
+ return sControllerType
+ }
+ return 0
+ }
+ return castFunc(structType)
+}
+
+func (m ControllerType) GetLengthInBits(ctx context.Context) uint16 {
+ return 32
+}
+
+func (m ControllerType) GetLengthInBytes(ctx context.Context) uint16 {
+ return m.GetLengthInBits(ctx) / 8
+}
+
+func ControllerTypeParse(ctx context.Context, theBytes []byte) (ControllerType, error) {
+ return ControllerTypeParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes))
+}
+
+func ControllerTypeParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer) (ControllerType, error) {
+ log := zerolog.Ctx(ctx)
+ _ = log
+ val, err := readBuffer.ReadUint32("ControllerType", 32)
+ if err != nil {
+ return 0, errors.Wrap(err, "error reading ControllerType")
+ }
+ if enum, ok := ControllerTypeByValue(val); !ok {
+ log.Debug().Interface("val", val).Msg("no value val found for ControllerType")
+ return ControllerType(val), nil
+ } else {
+ return enum, nil
+ }
+}
+
+func (e ControllerType) Serialize() ([]byte, error) {
+ wb := utils.NewWriteBufferByteBased()
+ if err := e.SerializeWithWriteBuffer(context.Background(), wb); err != nil {
+ return nil, err
+ }
+ return wb.GetBytes(), nil
+}
+
+func (e ControllerType) SerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer) error {
+ log := zerolog.Ctx(ctx)
+ _ = log
+ return writeBuffer.WriteUint32("ControllerType", 32, uint32(uint32(e)), utils.WithAdditionalStringRepresentation(e.PLC4XEnumName()))
+}
+
+// PLC4XEnumName returns the name that is used in code to identify this enum
+func (e ControllerType) PLC4XEnumName() string {
+ switch e {
+ case ControllerType_ANY:
+ return "ANY"
+ case ControllerType_S7_200:
+ return "S7_200"
+ case ControllerType_S7_300:
+ return "S7_300"
+ case ControllerType_S7_400:
+ return "S7_400"
+ case ControllerType_S7_1200:
+ return "S7_1200"
+ case ControllerType_S7_1500:
+ return "S7_1500"
+ case ControllerType_LOGO:
+ return "LOGO"
+ }
+ return fmt.Sprintf("Unknown(%v)", uint32(e))
+}
+
+func (e ControllerType) String() string {
+ return e.PLC4XEnumName()
+}
diff --git a/plc4go/protocols/s7/readwrite/model/DataItem.go b/plc4go/protocols/s7/readwrite/model/DataItem.go
index e687d29262..f6a5a876d9 100644
--- a/plc4go/protocols/s7/readwrite/model/DataItem.go
+++ b/plc4go/protocols/s7/readwrite/model/DataItem.go
@@ -30,11 +30,11 @@ import (
// Code generated by code-generation. DO NOT EDIT.
-func DataItemParse(ctx context.Context, theBytes []byte, dataProtocolId string, stringLength int32) (api.PlcValue, error) {
- return DataItemParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), dataProtocolId, stringLength)
+func DataItemParse(ctx context.Context, theBytes []byte, dataProtocolId string, controllerType ControllerType, stringLength int32) (api.PlcValue, error) {
+ return DataItemParseWithBuffer(ctx, utils.NewReadBufferByteBased(theBytes), dataProtocolId, controllerType, stringLength)
}
-func DataItemParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, dataProtocolId string, stringLength int32) (api.PlcValue, error) {
+func DataItemParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, dataProtocolId string, controllerType ControllerType, stringLength int32) (api.PlcValue, error) {
log := zerolog.Ctx(ctx)
_ = log
readBuffer.PullContext("DataItem")
@@ -298,22 +298,24 @@ func DataItemParseWithBuffer(ctx context.Context, readBuffer utils.ReadBuffer, d
return nil, errors.New("unsupported type")
}
-func DataItemSerialize(value api.PlcValue, dataProtocolId string, stringLength int32) ([]byte, error) {
+func DataItemSerialize(value api.PlcValue, dataProtocolId string, controllerType ControllerType, stringLength int32) ([]byte, error) {
wb := utils.NewWriteBufferByteBased()
- if err := DataItemSerializeWithWriteBuffer(context.Background(), wb, value, dataProtocolId, stringLength); err != nil {
+ if err := DataItemSerializeWithWriteBuffer(context.Background(), wb, value, dataProtocolId, controllerType, stringLength); err != nil {
return nil, err
}
return wb.GetBytes(), nil
}
-func DataItemSerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer, value api.PlcValue, dataProtocolId string, stringLength int32) error {
+func DataItemSerializeWithWriteBuffer(ctx context.Context, writeBuffer utils.WriteBuffer, value api.PlcValue, dataProtocolId string, controllerType ControllerType, stringLength int32) error {
log := zerolog.Ctx(ctx)
_ = log
m := struct {
DataProtocolId string
+ ControllerType ControllerType
StringLength int32
}{
DataProtocolId: dataProtocolId,
+ ControllerType: controllerType,
StringLength: stringLength,
}
_ = m
diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ControllerType.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ControllerType.java
new file mode 100644
index 0000000000..73d6222d34
--- /dev/null
+++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/ControllerType.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.plc4x.java.s7.readwrite;
+
+import java.util.HashMap;
+import java.util.Map;
+
+// Code generated by code-generation. DO NOT EDIT.
+
+public enum ControllerType {
+ ANY((long) 0L),
+ S7_200((long) 1L),
+ S7_300((long) 2L),
+ S7_400((long) 3L),
+ S7_1200((long) 4L),
+ S7_1500((long) 5L),
+ LOGO((long) 6L);
+ private static final Map<Long, ControllerType> map;
+
+ static {
+ map = new HashMap<>();
+ for (ControllerType value : ControllerType.values()) {
+ map.put((long) value.getValue(), value);
+ }
+ }
+
+ private final long value;
+
+ ControllerType(long value) {
+ this.value = value;
+ }
+
+ public long getValue() {
+ return value;
+ }
+
+ public static ControllerType enumForValue(long value) {
+ return map.get(value);
+ }
+
+ public static Boolean isDefined(long value) {
+ return map.containsKey(value);
+ }
+}
diff --git a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
index 4f1cf34662..13805cd6e1 100644
--- a/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
+++ b/plc4j/drivers/s7/src/main/generated/org/apache/plc4x/java/s7/readwrite/DataItem.java
@@ -42,7 +42,11 @@ public class DataItem {
private static final Logger LOGGER = LoggerFactory.getLogger(DataItem.class);
public static PlcValue staticParse(
- ReadBuffer readBuffer, String dataProtocolId, Integer stringLength) throws ParseException {
+ ReadBuffer readBuffer,
+ String dataProtocolId,
+ ControllerType controllerType,
+ Integer stringLength)
+ throws ParseException {
if (EvaluationHelper.equals(dataProtocolId, "IEC61131_BOOL")) { // BOOL
// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
@@ -250,15 +254,21 @@ public class DataItem {
}
public static void staticSerialize(
- WriteBuffer writeBuffer, PlcValue _value, String dataProtocolId, Integer stringLength)
+ WriteBuffer writeBuffer,
+ PlcValue _value,
+ String dataProtocolId,
+ ControllerType controllerType,
+ Integer stringLength)
throws SerializationException {
- staticSerialize(writeBuffer, _value, dataProtocolId, stringLength, ByteOrder.BIG_ENDIAN);
+ staticSerialize(
+ writeBuffer, _value, dataProtocolId, controllerType, stringLength, ByteOrder.BIG_ENDIAN);
}
public static void staticSerialize(
WriteBuffer writeBuffer,
PlcValue _value,
String dataProtocolId,
+ ControllerType controllerType,
Integer stringLength,
ByteOrder byteOrder)
throws SerializationException {
@@ -426,11 +436,15 @@ public class DataItem {
}
}
- public static int getLengthInBytes(PlcValue _value, String dataProtocolId, Integer stringLength) {
- return (int) Math.ceil((float) getLengthInBits(_value, dataProtocolId, stringLength) / 8.0);
+ public static int getLengthInBytes(
+ PlcValue _value, String dataProtocolId, ControllerType controllerType, Integer stringLength) {
+ return (int)
+ Math.ceil(
+ (float) getLengthInBits(_value, dataProtocolId, controllerType, stringLength) / 8.0);
}
- public static int getLengthInBits(PlcValue _value, String dataProtocolId, Integer stringLength) {
+ public static int getLengthInBits(
+ PlcValue _value, String dataProtocolId, ControllerType controllerType, Integer stringLength) {
int sizeInBits = 0;
if (EvaluationHelper.equals(dataProtocolId, "IEC61131_BOOL")) { // BOOL
// Reserved Field
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java
index 76b15027fa..1a30d7d55f 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/context/S7DriverContext.java
@@ -19,9 +19,9 @@
package org.apache.plc4x.java.s7.readwrite.context;
import org.apache.plc4x.java.s7.readwrite.COTPTpduSize;
+import org.apache.plc4x.java.s7.readwrite.ControllerType;
import org.apache.plc4x.java.s7.readwrite.DeviceGroup;
import org.apache.plc4x.java.s7.readwrite.configuration.S7Configuration;
-import org.apache.plc4x.java.s7.readwrite.types.S7ControllerType;
import org.apache.plc4x.java.s7.readwrite.utils.S7TsapIdEncoder;
import org.apache.plc4x.java.spi.configuration.HasConfiguration;
import org.apache.plc4x.java.spi.context.DriverContext;
@@ -35,7 +35,7 @@ public class S7DriverContext implements DriverContext, HasConfiguration<S7Config
private int pduSize;
private int maxAmqCaller;
private int maxAmqCallee;
- private S7ControllerType controllerType;
+ private ControllerType controllerType;
private int calledTsapId2;
@@ -61,14 +61,14 @@ public class S7DriverContext implements DriverContext, HasConfiguration<S7Config
if (configuration.remoteTsap > 0) {
this.calledTsapId = configuration.remoteTsap;
}
- this.controllerType = configuration.controllerType == null ? S7ControllerType.ANY : S7ControllerType.valueOf(configuration.controllerType);
+ this.controllerType = configuration.controllerType == null ? ControllerType.ANY : ControllerType.valueOf(configuration.controllerType);
// Initialize the parameters with initial version (Will be updated during the login process)
this.cotpTpduSize = getNearestMatchingTpduSize((short) configuration.getPduSize());
// The Siemens LOGO device seems to only work with very limited settings,
// so we're overriding some of the defaults.
- if (this.controllerType == S7ControllerType.LOGO && configuration.pduSize == 1024) {
+ if (this.controllerType == ControllerType.LOGO && configuration.pduSize == 1024) {
configuration.pduSize = 480;
this.pduSize = 480;
} else {
@@ -152,11 +152,11 @@ public class S7DriverContext implements DriverContext, HasConfiguration<S7Config
this.maxAmqCallee = maxAmqCallee;
}
- public S7ControllerType getControllerType() {
+ public ControllerType getControllerType() {
return controllerType;
}
- public void setControllerType(S7ControllerType controllerType) {
+ public void setControllerType(ControllerType controllerType) {
this.controllerType = controllerType;
}
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
index 0e8dd71817..7b679bcf91 100644
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
+++ b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/protocol/S7ProtocolLogic.java
@@ -36,7 +36,6 @@ import org.apache.plc4x.java.s7.events.S7Event;
import org.apache.plc4x.java.s7.readwrite.*;
import org.apache.plc4x.java.s7.readwrite.context.S7DriverContext;
import org.apache.plc4x.java.s7.readwrite.tag.*;
-import org.apache.plc4x.java.s7.readwrite.types.S7ControllerType;
import org.apache.plc4x.java.s7.readwrite.types.S7SubscriptionType;
import org.apache.plc4x.java.s7.readwrite.utils.S7PlcSubscriptionHandle;
import org.apache.plc4x.java.s7.utils.S7ParamErrorCode;
@@ -195,7 +194,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
// If the controller type is explicitly set, were finished with the login
// process. If it's set to ANY, we have to query the serial number information
// in order to detect the type of PLC.
- if (s7DriverContext.getControllerType() != S7ControllerType.ANY) {
+ if (s7DriverContext.getControllerType() != ControllerType.ANY) {
// Send an event that connection setup is complete.
context.fireConnected();
return;
@@ -569,7 +568,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
} else {
//TODO: Check for ALARM_S (S7300) and ALARM_8 (S7400), maybe we need verify the CPU
AlarmStateType alarmType;
- if (s7DriverContext.getControllerType() == S7ControllerType.S7_400) {
+ if (s7DriverContext.getControllerType() == ControllerType.S7_400) {
alarmType = AlarmStateType.ALARM_INITIATE;
} else {
alarmType = AlarmStateType.ALARM_S_INITIATE;
@@ -754,7 +753,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
try {
short cpuSubFunction;
- if (s7DriverContext.getControllerType() == S7ControllerType.S7_300) {
+ if (s7DriverContext.getControllerType() == ControllerType.S7_300) {
cpuSubFunction = 0x13;
} else {
cpuSubFunction = 0xf0;
@@ -1890,7 +1889,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
int stringLength = (tag instanceof S7StringFixedLengthTag) ? ((S7StringFixedLengthTag) tag).getStringLength() : 254;
ByteBuffer byteBuffer = null;
for (int i = 0; i < tag.getNumberOfElements(); i++) {
- int lengthInBits = DataItem.getLengthInBits(plcValue.getIndex(i), tag.getDataType().getDataProtocolId(), stringLength);
+ int lengthInBits = DataItem.getLengthInBits(plcValue.getIndex(i), tag.getDataType().getDataProtocolId(), s7DriverContext.getControllerType(), stringLength);
// Cap the length of the string with the maximum allowed size.
if(tag.getDataType() == TransportSize.STRING) {
lengthInBits = Math.min(lengthInBits, (stringLength * 8) + 16);
@@ -1901,7 +1900,7 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
lengthInBits = lengthInBits * 8;
}
final WriteBufferByteBased writeBuffer = new WriteBufferByteBased((int) Math.ceil(((float) lengthInBits) / 8.0f));
- DataItem.staticSerialize(writeBuffer, plcValue.getIndex(i), tag.getDataType().getDataProtocolId(), stringLength);
+ DataItem.staticSerialize(writeBuffer, plcValue.getIndex(i), tag.getDataType().getDataProtocolId(), s7DriverContext.getControllerType(), stringLength);
// Allocate enough space for all items.
if (byteBuffer == null) {
// TODO: This logic will cause problems when reading arrays of strings.
@@ -1924,14 +1923,15 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
try {
int stringLength = (tag instanceof S7StringFixedLengthTag) ? ((S7StringFixedLengthTag) tag).getStringLength() : 254;
if (tag.getNumberOfElements() == 1) {
+ // TODO: Pass the type of plc into the parse function ...
return DataItem.staticParse(readBuffer, tag.getDataType().getDataProtocolId(),
- stringLength);
+ s7DriverContext.getControllerType(), stringLength);
} else {
// Fetch all
final PlcValue[] resultItems = IntStream.range(0, tag.getNumberOfElements()).mapToObj(i -> {
try {
return DataItem.staticParse(readBuffer, tag.getDataType().getDataProtocolId(),
- stringLength);
+ s7DriverContext.getControllerType(), stringLength);
} catch (ParseException e) {
logger.warn("Error parsing tag item of type: '{}' (at position {}})", tag.getDataType().name(), i, e);
}
@@ -1976,25 +1976,25 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
* @param articleNumber article number string.
* @return type of controller.
*/
- private S7ControllerType decodeControllerType(String articleNumber) {
+ private ControllerType decodeControllerType(String articleNumber) {
if (!articleNumber.startsWith("6ES7 ")) {
- return S7ControllerType.ANY;
+ return ControllerType.ANY;
}
String model = articleNumber.substring(articleNumber.indexOf(' ') + 1, articleNumber.indexOf(' ') + 2);
switch (model) {
case "2":
- return S7ControllerType.S7_1200;
+ return ControllerType.S7_1200;
case "5":
- return S7ControllerType.S7_1500;
+ return ControllerType.S7_1500;
case "3":
- return S7ControllerType.S7_300;
+ return ControllerType.S7_300;
case "4":
- return S7ControllerType.S7_400;
+ return ControllerType.S7_400;
default:
if (logger.isInfoEnabled()) {
logger.info("Looking up unknown article number {}", articleNumber);
}
- return S7ControllerType.ANY;
+ return ControllerType.ANY;
}
}
@@ -2051,8 +2051,8 @@ public class S7ProtocolLogic extends Plc4xProtocolBase<TPKTPacket> {
private boolean isFeatureSupported() {
- return (s7DriverContext.getControllerType() == S7ControllerType.S7_300) ||
- (s7DriverContext.getControllerType() == S7ControllerType.S7_400);
+ return (s7DriverContext.getControllerType() == ControllerType.S7_300) ||
+ (s7DriverContext.getControllerType() == ControllerType.S7_400);
}
private CompletableFuture<S7MessageUserData> reassembledMessage(short sequenceNumber, List<PlcValue> plcValues) {
diff --git a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/types/S7ControllerType.java b/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/types/S7ControllerType.java
deleted file mode 100644
index 2291c55efc..0000000000
--- a/plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/types/S7ControllerType.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.plc4x.java.s7.readwrite.types;
-
-public enum S7ControllerType {
-
- ANY,
- S7_200,
- S7_300,
- S7_400,
- S7_1200,
- S7_1500,
- LOGO
-
-}
diff --git a/plc4j/tools/ui/frontend/project/src/generated/plc4j-tools-ui-frontend.ts b/plc4j/tools/ui/frontend/project/src/generated/plc4j-tools-ui-frontend.ts
index 6b7be35b35..68b3a72918 100644
--- a/plc4j/tools/ui/frontend/project/src/generated/plc4j-tools-ui-frontend.ts
+++ b/plc4j/tools/ui/frontend/project/src/generated/plc4j-tools-ui-frontend.ts
@@ -19,7 +19,7 @@
*/
/* tslint:disable */
/* eslint-disable */
-// Generated using typescript-generator version 3.2.1263 on 2024-01-27 21:34:50.
+// Generated using typescript-generator version 3.2.1263 on 2024-01-30 21:46:21.
export interface Device {
id: number;
diff --git a/protocols/s7/src/main/resources/protocols/s7/s7.mspec b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
index bd7a558425..2e9d7d3770 100644
--- a/protocols/s7/src/main/resources/protocols/s7/s7.mspec
+++ b/protocols/s7/src/main/resources/protocols/s7/s7.mspec
@@ -677,8 +677,8 @@
]
]
-[dataIo DataItem(vstring dataProtocolId, int 32 stringLength)
- [typeSwitch dataProtocolId
+[dataIo DataItem(vstring dataProtocolId, ControllerType controllerType, int 32 stringLength)
+ [typeSwitch dataProtocolId, controllerType
// -----------------------------------------
// Bit
// -----------------------------------------
@@ -1043,3 +1043,12 @@
['0X02' B10SEC]
]
+[enum ControllerType
+ [ANY ]
+ [S7_200 ]
+ [S7_300 ]
+ [S7_400 ]
+ [S7_1200]
+ [S7_1500]
+ [LOGO ]
+]