Ejemplo n.º 1
0
    def __init__(self, ua_peer):
        # service_id: service
        self.service_dict = dict()
        # receives the peer methods to add the opc-ua services
        self.__ua_peer = ua_peer

        # creates the service description opc-ua folder
        utils.default_folder(self.__ua_peer, self.__ua_peer.base_idx,
                             self.__ua_peer.ROOT_PATH,
                             self.__ua_peer.ROOT_LIST, 'ServiceDescriptionSet')
    def __init__(self, ua_peer):
        Thread.__init__(self, name='monitoring_thread')
        self.kill_event.clear()
        # creates the opc-ua folder
        folder_idx, folder_path, folder_list = utils.default_folder(
            ua_peer, ua_peer.base_idx, ua_peer.ROOT_PATH, ua_peer.ROOT_LIST,
            'HardwareMonitoring')
        # variables names
        var_names = ('CPU_PERCENT', 'CPU_FREQ_CURRENT', 'CPU_FREQ_MIN',
                     'CPU_FREQ_MAX', 'MEM_TOTAL', 'MEM_AVAILABLE',
                     'MEM_PERCENTAGE', 'MEM_USED', 'MEM_CACHED', 'MEM_SHARED')
        # zips both names and values in on dict
        tuple_vars = zip(var_names, self.measure_hardware())

        # ua variables
        ua_vars = []
        for var_name, var_value in tuple_vars:
            var_idx = '{0}:{1}'.format(folder_idx, var_name)
            browse_name = '2:{0}'.format(var_name)
            ua_var = ua_peer.create_variable(folder_path, var_idx, browse_name,
                                             var_value)
            ua_vars.append(ua_var)

        # joins the ua variables with the names
        self.ua_vars_dict = dict(zip(var_names, ua_vars))
Ejemplo n.º 3
0
    def __init__(self, ua_peer, set_xml_name, item_xml_name, loop_type=False):
        self.items_dict = dict()
        # receives the peer methods to add the opc-ua objects
        self.ua_peer = ua_peer
        # set settings
        # 'DeviceSet', 'ServiceInstanceSet'
        self.set_xml_name = set_xml_name
        # 'device', 'serviceinstance'
        self.item_xml_name = item_xml_name
        # 'Device', 'Instance'
        self.loop_type = loop_type

        # creates the opc-ua folder
        utils.default_folder(self.ua_peer, self.ua_peer.base_idx,
                             self.ua_peer.ROOT_PATH, self.ua_peer.ROOT_LIST,
                             self.set_xml_name)
Ejemplo n.º 4
0
    def refract_ua_equipment(self):
        # checks if is an equipment
        if self.source_type == 'EQUIPMENT':
            # creates the folders for the actuators and the sensors
            _, actuators_path, _ = utils.default_folder(
                self.ua_peer, self.base_idx, self.base_path,
                self.base_path_list, 'Actuators')
            actuators_obj = self.ua_peer.get_object(actuators_path)
            _, sensors_path, _ = utils.default_folder(self.ua_peer,
                                                      self.base_idx,
                                                      self.base_path,
                                                      self.base_path_list,
                                                      'Sensors')
            sensors_obj = self.ua_peer.get_object(sensors_path)

            # create the subscriptions for the actuators
            if 'ACTUATORS' in self.subscriptions_dict:
                # iterates over the subscriptions list
                for subscription in self.subscriptions_dict['ACTUATORS']:
                    # splits the subscription items
                    subscription_items = subscription['value'].split(':')
                    # adds that subscription to the folder
                    obj_ref = self.ua_peer.get_node('ns=2;s={0}'.format(
                        subscription_items[0]))
                    actuators_obj.add_reference(obj_ref,
                                                ua.ObjectIds.Organizes)

            # create the subscriptions for the sensors
            if 'SENSORS' in self.subscriptions_dict:
                # iterates over the subscriptions list
                for subscription in self.subscriptions_dict['SENSORS']:
                    # splits the subscription items
                    subscription_items = subscription['value'].split(':')
                    # adds that subscription to the folder
                    obj_ref = self.ua_peer.get_node('ns=2;s={0}'.format(
                        subscription_items[0]))
                    sensors_obj.add_reference(obj_ref, ua.ObjectIds.Organizes)
Ejemplo n.º 5
0
    def __init__(self, ua_peer, fb_name, fb_type, source_type, browse_name,
                 root_folder):
        """

        :param ua_peer:
        :param root_folder:
        :param fb_name:
        :param fb_type:
        :param browse_name:
        """
        self.fb_name = fb_name
        self.fb_type = fb_type
        self.ua_peer = ua_peer
        self.source_type = source_type

        # creates the path to set the folder
        folder_path_list = self.ua_peer.ROOT_LIST + [(2, root_folder)]
        folder_path = self.ua_peer.generate_path(folder_path_list)

        self.base_idx = 'ns=2;s={0}'.format(self.fb_name)
        # creates the device object
        self.base_path_list, self.base_path = utils.default_object(
            self.ua_peer, self.base_idx, folder_path, folder_path_list,
            browse_name)

        # creates the id and dId property
        utils.default_property(self.ua_peer, self.base_idx, self.base_path,
                               'ID', self.fb_name)
        utils.default_property(self.ua_peer, self.base_idx, self.base_path,
                               'dID', self.fb_type)
        utils.default_property(self.ua_peer, self.base_idx, self.base_path,
                               'SourceType', self.source_type)

        # creates the methods folder
        self.methods_idx, self.methods_path, methods_list = utils.default_folder(
            self.ua_peer, self.base_idx, self.base_path, self.base_path_list,
            'Methods')
        self.methods_dict = dict()

        # creates the variables folder
        self.vars_idx, self.vars_path, vars_list = utils.default_folder(
            self.ua_peer, self.base_idx, self.base_path, self.base_path_list,
            'Variables')
        """
        the ua_variables contains:
        - variable_name: key
        - opc-ua variable: value
        the variables_dict contains:
        - variable_name: key and value
        - value_rank
        - data_type
        - array_dimensions
        """
        self.ua_variables = dict()
        self.variables_dict = dict()

        # creates the subscriptions folder
        self.subs_idx, subs_path, subs_list = utils.default_folder(
            self.ua_peer, self.base_idx, self.base_path, self.base_path_list,
            'Subscriptions')
        self.subscriptions_folder = self.ua_peer.get_object(subs_path)
        # creates the dictionary where are stored the connections
        self.subscriptions_dict = dict()
        # create the variable to update the error state
        var_idx = '{0}:{1}'.format(self.base_idx, 'FBState')
        browse_name = '2:{0}'.format('FBState')
        self.fb_state = self.ua_peer.create_variable(self.base_path, var_idx,
                                                     browse_name, 1)