pycyphal.application.register.backend.dynamic module
- class pycyphal.application.register.backend.dynamic.DynamicBackend[source]
Bases:
pycyphal.application.register.backend.Backend
Register backend where register access is delegated to external getters and setters. It does not store values internally. Exceptions raised by getters/setters are wrapped into
BackendError
.Create new registers and change value of existing ones using
__setitem__()
.>>> from pycyphal.application.register import Bit >>> b = DynamicBackend() >>> b.persistent False >>> b.get("foo") is None True >>> b.index(0) is None True >>> foo = Value(bit=Bit([True, False, True])) >>> def set_foo(v: Value): ... global foo ... foo = v >>> b["foo"] = (lambda: foo), set_foo # Create new mutable register. >>> b["foo"].mutable True >>> list(b["foo"].value.bit.value) [True, False, True] >>> b["foo"] = Value(bit=Bit([False, True, True])) # Set new value. >>> list(b["foo"].value.bit.value) [False, True, True] >>> b["foo"] = lambda: foo # Replace register with a new one that is now immutable. >>> b["foo"] = Value(bit=Bit([False, False, False])) # Value cannot be changed. >>> list(b["foo"].value.bit.value) [False, True, True] >>> list(b) ['foo'] >>> del b["foo"] >>> list(b) []
- __getitem__(key: str) pycyphal.application.register.backend.Entry [source]
- __setitem__(key: str, value: Union[pycyphal.application.register.backend.Entry, uavcan.register.Value_1_0.Value_1_0, Callable[[], uavcan.register.Value_1_0.Value_1_0], Tuple[Callable[[], uavcan.register.Value_1_0.Value_1_0], Callable[[uavcan.register.Value_1_0.Value_1_0], None]]]) None [source]
- Parameters
key – The register name.
value –
If this is an instance of
Entry
orValue
, and the referenced register is mutable, its setter is invoked with the supplied instance ofValue
(ifEntry
is given, the value is extracted from there and the mutability flag is ignored). If the register is immutable, nothing is done. The caller is required to ensure that the type is acceptable.If this is a single callable, a new immutable register is defined (existing registers overwritten).
If this is a tuple of two callables, a new mutable register is defined (existing registers overwritten).