示例#1
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._guidTable.update({
            37:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            38:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            39:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=2\nunit='min'\nscale=0"
            ),
            40:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=2\nunit='%'\nscale=1"
            ),
            # SNMP Trap Community String
            10073:
            Value(u"type='TYPE_STRING'\nsize=16\nlength=16\nunit=''\nscale=0"),
            10156:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            10157:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            10158:
            Value(u"type='TYPE_STRING'\nsize=64\nlength=64\nunit=''\nscale=0"),
            10159:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%'\nscale=1"
            ),
            10160:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%'\nscale=1"
            ),
        })
示例#2
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)
        self._guidTable.update({
            # TransducerSelection
            10189:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # GenericTransducerParameters
            10190:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=4\nlength=4\nunit='mA/V'\nscale=0"
            ),
            # RezeroTransducer
            40050:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
        })

        self._pointerGuids = [(1, 1), (2, 1), (3, 1), (4, 2), (11, 1), (14, 1),
                              (34, 1), (35, 1), (36, 1), (41, 12), (43, 12),
                              (44, 2), (45, 2), (46, 12), (47, 12), (48, 2),
                              (49, 2), (5004, 2), (5005, 2), (5006, 1),
                              (5007, 1), (5024, 12), (5025, 12), (5026, 12),
                              (5027, 12), (5028, 2), (5029, 2), (5030, 2),
                              (5031, 2)]
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._guidTable.update({
            50013:
            Value(u"type='TYPE_RAW'\nsize=0\nlength=0\nunit=''\nscale=0"),
            50014:
            Value(u"type='TYPE_RAW'\nsize=0\nlength=0\nunit=''\nscale=0"),
        })
 def __init__(self, parent):
     super(Model, self).__init__(parent)
     self._guidTable.update({
         # added only those that are needed for snmp configuration, others
         # omitted
         # SNMPTrapUser
         10212: Value(u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # SNMPTrapEnable
         10222: Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0")
     })
示例#5
0
 def __init__(self, parent):
     super(Master, self).__init__(parent)
     self._guidTable.update({
         # ModuleName
         10001:
         Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
         # TemperatureWarningEvent
         10087:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0")
     })
示例#6
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._guidTable.update({
            # DeviceID
            10150: Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # DeviceVersion
            10151: Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # HeartbeatInterval
            10179: Value(u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit='kW'\nscale=0"),
            # SlaveCapabilities
            40036: Value(u"type='TYPE_COMMAND'\nsize=2\nlength=2\nunit=''\nscale=0"),
            # SlaveVersions
            40037: Value(u"type='TYPE_COMMAND'\nsize=4\nlength=4\nunit=''\nscale=0"),
        })
示例#7
0
 def __init__(self, parent):
     super(Model, self).__init__(parent)
     self._guidTable.update({
         # ModuleManagement
         40026:
         Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
     })
示例#8
0
 def __init__(self, parent):
     super(Sensor, self).__init__(parent)
     self._guidTable.update({
         # TemperatureWarningEvent
         10087:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # HumidityWarningEvent
         10088:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # DewPointWarningEvent
         10093:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # AnalogueInputWarningEvent
         10116:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
     })
示例#9
0
 def __init__(self, parent):
     super(Power, self).__init__(parent)
     self._guidTable.update({
         # CurrentWarningEvent
         10078:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # PowerWarningEvent
         10080:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # TotalCurrentWarningEvent
         10082:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # TotalPowerWarningEvent
         10084:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # VoltageWarningEvent
         10086:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
         # TemperatureWarningEvent
         10087:
         Value(
             u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
     })
示例#10
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)
        self._guidTable.update({
            50:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%'\nscale=1"
            )
        })

        self._pointerGuids = [(1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 8),
                              (7, 8), (8, 8), (9, 8), (10, 8), (11, 1),
                              (24, 1), (31, 8), (50, 8), (5000, 8), (5001, 8),
                              (5002, 1), (5003, 1), (5004, 1), (5005, 1),
                              (5006, 1), (5007, 1), (5010, 8), (5011, 8),
                              (5012, 8), (5013, 8), (5014, 1), (5015, 1),
                              (5016, 1), (5017, 1), (15, 8), (16, 8), (17, 1),
                              (18, 1), (19, 1), (20, 1), (21, 1), (22, 1)]
class ModelFactory(JSBASE):
    FIRMWARE_ID = (10004, 0, 1, Value(
        u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"))
    MODULE_INFO = (40031, 0, 1, Value(
        u"type='TYPE_VERSION_FULL'\nsize=4\nLength=4\nunit=''\nscale=0"))
    FIRMWARE_INFO = (10002, 0, 1, Value(
        u"type='TYPE_VERSION_FULL'\nsize=4\nlength=4\nunit=''\nscale=0"))

    def __init__(self, client, rtf=None):
        JSBASE.__init__(self)
        self._client = client
        if not rtf:
            self._model_dir = self._get_firmware_id()
        else:
            self._model_dir = rtf

        self._master_models = {}
        self._power_models = {}
        self._sensor_models = {}
        self._display_models = {}
        self._slave_power_models = {}

        ip = self._client.get_url
        self._ip = ip[ip.rindex('/', 0, 10) + 1:ip.rindex('/')]

        self._get_available_models()

    def _get_module_model(self, module_id, class_name, module_version=None):
        if self._client.basicAuth:
            # we need to use the pre 1.0 API
            from JumpscaleLib.clients.racktivity.energyswitch.modelfactory import Model_pre_1_0  # pylint: disable=W0404
            if hasattr(Model_pre_1_0, class_name):
                return getattr(Model_pre_1_0, class_name)
            return None

        if not module_version:
            code, module_version = self._get_module_version(module_id)
            if code:
                # This means the module is not present
                if code == 16:
                    return None

                # check if this is firmware version 1.0 as this didn't support
                # module versions
                code, version = self._get_firmware_version()
                if code:
                    raise j.exceptions.RuntimeError(
                        "Can't get the firmware version of the device (%s)" % self._ip)

                version = str(version)
                if version.startswith("1.0"):
                    from JumpscaleLib.clients.racktivity.energyswitch.modelfactory import Model_firmware_1_0  # pylint: disable=W0404
                    return getattr(Model_firmware_1_0, class_name)
                else:
                    raise j.exceptions.RuntimeError(
                        "Can't get the module version of %s (%s)" % (module_id, self._ip))

        # get the closest model
        parts = str(module_version).split(".")
        tuple_version = (int(parts[0]), int(
            parts[1]), int(parts[2]), int(parts[3]))
        int_version = self._convert_version_to_int(tuple_version)
        version = self._get_closest_version(
            int_version, class_name, str(module_version))

        try:
            model_class = "models.%s.%s_%s" % (
                self._model_dir, class_name, version.replace(".", "_"))
            model = __import__(model_class, globals(),
                               locals(), fromlist=["Model"], level=1)
            return model.Model
        except RuntimeError:
            raise j.exceptions.RuntimeError(
                "Unsupported module version '%s' for %s (%s)" % (version, module_id, self._ip))

    def _get_module_version(self, module_id):
        guid, portnumber, length, valdef = self.MODULE_INFO
        data = self._client.getAttribute(module_id, guid, portnumber, length)
        return convert.bin2value(data, valdef)

    def _get_firmware_version(self):
        guid, portnumber, length, valdef = self.FIRMWARE_INFO
        data = self._client.getAttribute("M1", guid, portnumber, length)
        return convert.bin2value(data, valdef)

    def _get_firmware_id(self):
        guid, portnumber, length, valdef = self.FIRMWARE_ID
        data = self._client.getAttribute("M1", guid, portnumber, length)
        code, firmware_id = convert.bin2value(data, valdef)
        if code == 0:
            return firmware_id
        else:
            return ''

    def _list_dir_filtered(self, path, name_filter):
        files_to_return = []

        dir_content = os.listdir(path)
        for dir_entry in dir_content:
            fullpath = os.path.join(path, dir_entry)
            if fnmatch.fnmatch(dir_entry, name_filter):
                files_to_return.append(fullpath)

        return files_to_return

    def _get_available_models(self):
        def get_version(path):
            # Get the basename and remove the ".py" or ".pyc" extension
            filename = os.path.basename(path).rsplit('.', 1)[0]
            parts = filename.split("_")
            if len(parts) == 5:
                tuple_version = (int(parts[1]), int(
                    parts[2]), int(parts[3]), int(parts[4]))
                int_version = self._convert_version_to_int(tuple_version)
                version = "%d.%d.%d.%d" % tuple_version
                return (int_version, version)
            return None, None

        def get_models_from_disk(self, model_dir_path):
            models = self._list_dir_filtered(
                model_dir_path, name_filter="Master_*.py*")
            for model in models:
                int_version, version = get_version(model)
                if version:
                    self._master_models[int_version] = version
            # get power models
            models = self._list_dir_filtered(
                model_dir_path, name_filter="Power_*.py*")
            for model in models:
                int_version, version = get_version(model)
                if version:
                    self._power_models[int_version] = version

            # get sensor models
            models = self._list_dir_filtered(
                model_dir_path, name_filter="Sensor_*.py*")
            for model in models:
                int_version, version = get_version(model)
                if version:
                    self._sensor_models[int_version] = version

            # get display models
            models = self._list_dir_filtered(
                model_dir_path, name_filter="Display_*.py*")
            for model in models:
                int_version, version = get_version(model)
                if version:
                    self._display_models[int_version] = version

            # get slave_power models
            models = self._list_dir_filtered(
                model_dir_path, name_filter="SlavePower_*.py*")
            for model in models:
                int_version, version = get_version(model)
                if version:
                    self._slave_power_models[int_version] = version

        def get_models_from_egg(self, egg_path, model_dir_path):
            rel_path = os.path.relpath(
                path=model_dir_path, start=egg_path) + os.path.sep
            search_str = r'^%s(.*\.pyc?$)' % rel_path
            master_str = r'^%s(Master_.*\.pyc?$)' % rel_path
            power_str = r'^%s(Power_.*\.pyc?$)' % rel_path
            sensor_str = r'^%s(Sensor_.*\.pyc?$)' % rel_path
            display_str = r'^%s(Display_.*\.pyc?$)' % rel_path
            slave_power_str = r'^%s(SlavePower_.*\.pyc?$)' % rel_path
            egg_file = zipfile.ZipFile(egg_path)
            file_names = egg_file.namelist()
            for filename in file_names:
                match = re.search(search_str, filename)
                if match and os.path.sep not in match.group(1):
                    if re.search(master_str, filename):
                        int_version, version = get_version(filename)
                        if version:
                            self._master_models[int_version] = version
                    elif re.search(power_str, filename):
                        int_version, version = get_version(filename)
                        if version:
                            self._power_models[int_version] = version
                    elif re.search(sensor_str, filename):
                        int_version, version = get_version(filename)
                        if version:
                            self._sensor_models[int_version] = version
                    elif re.search(display_str, filename):
                        int_version, version = get_version(filename)
                        if version:
                            self._display_models[int_version] = version
                    elif re.search(slave_power_str, filename):
                        int_version, version = get_version(filename)
                        if version:
                            self._slave_power_models[int_version] = version

        # get master models, power models, and sensor models
        self.logger.debug("{} {} {}".format(os.path.dirname(__file__), "models", self._model_dir))
        model_dir_path = os.path.join(os.path.dirname(__file__), "models", self._model_dir)
        match = re.search(r'.*\.egg', model_dir_path)
        if not match:  # outside an egg, so listing files will work
            get_models_from_disk(self, model_dir_path)

        else:  # inside a python egg
            egg_path = match.group()
            get_models_from_egg(self, egg_path, model_dir_path)

    def _get_closest_version(self, version, class_name, version_str):
        models = self._master_models
        if class_name == "Power":
            models = self._power_models
        elif class_name == "Sensor":
            models = self._sensor_models
        elif class_name == "Display":
            models = self._display_models
        elif class_name == "SlavePower":
            models = self._slave_power_models

        closest = version
        closest_diff = -sys.maxsize
        for model_version in models:
            diff = model_version - version
            if diff > closest_diff and diff <= 0:  # only match versions downwards
                closest = model_version
                closest_diff = diff

        if closest not in models:
            msg = "Unable to find valid model for %s %s (%s)" % (
                class_name, version_str, self._ip)
            raise Exception(msg)

        return models[closest]

    def _convert_version_to_int(self, version):
        return version[3] + (version[2] * 256) + (version[1] * (256 * 256)) + (version[0] * (256 * 256 * 256))

    def get_master(self, module_version=None):
        return self._get_module_model("M1", "Master", module_version)

    def get_power(self, module_version=None):
        return self._get_module_model("P1", "Power", module_version)

    def get_sensor(self, module_version=None):
        if module_version:
            return self._get_module_model('Ax', "Sensor", module_version)

        for i in range(1, 8):
            module_id = "A%d" % i
            try:
                mm = self._get_module_model(module_id, "Sensor")
                if mm:
                    return mm
            except (RuntimeError, AttributeError) as e:
                logging.warning("Failed to get module info of %s", module_id, exc_info=e)

        return None

    def get_display(self, module_version=None):
        if module_version:
            return self._get_module_model('Dx', "Display", module_version)

        for i in range(1, 40):
            module_id = "D%d" % i
            try:
                mm = self._get_module_model(module_id, "Display")
                if mm:
                    return mm
            except (RuntimeError, AttributeError) as e:
                logging.warning("Failed to get module info of %s",
                                module_id, exc_info=e)

        return None

    def get_slave_power(self, module_version=None):
        if module_version:
            return self._get_module_model('Qx', "SlavePower", module_version)

        for i in range(1, 40):
            module_id = "Q%d" % i
            try:
                mm = self._get_module_model(module_id, "SlavePower")
                if mm:
                    return mm
            except (RuntimeError, AttributeError) as e:
                logging.warning("Failed to get module info of %s",
                                module_id, exc_info=e)

        return None
示例#12
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._pointerGuids = [(1, 1), (2, 1), (3, 1), (4, 2), (11, 1), (14, 1),
                              (17, 2), (18, 1), (34, 1), (35, 1), (36, 1),
                              (41, 12), (42, 1), (43, 12), (44, 2), (45, 2),
                              (46, 12), (47, 12), (48, 2), (49, 2), (5006, 1),
                              (5007, 1), (5026, 12), (5027, 12), (5028, 2),
                              (5029, 2), (5030, 2), (5031, 2), (5004, 2),
                              (5005, 2), (5024, 12), (5025, 12)]

        self._guidTable.update({
            # GeneralModuleStatus
            1:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # SpecificModuleStatus
            2:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # CurrentTime
            3:
            Value(
                u"type='TYPE_TIMESTAMP'\nsize=4\nlength=4\nunit='UNIX'\nscale=0"
            ),
            # Voltage
            4:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # Temperature
            11:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # CurrentIP
            14:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # TotalCurrent
            17:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=3"
            ),
            # TotalRealPower
            18:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='W'\nscale=0"
            ),
            # CurrentSubNetMask
            34:
            Value(
                u"type='TYPE_SUBNETMASK'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # CurrentDNSServer
            35:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # CurrentDNSServer
            36:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # HighCurrent(DC Current)
            41:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # UpsCommunicationStatus
            42:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # HighPower(DC Power)
            43:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=2"
            ),
            # TotalHighCurrent
            44:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # TotalHighPower
            45:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=2"
            ),
            # PositiveEnergy
            46:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='kWh'\nscale=3"
            ),
            # NegativeEnergy
            47:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='kWh'\nscale=3"
            ),
            # TotalPositiveEnergy
            48:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='kWh'\nscale=3"
            ),
            # TotalNegativeEnergy
            49:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='kWh'\nscale=3"
            ),
            # Maxvoltage
            5004:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='V'\nscale=2"
            ),
            # Minvoltage
            5005:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='V'\nscale=2"
            ),
            # MinTemp.
            5006:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='C'\nscale=1"
            ),
            # MaxTemp
            5007:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='C'\nscale=1"
            ),
            # MinHighCurrent
            5024:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='A'\nscale=1"
            ),
            # MaxHighCurrent
            5025:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='A'\nscale=1"
            ),
            # MinHighPower
            5026:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='kW'\nscale=2"
            ),
            # MaxHighPower
            5027:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='kW'\nscale=2"
            ),
            # MinTotalHCur
            5028:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='A'\nscale=1"
            ),
            # MaxTotalHCur
            5029:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='A'\nscale=1"
            ),
            # MinTotalHPow
            5030:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='kW'\nscale=2"
            ),
            # MaxTotalHPow
            5031:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='kW'\nscale=2"
            ),
            # Address
            10000:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit=''\nscale=0"
            ),
            # ModuleName
            10001:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # FirmwareVersion
            10002:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # HardwareVersion
            10003:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # FirmwareID
            10004:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # HardwareID
            10005:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # RackName
            10006:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # RackPosition
            10007:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # TemperatureUnitSelector
            10010:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # IPAddress
            10011:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # SubNetMask
            10012:
            Value(
                u"type='TYPE_SUBNETMASK'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # StdGateway
            10013:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # DnsServer
            10014:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # MAC
            10015:
            Value(u"type='TYPE_MAC'\nsize=6\nlength=6\nunit=''\nscale=0"),
            # DHCPEnable
            10016:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # NTPServer
            10017:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # UseDefaultNTPServer
            10018:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # UseNTP
            10019:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # SNMPTrapRecvIP
            10020:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # SNMPTrapRecvPort
            10021:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # SNMPCommunityRead
            10022:
            Value(u"type='TYPE_STRING'\nsize=16\nlength=16\nunit=''\nscale=0"),
            # SNMPCommunityWrite
            10023:
            Value(u"type='TYPE_STRING'\nsize=16\nlength=16\nunit=''\nscale=0"),
            # SNMPControl
            10024:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ECSServer
            10028:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # UseECSServer
            10029:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # DisplayLock
            10031:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # DisplayTimeOn
            10032:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit='min'\nscale=0"
            ),
            # DisplayRotation
            10033:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            10039:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=3"
            ),
            # MaxVoltageWarning
            10047:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # MinVoltageWarning
            10049:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # MinTemperatureWarning
            10052:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # MaxTemperatureWarning
            10053:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # SNMPTrapCommunity
            10073:
            Value(u"type='TYPE_STRING'\nsize=16\nlength=16\nunit=''\nscale=0"),
            # GeneralEventEnable
            10074:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # SNMPSysContact
            10075:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # CurrentWarningEvent
            10078:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # PowerWarningEvent
            10080:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # TotalCurrentWarningEvent
            10082:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # TotalPowerWarningEvent
            10084:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # VoltageWarningEvent
            10086:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # TemperatureWarningEvent
            10087:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ECSServerPort
            10106:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # ExternalSensorLabel
            10109:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # HttpsOnly
            10127:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # TelnetSsl
            10128:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # CookieTimeToLive
            10130:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # DeviceID
            10150:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # DeviceVersion
            10151:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # SysName
            10152:
            Value(u"type='TYPE_STRING'\nsize=16\nlength=16\nunit=''\nscale=0"),
            # DebugIPAddress
            10162:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # MaxHighCurrentWarning
            10165:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # RecoveryPwrThresh
            10171:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='W'\nscale=0"
            ),
            # MinHighCurrentWarning
            10176:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # MinHighPowerWarning
            10177:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=2"
            ),
            # MaxHighPowerWarning
            10178:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=2"
            ),
            # HeartbeatInterval
            10179:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit='kW'\nscale=0"
            ),
            # MinTotalHCurrWarn
            10180:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # MaxTotalHCurrWarn
            10181:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # MinTotalHPowerWarn
            10182:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=2"
            ),
            # MaxTotalHPowerWarn
            10183:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=2"
            ),

            # JumpBoot
            40000:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40001:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40002:
            Value(
                u"type='TYPE_COMMAND'\nsize=16\nlength=16\nunit=''\nscale=0"),
            40003:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40004:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40005:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40006:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40007:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # ModInfo
            40008:
            Value(u"type='TYPE_STRING'\nsize=26\nlength=26\nunit=''\nscale=0"),
            40009:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40010:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40011:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40012:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            40013:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40014:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            40015:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModStatus
            40018:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModuleManagement
            40026:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModuleScan
            40027:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            50000:
            Value(u"type='TYPE_POINTER'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # Parameter
            50001:
            Value(u"type='TYPE_POINTER'\nsize=1\nlength=1\nunit=''\nscale=0"),
            50011:
            Value(u"type='TYPE_RAW'\nsize=16\nlength=16\nunit=''\nscale=0"),
            60001:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0")
        })
示例#13
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._guidTable.update({
            # CurrentTime
            3:
            Value(
                u"type='TYPE_TIMESTAMP'\nsize=4\nlength=4\nunit='UNIX'\nscale=0"
            ),
            # Voltage
            4:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # Temperature
            11:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # Humidity
            12:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%RH'\nscale=1"
            ),
            # DewPoint
            25:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='K'\nscale=1"
            ),
            # AnalogIn
            27:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # MotionDetected
            29:
            Value(u"type='TYPE_ENUM'\nsize=2\nlength=2\nunit=''\nscale=1"),
            # HighCurrent
            41:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # HighPower
            43:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=1"
            ),
            # MaxVoltage
            5004:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='V'\nscale=2"
            ),
            # MinVoltage
            5005:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='V'\nscale=2"
            ),
            # MinHighCurrent
            5024:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='A'\nscale=1"
            ),
            # MaxHighCurrent
            5025:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='A'\nscale=1"
            ),
            # MinHighPower
            5026:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='kW'\nscale=1"
            ),
            # MaxHighPower
            5027:
            Value(
                u"type='TYPE_SIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='kW'\nscale=1"
            ),
            # Module Address
            10000:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit=''\nscale=0"
            ),
            # Module Name
            10001:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # FirmwareVersion
            10002:
            Value(
                u"type='TYPE_VERSION_FULL'\nsize=4\nlength=4\nunit=''\nscale=0"
            ),
            # HardwareVersion
            10003:
            Value(
                u"type='TYPE_VERSION_FULL'\nsize=4\nlength=4\nunit=''\nscale=0"
            ),
            # FirmwareID
            10004:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # HardwareID
            10005:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # TempUnitSelector
            10010:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # MinAnalogInputWarn
            10111:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # MaxAnalogInputWarn
            10112:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # MaxVoltageWarning
            10047:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # MinVoltageWarning
            10049:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # MinTemperatureWarning
            10052:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # MaxTemperatureWarning
            10053:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # MinHumidityWarn
            10054:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%RH'\nscale=1"
            ),
            # MaxHumidityWarn
            10055:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%RH'\nscale=1"
            ),
            # ExternalSensorLabel
            10109:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # MaxHighCurrentWarning
            10165:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # MinHighCurrentWarning
            10176:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='A'\nscale=1"
            ),
            # MaxHighPowerWarning
            10177:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=1"
            ),
            # MinHighPowerWarning
            10178:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='kW'\nscale=1"
            ),
            # CmdLocate
            40028:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModuleCapabilities
            40030:
            Value(u"type='TYPE_COMMAND'\nsize=2\nlength=2\nunit=''\nscale=0")
        })
示例#14
0
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._pointerGuids = [(1, 1), (2, 1), (3, 1), (4, 3), (5, 1), (9, 4),
                              (10, 4), (11, 1), (24, 1), (31, 8), (50, 4),
                              (51, 2), (52, 4), (53, 4), (5004, 3), (5005, 3),
                              (5006, 1), (5007, 1), (5012, 3), (5013, 3),
                              (5032, 4), (5033, 4), (5034, 4), (5035, 4),
                              (16, 3), (30, 4), (54, 3)]

        self._guidTable.update({
            # GeneralModuleStatus
            1:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # SpecificModuleStatus
            2:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # CurrentTime
            3:
            Value(
                u"type='TYPE_TIMESTAMP'\nsize=4\nlength=4\nunit='UNIX'\nscale=0"
            ),
            # Voltage
            4:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # Frequency
            5:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='Hz'\nscale=3"
            ),
            # ActiveEnergy
            9:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='kWh'\nscale=3"
            ),
            # ApparentEnergy
            10:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='kVAh'\nscale=3"
            ),
            # Temperature
            11:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # PowerFactor
            16:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit='%'\nscale=0"
            ),
            # TimeOnline
            24:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='s'\nscale=0"
            ),
            # IOPort
            30:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # LogMeInfo
            31:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # THD
            50:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%'\nscale=1"
            ),
            # Phase
            51:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='%'\nscale=0"
            ),
            # BigCurrent
            52:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='A'\nscale=4"
            ),
            # BigPower
            53:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='W'\nscale=3"
            ),
            # BigApparentPower
            54:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='VA'\nscale=3"
            ),
            # Status
            1000:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # MaxVoltage
            5004:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='V'\nscale=2"
            ),
            # MinVoltage
            5005:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='V'\nscale=2"
            ),
            # MinTemperature
            5006:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='C'\nscale=1"
            ),
            # MaxTemperature
            5007:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=6\nlength=6\nunit='C'\nscale=1"
            ),
            # MinPowerFactor
            5012:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=5\nlength=5\nunit='%'\nscale=0"
            ),
            # MaxPowerFactor
            5013:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=5\nlength=5\nunit='%'\nscale=0"
            ),
            # MinBigCurrent
            5032:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=8\nlength=8\nunit='A'\nscale=4"
            ),
            # MaxBigCurrent
            5033:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=8\nlength=8\nunit='A'\nscale=4"
            ),
            # MinBigPower
            5034:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=8\nlength=8\nunit='W'\nscale=3"
            ),
            # MaxBigPower
            5035:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER_WITH_TS'\nsize=8\nlength=8\nunit='W'\nscale=3"
            ),
            # ModuleName
            10001:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # FirmwareVersion
            10002:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # HardwareVersion
            10003:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # FirmwareID
            10004:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # HardwareID
            10005:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # MaxVoltageWarning
            10047:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # MinVoltageWarning
            10049:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='V'\nscale=2"
            ),
            # CurrentWarningEvent
            10078:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # PowerWarningEvent
            10080:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ExternalSensorLabel
            10109:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # MaxBigCurrentWarning
            10193:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='A'\nscale=4"
            ),
            # MaxBigPowerWarning
            10194:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='A'\nscale=3"
            ),
            # CurrentSensorSelector
            10197:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # ModInfo
            40008:
            Value(u"type='TYPE_STRING'\nsize=26\nlength=26\nunit=''\nscale=0"),
        })
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._pointerGuids = []

        self._guidTable.update({
            # GeneralModuleStatus
            1:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # SpecificModuleStatus
            2:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # CurrentTime
            3:
            Value(
                u"type='TYPE_TIMESTAMP'\nsize=4\nlength=4\nunit='UNIX'\nscale=0"
            ),
            # TimeOnline
            24:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=4\nlength=4\nunit='s'\nscale=0"
            ),
            # LogMeInfo
            31:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # Status
            1000:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # ModuleName
            10001:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # FirmwareVersion
            10002:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # HardwareVersion
            10003:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # FirmwareID
            10004:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # HardwareID
            10005:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # ModInfo
            40008:
            Value(u"type='TYPE_STRING'\nsize=26\nlength=26\nunit=''\nscale=0"),
        })
示例#16
0
class RackSal(JSBASE):
    MODULE_INFO = (40031, 0, 1, Value(
        u"type='TYPE_VERSION_FULL'\nsize=4\nLength=4\nunit=''\nscale=0"))

    def __init__(self, username, password, hostname, port, rtf=None, moduleinfo=None):  # pylint: disable=W0622
        JSBASE.__init__(self)
        self.client = connection.Connect(username, password, hostname, port)
        self.__rtf = rtf
        self.__master_inited = False
        self.__master = None
        self.__power_inited = False
        self.__power = None
        self.__sensor_inited = False
        self.__sensor = None
        self.__display_inited = False
        self.__display = None
        self.__slave_power_inited = False
        self.__slave_power = None
        self.__factory = ModelFactory(self.client, rtf)
        self.__moduleinfo = moduleinfo or {}

    @property
    def master(self):
        if self.__master_inited is False:
            self.__master_inited = True
            self.__master = self.__factory.get_master(
                self.__moduleinfo.get('M'))(self)
        return self.__master

    @property
    def power(self):
        if self.__power_inited is False:
            self.__power_inited = True
            power_class = self.__factory.get_power(self.__moduleinfo.get('P'))
            if power_class:
                self.__power = power_class(self)
            else:
                self.__power = None
        return self.__power

    @property
    def sensor(self):
        if self.__sensor_inited is False:
            self.__sensor_inited = True
            # sal does not handle now sensors with different versions
            sensor_class = self.__factory.get_sensor(
                self.__moduleinfo.get('A'))
            if sensor_class:
                self.__sensor = sensor_class(self)
            else:
                self.__sensor = None
        return self.__sensor

    @property
    def display(self):
        if self.__display_inited is False:
            self.__display_inited = True
            # sal does not handle now displays with different versions
            display_class = self.__factory.get_display(
                self.__moduleinfo.get('D'))
            if display_class:
                self.__display = display_class(self)
            else:
                self.__display = None
        return self.__display

    @property
    def slave_power(self):
        if self.__slave_power_inited is False:
            self.__slave_power_inited = True
            # sal does not handle now slave_powers with different versions
            slave_power_class = self.__factory.get_slave_power(
                self.__moduleinfo.get('Q'))
            if slave_power_class:
                self.__slave_power = slave_power_class(self)
            else:
                self.__slave_power = None
        return self.__slave_power

    def getObjectFromData(self, data, valDef, setter=False, count=1):
        if setter:
            return convert.bin2int(data)
        if count == 1:
            return convert.bin2value(data, valDef)
        if data[0] != "\0":  # pylint: disable=W1401
            # This is an error code, return it
            return convert.bin2value(data, valDef)
        # Remove the error byte
        data = data[1:]
        # get length of each port
        length = len(data) / count
        # Split the ports
        data_list = convert.slice_string(data, length)
        result = []
        for data in data_list:
            result.append(convert.bin2value(
                data, valDef, checkErrorByte=False)[1])
        return 0, result

    def getModuleVersion(self, moduleID):
        """
        this function returns the module version or None
        """
        guid, portnumber, length, valdef = self.MODULE_INFO
        data = self.client.getAttribute(moduleID, guid, portnumber, length)
        code, version = convert.bin2value(data, valdef)
        if not code:
            return version

    def logout(self):
        self.client.logout()

    def translateDetailedLog(self, moduleID, binaryfile, csvfile, headerNames=None):
        """
        decodes detailed logging
        @param moduleID - module to get log for (Mx, Px, Ax)
        @param binaryfile - filename of binary log
        @param csvfile - filename for csv
        """

        def prepareValue(value, info):
            result = []
            if isinstance(value, list):
                for val in value:
                    result.extend(prepareValue(val, info))
            elif isinstance(value, str):
                result.append('"%s"' % value)
            elif isinstance(value, tuple):
                result.append(str(round(value[0], 3)))
                result.append('"%s"' % time.strftime(
                    "%Y-%m-%d %H:%M:%S", time.gmtime(value[1])))
            else:
                if info[1].type == 'TYPE_TIMESTAMP':
                    result.append('"%s"' % time.strftime(
                        "%Y-%m-%d %H:%M:%S", time.gmtime(value)))
                else:
                    result.append(str(round(value, 3)))

            return result

        def prepareHeader(info, nr=None):
            hdr = []
            if info[2] > 1 and nr is None:
                for i in range(info[2]):
                    hdr.append(prepareHeader(info, i + 1))
            else:
                tmpl = "%s"
                if nr:
                    tmpl += " (%d)" % nr
                if isinstance(headerNames, dict) and info[0] in headerNames:
                    name = headerNames[info[0]]
                else:
                    name = str(info[0])
                hdr.append(tmpl % name)
                if info[1].type.endswith('_WITH_TS'):
                    hdr.append(tmpl % ("%s timestamp" % name))
            return ", ".join(hdr)

        def calculatePointerSize(structure):
            size = 0
            for elem in structure:
                size += elem[2] * elem[1].size

            return size

        if moduleID[0] == 'M':
            paramInfo = self.master.definePointerStructure()
        elif moduleID[0] == 'P' and self.power:
            paramInfo = self.power.definePointerStructure()
        elif moduleID[0] == 'A' and self.sensor:
            paramInfo = self.sensor.definePointerStructure()
        elif moduleID[0] == 'Q' and self.slave_power:
            paramInfo = self.slave_power.definePointerStructure()
        else:
            raise ValueError('Requested moduleID not found')

        chunk = calculatePointerSize(paramInfo)

        # prepare header information
        lineData = []
        for idx, info in enumerate(paramInfo):
            if info[0] < 3:
                continue
            lineData.append(prepareHeader(info))

        with open(csvfile, "w") as out:
            out.write(", ".join(lineData))
            out.write("\n")
            with open(binaryfile, "rb") as fp:
                while True:
                    data = fp.read(chunk)
                    if not data:
                        break
                    try:
                        array = convert.pointer2values(data, paramInfo)
                    except IndexError:
                        break
                    lineData = []
                    for idx, info in enumerate(paramInfo):
                        if info[0] < 3:
                            continue
                        lineData.extend(prepareValue(array[idx], info))

                    out.write(", ".join(lineData))
                    out.write("\n")
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._guidTable.update({
            # Temperature
            11:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # ModuleName
            10001:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # FirmwareVersion
            10002:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # HardwareVersion
            10003:
            Value(u"type='TYPE_VERSION'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # FirmwareID
            10004:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # HardwareID
            10005:
            Value(u"type='TYPE_STRING'\nsize=8\nlength=8\nunit=''\nscale=0"),
            # SNMPTrapRecvIP
            10020:
            Value(u"type='TYPE_IP'\nsize=4\nlength=4\nunit=''\nscale=0"),
            # SNMPTrapRecvPort
            10021:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=2\nlength=2\nunit=''\nscale=0"
            ),
            # MinTemperatureWarning
            10052:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # MaxTemperatureWarning
            10053:
            Value(
                u"type='TYPE_SIGNED_NUMBER'\nsize=2\nlength=2\nunit='C'\nscale=1"
            ),
            # GeneralEventEnable
            10074:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # TemperatureWarningEvent
            10087:
            Value(
                u"type='TYPE_EVENTFLAGS'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # SNMPTrapUser
            10212:
            Value(
                u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit=''\nscale=0"
            ),
            # SNMPTrapEnable
            10222:
            Value(u"type='TYPE_ENUM'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModInfo
            40008:
            Value(u"type='TYPE_STRING'\nsize=26\nlength=26\nunit=''\nscale=0"),
            # LoginAndPassword
            40012:
            Value(u"type='TYPE_STRING'\nsize=32\nlength=32\nunit=''\nscale=0"),
            # ModStatus
            40018:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModuleManagement
            40026:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
            # ModuleScan
            40027:
            Value(u"type='TYPE_COMMAND'\nsize=1\nlength=1\nunit=''\nscale=0"),
        })
    def __init__(self, parent):
        super(Model, self).__init__(parent)

        self._guidTable.update({
            10161: Value(u"type='TYPE_UNSIGNED_NUMBER'\nsize=1\nlength=1\nunit='%'\nscale=0"),
        })