Ejemplo n.º 1
0
    def apply_config(self):
        """\
        Apply the configuration actions to the node targeted by this object.
        
        After this method has been called the 
        :py:meth:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock.is_complete`
        method will return True.
        
        See :py:class:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock`.

        """

        try:
            if not AbstractXBeeConfigBlockDDO._is_applicable(self):
                # If the block is not applicable, mark this block as complete:
                return AbstractXBeeConfigBlockDDO.apply_config(self)
        except Exception, e:
            # trace message will be printed by _is_applicable() or
            # apply_config() upon exception.
            return False
    def apply_config(self):
        """\
        Apply the configuration actions to the node targeted by this object.
        
        After this method has been called the 
        :py:meth:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock.is_complete`
        method will return True.
        
        See :py:class:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock`.

        """

        try:
            if not AbstractXBeeConfigBlockDDO._is_applicable(self):
                # If the block is not applicable, mark this block as complete:
                return AbstractXBeeConfigBlockDDO.apply_config(self)
        except Exception, e:
            # trace message will be printed by _is_applicable() or
            # apply_config() upon exception.
            return False
Ejemplo n.º 3
0
    def apply_config(self):
        '''
        Apply the configuration actions to the node targeted by this object.

        After this method has been called the
        :py:meth:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock.is_complete`
        method will return True.

        See :py:class:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock`.
        '''
        try:
            if not AbstractXBeeConfigBlockDDO._is_applicable(self):
                # If the block is not applicable, mark this block as complete:
                return AbstractXBeeConfigBlockDDO.apply_config(self)

        except:
            # Trace messages handled by _is_applicable() and apply_config()
            return False

        # Special case:
        #
        # Check if sleep mode is unavailable on this module/firmware
        # combination:
        if not self.__is_sleep_mode_available():
            if self.__sleep_mode == SM_DISABLED:
                # This sleep block has been filled out with sleeping
                # disabled however sleep configuration is not available:
                # mark this block as complete.
                self.__tracer.debug('sleep mode unsupported and SM_DISABLED'
                                    ' given, block complete.')
                return AbstractXBeeConfigBlockDDO.apply_config(self)
            else:
                # We are unable to apply this block, mark it as a
                # block application failure:
                self.__tracer.warning('sleep mode unsupported'
                                      ' but sleep parameters given,'
                                      ' block FAILED. Please disable '
                                      'sleeping on this device.')
                return False

        # Configure the node:
        pending_mnemonics = self.__pending_parameters.keys()

        for mnemonic in pending_mnemonics:
            # NOTE: this message is duplicated in the XBeeConfigBlockDDO source
            self.__tracer.debug(
                "Apply_config: trying '%s' = '%s' to '%s'", mnemonic,
                format_hexrepr(self.__pending_parameters[mnemonic]),
                AbstractXBeeConfigBlockDDO.ext_addr_get(self))
            try:
                AbstractXBeeConfigBlockDDO.configurator_get(self).\
                    ddo_set_param(
                        AbstractXBeeConfigBlockDDO.ext_addr_get(self),
                        mnemonic,
                        self.__pending_parameters[mnemonic],
                        retries=DDO_RETRY_ATTEMPTS)
            except Exception, e:
                self.__tracer.error(
                    "'%s' = '%s' to '%s' failed (%s)", mnemonic,
                    format_hexrepr(self.__pending_parameters[mnemonic]),
                    AbstractXBeeConfigBlockDDO.ext_addr_get(self), str(e))
                return False
            del (self.__pending_parameters[mnemonic])
    def apply_config(self):
        """\
        Apply the configuration actions to the node targeted by this object.
        
        After this method has been called the
        :py:meth:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock.is_complete`
        method will return True.
        
        See :py:class:`~devices.xbee.xbee_config_blocks.xbee_config_block.XBeeConfigBlock`.

        """  
        try:
            if not AbstractXBeeConfigBlockDDO._is_applicable(self):
                # If the block is not applicable, mark this block as complete:
                return AbstractXBeeConfigBlockDDO.apply_config(self)
              
        except:
            # Trace messages handled by _is_applicable() and apply_config()            
            return False

        # Special case:
        #
        # Check if sleep mode is unavailable on this module/firmware
        # combination:
        if not self.__is_sleep_mode_available():
            if self.__sleep_mode == SM_DISABLED:
                # This sleep block has been filled out with sleeping
                # disabled however sleep configuration is not available:
                # mark this block as complete.
                self.__tracer.debug("sleep mode unsupported and SM_DISABLED" + 
                                    " given, block complete.")
                return AbstractXBeeConfigBlockDDO.apply_config(self)
            else:
                # We are unable to apply this block, mark it as a
                # block application failure:
                self.__tracer.warning("sleep mode unsupported" +
                                   " but sleep parameters given," + 
                                   " block FAILED. Please disable " +
                                   "sleeping on this" +
                                   " device.")
                return False

        # Configure the node:                
        pending_mnemonics = self.__pending_parameters.keys()
        for mnemonic in pending_mnemonics:
            # NOTE: this message is duplicated in the XBeeConfigBlockDDO source
            self.__tracer.debug("Apply_config: trying '%s' = '%s' to '%s'",
                             mnemonic,
                             format_hexrepr(
                                 self.__pending_parameters[mnemonic]),
                             AbstractXBeeConfigBlockDDO.ext_addr_get(self))
            try:
                AbstractXBeeConfigBlockDDO.configurator_get(self).ddo_set_param(
                    AbstractXBeeConfigBlockDDO.ext_addr_get(self),
                    mnemonic,
                    self.__pending_parameters[mnemonic],
                    retries=DDO_RETRY_ATTEMPTS)
            except Exception, e:
                self.__tracer.error("'%s' = '%s' to '%s' failed (%s)",
                                mnemonic,
                                format_hexrepr(
                                    self.__pending_parameters[mnemonic]),
                                AbstractXBeeConfigBlockDDO.ext_addr_get(self),
                                str(e))
                return False
            del(self.__pending_parameters[mnemonic])