How to use the mobly.controllers.monsoon.MonsoonError function in mobly

To help you get started, we’ve selected a few mobly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / mobly / mobly / controllers / monsoon.py View on Github external
if any(conditions):
            raise MonsoonError(err_msg)
        hz_str = lines[4].split()[2]
        hz = int(hz_str[:-2])
        voltage_str = lines[2].split()[1]
        voltage = int(voltage_str[:-1])
        lines = lines[6:]
        t = []
        v = []
        for l in lines:
            try:
                timestamp, value = l.split(' ')
                t.append(int(timestamp))
                v.append(float(value))
            except ValueError:
                raise MonsoonError(err_msg)
        return MonsoonData(v, t, hz, voltage)
github google / mobly / mobly / controllers / monsoon.py View on Github external
def SetMaxPowerUpCurrent(self, i):
        """Set the max power up current.
        """
        if i < 0 or i > 8:
            raise MonsoonError(("Target max current %sA, is out of acceptable "
                                "range [0, 8].") % i)
        val = 1023 - int((i / 8) * 1023)
        self._SendStruct("BBB", 0x01, 0x08, val & 0xff)
        self._SendStruct("BBB", 0x01, 0x09, val >> 8)
github google / mobly / mobly / controllers / monsoon.py View on Github external
def SetMaxCurrent(self, i):
        """Set the max output current.
        """
        if i < 0 or i > 8:
            raise MonsoonError(("Target max current %sA, is out of acceptable "
                                "range [0, 8].") % i)
        val = 1023 - int((i / 8) * 1023)
        self._SendStruct("BBB", 0x01, 0x0a, val & 0xff)
        self._SendStruct("BBB", 0x01, 0x0b, val >> 8)
github google / mobly / mobly / controllers / monsoon.py View on Github external
def create(configs):
    if not configs:
        raise MonsoonError('Configuration is empty, abort!')
    elif not isinstance(configs, list):
        raise MonsoonError('Configuration should be a list, abort!')
    elif isinstance(configs[0], dict):
        # Configs is a list of dicts.
        objs = get_instances_with_configs(configs)
    elif isinstance(configs[0], int):
        # Configs is a list of ints representing serials.
        objs = get_instances(configs)
    else:
        raise Exception('No valid config found in: %s' % configs)
    return objs
github google / mobly / mobly / controllers / monsoon.py View on Github external
def _validate_data(self):
        """Verifies that the data points contained in the class are valid.
        """
        msg = "Error! Expected {} timestamps, found {}.".format(
            len(self._data_points), len(self._timestamps))
        if len(self._data_points) != len(self._timestamps):
            raise MonsoonError(msg)
github google / mobly / mobly / controllers / monsoon.py View on Github external
self._SendStruct("BBB", 0x01, 0x00, 0x00)
        while 1:  # Keep reading, discarding non-status packets
            read_bytes = self._ReadPacket()
            if not read_bytes:
                return None
            calsize = struct.calcsize(STATUS_FORMAT)
            if len(read_bytes) != calsize or read_bytes[0] != 0x10:
                logging.warning("Wanted status, dropped type=0x%02x, len=%d",
                                read_bytes[0], len(read_bytes))
                continue
            status = dict(
                zip(STATUS_FIELDS, struct.unpack(STATUS_FORMAT, read_bytes)))
            p_type = status["packetType"]
            if p_type != 0x10:
                raise MonsoonError("Package type %s is not 0x10." % p_type)
            for k in status.keys():
                if k.endswith("VoltageSetting"):
                    status[k] = 2.0 + status[k] * 0.01
                elif k.endswith("FineCurrent"):
                    pass  # needs calibration data
                elif k.endswith("CoarseCurrent"):
                    pass  # needs calibration data
                elif k.startswith("voltage") or k.endswith("Voltage"):
                    status[k] = status[k] * 0.000125
                elif k.endswith("Resistor"):
                    status[k] = 0.05 + status[k] * 0.0001
                    if k.startswith("aux") or k.startswith("defAux"):
                        status[k] += 0.05
                elif k.endswith("CurrentLimit"):
                    status[k] = 8 * (1023 - status[k]) / 1023.0
            return status
github google / mobly / mobly / controllers / monsoon.py View on Github external
def _check_dut(self):
        """Verifies there is a DUT attached to the monsoon.

        This should be called in the functions that operate the DUT.
        """
        if not self.dut:
            raise MonsoonError("Need to attach the device before using it.")
github google / mobly / mobly / controllers / monsoon.py View on Github external
def create(configs):
    if not configs:
        raise MonsoonError('Configuration is empty, abort!')
    elif not isinstance(configs, list):
        raise MonsoonError('Configuration should be a list, abort!')
    elif isinstance(configs[0], dict):
        # Configs is a list of dicts.
        objs = get_instances_with_configs(configs)
    elif isinstance(configs[0], int):
        # Configs is a list of ints representing serials.
        objs = get_instances(configs)
    else:
        raise Exception('No valid config found in: %s' % configs)
    return objs
github google / mobly / mobly / controllers / monsoon.py View on Github external
"""Instantiates a MonsoonData object.

        Args:
            data_points: A list of current values in Amp (float).
            timestamps: A list of epoch timestamps (int).
            hz: The hertz at which the data points are measured.
            voltage: The voltage at which the data points are measured.
            offset: The number of initial data points to discard
                in calculations.
        """
        self._data_points = data_points
        self._timestamps = timestamps
        self.offset = offset
        num_of_data_pt = len(self._data_points)
        if self.offset >= num_of_data_pt:
            raise MonsoonError(
                ("Offset number (%d) must be smaller than the "
                 "number of data points (%d).") % (offset, num_of_data_pt))
        self.data_points = self._data_points[self.offset:]
        self.timestamps = self._timestamps[self.offset:]
        self.hz = hz
        self.voltage = voltage
        self.tag = None
        self._validate_data()