Skip to content

Commit d4f4762

Browse files
committed
trying different bacnet config
1 parent 8bc8d55 commit d4f4762

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

buildingmotif/bin/cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,17 @@ def app():
156156
@subcommand(
157157
arg("-o", "--output_file", help="Output file for BACnet scan", required=True),
158158
arg("-ip", help="ip address of BACnet network to scan", default=None),
159+
arg(
160+
"--local-broadcast",
161+
action="store_false",
162+
dest="global_broadcast",
163+
help="Limit discovery to local broadcast; defaults to global broadcast",
164+
default=True,
165+
),
159166
)
160167
def scan(args):
161168
"""Scans a BACnet network and generates a JSON file for later processing"""
162-
bacnet_network = BACnetNetwork(args.ip)
169+
bacnet_network = BACnetNetwork(args.ip, global_broadcast=args.global_broadcast)
163170
bacnet_network.dump(Path(args.output_file))
164171

165172

buildingmotif/ingresses/bacnet.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(
2828
ip: Optional[str] = None,
2929
*,
3030
discover_kwargs: Optional[Dict[str, Any]] = None,
31+
global_broadcast: bool = True,
3132
ping: bool = False,
3233
device_kwargs: Optional[Dict[str, Any]] = None,
3334
):
@@ -39,16 +40,20 @@ def __init__(
3940
:type ip: Optional[str], optional
4041
:param discover_kwargs: Optional kwargs forwarded to BAC0._discover.
4142
:type discover_kwargs: Optional[Dict[str, Any]]
43+
:param global_broadcast: Whether to issue global broadcast Who-Is requests.
44+
:type global_broadcast: bool
4245
:param ping: Whether to ping devices during connect; defaults to False.
4346
:type ping: bool
4447
:param device_kwargs: Optional kwargs forwarded to BAC0.device.
4548
:type device_kwargs: Optional[Dict[str, Any]]
4649
"""
4750
self.objects: Dict[Tuple[str, int], List[Dict[str, Any]]] = {}
51+
discover_kwargs = dict(discover_kwargs or {})
52+
discover_kwargs.setdefault("global_broadcast", global_broadcast)
4853
self._run_async(
4954
self._collect_objects(
5055
ip=ip,
51-
discover_kwargs=discover_kwargs or {},
56+
discover_kwargs=discover_kwargs,
5257
ping=ping,
5358
device_kwargs=device_kwargs or {},
5459
)

docs/guides/docker-compose-bacnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ networks:
1212
driver: default
1313
config:
1414
- subnet: "172.24.0.0/16"
15-
gateway: "172.24.0.1"
15+
gateway: "172.24.0.1"

tests/integration/fixtures/bacnet/virtual_bacnet.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import random
23
import sys
34

@@ -27,8 +28,33 @@ class VirtualDevice:
2728
def __init__(self, host: str = "0.0.0.0"):
2829
parser = ConfigArgumentParser(description=__doc__)
2930
args = parser.parse_args()
31+
logging.basicConfig(level=logging.INFO)
32+
33+
_log.info("Starting Virtual BACnet device")
34+
_log.debug("Parsed arguments: %s", args)
35+
if not getattr(args, "ini", None):
36+
raise ValueError("BACpypes configuration file (--ini) is required")
37+
_log.info("Using configuration ini: %s", args.ini)
38+
3039
self.device = LocalDeviceObject(ini=args.ini)
40+
_log.info(
41+
"Created LocalDeviceObject name=%s identifier=%s",
42+
self.device.objectName,
43+
getattr(self.device, "objectIdentifier", None),
44+
)
3145
self.application = VirtualBACnetApp(self.device, host)
46+
# ensure protocol services advertised match application capabilities
47+
# try:
48+
# self.device.protocolServicesSupported = (
49+
# self.application.get_services_supported()
50+
# )
51+
# except AttributeError:
52+
# _log.warning("Unable to set protocolServicesSupported on LocalDeviceObject")
53+
# else:
54+
# _log.debug(
55+
# "protocolServicesSupported: %s",
56+
# self.device.protocolServicesSupported,
57+
# )
3258

3359
# setup points
3460
self.points = {
@@ -54,9 +80,16 @@ def __init__(self, host: str = "0.0.0.0"):
5480
),
5581
}
5682

57-
for p in self.points.values():
58-
self.application.add_object(p)
83+
for name, point in self.points.items():
84+
self.application.add_object(point)
85+
_log.info(
86+
"Registered BACnet object %s identifier=%s value=%s",
87+
name,
88+
point.objectIdentifier,
89+
getattr(point, "presentValue", None),
90+
)
5991

92+
_log.info("Virtual device listening on host %s", host)
6093
run()
6194

6295

tests/integration/test_bacnet_ingress.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def test_bacnet_ingress(bm):
1414
BLDG = Namespace("urn:building/")
1515
m = Model.create(BLDG, "test building for bacnet scan")
16-
bacnet = BACnetNetwork("172.24.0.2/32")
16+
bacnet = BACnetNetwork("172.24.0.2/24")
1717
tobrick = BACnetToBrickIngress(bm, bacnet)
1818
m.add_graph(tobrick.graph(BLDG))
1919

@@ -35,7 +35,7 @@ def test_bacnet_scan_cli(bm, tmp_path):
3535
d.mkdir()
3636
output_file = d / "output.json"
3737
subprocess.run(
38-
shlex.split(f'buildingmotif scan -o "{str(output_file)}" -ip 172.24.0.2/32')
38+
shlex.split(f'buildingmotif scan -o "{str(output_file)}" -ip 172.24.0.2/24')
3939
)
4040
assert output_file.exists()
4141
bacnet = BACnetNetwork.load(output_file)

0 commit comments

Comments
 (0)