def gw_extended_address_tuple(): """\ Retrieves the 64-bit address of the gateway. Returns a tuple of two byte strings, most significant word first. """ global cached_gw_address_tuple if not cached_gw_address_tuple: sh = retry_ddo_get_param(3, None, 'SH') sl = retry_ddo_get_param(3, None, 'SL') cached_gw_address_tuple = (sh, sl) return cached_gw_address_tuple
def ddo_get_param(self, dest, param, timeout=GLOBAL_DDO_TIMEOUT, retries=3, use_cache=False): """\ Work with the XBee Device Manager Configurator to schedule a pending DDO get request. Working with the manager--as opposed to performing a request directly with xbee.ddo_get_param--ensures that requests are scheduled in an optimal manner. If use_cache is True, the parameter will first be sought in the DDO parameter cache. If the parameter is not found in the cache it will be set from a successful network request. Returns the DDO parameter value. """ result = None if use_cache: try: result = \ self.__xbee_device_manager._xbee_device_ddo_param_cache_get( dest, param) # Non-fatal exception - Just a cache miss. except XBeeDDOParamCacheMissNodeNotFound: pass # Non-fatal exception - Just a cache miss. except XBeeDDOParamCacheMissParamNotFound: pass except: raise if result is not None: return result self.__ddo_semaphore.acquire() try: result = retry_ddo_get_param(retries, dest, param, timeout) # Update the parameter cache: self.__xbee_device_manager._xbee_device_ddo_param_cache_set( dest, param, result) finally: self.__ddo_semaphore.release() return result
def ddo_get_param(self, dest, param, timeout=GLOBAL_DDO_TIMEOUT, retries=3, use_cache=False, blocking=True): """ Work with the XBee Device Manager Configurator to schedule a pending DDO get request. Working with the manager--as opposed to performing a request directly with xbee.ddo_get_param--ensures that requests are scheduled in an optimal manner. If use_cache is True, the parameter will first be sought in the DDO parameter cache. If the parameter is not found in the cache it will be set from a successful network request. Returns the DDO parameter value. Returns False if blocking=False and the method would block. Note: if blocking calls are used in a Digimesh network, they could block for an entire sleep period. """ result = None if use_cache: try: result = \ self.__xbee_device_manager._xbee_device_ddo_param_cache_get( dest, param) # Non-fatal exception - Just a cache miss. except XBeeDDOParamCacheMissNodeNotFound: pass # Non-fatal exception - Just a cache miss. except XBeeDDOParamCacheMissParamNotFound: pass except: raise if result is not None: return result if dest is not None: if blocking: # block until awake while not self.__xbee_device_manager._awakeEvent.isSet(): # kill signal if not self.__running: return False self.__xbee_device_manager._awakeEvent.wait(MAX_BLOCK) else: # in non-blocking, if the node is not awake, simply # return False if not self.__xbee_device_manager._awakeEvent.isSet(): return False blocked = self.__ddo_semaphore.acquire(blocking=blocking) if not blocked: # didn't want to block return False # HACK: wait for running network discovery call to finish while not self.__xbee_device_manager.NETWORK_DISCOVER_HACK.isSet(): # killed if not self.__running: return False self.__xbee_device_manager.NETWORK_DISCOVER_HACK.wait(MAX_BLOCK) try: result = retry_ddo_get_param(retries, dest, param, timeout) # Update the parameter cache: self.__xbee_device_manager._xbee_device_ddo_param_cache_set( dest, param, result) finally: self.__ddo_semaphore.release() return result