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:
Sven Sager
2026-02-04 08:34:22 +01:00
parent b16331cf84
commit 415e8502f7

View File

@@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH # SPDX-FileCopyrightText: 2025 KUNBUS GmbH
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
"""D-Bus interfaces for IOs.""" """D-Bus interfaces for IOs."""
from typing import Union from typing import Union
from dbus import SystemBus, SessionBus from dbus import SystemBus, SessionBus
@@ -34,15 +35,26 @@ class InterfaceInput:
PropertiesChanged = signal() PropertiesChanged = signal()
def __init__(self, dbus: Union[SystemBus, SessionBus], io: IOBase): def __init__(self, dbus: Union[SystemBus, SessionBus], io: IOBase):
self._raw = False
self.dbus = dbus self.dbus = dbus
self.io = io self.io = io
try:
self.variant_type = get_variant_type(self.io) 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): def emit_io_change(self):
if self.interface_name: if self.interface_name:
self.PropertiesChanged( self.PropertiesChanged(
self.interface_name, 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 @property
def defaultvalue(self) -> Variant: 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 @property
def length(self) -> int: def length(self) -> int:
@@ -95,7 +110,10 @@ class InterfaceInput:
@property @property
def value(self) -> Variant: 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): class InterfaceOutput(InterfaceInput):
@@ -123,6 +141,9 @@ class InterfaceOutput(InterfaceInput):
@value.setter @value.setter
def value(self, value: Variant) -> None: def value(self, value: Variant) -> None:
if self._raw:
self.io.set_value(value)
else:
self.io.value = value self.io.value = value
self.io._parentdevice._modio.writeprocimg() self.io._parentdevice._modio.writeprocimg()