Пример #1
0
 def get_own_state(self, monitoruri):
     '''
     Gets the master info from local master discovery and set it to all sync threads.
     This function is running in a thread!!!
     '''
     try:
         socket.setdefaulttimeout(3)
         own_monitor = xmlrpclib.ServerProxy(monitoruri)
         self.__own_state = own_monitor.masterInfo()
         own_state = MasterInfo.from_list(self.__own_state)
         socket.setdefaulttimeout(None)
         with self.__lock:
             # update the state for all sync threads
             for (_, s) in self.masters.iteritems():
                 s.set_own_masterstate(own_state,
                                       self.__sync_topics_on_demand)
             self.__timestamp_local = own_state.timestamp_local
     except:
         import traceback
         rospy.logwarn("ERROR while getting own state from '%s': %s",
                       monitoruri, traceback.format_exc())
         socket.setdefaulttimeout(None)
         time.sleep(3)
         if self.own_state_getter is not None and not rospy.is_shutdown():
             self.own_state_getter = threading.Thread(
                 target=self.get_own_state, args=(monitoruri, ))
             self.own_state_getter.start()
Пример #2
0
 def update_master(self, mastername, masteruri, timestamp, timestamp_local,
                   discoverer_name, monitoruri, online):
     '''
     Updates the timestamp of the given ROS master, or creates a new L{SyncThread} to
     synchronize the local master with given ROS master.
     @param mastername: the name of the remote ROS master to update or synchronize.
     @type mastername: C{str}
     @param masteruri: the URI of the remote ROS master.
     @type masteruri: C{str}
     @param timestamp: the timestamp of the remote ROS master.
     @type timestamp: C{float64}
     @param timestamp_local: the timestamp of the remote ROS master. (only local changes)
     @type timestamp_local: C{float64}
     @param discoverer_name: the name of the remote master_discoverer node
     @type discoverer_name: C{str}
     @param monitoruri: the URI of the RPC interface of the remote master_discoverer node.
     @type monitoruri: C{str}
     @param online: the current state on the master.
     @type online: C{bool}
     '''
     try:
         with self.__lock:
             if (masteruri != self.materuri):
                 if self._can_sync(mastername):
                     # do not sync to the master, if it is in ignore list
                     if self.__resync_on_reconnect and mastername in self.masters:
                         self.masters[mastername].set_online(
                             online, self.__resync_on_reconnect_timeout)
                     if online:
                         if mastername in self.masters:
                             # updates only, if local changes are occured
                             self.masters[mastername].update(
                                 mastername, masteruri, discoverer_name,
                                 monitoruri, timestamp_local)
                         else:
                             self.masters[mastername] = SyncThread(
                                 mastername, masteruri, discoverer_name,
                                 monitoruri, 0.0,
                                 self.__sync_topics_on_demand)
                             if self.__own_state is not None:
                                 self.masters[
                                     mastername].set_own_masterstate(
                                         MasterInfo.from_list(
                                             self.__own_state))
                             self.masters[mastername].update(
                                 mastername, masteruri, discoverer_name,
                                 monitoruri, timestamp_local)
             elif self.__timestamp_local != timestamp_local and self.__sync_topics_on_demand:
                 # get the master info from local discovery master and set it to all sync threads
                 self.own_state_getter = threading.Thread(
                     target=self.get_own_state, args=(monitoruri, ))
                 self.own_state_getter.start()
     except:
         import traceback
         rospy.logwarn("ERROR while update master[%s]: %s", str(mastername),
                       traceback.format_exc())
Пример #3
0
 def run(self):
     '''
     '''
     try:
         delay = self._delayed_exec + 0.5 + random.random()
         # 'print "wait request update", self._monitoruri, delay
         time.sleep(delay)
         # 'print "request update", self._monitoruri
         socket.setdefaulttimeout(25)
         remote_monitor = xmlrpcclient.ServerProxy(self._monitoruri)
         # get first master errors
         try:
             muri, errors = remote_monitor.masterErrors()
             self.master_errors_signal.emit(muri, errors)
         except xmlrpcclient.Fault as _err:
             rospy.logwarn(
                 "Older master_discovery on %s detected. It does not support master error reports!"
                 % self._masteruri)
         # get the time difference
         try:
             myts = time.time()
             muri, remote_ts = remote_monitor.getCurrentTime()
             self.timediff_signal.emit(
                 muri, remote_ts - myts - (time.time() - myts) / 2.0)
         except xmlrpcclient.Fault as _errts:
             rospy.logwarn(
                 "Older master_discovery on %s detected. It does not support getCurrentTime!"
                 % self._masteruri)
         # get the user name
         try:
             muri, username = remote_monitor.getUser()
             self.username_signal.emit(muri, username)
         except xmlrpcclient.Fault as _errts:
             rospy.logwarn(
                 "Older master_discovery on %s detected. It does not support getUser!"
                 % self._masteruri)
         # now get master info from master discovery
         remote_info = remote_monitor.masterInfo()
         master_info = MasterInfo.from_list(remote_info)
         master_info.check_ts = time.time()
         # 'print "request success", self._monitoruri
         self.update_signal.emit(master_info)
     except Exception:
         import traceback
         #      print traceback.print_exc()
         formatted_lines = traceback.format_exc(1).splitlines()
         rospy.logwarn(
             "Cannot update ROS state, connection to %s failed:\n\t%s",
             utf8(self._monitoruri), formatted_lines[-1])
         # 'print "request failed", self._monitoruri
         self.error_signal.emit(self._masteruri, formatted_lines[-1])
     finally:
         if socket is not None:
             socket.setdefaulttimeout(None)