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


The following commit(s) were added to refs/heads/develop by this push:
     new 9cf49c4d84 feat(plc4py): Add base address when reading certain UDTs
9cf49c4d84 is described below

commit 9cf49c4d841b153b189392d26547980b713d8ce1
Author: hutcheb <[email protected]>
AuthorDate: Fri Oct 11 19:53:10 2024 +0800

    feat(plc4py): Add base address when reading certain UDTs
---
 plc4py/plc4py/drivers/umas/UmasDevice.py                 |  2 +-
 plc4py/plc4py/drivers/umas/UmasVariables.py              | 14 ++++++++++----
 .../UmasPDUReadUnlocatedVariableNamesRequest.py          |  6 +++---
 .../umas/readwrite/UmasUnlocatedVariableReference.py     | 16 ++++++++--------
 .../umas/src/main/resources/protocols/umas/umas.mspec    |  4 ++--
 5 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/plc4py/plc4py/drivers/umas/UmasDevice.py 
b/plc4py/plc4py/drivers/umas/UmasDevice.py
index 828886999e..96f854d8ea 100644
--- a/plc4py/plc4py/drivers/umas/UmasDevice.py
+++ b/plc4py/plc4py/drivers/umas/UmasDevice.py
@@ -171,7 +171,7 @@ class UmasDevice:
         return_dict = {}
         for kea, tag in tags.items():
             temp_variable = UmasVariableBuilder(
-                kea, tag, data_types, data_type_children
+                kea, tag, data_types, data_type_children, 
base_offset=tag.base_offset
             ).build()
             if temp_variable is not None:
                 return_dict[kea] = temp_variable
diff --git a/plc4py/plc4py/drivers/umas/UmasVariables.py 
b/plc4py/plc4py/drivers/umas/UmasVariables.py
index 823e7dda88..421173bee3 100644
--- a/plc4py/plc4py/drivers/umas/UmasVariables.py
+++ b/plc4py/plc4py/drivers/umas/UmasVariables.py
@@ -39,6 +39,7 @@ class UmasVariable:
     variable_name: str
     data_type: int
     block_no: int
+    base_offset: int
     offset: int
 
     def get_variable_reference(self, address: str) -> 
VariableReadRequestReference:
@@ -60,7 +61,7 @@ class UmasElementryVariable(UmasVariable):
                 is_array=1,
                 data_size_index=UmasDataType(self.data_type).request_size,
                 block=self.block_no,
-                base_offset=0x0000,
+                base_offset=self.base_offset,
                 offset=self.offset,
                 array_length=16,
             )
@@ -69,7 +70,7 @@ class UmasElementryVariable(UmasVariable):
                 is_array=0,
                 data_size_index=UmasDataType(self.data_type).request_size,
                 block=self.block_no,
-                base_offset=0x0000,
+                base_offset=self.base_offset,
                 offset=self.offset,
                 array_length=None,
             )
@@ -116,7 +117,7 @@ class UmasArrayVariable(UmasVariable):
                 is_array=0,
                 data_size_index=data_type_enum.request_size,
                 block=self.block_no,
-                base_offset=0x0000,
+                base_offset=self.base_offset,
                 offset=self.offset
                 + (address_index - self.start_index) * 
data_type_enum.data_type_size,
                 array_length=None,
@@ -126,7 +127,7 @@ class UmasArrayVariable(UmasVariable):
                 is_array=1,
                 data_size_index=data_type_enum.request_size,
                 block=self.block_no,
-                base_offset=0x0000,
+                base_offset=self.base_offset,
                 offset=self.offset,
                 array_length=self.end_index - self.start_index + 1,
             )
@@ -142,6 +143,7 @@ class UmasVariableBuilder:
     data_type_references: List[UmasDatatypeReference]
     udt_definitions: Dict[str, List[UmasUDTDefinition]]
     block: int = -1
+    base_offset: int = 0
     offset: int = 0
 
     def build(self) -> UmasVariable:
@@ -160,6 +162,7 @@ class UmasVariableBuilder:
                 self.tag_name,
                 data_type,
                 self.block,
+                self.base_offset,
                 self.tag_reference.offset + self.offset,
             )
         else:
@@ -180,6 +183,7 @@ class UmasVariableBuilder:
                                 child,
                                 self.data_type_references,
                                 self.udt_definitions,
+                                base_offset=self.base_offset,
                                 offset=self.tag_reference.offset,
                                 block=self.block,
                             ).build()
@@ -187,6 +191,7 @@ class UmasVariableBuilder:
                             self.tag_name,
                             data_type,
                             self.block,
+                            self.base_offset,
                             self.tag_reference.offset,
                             children,
                         )
@@ -212,6 +217,7 @@ class UmasVariableBuilder:
                             self.tag_reference.value,
                             data_type,
                             self.block,
+                            self.base_offset,
                             self.tag_reference.offset + self.offset,
                             int(match.group("start_number")),
                             int(match.group("end_number")),
diff --git 
a/plc4py/plc4py/protocols/umas/readwrite/UmasPDUReadUnlocatedVariableNamesRequest.py
 
b/plc4py/plc4py/protocols/umas/readwrite/UmasPDUReadUnlocatedVariableNamesRequest.py
index 8996d19a44..2a31ba96a5 100644
--- 
a/plc4py/plc4py/protocols/umas/readwrite/UmasPDUReadUnlocatedVariableNamesRequest.py
+++ 
b/plc4py/plc4py/protocols/umas/readwrite/UmasPDUReadUnlocatedVariableNamesRequest.py
@@ -71,7 +71,7 @@ class UmasPDUReadUnlocatedVariableNamesRequest(UmasPDUItem):
         )
 
         # Const Field (blank)
-        write_buffer.write_unsigned_byte(self.BLANK, logical_name="blank")
+        write_buffer.write_unsigned_short(self.BLANK, logical_name="blank")
 
         write_buffer.pop_context("UmasPDUReadUnlocatedVariableNamesRequest")
 
@@ -98,7 +98,7 @@ class UmasPDUReadUnlocatedVariableNamesRequest(UmasPDUItem):
         length_in_bits += 16
 
         # Const Field (blank)
-        length_in_bits += 8
+        length_in_bits += 16
 
         return length_in_bits
 
@@ -153,7 +153,7 @@ class UmasPDUReadUnlocatedVariableNamesRequest(UmasPDUItem):
             byte_length=byte_length,
         )
 
-        BLANK: int = read_buffer.read_unsigned_byte(
+        BLANK: int = read_buffer.read_unsigned_short(
             logical_name="blank",
             byte_order=ByteOrder.LITTLE_ENDIAN,
             umas_request_function_key=umas_request_function_key,
diff --git 
a/plc4py/plc4py/protocols/umas/readwrite/UmasUnlocatedVariableReference.py 
b/plc4py/plc4py/protocols/umas/readwrite/UmasUnlocatedVariableReference.py
index 2fe38b3ff5..9a7874957f 100644
--- a/plc4py/plc4py/protocols/umas/readwrite/UmasUnlocatedVariableReference.py
+++ b/plc4py/plc4py/protocols/umas/readwrite/UmasUnlocatedVariableReference.py
@@ -34,7 +34,7 @@ class UmasUnlocatedVariableReference:
     unknown1: int
     block: int
     offset: int
-    unknown5: int
+    base_offset: int
     unknown4: int
     string_length: int
     value: str
@@ -62,9 +62,9 @@ class UmasUnlocatedVariableReference:
             self.offset, bit_length=8, logical_name="offset"
         )
 
-        # Simple Field (unknown5)
+        # Simple Field (baseOffset)
         write_buffer.write_unsigned_byte(
-            self.unknown5, bit_length=8, logical_name="unknown5"
+            self.base_offset, bit_length=8, logical_name="baseOffset"
         )
 
         # Simple Field (unknown4)
@@ -105,7 +105,7 @@ class UmasUnlocatedVariableReference:
         # Simple field (offset)
         length_in_bits += 8
 
-        # Simple field (unknown5)
+        # Simple field (baseOffset)
         length_in_bits += 8
 
         # Simple field (unknown4)
@@ -143,8 +143,8 @@ class UmasUnlocatedVariableReference:
             logical_name="offset", bit_length=8
         )
 
-        unknown5: int = read_buffer.read_unsigned_byte(
-            logical_name="unknown5", bit_length=8
+        base_offset: int = read_buffer.read_unsigned_byte(
+            logical_name="base_offset", bit_length=8
         )
 
         unknown4: int = read_buffer.read_unsigned_short(
@@ -170,7 +170,7 @@ class UmasUnlocatedVariableReference:
                 unknown1,
                 block,
                 offset,
-                unknown5,
+                base_offset,
                 unknown4,
                 string_length,
                 value,
@@ -191,7 +191,7 @@ class UmasUnlocatedVariableReference:
             and (self.unknown1 == that.unknown1)
             and (self.block == that.block)
             and (self.offset == that.offset)
-            and (self.unknown5 == that.unknown5)
+            and (self.base_offset == that.base_offset)
             and (self.unknown4 == that.unknown4)
             and (self.string_length == that.string_length)
             and (self.value == that.value)
diff --git a/protocols/umas/src/main/resources/protocols/umas/umas.mspec 
b/protocols/umas/src/main/resources/protocols/umas/umas.mspec
index 08d611a86d..1b5a32b0c1 100644
--- a/protocols/umas/src/main/resources/protocols/umas/umas.mspec
+++ b/protocols/umas/src/main/resources/protocols/umas/umas.mspec
@@ -97,7 +97,7 @@
             [simple     uint 32         hardwareId]
             [simple     uint 16         blockNo]
             [simple     uint 16         offset]
-            [const      uint 8          blank 0x00]
+            [const      uint 16         blank 0x00]
         ]
         ['0xFD'     UmasPDUErrorResponse
             [array      uint 8          block count 'byteLength - 2']
@@ -208,7 +208,7 @@
     [simple     uint 8           unknown1]
     [simple     uint 16          block]
     [simple     uint 8           offset]
-    [simple     uint 8           unknown5]
+    [simple     uint 8           baseOffset]
     [simple     uint 16          unknown4]
     [simple     uint 16          stringLength]
     [manual vstring value  'STATIC_CALL("parseTerminatedString", readBuffer, 
stringLength)' 'STATIC_CALL("serializeTerminatedString", writeBuffer, value, 
stringLength)' '(stringLength * 8)']

Reply via email to