Exemplo n.º 1
0
 def periodicRun(self):
     hasLeg = False
     hasRMB = False
     if self.currentLeg and self.currentLeg.isActive():
         hasLeg = True
         if self.currentLeg.getAnchorDistance() is not None:
             routerInfo = "Anchor watch, from %s, (anchor radius %sm)" % (
                 str(self.currentLeg.getFrom()),
                 str(self.currentLeg.getAnchorDistance()))
         else:
             routerInfo = "from %s, to %s, route=%s, activeWp=%s, approach=%s (approach radius %sm)" % (
                 str(self.currentLeg.getFrom()), str(
                     self.currentLeg.getTo()),
                 self.currentLeg.getRouteName(),
                 self.currentLeg.getCurrentTarget(),
                 self.currentLeg.isApproach(),
                 self.currentLeg.getApproachDistance())
         AVNLog.debug(routerInfo)
         self.setInfo("leg", routerInfo, WorkerStatus.RUNNING)
     try:
         if self.currentLeg is not None and self.currentLeg.getAnchorDistance(
         ) is not None:
             self.computeAnchor()
         else:
             self.startStopAlarm(False, self.ALARMS.anchor)
             self.startStopAlarm(False, self.ALARMS.gps)
             computeRMB = self.getBoolParam("computeRMB")
             computeAPB = self.getBoolParam("computeAPB")
             if computeRMB or computeAPB:
                 hasRMB = self.computeRMB(computeRMB, computeAPB)
     except Exception as e:
         AVNLog.warn("exception in computeRMB %s, retrying",
                     traceback.format_exc())
     try:
         self.computeApproach()
     except:
         AVNLog.warn("exception in computeApproach %s, retrying",
                     traceback.format_exc())
     if (not hasLeg):
         self.setInfo("leg", "no leg", WorkerStatus.INACTIVE)
     if (not hasRMB):
         self.setInfo("autopilot", "no autopilot data",
                      WorkerStatus.INACTIVE)
     try:
         lat = self.navdata.getSingleValue(AVNStore.BASE_KEY_GPS + ".lat")
         lon = self.navdata.getSingleValue(AVNStore.BASE_KEY_GPS + ".lon")
         if lat is not None and lon is not None:
             self.startStopAlarm(False, self.ALARMS.gps)
     except:
         pass
     AVNLog.debug("router main loop")
Exemplo n.º 2
0
 def _publish(self, description: ServiceDescription) -> object:
     if description.group is not None:
         try:
             description.group.Reset()
         except:
             pass
         try:
             description.group.Free()
         except:
             pass
         try:
             description.group = None
             if description.oldKey is not None:
                 self.deleteInfo(description.oldKey)
             else:
                 self.deleteInfo(description.getKey())
         except:
             pass
     if description.name is None or description.name == '':
         return False
     description.group = dbus.Interface(
         dbus.SystemBus().get_object(self.DBUS_NAME,
                                     self.server.EntryGroupNew()),
         self.DBUS_INTERFACE_ENTRY_GROUP)
     timeout = self.getFloatParam('timeout')
     retries = self.getIntParam('maxRetries')
     num = 0
     retry = True
     self.setInfo(description.getKey(), "trying to register",
                  WorkerStatus.STARTED)
     while retry:
         retry = False
         AVNLog.info("trying to register %s for %s",
                     description.currentName, str(self.port))
         try:
             description.group.AddService(self.IF_UNSPEC, self.PROTO_INET,
                                          dbus.UInt32(0),
                                          description.currentName,
                                          description.type,
                                          self.server.GetDomainName(),
                                          self.server.GetHostNameFqdn(),
                                          description.port, '')
             description.group.Commit()
         except Exception as e:
             AVNLog.warn("unable to register avahi service %s, error: %s",
                         description.currentName, str(e))
             if description.retry(retries):
                 retry = True
             continue
         waitTime = timeout * 10
         state = description.group.GetState()
         while state in [
                 self.ENTRY_GROUP_REGISTERING, self.ENTRY_GROUP_UNCOMMITED
         ] and waitTime > 0:
             waitTime -= 1
             time.sleep(0.1)
             state = description.group.GetState()
         if state == self.ENTRY_GROUP_COLLISION:
             if not description.retry(retries):
                 AVNLog.error("max retries reached for %s",
                              description.name)
             else:
                 retry = True
             continue
         if state != self.ENTRY_GROUP_ESTABLISHED:
             try:
                 description.group.Reset()
             except:
                 pass
             description.group = None
             self.setInfo(
                 description.getKey(),
                 "unable to register service, state=%s" % str(state),
                 WorkerStatus.ERROR)
             return False
         description.isRegistered = True
         self.setInfo(description.getKey(), "registered", WorkerStatus.NMEA)
         self.hostname = self.server.GetHostNameFqdn()
         return True
     self.setInfo(description.getKey(),
                  "unable to register service after retries",
                  WorkerStatus.ERROR)
     return False