You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2023/05/07 05:32:31 UTC

[plc4x] branch develop updated (2da0afab14 -> 2db561306e)

This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


    from 2da0afab14 Feat/profinet ip set (#927)
     new 9af6b0e69b feat(plc4py): Implement the WriteBuffer interface
     new 6b5cdf700c feat(plc4py): Fix issue with naming of optional enum code-gen
     new 2db561306e feat(plc4py): Formatting and more dummy methods

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../templates/python/enum-template.python.ftlh     |  2 +-
 .../plc4py/plc4py/spi/generation/WriteBuffer.py    | 97 ++++++++++++++++++++++
 sandbox/plc4py/plc4py/spi/generation/__init__.py   | 17 ++++
 sandbox/plc4py/plc4py/spi/values/common.py         | 23 +++++
 sandbox/plc4py/plc4py/utils/GenericTypes.py        | 11 +++
 5 files changed, 149 insertions(+), 1 deletion(-)
 create mode 100644 sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
 create mode 100644 sandbox/plc4py/plc4py/spi/generation/__init__.py
 create mode 100644 sandbox/plc4py/plc4py/spi/values/common.py


[plc4x] 01/03: feat(plc4py): Implement the WriteBuffer interface

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 9af6b0e69bc5536d626ee509fc8e99537e8e4228
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Sun May 7 07:04:36 2023 +0200

    feat(plc4py): Implement the WriteBuffer interface
---
 .../plc4py/plc4py/spi/generation/WriteBuffer.py    | 98 ++++++++++++++++++++++
 sandbox/plc4py/plc4py/spi/generation/__init__.py   | 17 ++++
 sandbox/plc4py/plc4py/spi/values/common.py         | 20 +++++
 sandbox/plc4py/plc4py/utils/GenericTypes.py        | 11 +++
 4 files changed, 146 insertions(+)

diff --git a/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py b/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
new file mode 100644
index 0000000000..f58c25d2dd
--- /dev/null
+++ b/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
@@ -0,0 +1,98 @@
+#  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
+#
+#    http://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.
+
+from ctypes import *
+from dataclasses import dataclass
+from typing import List
+
+from plc4py.spi.values.common import Serializable
+from plc4py.utils.GenericTypes import ByteOrder, ByteOrderAware
+
+
+class PositionAware:
+
+    def get_pos(self) -> int:
+        raise NotImplementedError
+
+
+@dataclass
+class WriteBuffer(ByteOrderAware, PositionAware):
+    byte_order: ByteOrder
+
+    def get_pos(self) -> int:
+        raise NotImplementedError
+
+    def push_context(self, logical_name: str, **kwargs) -> None:
+        raise NotImplementedError
+
+    def pop_context(self, logical_name: str, **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_bit(self, value: c_bool, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_byte(self, value: c_byte, logical_name: str = "", **kwargs) -> None:
+        self.write_signed_byte(value, logical_name, kwargs)
+
+    def write_byte_array(self, value: List[c_byte], logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_unsigned_byte(self, value: c_ubyte, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_unsigned_short(self, value: c_uint16, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_unsigned_int(self, value: c_uint32, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_unsigned_long(self, value: c_uint64, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_signed_byte(self, value: c_byte, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_short(self, value: c_int16, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_int(self, value: c_int32, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_long(self, value: c_int64, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_float(self, value: c_float, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_double(self, value: c_double, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_str(self, value: str, logical_name: str = "", bit_length: int = -1, **kwargs) -> None:
+        raise NotImplementedError
+
+    def write_virtual(self, value: str, logical_name: str = "", **kwargs) -> None:
+        raise NotImplementedError
+
+
+    #
+    # This method can be used to influence serializing (e.g. intercept whole types and render them in a simplified form)
+    #
+    # @param value the value to be serialized
+    # @throws SerializationException if something goes wrong
+    #
+    def write_serializable(self, value: Serializable) -> None:
+        value.serialize(self)
diff --git a/sandbox/plc4py/plc4py/spi/generation/__init__.py b/sandbox/plc4py/plc4py/spi/generation/__init__.py
new file mode 100644
index 0000000000..c3434ab60d
--- /dev/null
+++ b/sandbox/plc4py/plc4py/spi/generation/__init__.py
@@ -0,0 +1,17 @@
+#  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
+#
+#    http://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.
+
diff --git a/sandbox/plc4py/plc4py/spi/values/common.py b/sandbox/plc4py/plc4py/spi/values/common.py
new file mode 100644
index 0000000000..2c76fbc8b8
--- /dev/null
+++ b/sandbox/plc4py/plc4py/spi/values/common.py
@@ -0,0 +1,20 @@
+#  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
+#
+#    http://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.
+
+
+class Serializable:
+    pass
diff --git a/sandbox/plc4py/plc4py/utils/GenericTypes.py b/sandbox/plc4py/plc4py/utils/GenericTypes.py
index 863931f55b..9b46d976dc 100644
--- a/sandbox/plc4py/plc4py/utils/GenericTypes.py
+++ b/sandbox/plc4py/plc4py/utils/GenericTypes.py
@@ -16,6 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 #
+from dataclasses import dataclass
 from enum import Enum, auto
 from typing import Generator
 
@@ -42,3 +43,13 @@ class ByteOrder(Enum):
 
     LITTLE_ENDIAN = auto()
     BIG_ENDIAN = auto()
+
+    def __new__(cls, value):
+        obj = object.__new__(cls)
+        obj._value_ = value
+        return obj
+
+
+@dataclass
+class ByteOrderAware:
+    byte_order: ByteOrder


[plc4x] 03/03: feat(plc4py): Formatting and more dummy methods

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 2db561306ee49f2ee17363dd7db5306e0e0c4595
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Sun May 7 07:10:07 2023 +0200

    feat(plc4py): Formatting and more dummy methods
---
 sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py | 3 +--
 sandbox/plc4py/plc4py/spi/values/common.py          | 5 ++++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py b/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
index f58c25d2dd..63d4d5969c 100644
--- a/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
+++ b/sandbox/plc4py/plc4py/spi/generation/WriteBuffer.py
@@ -46,7 +46,7 @@ class WriteBuffer(ByteOrderAware, PositionAware):
         raise NotImplementedError
 
     def write_byte(self, value: c_byte, logical_name: str = "", **kwargs) -> None:
-        self.write_signed_byte(value, logical_name, kwargs)
+        self.write_signed_byte(value, logical_name, **kwargs)
 
     def write_byte_array(self, value: List[c_byte], logical_name: str = "", **kwargs) -> None:
         raise NotImplementedError
@@ -87,7 +87,6 @@ class WriteBuffer(ByteOrderAware, PositionAware):
     def write_virtual(self, value: str, logical_name: str = "", **kwargs) -> None:
         raise NotImplementedError
 
-
     #
     # This method can be used to influence serializing (e.g. intercept whole types and render them in a simplified form)
     #
diff --git a/sandbox/plc4py/plc4py/spi/values/common.py b/sandbox/plc4py/plc4py/spi/values/common.py
index 2c76fbc8b8..c5ca06e1a6 100644
--- a/sandbox/plc4py/plc4py/spi/values/common.py
+++ b/sandbox/plc4py/plc4py/spi/values/common.py
@@ -14,7 +14,10 @@
 #  KIND, either express or implied.  See the License for the
 #  specific language governing permissions and limitations
 #  under the License.
+from plc4py.spi.generation.WriteBuffer import WriteBuffer
 
 
 class Serializable:
-    pass
+
+    def serialize(self, write_buffer: WriteBuffer):
+        pass


[plc4x] 02/03: feat(plc4py): Fix issue with naming of optional enum code-gen

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 6b5cdf700c5a2e3073ef87c17548120d35749870
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Sun May 7 07:05:04 2023 +0200

    feat(plc4py): Fix issue with naming of optional enum code-gen
---
 .../src/main/resources/templates/python/enum-template.python.ftlh       | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/code-generation/language-python/src/main/resources/templates/python/enum-template.python.ftlh b/code-generation/language-python/src/main/resources/templates/python/enum-template.python.ftlh
index 7d3ec03263..5b882ce5c9 100644
--- a/code-generation/language-python/src/main/resources/templates/python/enum-template.python.ftlh
+++ b/code-generation/language-python/src/main/resources/templates/python/enum-template.python.ftlh
@@ -95,7 +95,7 @@ class ${type.name}(Enum):
     <#if type.constantNames?has_content>
     def __new__(cls, value, <@compress single_line=true>
         <#list type.constantNames as constantName>
-            ${constantName}
+            ${helper.camelCaseToSnakeCase(constantName)}
             <#sep>, </#sep>
         </#list>):
         </...@compress>