summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark De Ruyter <markdr@google.com>2019-10-07 12:06:39 -0700
committerMark De Ruyter <markdr@google.com>2019-10-07 18:08:23 -0700
commitf2b7e06f1c47c1897c228750191249038d645dab (patch)
tree968e871a05d848ca69178a56546c4baa1374c9b9
parent673c70f6539682ee7d4815c87e57e1a447a87f31 (diff)
downloadplatform_tools_test_connectivity-f2b7e06f1c47c1897c228750191249038d645dab.tar.gz
platform_tools_test_connectivity-f2b7e06f1c47c1897c228750191249038d645dab.tar.bz2
platform_tools_test_connectivity-f2b7e06f1c47c1897c228750191249038d645dab.zip
Fixes the discrepency between new and old Monsoon libraries.
LVPM had a bug in the documentation that suggested the values were unsigned two-byte integers (they are actually signed). HVPM had a bug where we did not divide the result by 1000 to convert to mA. Bug: 142152817 Test: Manually ran white and black monsoon libraries and compared to existing results. Change-Id: I11acc67937b0d76c06a1843e15ff10679e43fcd8
-rw-r--r--acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/packet.py6
-rw-r--r--acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/transformers.py6
-rw-r--r--acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/packet.py14
-rw-r--r--acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/stock_transformers.py28
4 files changed, 14 insertions, 40 deletions
diff --git a/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/packet.py b/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/packet.py
index f62975d212..223337054d 100644
--- a/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/packet.py
+++ b/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/packet.py
@@ -53,8 +53,8 @@ class HvpmMeasurement(object):
1 │ 2 │ uint16 │ Main │ Fine │ Calibration/Measurement value
2 │ 4 │ uint16 │ USB │ Coarse │ Calibration/Measurement value
3 │ 6 │ uint16 │ USB │ Fine │ Calibration/Measurement value
- 4 │ 8 │ int16 │ Aux │ Coarse │ Calibration/Measurement value
- 5 │ 10 │ int16 │ Aux │ Fine │ Calibration/Measurement value
+ 4 │ 8 │ uint16 │ Aux │ Coarse │ Calibration/Measurement value
+ 5 │ 10 │ uint16 │ Aux │ Fine │ Calibration/Measurement value
6 │ 12 │ uint16 │ Main │ Voltage │ Main V measurement, or Aux V
│ │ │ │ │ if setVoltageChannel == 1
7 │ 14 │ uint16 │ USB │ Voltage │ USB Voltage
@@ -76,7 +76,7 @@ class HvpmMeasurement(object):
SIZE = 18
def __init__(self, raw_data, sample_time):
- self.values = struct.unpack('>4H2h2H2B', raw_data)
+ self.values = struct.unpack('>8H2B', raw_data)
self._sample_time = sample_time
def __getitem__(self, channel_and_reading_granularity):
diff --git a/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/transformers.py b/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/transformers.py
index e91a89b856..5ddc23c13d 100644
--- a/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/transformers.py
+++ b/acts/framework/acts/controllers/monsoon_lib/sampling/hvpm/transformers.py
@@ -438,10 +438,10 @@ class CalibrationApplier(ParallelTransformer):
zero_offset += cal_zero
if cal_ref - zero_offset != 0:
slope = scale / (cal_ref - zero_offset)
- if granularity == Granularity.FINE:
- slope /= 1000
else:
slope = 0
+ if granularity == Granularity.FINE:
+ slope /= 1000
index = HvpmMeasurement.get_index(channel, granularity)
calibrated_value[:, granularity] = slope * (
@@ -452,7 +452,7 @@ class CalibrationApplier(ParallelTransformer):
readings[:, channel] = np.where(
measurements[:, fine_data_position] < self.fine_threshold,
calibrated_value[:, Granularity.FINE],
- calibrated_value[:, Granularity.COARSE])
+ calibrated_value[:, Granularity.COARSE]) / 1000.0 # to mA
main_voltage_index = HvpmMeasurement.get_index(Channel.MAIN,
Reading.VOLTAGE)
diff --git a/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/packet.py b/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/packet.py
index 80c8274bd8..b0f88394af 100644
--- a/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/packet.py
+++ b/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/packet.py
@@ -54,9 +54,9 @@ class LvpmMeasurement(object):
Val │ Byte │ Type │ Monsoon │ Reading │
Pos │ Offset │ Format │ Channel │ Type │ Description
────┼────────┼────────┼─────────┼─────────┼──────────────────────────────
- 0 │ 0 │ uint16 │ Main │ Current │ Calibration value.
- 1 │ 2 │ uint16 │ USB │ Current │ Calibration value.
- 2 │ 4 │ uint16 │ Aux │ Current │ Calibration value.
+ 0 │ 0 │ int16 │ Main │ Current │ Calibration value.
+ 1 │ 2 │ int16 │ USB │ Current │ Calibration value.
+ 2 │ 4 │ int16 │ Aux │ Current │ Calibration value.
3 │ 6 │ uint16 │ Main │ Voltage │ Calibration value.
If the measurement is a power reading:
@@ -64,11 +64,11 @@ class LvpmMeasurement(object):
Val │ Byte │ Type │ Monsoon │ Reading │
Pos │ Offset │ Format │ Channel │ Type │ Description
────┼────────┼────────┼─────────┼─────────┼──────────────────────────────
- 0 │ 0 │ uint16 │ Main │ Current │ b0: if 1, Coarse, else Fine
+ 0 │ 0 │ int16 │ Main │ Current │ b0: if 1, Coarse, else Fine
│ │ │ │ │ b1-7: Measurement value.
- 1 │ 2 │ uint16 │ USB │ Current │ b0: if 1, Coarse, else Fine
+ 1 │ 2 │ int16 │ USB │ Current │ b0: if 1, Coarse, else Fine
│ │ │ │ │ b1-7: Measurement value.
- 2 │ 4 │ uint16 │ Aux │ Current │ b0: if 1, Coarse, else Fine
+ 2 │ 4 │ int16 │ Aux │ Current │ b0: if 1, Coarse, else Fine
│ │ │ │ │ b1-7: Measurement value.
3 │ 6 │ uint16 │ Main │ Voltage │ Measurement value.
@@ -86,7 +86,7 @@ class LvpmMeasurement(object):
sample_type: The type of sample that was recorded.
entry_index: The index of the measurement within the packet.
"""
- self.values = struct.unpack('>4H', raw_data)
+ self.values = struct.unpack('>3hH', raw_data)
self._sample_time = sample_time
self._sample_type = sample_type
diff --git a/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/stock_transformers.py b/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/stock_transformers.py
index eaf60b0e43..becc4ee99c 100644
--- a/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/stock_transformers.py
+++ b/acts/framework/acts/controllers/monsoon_lib/sampling/lvpm_stock/stock_transformers.py
@@ -340,32 +340,6 @@ class CalibrationApplier(ParallelTransformer):
return False
return True
- @staticmethod
- def _get_currents(sample, calibration_data):
- """Returns the list of current values for each channel.
-
- Args:
- sample: The Sample object to determine the current values of.
- calibration_data: The CalibrationCollection used to calibrate the
- sample.
-
- Returns:
-
- """
- currents = [0] * 3
- for channel in Channel.values:
- current = sample[channel]
- granularity = Granularity.FINE
- if current & 1:
- current &= ~1
- granularity = Granularity.COARSE
-
- zero = calibration_data.get(channel, Origin.ZERO, granularity)
- scale = calibration_data.get(channel, Origin.SCALE, granularity)
- currents[channel] = (current - zero) * scale
-
- return currents
-
def _transform_buffer(self, buffer):
calibration_data = buffer.calibration_data
@@ -393,7 +367,7 @@ class CalibrationApplier(ParallelTransformer):
# Monsoon.py algorithm.
readings[:, channel] = np.where(
measurements[:, channel] & 1,
- (measurements[:, channel] - 1 - coarse_zero) * coarse_scale,
+ ((measurements[:, channel] & ~1) - coarse_zero) * coarse_scale,
(measurements[:, channel] - fine_zero) * fine_scale)
for i in range(len(buffer.samples)):