コード例 #1
0
    def __check_if_device_is_already_in_system(self, new_address):
        """\
            Attempt to determine if the detected device is already
            configured or in purgatory.

            Parameters:
                * **new_address**: The XBee address of the new device.

            Return type:
                * bool

        """
        device_list = self.__generate_running_xbee_devices_list()

        # Search the device list to see if this is a device
        # we already know about...
        for device in device_list:
            try:
                existing_address = device.get_setting("extended_address")
            except Exception, e:
                # print e
                # print device
                continue

            if existing_address == None or existing_address == '':
                continue

            new_address = normalize_address(new_address)
            existing_address = normalize_address(existing_address)
            if existing_address == new_address:
                #print "XBeeAutoEnum: __check_if_device_is_already_in_system -"\
                #      " DUPLICATE %s not re-adding." % (new_address)
                return True
コード例 #2
0
    def __check_if_device_is_already_in_system(self, new_address):
        """\
            Attempt to determine if the detected device is already
            configured or in purgatory.

            Parameters:
                * **new_address**: The XBee address of the new device.

            Return type:
                * bool

        """
        device_list = self.__generate_running_xbee_devices_list()

        # Search the device list to see if this is a device
        # we already know about...
        for device in device_list:
            try:
                existing_address = device.get_setting('extended_address')
            except Exception, e:
                # print e
                # print device
                continue

            if existing_address == None or existing_address == '':
                continue

            new_address = normalize_address(new_address)
            existing_address = normalize_address(existing_address)
            if existing_address == new_address:
                #print "XBeeAutoEnum:
                #      __check_if_device_is_already_in_system -"\ "
                #      DUPLICATE %s not re-adding." % (new_address)
                return True
コード例 #3
0
    def __init__(self, ext_addr):
        """\
        Instantiate a :py:class:`XBeeConfigBlock`.
        
        Parameters:
            * **ext_addr**: the extended address of the node to which this
                            configuration will be applied.

        """

        ## State information:
        # The extended address of the target node to be configured:
        self.__ext_addr = ext_addr
        # A reference to the appropriate XBeeDeviceManagerConfigurator:
        self.__configurator = None
        # Applicable/un-applicable modules identifiers:
        self.__modules = ( )
        # Applicable/un-applicable product identifiers:
        self.__products = ( )
        # Applicability modes:
        self.__module_applicability = self.APPLICABILITY_ALL
        self.__product_applicability = self.APPLICABILITY_ALL

        if self.__ext_addr != None:
            self.__ext_addr = normalize_address(ext_addr)

        # Initialization:
        self.reset()
コード例 #4
0
    def cache_set(self, addr_extended, param, value):
        '''
        Set a value to the cache.
        
        If `value` is None the cached value will be invalidated for
        `addr_extended`.
        
        If `value` is given as an integer it will be packed to a 16-bit
        big-endian ordered byte string.  This is to mimic the return
        value of ddo_get_param when values are retrieved from the cache.
        
        :param addr_extended: a valid XBee extended address string
        :param param: a two letter mnemonic string of a DDO parameter
        :param value: a string or integer
        :rtype: None
        '''
        addr_extended = normalize_address(addr_extended)
        param = param.upper()
        if addr_extended not in self.__ddo_param_cache:
            self.__ddo_param_cache[addr_extended] = {}
        
        if value is None:
            self.cache_invalidate(addr_extended, param)
        else:
            if isinstance(value, int):
                if value <= 0xffff:
                    value = struct.pack(">H", value)
                else:
                    # try to mimic 4 byte return value for large items
                    value = struct.pack(">I", value)

            self._tracer.debug("CACHE STORE: cached '%s' = %s for '%s'" % (
                               param, repr(value), addr_extended))
            self.__ddo_param_cache[addr_extended][param] = value
コード例 #5
0
    def cache_get(self, addr_extended, param):
        '''
        Retrieve a value from the cache.
        
        :raises XBeeDDOParamCacheMissNodeNotFound: if the node is not in the
                                                   cache.
        :raises XBeeDDOParamCacheMissParamNotFound: if the parameter does not
                                                    exist in the cache for the
                                                    given node address.
        :param addr_extended: a valid XBee extended address string
        :param param: a two letter mnemonic string of a DDO parameter
        :retval: returns the cached parameter value as a string
        '''
        addr_extended = normalize_address(addr_extended)
        if addr_extended not in self.__ddo_param_cache:
            self._tracer.debug("CACHE MISS param '%s' addr '%s'"
                               "reason: node not found" % (
                                   param, addr_extended))
            raise XBeeDDOParamCacheMissNodeNotFound()
        
        if param not in self.__ddo_param_cache[addr_extended]:
            self._tracer.debug("CACHE MISS param '%s' addr '%s'"
                               "reason: param not found" % (
                                   param, addr_extended))
            raise XBeeDDOParamCacheMissParamNotFound()

        self._tracer.debug("CACHE HIT: '%s' = %s for '%s'" % (
            param, repr(self.__ddo_param_cache[addr_extended][param]),
            addr_extended))
        
        return self.__ddo_param_cache[addr_extended][param]
コード例 #6
0
    def cache_invalidate(self, addr_extended, param=None):
        '''
        Invalidate a portion of the cache.

        If `addr_extended` is given and `param` is None, all parameters
        for `addr_extended` will be invalidated.
        
        If `param` is not None and it is a valid two-letter DDO mnemonic,
        only that parameter will be invalidated from the cache for the
        node given by `addr_extended`. 
        
        :raises XBeeDDOParamCacheMissNodeNotFound: if `addr_extended` is not
                                                   found in the cache.       
        :param addr_extended: a valid XBee extended address string
        :param param: a two letter mnemonic string of a DDO parameter
        :rtype: None
        '''
        addr_extended = normalize_address(addr_extended)
        param = param.upper()
        if addr_extended not in self.__ddo_param_cache:
            raise XBeeDDOParamCacheMissNodeNotFound
        
        if param is None:
            del(self.__ddo_param_cache[addr_extended])
            
        if param not in self.__ddo_param_cache[addr_extended]:
            # no-op
            return
        
        del(self.__ddo_param_cache[addr_extended][param])
コード例 #7
0
    def cache_set(self, addr_extended, param, value):
        """\
        Set a value to the cache.
        
        If `value` is None the cached value will be invalidated for
        `addr_extended`.
        
        If `value` is given as an integer it will be packed to a 16-bit
        big-endian ordered byte string.  This is to mimic the return
        value of ddo_get_param when values are retrieved from the cache.
        
        :param addr_extended: a valid XBee extended address string
        :param param: a two letter mnemonic string of a DDO parameter
        :param value: a string or integer
        :rtype: None
        """
        addr_extended = normalize_address(addr_extended)
        param = param.upper()
        if addr_extended not in self.__ddo_param_cache:
            self.__ddo_param_cache[addr_extended] = { }
        
        if value is None:
            self.cache_invalidate(addr_extended, param)
        else:
            if isinstance(value, int):
                value = struct.pack(">H", value)

# TODO: change to become trace message
#            print "CACHE STORE: cached '%s' = %s for '%s'" % (
#                    param, repr(value), addr_extended)
            self.__ddo_param_cache[addr_extended][param] = value
コード例 #8
0
    def cache_get(self, addr_extended, param):
        """\
        Retrieve a value from the cache.
        
        :raises XBeeDDOParamCacheMissNodeNotFound: if the node is not in the
                                                   cache.
        :raises XBeeDDOParamCacheMissParamNotFound: if the parameter does not
                                                    exist in the cache for the
                                                    given node address.
        :param addr_extended: a valid XBee extended address string
        :param param: a two letter mnemonic string of a DDO parameter
        :retval: returns the cached parameter value as a string
        """
        addr_extended = normalize_address(addr_extended)
        if addr_extended not in self.__ddo_param_cache:
# TODO: change to trace message            
#            print "CACHE MISS param '%s' addr '%s' reason: MOE" % (
#                    param, addr_extended)
            raise XBeeDDOParamCacheMissNodeNotFound
        
        if param not in self.__ddo_param_cache[addr_extended]:
# TODO: change to trace message            
#            print "CACHE MISS param '%s' addr '%s' reason: LARRY" % (
#                    param, addr_extended)
            raise XBeeDDOParamCacheMissParamNotFound

# TODO: change to trace message
#        print "CACHE HIT: '%s' = %s for '%s'" % (
#                param, repr(self.__ddo_param_cache[addr_extended][param]), addr_extended)    
        
        return self.__ddo_param_cache[addr_extended][param]
コード例 #9
0
    def cache_invalidate(self, addr_extended, param=None):
        """\
        Invalidate a portion of the cache.

        If `addr_extended` is given and `param` is None, all parameters
        for `addr_extended` will be invalidated.
        
        If `param` is not None and it is a valid two-letter DDO mnemonic,
        only that parameter will be invalidated from the cache for the
        node given by `addr_extended`. 
        
        :raises XBeeDDOParamCacheMissNodeNotFound: if `addr_extended` is not
                                                   found in the cache.       
        :param addr_extended: a valid XBee extended address string
        :param param: a two letter mnemonic string of a DDO parameter
        :rtype: None
        """
        
        addr_extended = normalize_address(addr_extended)
        param = param.upper()
        if addr_extended not in self.__ddo_param_cache:
            raise XBeeDDOParamCacheMissNodeNotFound
        
        if param is None:
            del(self.__ddo_param_cache[addr_extended])
            
        if param not in self.__ddo_param_cache[addr_extended]:
            # no-op
            return
        
        del(self.__ddo_param_cache[addr_extended][param])
コード例 #10
0
    def __init__(self, ext_addr):
        """
        Instantiate a :py:class:`XBeeConfigBlock`.

        Parameters:
            * **ext_addr**: the extended address of the node to which this
                            configuration will be applied.

        """

        ## State information:
        # The extended address of the target node to be configured:
        self._ext_addr = ext_addr
        # A reference to the appropriate XBeeDeviceManagerConfigurator:
        self.__configurator = None
        # Applicable/un-applicable modules identifiers:
        self.__modules = ( )
        # Applicable/un-applicable product identifiers:
        self.__products = ( )
        # Applicability modes:
        self.__module_applicability = self.APPLICABILITY_ALL
        self.__product_applicability = self.APPLICABILITY_ALL

        if self._ext_addr != None:
            self._ext_addr = normalize_address(ext_addr)

        # Initialization:
        self.reset()