Skip to content

Commit d1a2abc

Browse files
authored
Merge pull request #417 from Mentalab-hub/APIS-1558-packet-parser-crashes-for-old-calibration-packet-in-explore-py-develop-branch
handle calibration parser with fallback
2 parents f8b4c81 + 6138726 commit d1a2abc

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/explorepy/packet.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ def __str__(self):
709709
class CalibrationInfoBase(Packet):
710710
"""Base class for calibration packets"""
711711

712-
channels = 1
712+
channels = 4
713713
offset_multiplier = 0.001
714714

715715
def __init__(self, timestamp, payload, time_offset=0):
@@ -720,8 +720,13 @@ def __init__(self, timestamp, payload, time_offset=0):
720720

721721
def _convert(self, bin_data):
722722
dtype_u16 = np.dtype("<u2")
723-
723+
calib_pair_count = len(bin_data) // 4
724724
for i in range(self.channels):
725+
if calib_pair_count <= i:
726+
# Copy first value
727+
self.slope.append(self.slope[0])
728+
self.offset.append(self.offset[0])
729+
continue
725730
base = i * 4
726731

727732
slope = np.frombuffer(
@@ -756,7 +761,6 @@ class CalibrationInfo_USBC(CalibrationInfoBase):
756761

757762

758763
class CalibrationInfoPro(CalibrationInfoBase):
759-
channels = 4
760764
offset_multiplier = 0.01
761765

762766

0 commit comments

Comments
 (0)