Skip to content

Commit

Permalink
addded network singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
theMladyPan committed Jul 17, 2024
1 parent 1c8d18f commit 2e6d5d6
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 125 deletions.
21 changes: 6 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
[project]
name = "xerxes-protocol"
version = "1.4.4"
version = "1.4.5"
description = "Python implementation for xerxes-protocol"
readme = "README.md"
requires-python = ">=3.8"
license = {file = "LICENSE"}
authors = [
{name = "Stanislav Rubint", email = "stanislav@rubint.sk"}
]
dependencies = [
"pyserial",
"pytest",
"rich",
"coverage"
]
keywords = [
"xerxes"
]
license = { file = "LICENSE" }
authors = [{ name = "Stanislav Rubint", email = "stanislav@rubint.sk" }]
dependencies = ["pyserial", "pytest", "rich", "coverage"]
keywords = ["xerxes"]

[project.urls]
homepage = "http://metrotech.sk"
Expand All @@ -30,4 +21,4 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
classifiers = {file = "setup.cfg"}
classifiers = { file = "setup.cfg" }
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name="xerxes-protocol",
version="1.4.4",
version="1.4.5",
author="Stanislav Rubint",
author_email="stanislav@rubint.sk",
description="Python implementation for xerxes-protocol",
Expand Down
13 changes: 7 additions & 6 deletions xerxes_protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,33 @@
LeafData,
LeafConfig,
WriteError,
WriteErrorReadOnly
WriteErrorReadOnly,
)

from xerxes_protocol.hierarchy.root import XerxesRoot # noqa: F401

from xerxes_protocol.network import (
XerxesNetwork,
XerxesNetworkSingleton,
Addr,
XerxesPingReply,
XerxesMessage,
ChecksumError,
MessageIncomplete,
InvalidMessage,
NetworkError,
checksum
checksum,
)
from xerxes_protocol.ids import (
MsgIdMixin,
MsgId,
DevId,
DevIdMixin,
MAGIC_UNLOCK
MAGIC_UNLOCK,
)
from xerxes_protocol.defaults import (
PROTOCOL_VERSION_MAJOR,
PROTOCOL_VERSION_MINOR
PROTOCOL_VERSION_MINOR,
)
from xerxes_protocol.memory import (
ElementType,
Expand All @@ -53,14 +54,14 @@
MemoryNonVolatile,
MemoryVolatile,
MemoryReadOnly,
XerxesMemoryMap
XerxesMemoryMap,
)
from xerxes_protocol.error_flags import (
ERROR_MASK_UART_OVERLOAD,
ERROR_MASK_CPU_OVERLOAD,
ERROR_MASK_BUS_COLLISION,
ERROR_MASK_WATCHDOG_TIMEOUT,
ERROR_MASK_SENSOR_OVERLOAD
ERROR_MASK_SENSOR_OVERLOAD,
)

from xerxes_protocol.debug_serial import DebugSerial
31 changes: 31 additions & 0 deletions xerxes_protocol/hierarchy/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,34 @@ def isPingLatest(pingPacket: XerxesPingReply) -> bool:
and pingPacket.v_min == PROTOCOL_VERSION_MINOR
and pingPacket.dev_id != DevId.NULL
)


class XerxesRootSingleton:
"""Singleton class for XerxesRoot.
This class is a singleton for the XerxesRoot class. It is used to create
only one instance of the XerxesRoot class.
Args:
my_addr (Union[Addr, int, bytes]): The address of this node.
network (XerxesNetwork): The network to use.
Attributes:
_instance (XerxesRoot): The instance of the XerxesRoot class.
"""

_instance = None

def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = XerxesRoot(*args, **kwargs)
return cls._instance

def __getattr__(self, name):
return getattr(self._instance, name)

def __setattr__(self, name, value):
return setattr(self._instance, name, value)

def __delattr__(self, name):
return delattr(self._instance, name)
Loading

0 comments on commit 2e6d5d6

Please sign in to comment.