Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing SHF result field #64

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/labone/core/shf_vector_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ShfResultLoggerVectorExtraHeader:
holdoff_errors_reslog: Number of hold-off errors in the result logger
holdoff_errors_readout: Number of hold-off errors in the readout
holdoff_errors_spectr: Number of hold-off errors in the spectrum
first_sample_timestamp: Timestamp of the first sample
"""

timestamp: int
Expand All @@ -90,6 +91,7 @@ class ShfResultLoggerVectorExtraHeader:
holdoff_errors_reslog: int
holdoff_errors_readout: int
holdoff_errors_spectr: int
first_sample_timestamp: int

@staticmethod
def from_binary(
Expand Down Expand Up @@ -126,6 +128,7 @@ def from_binary(
holdoff_errors_reslog=struct.unpack("H", binary[52:54])[0],
holdoff_errors_readout=struct.unpack("H", binary[54:56])[0],
holdoff_errors_spectr=struct.unpack("H", binary[56:58])[0],
first_sample_timestamp=struct.unpack("q", binary[58:66])[0],
)
raise SHFHeaderVersionNotSupportedError(version=version.as_tuple())

Expand All @@ -138,7 +141,7 @@ def to_binary(self) -> tuple[bytes, _HeaderVersion]:
this encoding.
"""
return struct.pack(
"qIIddIIIIIHHHH",
"=qIIddIIIIIHHHqH",
self.timestamp,
self.job_id,
self.repetition_id,
Expand All @@ -152,6 +155,7 @@ def to_binary(self) -> tuple[bytes, _HeaderVersion]:
self.holdoff_errors_reslog,
self.holdoff_errors_readout,
self.holdoff_errors_spectr,
self.first_sample_timestamp,
0, # padding to make the number of bytes divisible by 4
# this is necessary because the length of the header is encoded
# in multiples of 4 bytes (32 bit words)
Expand Down
6 changes: 4 additions & 2 deletions tests/core/test_shf_vector_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_shf_demodulator_vector( # noqa: PLR0913
@pytest.mark.parametrize("header_version", [1])
@pytest.mark.parametrize("x", range(0, 30, 7))
def test_shf_result_logger_vector(vector_length, header_version, x):
header_length = 64
header_length = 72
input_vector = VectorData(
valueType=VectorValueType.SHF_RESULT_LOGGER_VECTOR_DATA.value,
vectorElementType=2,
Expand Down Expand Up @@ -317,6 +317,7 @@ def test_shf_waveform_logger_vector(vector_length, x, y):
holdoff_errors_reslog=10,
holdoff_errors_readout=11,
holdoff_errors_spectr=12,
first_sample_timestamp=13,
),
ShfDemodulatorVectorExtraHeader(
timestamp=0,
Expand Down Expand Up @@ -385,6 +386,7 @@ def __getattr__(self, item):
holdoff_errors_reslog=10,
holdoff_errors_readout=11,
holdoff_errors_spectr=12,
first_sample_timestamp=13,
),
np.array([50 + 100j, 100 + 150j], dtype=np.complex64),
),
Expand Down Expand Up @@ -490,7 +492,7 @@ def test_encoding_decoding_are_invers_shf_demod_sample(header, data):
),
),
(
ShfResultLoggerVectorExtraHeader(0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0),
ShfResultLoggerVectorExtraHeader(0, 0, 0, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
SHFDemodSample(
np.array([6, 3], dtype=np.int64),
np.array([7, 2], dtype=np.int64),
Expand Down
1 change: 1 addition & 0 deletions tests/mock/module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ async def test_shf_result_logger_vector_handled_correctly_in_set_and_subscribe()
10,
11,
12,
13,
)

session = await AutomaticLabOneServer({"/a/b": {}}).start_pipe()
Expand Down
Loading