Exemplo n.º 1
0
    def _retry_read(self):
        """Retry read connections. Intended to be called by
    _connect_rover_fired.

    """
        i = 0
        repeats = 5
        _rover_pragma = self.rover_pragma
        while self.http and not self.http.connect_read(pragma=_rover_pragma):
            print "Attempting to read observation from Skylark..."
            time.sleep(0.1)
            i += 1
            if i >= repeats:
                msg = (
                    "\nUnable to receive observations from Skylark!\n\n"
                    "Please check that:\n"
                    " - you have a network connection\n"
                    " - your Piksi has a single-point position\n"
                    " - a Skylark-connected Piksi receiver \n   is nearby (within 5km)"
                )
                self._prompt_networking_error(msg)
                self.http.read_close()
                return
        print "Connected as a rover!"
        with Handler(Framer(self.http.read, self.http.write)) as net_link:
            self.net_link = net_link
            self.fwd = Forwarder(net_link, swriter(self.link))
            self.fwd.start()
            while True:
                time.sleep(1)
                if not net_link.is_alive():
                    sys.stderr.write(
                        "Network observation stream disconnected!")
                    break
Exemplo n.º 2
0
  def _retry_read(self):
    """Retry read connections. Intended to be called by
    _connect_rover_fired.

    """
    i = 0
    repeats = 5
    _rover_pragma = self.rover_pragma
    while self.http and not self.http.connect_read(pragma=_rover_pragma):
      print "Attempting to read observation from Skylark..."
      time.sleep(0.1)
      i += 1
      if i >= repeats:
        msg = ("\nUnable to receive observations from Skylark!\n\n"
               "Please check that:\n"
               " - you have a network connection\n"
               " - your Piksi has a single-point position\n"
               " - a Skylark-connected Piksi receiver \n   is nearby (within 5km)")
        self._prompt_networking_error(msg)
        self.http.read_close()
        return
    print "Connected as a rover!"
    with Handler(Framer(self.http.read, self.http.write)) as net_link:
      self.net_link = net_link
      self.fwd = Forwarder(net_link, swriter(self.link))
      self.fwd.start()
      while True:
        time.sleep(1)
        if not net_link.is_alive():
          sys.stderr.write("Network observation stream disconnected!")
          break
Exemplo n.º 3
0
    def _retry_read(self):
        """Retry read connections. Intended to be called by
    _connect_rover_fired.

    """
        i = 0
        repeats = 5
        _rover_pragma = self.rover_pragma
        _rover_device_uid = self.rover_device_uid or self.device_uid
        while self.http and not self.http.connect_read(
                device_uid=_rover_device_uid, pragma=_rover_pragma):
            print "Attempting to read observation from Skylark..."
            time.sleep(0.1)
            i += 1
            if i >= repeats:
                msg = (
                    "\nUnable to receive observations from Skylark!\n\n"
                    "Please check that:\n"
                    " - you have a network connection\n"
                    " - your Piksi has a single-point position\n"
                    " - a Skylark-connected Piksi receiver \n   is nearby (within 5km)"
                )
                self._prompt_networking_error(msg)
                self.http.read_close()
                return
        print "Connected as a rover!"
        with Handler(Framer(self.http.read, self.http.write)) as net_link:
            self.net_link = net_link
            self.fwd = Forwarder(net_link, swriter(self.link))
            self.fwd.start()
            while True:
                time.sleep(1)
                if not net_link.is_alive():
                    sys.stderr.write(
                        "Network observation stream disconnected!")
                    break
        # Unless the user has initiated a reconnection, assume here that the rover
        # still wants to be connected, so if we break out of the handler loop,
        # cleanup rover connection and try reconnecting.
        if self.connected_rover:
            sys.stderr.write("Going for a networking reconnection!")
            self._disconnect_rover_fired()
            self._connect_rover_fired()
Exemplo n.º 4
0
        print "No serial device selected!"
        sys.exit(1)
    else:
        print "Using serial device '%s'" % port

with s.get_driver(args.ftdi, port, baud) as driver:
    with sbpc.Handler(sbpc.Framer(driver.read, driver.write, args.verbose)) as link:
        if os.path.isdir(log_filename):
            log_filename = os.path.join(log_filename, s.LOG_FILENAME)
        with s.get_logger(args.log, log_filename) as logger:
            if args.reset:
                link(MsgReset())
            link.add_callback(logger)
            log_filter = DEFAULT_LOG_LEVEL_FILTER
            if args.initloglevel[0]:
                log_filter = args.initloglevel[0]
            if base and use_broker:
                device_id = get_uuid(channel, serial_id)
                with HTTPDriver(str(device_id), base) as http_driver:
                    with sbpc.Handler(sbpc.Framer(http_driver.read, None, args.verbose)) as slink:
                        slink.add_callback(swriter(link))
                        SwiftConsole(link, args.update, log_filter, False).configure_traits()
            else:
                SwiftConsole(link, args.update, log_filter, False).configure_traits()

# Force exit, even if threads haven't joined
try:
    os._exit(0)
except:
    pass
Exemplo n.º 5
0
with s.get_driver(args.ftdi, port, baud) as driver:
    with sbpc.Handler(sbpc.Framer(driver.read, driver.write,
                                  args.verbose)) as link:
        if os.path.isdir(log_filename):
            log_filename = os.path.join(log_filename, s.LOG_FILENAME)
        with s.get_logger(args.log, log_filename) as logger:
            if args.reset:
                link(MsgReset())
            link.add_callback(logger)
            log_filter = DEFAULT_LOG_LEVEL_FILTER
            if args.initloglevel[0]:
                log_filter = args.initloglevel[0]
            if base and use_broker:
                device_id = get_uuid(channel, serial_id)
                with HTTPDriver(str(device_id), base) as http_driver:
                    with sbpc.Handler(
                            sbpc.Framer(http_driver.read, None,
                                        args.verbose)) as slink:
                        slink.add_callback(swriter(link))
                        SwiftConsole(link, args.update, log_filter,
                                     False).configure_traits()
            else:
                SwiftConsole(link, args.update, log_filter,
                             False).configure_traits()

# Force exit, even if threads haven't joined
try:
    os._exit(0)
except:
    pass
Exemplo n.º 6
0
  def connect(self, link, read_config):
    """Retry read connections. Intended to be called when thread started
    Only shared resource here is the self.link
    Parameters
    ----------
    link : SbpHandler
    read_config :  SkylarkConsoleConnectConfig object 
    
    Returns
    ----------
    ret : int
       0 if exited normally by thread stopping
      -1 if unable to connect as base station
      -2 if unable to connect as rover
      -3 if we lost our net connection to skylark (we restart in this case unless stopped)

    """
    assert isinstance(read_config, SkylarkConsoleConnectConfig)
    self._connect_time = time.time()
    if self.verbose:
      print(("SkylarkWatchdogThread connection attempted at time {0} with parameters {1}".format(
                 self.get_connect_time(), read_config))) 
    i = 0
    repeats = 5
    http = HTTPDriver(device_uid=read_config.base_uuid, url=read_config.skylark_url)
    if not http.connect_write(link, read_config.whitelist, pragma=read_config.base_pragma):
        msg = ("\nUnable to connect to Skylark!\n\n" + 
               "Please check that you have a network connection.")
        self._prompt_networking_error(msg)
        http.close()
        self.stop()
        return -1 # unable to connect as base
    time.sleep(1)

    # If we get here, we were able to connect as a base
    print("Attempting to read observation from Skylark...")
    while (not self.stopped() and http 
           and not http.connect_read(device_uid=read_config.rover_uuid, pragma=read_config.rover_pragma)):
      time.sleep(0.1)
      i += 1
      if i >= repeats:
        msg = ("\nUnable to receive observations from Skylark!\n\n"
               "Please check that:\n"
               " - you have a network connection\n"
               " - your Piksi has a single-point position\n"
               " - a Skylark-connected Piksi receiver \n   is nearby (within 5km)")
        self._prompt_networking_error(msg)
        http.close()
        self.stop()
        return -2 # Unable to connect as rover

    # If we get here, we were able to connect as rover
    print("Connected as a rover!")
    with Handler(Framer(http.read, http.write)) as net_link:
      fwd = Forwarder(net_link, swriter(link))
      if self.verbose:
        print("Starting forwarder")
      fwd.start()
      # now we sleep until we stop the thread or our http handler dies
      while not self.stopped() and net_link.is_alive():
          time.sleep(0.1)

    # when we leave this loop, we are no longer connected to skylark so the fwd should be stopped
    if self.verbose:
      print("Stopping forwarder")
    fwd.stop()
    if self.verbose:
      print("Stopping HTTPDriver")
    http.close() 
    # now manage the return code
    if self.stopped():
      return 0 # If we stop from the event, it it intended and we return 0
    else:
      return -3 # Lost connection
Exemplo n.º 7
0
    def connect(self, link, read_config):
        """Retry read connections. Intended to be called when thread started
        Only shared resource here is the self.link
        Parameters
        ----------
        link : SbpHandler
        read_config :  HttpConsoleConnectConfig object

        Returns
        ----------
        ret : int
           0 if exited normally by thread stopping
          -1 if unable to connect as base station
          -2 if unable to connect as rover
          -3 if we lost our network connection (we restart in this case unless stopped)

        """
        assert isinstance(read_config, HttpConsoleConnectConfig)
        self._connect_time = time.time()
        if self.verbose:
            print(
                "HttpWatchdogThread connection attempted at time {0} with parameters {1}".
                format(self.get_connect_time(), read_config))
        i = 0
        repeats = 5
        http = HTTPDriver(
            device_uid=read_config.base_uuid, url=read_config.url)
        if not http.connect_write(
                link, read_config.whitelist, pragma=read_config.base_pragma):
            msg = ("\nUnable to connect!\n\n" +
                   "Please check that you have a network connection.")
            self._prompt_networking_error(msg)
            http.close()
            self.stop()
            return -1  # unable to connect as base
        time.sleep(1)

        # If we get here, we were able to connect as a base
        print("Attempting to read observations ...")
        while (not self.stopped() and http and not http.connect_read(
                device_uid=read_config.rover_uuid,
                pragma=read_config.rover_pragma)):
            time.sleep(0.1)
            i += 1
            if i >= repeats:
                msg = ("\nUnable to receive observations!\n\n"
                       "Please check that:\n"
                       " - you have a network connection\n"
                       " - your Piksi has a single-point position\n"
                       " - your Piksi has sent its settings to the console")
                self._prompt_networking_error(msg)
                http.close()
                self.stop()
                return -2  # Unable to connect as rover

        # If we get here, we were able to connect as rover
        print("Connected as a rover!")
        with Handler(Framer(http.read, http.write)) as net_link:
            fwd = Forwarder(net_link, swriter(link))
            if self.verbose:
                print("Starting forwarder")
            fwd.start()
            # now we sleep until we stop the thread or our http handler dies
            while not self.stopped() and net_link.is_alive():
                time.sleep(0.1)

        # when we leave this loop, we are no longer connected so the fwd should be stopped
        if self.verbose:
            print("Stopping forwarder")
        fwd.stop()
        if self.verbose:
            print("Stopping HTTPDriver")
        http.close()
        # now manage the return code
        if self.stopped():
            return 0  # If we stop from the event, it it intended and we return 0
        else:
            return -3  # Lost connection