Skip to content

Commit

Permalink
fix(plc4py/umas): Fixed alignment on return packet
Browse files Browse the repository at this point in the history
  • Loading branch information
hutcheb committed Jan 14, 2024
1 parent e2b9b5a commit 29517d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
5 changes: 3 additions & 2 deletions protocols/umas/src/main/resources/protocols/umas/umas.mspec
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@
]

['0xFE','true' UmasPDUResponse
[simple uint 32 range]
[simple uint 8 range]
[simple uint 32 ident]
[simple uint 16 model]
[simple uint 16 comVersion]
[simple uint 16 comPatch]
[simple uint 16 intVersion]
[simple uint 8 hardwareVersion]
[simple uint 16 hardwareVersion]
[simple uint 32 crashCode]
[simple uint 32 stringLength]
[simple vstring 'stringLength*8' stringValue]
Expand Down
31 changes: 23 additions & 8 deletions sandbox/plc4py/plc4py/protocols/umas/readwrite/UmasPDUResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class UmasPDUResponse(UmasPDUItem):
ident: int
model: int
com_version: int
com_patch: int
int_version: int
hardware_version: int
crash_code: int
Expand All @@ -48,7 +49,7 @@ def serialize_umas_pdu_item_child(self, write_buffer: WriteBuffer):
write_buffer.push_context("UmasPDUResponse")

# Simple Field (range)
write_buffer.write_unsigned_int(self.range, logical_name="range")
write_buffer.write_unsigned_byte(self.range, logical_name="range")

# Simple Field (ident)
write_buffer.write_unsigned_int(self.ident, logical_name="ident")
Expand All @@ -59,11 +60,14 @@ def serialize_umas_pdu_item_child(self, write_buffer: WriteBuffer):
# Simple Field (comVersion)
write_buffer.write_unsigned_short(self.com_version, logical_name="comVersion")

# Simple Field (comPatch)
write_buffer.write_unsigned_short(self.com_patch, logical_name="comPatch")

# Simple Field (intVersion)
write_buffer.write_unsigned_short(self.int_version, logical_name="intVersion")

# Simple Field (hardwareVersion)
write_buffer.write_unsigned_byte(
write_buffer.write_unsigned_short(
self.hardware_version, logical_name="hardwareVersion"
)

Expand All @@ -86,7 +90,7 @@ def length_in_bits(self) -> int:
_value: UmasPDUResponse = self

# Simple field (range)
length_in_bits += 32
length_in_bits += 8

# Simple field (ident)
length_in_bits += 32
Expand All @@ -97,11 +101,14 @@ def length_in_bits(self) -> int:
# Simple field (comVersion)
length_in_bits += 16

# Simple field (comPatch)
length_in_bits += 16

# Simple field (intVersion)
length_in_bits += 16

# Simple field (hardwareVersion)
length_in_bits += 8
length_in_bits += 16

# Simple field (crashCode)
length_in_bits += 32
Expand All @@ -118,8 +125,8 @@ def length_in_bits(self) -> int:
def static_parse_builder(read_buffer: ReadBuffer, response: bool):
read_buffer.push_context("UmasPDUResponse")

range: int = read_buffer.read_unsigned_int(
logical_name="range", bit_length=32, response=response
range: int = read_buffer.read_unsigned_byte(
logical_name="range", bit_length=8, response=response
)

ident: int = read_buffer.read_unsigned_int(
Expand All @@ -134,12 +141,16 @@ def static_parse_builder(read_buffer: ReadBuffer, response: bool):
logical_name="comVersion", bit_length=16, response=response
)

com_patch: int = read_buffer.read_unsigned_short(
logical_name="comPatch", bit_length=16, response=response
)

int_version: int = read_buffer.read_unsigned_short(
logical_name="intVersion", bit_length=16, response=response
)

hardware_version: int = read_buffer.read_unsigned_byte(
logical_name="hardwareVersion", bit_length=8, response=response
hardware_version: int = read_buffer.read_unsigned_short(
logical_name="hardwareVersion", bit_length=16, response=response
)

crash_code: int = read_buffer.read_unsigned_int(
Expand All @@ -163,6 +174,7 @@ def static_parse_builder(read_buffer: ReadBuffer, response: bool):
ident,
model,
com_version,
com_patch,
int_version,
hardware_version,
crash_code,
Expand All @@ -183,6 +195,7 @@ def equals(self, o: object) -> bool:
and (self.ident == that.ident)
and (self.model == that.model)
and (self.com_version == that.com_version)
and (self.com_patch == that.com_patch)
and (self.int_version == that.int_version)
and (self.hardware_version == that.hardware_version)
and (self.crash_code == that.crash_code)
Expand Down Expand Up @@ -212,6 +225,7 @@ class UmasPDUResponseBuilder:
ident: int
model: int
com_version: int
com_patch: int
int_version: int
hardware_version: int
crash_code: int
Expand All @@ -225,6 +239,7 @@ def build(self, pairing_key) -> UmasPDUResponse:
self.ident,
self.model,
self.com_version,
self.com_patch,
self.int_version,
self.hardware_version,
self.crash_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def manual_test_plc_driver_umas_connect():
assert not connection.is_connected()


async def test_plc_driver_umas_read():
async def m_test_plc_driver_umas_read():
driver_manager = PlcDriverManager()
async with driver_manager.connection("umas://192.168.1.174:502") as connection:
with connection.read_request_builder() as builder:
Expand Down

0 comments on commit 29517d5

Please sign in to comment.