From 3c116bc822093902d732ee53e527de94631ae5a7 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 2 Apr 2024 15:34:36 +0000
Subject: [PATCH] Polling periods are in milliseconds. Made this more explicit.

---
 README.md                                              |  1 +
 tangostationcontrol/VERSION                            |  2 +-
 .../default/devices/test_device_temperature_manager.py |  6 ++++--
 .../default/devices/test_lofar_device.py               |  4 ++--
 .../tangostationcontrol/common/constants.py            |  8 ++++----
 .../tangostationcontrol/devices/apsct.py               |  4 ++--
 .../tangostationcontrol/devices/apspu.py               |  4 ++--
 .../devices/base_device_classes/lofar_device.py        | 10 +++++-----
 .../devices/base_device_classes/recv_device.py         |  4 ++--
 tangostationcontrol/tangostationcontrol/devices/ccd.py |  4 ++--
 .../tangostationcontrol/devices/observation_field.py   |  6 +++---
 .../tangostationcontrol/devices/sdp/firmware.py        |  6 +++---
 .../tangostationcontrol/devices/sdp/sdp.py             |  6 +++---
 .../tangostationcontrol/devices/temperature_manager.py |  4 ++--
 .../tangostationcontrol/devices/unb2.py                |  4 ++--
 15 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/README.md b/README.md
index cca501671..af8b42b1d 100644
--- a/README.md
+++ b/README.md
@@ -166,6 +166,7 @@ Next change the version in the following places:
 
 # Release Notes
 
+* 0.32.4 Fixed polling period (from 2500s to 2.5s).
 * 0.32.3 Fixed disappeared metrics from LOFARDevice, OPCUADevice, StationManager.
 * 0.32.2 Change hardware_powered_R to hardware_powered_fraction_R to report partial power.
          Implemented hardware_powered_fraction_R for more devices.
diff --git a/tangostationcontrol/VERSION b/tangostationcontrol/VERSION
index d721c7684..eb7713622 100644
--- a/tangostationcontrol/VERSION
+++ b/tangostationcontrol/VERSION
@@ -1 +1 @@
-0.32.3
+0.32.4
diff --git a/tangostationcontrol/integration_test/default/devices/test_device_temperature_manager.py b/tangostationcontrol/integration_test/default/devices/test_device_temperature_manager.py
index 0d695a028..5dfd4fe87 100644
--- a/tangostationcontrol/integration_test/default/devices/test_device_temperature_manager.py
+++ b/tangostationcontrol/integration_test/default/devices/test_device_temperature_manager.py
@@ -8,7 +8,7 @@ from integration_test.default.devices.base import AbstractTestBases
 
 from tango import DeviceProxy, Database, DevState, DevFailed
 from tangostationcontrol.common.constants import (
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_POLLING_PERIOD_MS,
     N_elements,
     N_pol,
     N_rcu,
@@ -59,7 +59,9 @@ class TestDeviceTemperatureManager(AbstractTestBases.TestDeviceBase):
         for recvh_name in self.recvh_names:
             recv_proxy = self.setup_proxy(recvh_name)
             proxies.append(recv_proxy)
-            recv_proxy.poll_attribute(self.hbat_led_attribute, DEFAULT_POLLING_PERIOD)
+            recv_proxy.poll_attribute(
+                self.hbat_led_attribute, DEFAULT_POLLING_PERIOD_MS
+            )
             self.assertTrue(recv_proxy.is_attribute_polled(self.hbat_led_attribute))
 
         return proxies
diff --git a/tangostationcontrol/integration_test/default/devices/test_lofar_device.py b/tangostationcontrol/integration_test/default/devices/test_lofar_device.py
index 83ac64aca..2852aa730 100644
--- a/tangostationcontrol/integration_test/default/devices/test_lofar_device.py
+++ b/tangostationcontrol/integration_test/default/devices/test_lofar_device.py
@@ -5,7 +5,7 @@ import time
 
 from tango import DevState
 
-from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD
+from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD_MS
 
 from integration_test import base
 from integration_test.device_proxy import TestDeviceProxy
@@ -28,7 +28,7 @@ class TestProxyAttributeAccess(base.IntegrationTestCase):
         # make sure the attribute is polled, so we force proxies to access the poll first
         if self.proxy.is_attribute_polled(self.ATTRIBUTE_NAME):
             self.proxy.stop_poll_attribute(self.ATTRIBUTE_NAME)
-        self.proxy.poll_attribute(self.ATTRIBUTE_NAME, DEFAULT_POLLING_PERIOD)
+        self.proxy.poll_attribute(self.ATTRIBUTE_NAME, DEFAULT_POLLING_PERIOD_MS)
 
     def dont_poll_attribute(self):
         # make sure the attribute is NOT polled, so we force proxies to access the device
diff --git a/tangostationcontrol/tangostationcontrol/common/constants.py b/tangostationcontrol/tangostationcontrol/common/constants.py
index 45684b655..766c66da9 100644
--- a/tangostationcontrol/tangostationcontrol/common/constants.py
+++ b/tangostationcontrol/tangostationcontrol/common/constants.py
@@ -103,11 +103,11 @@ MAX_POINTINGS = N_beamlets_max
 # max size for a statistic packet
 MAX_ETH_FRAME_SIZE = 9000
 
-# The default polling period for polled attributes
-DEFAULT_POLLING_PERIOD = 1000
+# The default polling period for polled attributes (in milliseconds)
+DEFAULT_POLLING_PERIOD_MS = 1000
 
-# The default polling period for attributes polled to update metrics in Prometheus
-DEFAULT_METRICS_POLLING_PERIOD = 2500
+# The default polling period for attributes polled to update metrics in Prometheus (in milliseconds)
+DEFAULT_METRICS_POLLING_PERIOD_MS = 2500
 
 # default numer tiles in a HBA for the non-international stations.
 DEFAULT_N_HBA_TILES = 48
diff --git a/tangostationcontrol/tangostationcontrol/devices/apsct.py b/tangostationcontrol/tangostationcontrol/devices/apsct.py
index 7c7c1890e..f1aebc77b 100644
--- a/tangostationcontrol/tangostationcontrol/devices/apsct.py
+++ b/tangostationcontrol/tangostationcontrol/devices/apsct.py
@@ -14,7 +14,7 @@ from tango import AttrWriteType
 # PyTango imports
 from tango import DebugIt
 from tango.server import command, attribute, device_property
-from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD
+from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD_MS
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
 from tangostationcontrol.common.states import DEFAULT_COMMAND_STATES
 from tangostationcontrol.devices.base_device_classes.opcua_device import OPCUADevice
@@ -175,7 +175,7 @@ class APSCT(OPCUADevice):
     APSCT_TEMP_error_R = attribute(
         dtype=bool,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
     APSCT_VOUT_error_R = attribute(dtype=bool, fisallowed="is_attribute_access_allowed")
 
diff --git a/tangostationcontrol/tangostationcontrol/devices/apspu.py b/tangostationcontrol/tangostationcontrol/devices/apspu.py
index b40cf0bef..8555a3148 100644
--- a/tangostationcontrol/tangostationcontrol/devices/apspu.py
+++ b/tangostationcontrol/tangostationcontrol/devices/apspu.py
@@ -12,7 +12,7 @@ from attribute_wrapper.attribute_wrapper import AttributeWrapper
 from tango import AttrWriteType
 from tango.server import attribute, device_property
 
-from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD
+from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD_MS
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
 from tangostationcontrol.devices.base_device_classes.opcua_device import OPCUADevice
 from tangostationcontrol.metrics import device_metrics
@@ -121,7 +121,7 @@ class APSPU(OPCUADevice):
     APSPU_TEMP_error_R = attribute(
         dtype=bool,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
     APSPU_VOUT_error_R = attribute(dtype=bool, fisallowed="is_attribute_access_allowed")
 
diff --git a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py
index 739ac0dca..5f315d2fa 100644
--- a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py
+++ b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/lofar_device.py
@@ -41,8 +41,8 @@ from tangostationcontrol.common.device_decorators import (
     DurationMetric,
 )
 from tangostationcontrol.common.constants import (
-    DEFAULT_METRICS_POLLING_PERIOD,
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_METRICS_POLLING_PERIOD_MS,
+    DEFAULT_POLLING_PERIOD_MS,
 )
 from tangostationcontrol.common.events import EventSubscriptions
 from tangostationcontrol.common.lofar_logging import (
@@ -240,7 +240,7 @@ class LOFARDevice(Device):
         and self.event_loop_thread.is_running(),
         # Tango needs to poll this, as otherwise this attribute will never
         # be exposed as "False" as the event thread must run to do so.
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
 
     poll_thread_running_R = attribute(
@@ -254,7 +254,7 @@ class LOFARDevice(Device):
         ),
         # Tango needs to poll this, as otherwise this attribute will never
         # be exposed as "False" as the event thread must run to do so.
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
 
     # list of translator property names to be set by set_translator_defaults
@@ -504,7 +504,7 @@ class LOFARDevice(Device):
         self.poll_task = PeriodicTask(
             self.event_loop_thread.event_loop,
             self.attribute_poller.poll,
-            DEFAULT_METRICS_POLLING_PERIOD,
+            DEFAULT_METRICS_POLLING_PERIOD_MS / 1000.0,
         )
 
         # WARNING: any values read so far are stale.
diff --git a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py
index fff0279eb..88a6b3fae 100644
--- a/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py
+++ b/tangostationcontrol/tangostationcontrol/devices/base_device_classes/recv_device.py
@@ -19,7 +19,7 @@ from tango.server import command, device_property, attribute
 from tangostationcontrol.common.constants import (
     N_rcu,
     N_rcu_inp,
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_POLLING_PERIOD_MS,
 )
 from tangostationcontrol.common.frequency_bands import bands
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
@@ -332,7 +332,7 @@ class RECVDevice(OPCUADevice):
         dtype=(bool,),
         max_dim_x=N_rcu,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
     RECV_VOUT_error_R = attribute(
         dtype=(bool,), max_dim_x=N_rcu, fisallowed="is_attribute_access_allowed"
diff --git a/tangostationcontrol/tangostationcontrol/devices/ccd.py b/tangostationcontrol/tangostationcontrol/devices/ccd.py
index 9aecfc11f..4b53c3e53 100644
--- a/tangostationcontrol/tangostationcontrol/devices/ccd.py
+++ b/tangostationcontrol/tangostationcontrol/devices/ccd.py
@@ -14,7 +14,7 @@ from tango import AttrWriteType
 # PyTango imports
 from tango import DebugIt
 from tango.server import command, attribute, device_property
-from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD
+from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD_MS
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
 from tangostationcontrol.common.states import DEFAULT_COMMAND_STATES
 from tangostationcontrol.devices.base_device_classes.opcua_device import OPCUADevice
@@ -164,7 +164,7 @@ class CCD(OPCUADevice):
     CCD_TEMP_error_R = attribute(
         dtype=bool,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
     CCD_VOUT_error_R = attribute(dtype=bool, fisallowed="is_attribute_access_allowed")
 
diff --git a/tangostationcontrol/tangostationcontrol/devices/observation_field.py b/tangostationcontrol/tangostationcontrol/devices/observation_field.py
index 6c8253d5a..36949e49d 100644
--- a/tangostationcontrol/tangostationcontrol/devices/observation_field.py
+++ b/tangostationcontrol/tangostationcontrol/devices/observation_field.py
@@ -15,7 +15,7 @@ from jsonschema.exceptions import ValidationError
 from tango import AttrWriteType, DeviceProxy, DevState, Util
 from tango.server import attribute
 from tangostationcontrol.common.constants import (
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_POLLING_PERIOD_MS,
     MAX_ANTENNA,
     MAX_PARALLEL_SUBBANDS,
     N_beamlets_ctrl,
@@ -66,8 +66,8 @@ class ObservationField(LOFARDevice):
     @attribute(
         doc="Return a value that changes over time, to check if the device is alive.",
         dtype=numpy.float64,
-        polling_period=DEFAULT_POLLING_PERIOD,
-        period=str(DEFAULT_POLLING_PERIOD),
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
+        period=str(DEFAULT_POLLING_PERIOD_MS),
         rel_change="1.0",
     )
     def alive_R(self):
diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/firmware.py b/tangostationcontrol/tangostationcontrol/devices/sdp/firmware.py
index fb136f35d..0bbdb1f24 100644
--- a/tangostationcontrol/tangostationcontrol/devices/sdp/firmware.py
+++ b/tangostationcontrol/tangostationcontrol/devices/sdp/firmware.py
@@ -22,7 +22,7 @@ from tangostationcontrol.common.constants import (
     CLK_200_MHZ,
     CLK_160_MHZ,
     N_subbands,
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_POLLING_PERIOD_MS,
 )
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
 from tangostationcontrol.devices.base_device_classes.opcua_device import OPCUADevice
@@ -132,7 +132,7 @@ class SDPFirmware(OPCUADevice):
         datatype=numpy.int32,
         dims=(N_pn,),
         doc="Active FPGA image (0=factory, 1=user)",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
         abs_change="1",
     )
     FPGA_boot_image_RW = AttributeWrapper(
@@ -273,7 +273,7 @@ class SDPFirmware(OPCUADevice):
         dtype=numpy.uint32,
         access=AttrWriteType.READ_WRITE,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
         abs_change="1",
     )
 
diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py b/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py
index 76f0c0df9..ee6fc00b4 100644
--- a/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py
+++ b/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py
@@ -21,7 +21,7 @@ from tangostationcontrol.common.constants import (
     N_subband_res,
     N_subbands,
     DEFAULT_SUBBAND,
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_POLLING_PERIOD_MS,
     SDP_UNIT_WEIGHT,
 )
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
@@ -450,7 +450,7 @@ class SDP(OPCUADevice):
         max_dim_x=S_pn,
         access=AttrWriteType.READ_WRITE,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
         abs_change="1",
     )
     subband_frequency_R = attribute(
@@ -460,7 +460,7 @@ class SDP(OPCUADevice):
         max_dim_y=N_pn * S_pn,
         max_dim_x=N_subbands,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
         abs_change="1.0",
     )
 
diff --git a/tangostationcontrol/tangostationcontrol/devices/temperature_manager.py b/tangostationcontrol/tangostationcontrol/devices/temperature_manager.py
index cb4c8db03..c0d815260 100644
--- a/tangostationcontrol/tangostationcontrol/devices/temperature_manager.py
+++ b/tangostationcontrol/tangostationcontrol/devices/temperature_manager.py
@@ -20,7 +20,7 @@ from tango.server import command
 
 # Additional import
 from tangostationcontrol.common.case_insensitive_dict import CaseInsensitiveDict
-from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD
+from tangostationcontrol.common.constants import DEFAULT_POLLING_PERIOD_MS
 from tangostationcontrol.common.lofar_logging import (
     device_logging_to_python,
     log_exceptions,
@@ -139,7 +139,7 @@ class TemperatureManager(LOFARDevice):
 
     is_alarming_R = attribute(
         dtype=bool,
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
         fisallowed="is_attribute_access_allowed",
     )
 
diff --git a/tangostationcontrol/tangostationcontrol/devices/unb2.py b/tangostationcontrol/tangostationcontrol/devices/unb2.py
index 85d7e4de3..2da85760f 100644
--- a/tangostationcontrol/tangostationcontrol/devices/unb2.py
+++ b/tangostationcontrol/tangostationcontrol/devices/unb2.py
@@ -16,7 +16,7 @@ from tangostationcontrol.common.constants import (
     N_fpga,
     N_ddr,
     N_qsfp,
-    DEFAULT_POLLING_PERIOD,
+    DEFAULT_POLLING_PERIOD_MS,
 )
 from tangostationcontrol.common.lofar_logging import device_logging_to_python
 from tangostationcontrol.common.states import DEFAULT_COMMAND_STATES
@@ -368,7 +368,7 @@ class UNB2(OPCUADevice):
         dtype=(bool,),
         max_dim_x=N_unb,
         fisallowed="is_attribute_access_allowed",
-        polling_period=DEFAULT_POLLING_PERIOD,
+        polling_period=DEFAULT_POLLING_PERIOD_MS,
     )
     UNB2_VOUT_error_R = attribute(
         dtype=(bool,), max_dim_x=N_unb, fisallowed="is_attribute_access_allowed"
-- 
GitLab