fix(io): Handle large integer values with fallback to raw byte arrays
Added a fallback mechanism to handle cases where integer values exceed valid range by using raw byte arrays (`ay`). Updated D-Bus methods and properties to support this behavior. Signed-off-by: Sven Sager <s.sager@kunbus.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
"""D-Bus interfaces for IOs."""
|
||||
|
||||
from typing import Union
|
||||
|
||||
from dbus import SystemBus, SessionBus
|
||||
@@ -34,15 +35,26 @@ class InterfaceInput:
|
||||
PropertiesChanged = signal()
|
||||
|
||||
def __init__(self, dbus: Union[SystemBus, SessionBus], io: IOBase):
|
||||
self._raw = False
|
||||
self.dbus = dbus
|
||||
self.io = io
|
||||
self.variant_type = get_variant_type(self.io)
|
||||
try:
|
||||
self.variant_type = get_variant_type(self.io)
|
||||
except ValueError:
|
||||
# Fallback to bytes if the integer is too large
|
||||
self._raw = True
|
||||
self.variant_type = "ay"
|
||||
|
||||
def emit_io_change(self):
|
||||
if self.interface_name:
|
||||
self.PropertiesChanged(
|
||||
self.interface_name,
|
||||
{"value": Variant(self.variant_type, self.io.value)},
|
||||
{
|
||||
"value": Variant(
|
||||
self.variant_type,
|
||||
self.io.get_value() if self._raw else self.io.value,
|
||||
),
|
||||
},
|
||||
[],
|
||||
)
|
||||
|
||||
@@ -70,7 +82,10 @@ class InterfaceInput:
|
||||
|
||||
@property
|
||||
def defaultvalue(self) -> Variant:
|
||||
return Variant(self.variant_type, self.io.defaultvalue)
|
||||
return Variant(
|
||||
self.variant_type,
|
||||
self.io.get_value() if self._raw else self.io.defaultvalue,
|
||||
)
|
||||
|
||||
@property
|
||||
def length(self) -> int:
|
||||
@@ -95,7 +110,10 @@ class InterfaceInput:
|
||||
|
||||
@property
|
||||
def value(self) -> Variant:
|
||||
return Variant(self.variant_type, self.io.value)
|
||||
return Variant(
|
||||
self.variant_type,
|
||||
self.io.get_value() if self._raw else self.io.value,
|
||||
)
|
||||
|
||||
|
||||
class InterfaceOutput(InterfaceInput):
|
||||
@@ -123,7 +141,10 @@ class InterfaceOutput(InterfaceInput):
|
||||
|
||||
@value.setter
|
||||
def value(self, value: Variant) -> None:
|
||||
self.io.value = value
|
||||
if self._raw:
|
||||
self.io.set_value(value)
|
||||
else:
|
||||
self.io.value = value
|
||||
self.io._parentdevice._modio.writeprocimg()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user