Skip to content

Commit

Permalink
Merge pull request #432 from torablien/sleep_arg
Browse files Browse the repository at this point in the history
Add a sleep arg to `whois()` and `discover()` to support variance in response latency
  • Loading branch information
ChristianTremblay authored Dec 11, 2023
2 parents e8fba5c + 78c58c2 commit 4d8fd90
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions BAC0/core/functions/Discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class Discover:
Define BACnet WhoIs and IAm functions.
"""

def whois(self, *args, global_broadcast=False, destination=None):
def whois(self, *args, global_broadcast=False, destination=None, sleep_ms=100):
"""
Build a WhoIs request
Expand All @@ -175,6 +175,7 @@ def whois(self, *args, global_broadcast=False, destination=None):
whois(global_broadcast=True) # WhoIs broadcast globally. Every device will respond with an IAm
whois('2:5') # WhoIs looking for the device at (Network 2, Address 5)
whois('10 1000') # WhoIs looking for devices in the ID range (10 - 1000)
whois(sleep_ms=3000) # WhoIs waiting for 3 seconds for responses
"""
if not self._started:
Expand Down Expand Up @@ -221,8 +222,7 @@ def whois(self, *args, global_broadcast=False, destination=None):
if iocb.ioError: # unsuccessful: error/reject/abort
pass

for each in range(100):
time.sleep(1 / 1000)
time.sleep(sleep_ms / 1000)
self.discoveredDevices = self.this_application.i_am_counter
return self.this_application._last_i_am_received

Expand Down
2 changes: 1 addition & 1 deletion BAC0/db/influxdb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
try:
from influxdb_client import InfluxDBClient, Point, WriteOptions
from influxdb_client.client.write import WriteApi
from influxdb_client.client.write_api import WriteApi
except ImportError:
raise ImportError("Install influxdb to use this feature")

Expand Down
3 changes: 3 additions & 0 deletions BAC0/scripts/Lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def discover(
limits: t.Tuple[int, int] = (0, 4194303),
global_broadcast: bool = False,
reset: bool = False,
whois_sleep_ms: int = 100,
):
"""
Discover is meant to be the function used to explore the network when we
Expand Down Expand Up @@ -288,6 +289,7 @@ def discover(
deviceInstanceRangeHighLimit,
),
global_broadcast=global_broadcast,
sleep_ms=whois_sleep_ms,
)
for each in _res:
found.append(each)
Expand All @@ -303,6 +305,7 @@ def discover(
deviceInstanceRangeLowLimit, deviceInstanceRangeHighLimit
),
global_broadcast=global_broadcast,
sleep_ms=whois_sleep_ms,
)
for each in _res:
found.append(each)
Expand Down

0 comments on commit 4d8fd90

Please sign in to comment.