Skip to content

Commit c7aecfe

Browse files
FIX: ensure that data is processed in blocks of 6 uint32s
1 parent c44cd99 commit c7aecfe

1 file changed

Lines changed: 31 additions & 25 deletions

File tree

aidatlu/constellation/aidatlu_satellite.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python3
2+
from collections import deque
23
import os
34
import threading
45
import time
@@ -95,33 +96,16 @@ def _pull_fifo_event(self):
9596
def do_run(self, run_identifier: str) -> str:
9697
t = threading.Thread(target=self.aidatlu.handle_status)
9798
t.start()
99+
100+
# We ideally pull 6 uint32s, but we might pull more or less
101+
# Thus, add data to a queue and pop in blocks of 6 uint32s
102+
data_queue = deque()
98103
while not self._state_thread_evt.is_set():
99104
evt = self.aidatlu.pull_fifo_event()
100-
if np.size(evt) == 6:
101-
timestamp = (np.uint64(evt[0]) & 0x0000FFFF << 32) + evt[1]
102-
# Collect metadata
103-
meta = {
104-
"dtype": f"{evt.dtype}",
105-
"flag_trigger": True,
106-
"trigger": int(evt[3]),
107-
"timestamp_begin": int(timestamp * 1000),
108-
"timestamp_end": int((timestamp + 25) * 1000),
109-
}
110-
# Assemble payload in legacy format - first scalers then input bitmask
111-
payload = [
112-
(evt[2] >> 24) & 0xFF,
113-
(evt[2] >> 16) & 0xFF,
114-
(evt[2] >> 8) & 0xFF,
115-
evt[2] & 0xFF,
116-
(evt[4] >> 24) & 0xFF,
117-
(evt[4] >> 16) & 0xFF,
118-
(evt[0] >> 16) & 0x3F,
119-
]
120-
self.data_queue.put((payload, meta))
121-
elif np.size(evt) > 1:
122-
self.log.warning(
123-
f"Wrong event data length, got {np.size(evt)}, expected 6"
124-
)
105+
if np.size(evt) > 1:
106+
data_queue.extend(evt)
107+
while len(data_queue) >= 6:
108+
self._handle_event([data_queue.popleft() for _ in range(6)])
125109

126110
t.do_run = False
127111
self.aidatlu.stop_run()
@@ -153,6 +137,28 @@ def _init_tlu(self, config: Configuration) -> None:
153137
self.aidatlu.dut_logic.log = self.log
154138
self.aidatlu.config_parser.log = self.log
155139

140+
def _handle_event(self, evt) -> None:
141+
timestamp = (np.uint64(evt[0]) & 0x0000FFFF << 32) + evt[1]
142+
# Collect metadata
143+
meta = {
144+
"dtype": f"{evt.dtype}",
145+
"flag_trigger": True,
146+
"trigger": int(evt[3]),
147+
"timestamp_begin": int(timestamp * 1000),
148+
"timestamp_end": int((timestamp + 25) * 1000),
149+
}
150+
# Assemble payload in legacy format - first scalers then input bitmask
151+
payload = [
152+
(evt[2] >> 24) & 0xFF,
153+
(evt[2] >> 16) & 0xFF,
154+
(evt[2] >> 8) & 0xFF,
155+
evt[2] & 0xFF,
156+
(evt[4] >> 24) & 0xFF,
157+
(evt[4] >> 16) & 0xFF,
158+
(evt[0] >> 16) & 0x3F,
159+
]
160+
self.data_queue.put((payload, meta))
161+
156162
@schedule_metric("Hz", MetricsType.LAST_VALUE, 1)
157163
def pre_veto_rate_rate(self) -> Any:
158164
if self.fsm.current_state_value == SatelliteState.RUN and hasattr(

0 commit comments

Comments
 (0)