Skip to content

Commit

Permalink
[squash] Improve naming, add docstring and type
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxrdv committed Dec 1, 2023
1 parent e38ebd7 commit ab0d89f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scaaml/capture/scope/lecroy/lecroy_waveform.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import dataclasses
import datetime
import struct
from typing import Union
from typing import Tuple, Union

import numpy as np

Expand Down Expand Up @@ -92,14 +92,20 @@ def get_double(self) -> float:
return struct.unpack_from(f"{self._order:s}d", self.raw_data,
self._ofs - 8)[0]

def get_unit(self, amount=1):
"""Parse a unit from self.raw_data.
def unpack_wave(self, amount: int) -> Tuple[int]:
"""Parse the whole waveform from self.raw_data. Increments the ofset
`self._ofs` by the number of parsed bytes.
Args:
amount (int): Number of units (depending on self._unit).
Returns: A tuple of `amount` values.
"""
fmt = f"{self._order}{amount}{self._unit}"
size = struct.calcsize(fmt)
val = struct.unpack_from(fmt, self.raw_data, self._ofs)
self._ofs += size
return val[0] if amount == 1 else val
return val

def get_timestamp(self) -> datetime.datetime:
"""Parse timestamp from self.raw_data.
Expand Down Expand Up @@ -277,13 +283,13 @@ def parse(self):
block_len = self._wave_description.wave1_len
if block_len > 0:
self.d["wave1"] = np.array(
self.get_unit(self._wave_description.wave_array_count))
self.unpack_wave(self._wave_description.wave_array_count))

# Receive wave2
block_len = self._wave_description.wave2_len
if block_len > 0:
self.d["wave2"] = np.array(
self.get_unit(self._wave_description.wave_array_count))
self.unpack_wave(self._wave_description.wave_array_count))
assert self._ofs == len(self.raw_data)


Expand Down

0 comments on commit ab0d89f

Please sign in to comment.