Skip to content

Commit

Permalink
Adding use_router which leads to update_router_reference (after findi…
Browse files Browse the repository at this point in the history
…ng this router with who_is)
  • Loading branch information
ChristianTremblay committed Sep 13, 2024
1 parent 913364c commit 6158c5c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions BAC0/core/functions/Alias.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from typing import List, Tuple, Optional, Union

from bacpypes3.app import Application
from bacpypes3.pdu import Address, GlobalBroadcast
Expand All @@ -7,6 +8,11 @@

from ...core.utils.notes import note_and_log

ROUTER_TUPLE_TYPE = Union[
Tuple[Union[Address, str], Union[int, List[int]]],
Tuple[Union[Address, str], Union[int, List[int]], Optional[int]],
]


@note_and_log
class Alias:
Expand Down Expand Up @@ -110,6 +116,36 @@ async def init_routing_table(self, address):
_app: Application = _this_application.app
await _app.nse.initialize_routing_table()

async def use_router(
self,
router_infos: Union[
Tuple[Union[Address, str], Union[int, List[int]]],
Tuple[Union[Address, str], Union[int, List[int]], Optional[int]],
] = (None, None, None),
):
address, dnets = router_infos[:2]
try:
snet = router_infos[2]
except IndexError:
snet = None
_this_application: BAC0Application = self.this_application
_app: Application = _this_application.app
if not isinstance(address, Address):
address = Address(address)
if not isinstance(dnets, list):
dnets = [dnets]
response = await self.who_is(address=address)
if response:
self._log.info(f"Router found at {address}")
self._log.info(
f"Adding router reference -> Snet : {snet} Addr : {address} dnets : {dnets}"
)
await _app.nsap.update_router_references(
snet=snet, address=address, dnets=dnets
)
else:
self._log.warning(f"Router not found at {address}")

async def what_is_network_number(self, destination=None, timeout=3):
"""
winn [ <addr> ]
Expand Down
2 changes: 1 addition & 1 deletion BAC0/scripts/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Base:

def __init__(
self,
localIPAddr: str = "127.0.0.1",
localIPAddr: Address = Address("127.0.0.1/24"),
networkNumber: int = None,
localObjName: str = "BAC0",
deviceId: int = None,
Expand Down

0 comments on commit 6158c5c

Please sign in to comment.