Skip to content

Commit

Permalink
Combine struct.unpack() calls for performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
d-cogswell committed Sep 26, 2024
1 parent 45f998f commit f106747
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions NewareNDA/NewareNDAx.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,10 @@ def _bytes_to_list_ndc(bytes):
"""Helper function for interpreting an ndc byte string"""

# Extract fields from byte string
[Index, Cycle] = struct.unpack('<II', bytes[8:16])
[Step] = struct.unpack('<B', bytes[16:17])
[Status] = struct.unpack('<B', bytes[17:18])
[Time] = struct.unpack('<Q', bytes[23:31])
[Voltage, Current] = struct.unpack('<ii', bytes[31:39])
[Charge_capacity, Discharge_capacity] = struct.unpack('<qq', bytes[43:59])
[Charge_energy, Discharge_energy] = struct.unpack('<qq', bytes[59:75])
[Index, Cycle, Step, Status] = struct.unpack('<IIBB', bytes[8:18])
[Time, Voltage, Current] = struct.unpack('<Qii', bytes[23:39])
[Charge_capacity, Discharge_capacity,
Charge_energy, Discharge_energy] = struct.unpack('<qqqq', bytes[43:75])
[Y, M, D, h, m, s] = struct.unpack('<HBBBBB', bytes[75:82])
[Range] = struct.unpack('<i', bytes[82:86])

Expand Down

0 comments on commit f106747

Please sign in to comment.