diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d3271e..372d9ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## AISCoT 7.3.2 + +- Add `SENSOR_BEACON=0` to disable the periodic receiver marker without + disabling vessel tracks. + ## AISCoT 7.3.1 * Close the local AIS UDP listener before PyTAK rebuilds workers after a TAK diff --git a/docs/configuration.md b/docs/configuration.md index fd675e7..61bec2b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -32,6 +32,11 @@ AISCOT has the following built-in configuration parameters: CoT Stale period ("timeout"), in seconds. +* **`SENSOR_BEACON`**: + * Default: ``1`` + + Set to ``0`` to disable the periodic receiver marker. Vessel tracks remain enabled. + * **`COT_TYPE`**: * Default: ``a-u-S-X-M`` diff --git a/example-config.ini b/example-config.ini index 594b0c0..a326ef9 100644 --- a/example-config.ini +++ b/example-config.ini @@ -18,6 +18,9 @@ COT_URL = udp://172.17.2.151:4242 ; Optional. Override default CoT Stale period (in seconds). ; COT_STALE = 60 +; Optional. Disable the periodic receiver marker without disabling vessel tracks. +; SENSOR_BEACON = 0 + ; Optional. Prepend conventional ship-type callsign prefixes (T/B, P/V, M/V, ...). ; VESSEL_NAME_PREFIX = True @@ -29,4 +32,4 @@ COT_URL = udp://172.17.2.151:4242 ; SHIPCLASS_ICONS = False ; Optional. Only forward vessels that are underway; drop parked (anchored/moored) hulls. -; UNDERWAY_ONLY = False \ No newline at end of file +; UNDERWAY_ONLY = False diff --git a/src/aiscot/VERSION b/src/aiscot/VERSION index 643916c..eab246c 100644 --- a/src/aiscot/VERSION +++ b/src/aiscot/VERSION @@ -1 +1 @@ -7.3.1 +7.3.2 diff --git a/src/aiscot/functions.py b/src/aiscot/functions.py index ad06c15..46a4ae8 100644 --- a/src/aiscot/functions.py +++ b/src/aiscot/functions.py @@ -48,6 +48,12 @@ def cfg_bool(value, default: bool = False) -> bool: return str(value).strip().lower() in pytak.BOOLEAN_TRUTH +def sensor_beacon_enabled(config: Union[dict, SectionProxy]) -> bool: + """Return whether the periodic receiver beacon is enabled.""" + value = config.get("SENSOR_BEACON", "1") + return str(value).strip().lower() not in {"0", "false", "no", "off"} + + def create_tasks( config: Union[dict, SectionProxy], clitool: pytak.CLITool ) -> Set[pytak.Worker,]: @@ -73,7 +79,8 @@ def create_tasks( Set of coroutine tasks. """ tasks = set([aiscot.AISWorker(clitool.tx_queue, config)]) - tasks.add(aiscot.SensorWorker(clitool.tx_queue, config)) + if sensor_beacon_enabled(config): + tasks.add(aiscot.SensorWorker(clitool.tx_queue, config)) return tasks diff --git a/tests/test_functions.py b/tests/test_functions.py index c422820..69b1830 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -20,12 +20,32 @@ import io import xml.etree.ElementTree as ET +from types import SimpleNamespace +from unittest.mock import patch import pytest import aiscot +@pytest.mark.parametrize("value", ["0", "false", "False", "no", "off"]) +def test_sensor_beacon_switch(value): + """Receiver beacons default on and accept common false values.""" + assert aiscot.functions.sensor_beacon_enabled({}) + assert not aiscot.functions.sensor_beacon_enabled({"SENSOR_BEACON": value}) + + +def test_create_tasks_can_omit_sensor_beacon(): + """Disabling the receiver beacon keeps vessel processing enabled.""" + clitool = SimpleNamespace(tx_queue=object()) + with patch.object(aiscot, "AISWorker", return_value="vessels"), patch.object( + aiscot, "SensorWorker", return_value="receiver" + ) as sensor_worker: + tasks = aiscot.functions.create_tasks({"SENSOR_BEACON": "0"}, clitool) + assert tasks == {"vessels"} + sensor_worker.assert_not_called() + + @pytest.fixture def sample_data_libais(): return {