From b7e848d7490eba9036141075509cf2da7090bc87 Mon Sep 17 00:00:00 2001 From: Chadwick Boulay Date: Fri, 22 Nov 2024 01:42:07 -0500 Subject: [PATCH 1/2] _monitor_state records arrival time --- src/pycbsdk/cbhw/device/nsp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index 2b414e2..bd8e4fc 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -472,6 +472,7 @@ def _handle_nplay(self, pkt): self._config["nplay"] = pkt def _handle_procmon(self, pkt): + arrival_time = time.time() update_interval = max(pkt.header.time - self._monitor_state["time"], 1) pkt_delta = self.pkts_received - self._monitor_state["pkts_received"] @@ -492,6 +493,7 @@ def _handle_procmon(self, pkt): "counter": pkt.counter if has_counter else -1, "time": pkt.header.time, "pkts_received": self.pkts_received, + "sys_time": arrival_time, } def _handle_log(self, pkt): From 497a10609f42de62688b631460c7a6980590b905 Mon Sep 17 00:00:00 2001 From: Chadwick Boulay Date: Fri, 22 Nov 2024 01:42:35 -0500 Subject: [PATCH 2/2] Add method to obtain monitor_state --- src/pycbsdk/cbhw/device/nsp.py | 3 +++ src/pycbsdk/cbsdk.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index bd8e4fc..766278f 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -1131,6 +1131,9 @@ def get_transport(self, force_refresh=False) -> int: self.set_transport("CHECK", True, timeout=0.5) return self._config["transport"] + def get_monitor_state(self) -> dict: + return self._monitor_state.copy() + def reset(self) -> int: print("TODO: reset NSP proctime to 0") return 0 diff --git a/src/pycbsdk/cbsdk.py b/src/pycbsdk/cbsdk.py index b5128f6..b1c3ec4 100644 --- a/src/pycbsdk/cbsdk.py +++ b/src/pycbsdk/cbsdk.py @@ -170,6 +170,10 @@ def get_runlevel(device: NSPDevice) -> CBRunLevel: return device.get_runlevel() +def get_monitor_state(device: NSPDevice) -> dict: + return device.get_monitor_state() + + def register_event_callback( device: NSPDevice, channel_type: CBChannelType, func: Callable[[Structure], None] ):