Beispiel #1
0
def main():
    """
  Get configuration, get driver, and build handler and start it.
  """
    args = get_args()
    port = args.port[0]
    baud = args.baud[0]
    use_ftdi = args.ftdi
    # Driver with context
    with serial_link.get_driver(use_ftdi, port, baud) as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write)) as link:
            link.add_callback(serial_link.log_printer, SBP_MSG_LOG)
            link.add_callback(serial_link.printer, SBP_MSG_PRINT_DEP)

            data = open(args.file, 'rb').read()

            def progress_cb(size):
                sys.stdout.write("\rProgress: %d%%    \r" %
                                 (100 * size / len(data)))
                sys.stdout.flush()

            print('Transferring image file...')
            FileIO(link).write("upgrade.image_set.bin",
                               data,
                               progress_cb=progress_cb)
            print('Committing file to flash...')
            code = shell_command(link, "upgrade_tool upgrade.image_set.bin",
                                 300)
            if code != 0:
                print('Failed to perform upgrade (code = %d)' % code)
                return
            print('Resetting Piksi...')
            link(MsgReset(flags=0))
Beispiel #2
0
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  use_ftdi = args.ftdi
  # Driver with context
  with serial_link.get_driver(use_ftdi, port, baud) as driver:
    # Handler with context
    with Handler(Framer(driver.read, driver.write)) as link:
      link.add_callback(serial_link.log_printer, SBP_MSG_LOG)
      link.add_callback(serial_link.printer, SBP_MSG_PRINT_DEP)

      data = open(args.file).read()
      def progress_cb(size):
          sys.stdout.write("\rProgress: %d%%    \r" % (100 * size / len(data)))
          sys.stdout.flush();
      print('Transferring image file...')
      FileIO(link).write("upgrade.image_set.bin", data, progress_cb=progress_cb)
      print('Committing file to flash...')
      code = shell_command(link, "upgrade_tool upgrade.image_set.bin", 300)
      if code != 0:
        print('Failed to perform upgrade (code = %d)' % code)
        return
      print('Resetting Piksi...')
      link(MsgReset(flags=0))
Beispiel #3
0
def main():
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    # Handler with context
    with Handler(driver.read, driver.write, args.verbose) as link:
      f = FileIO(link)

      try:
        if args.read:
          data = f.read(args.read[0])
          if args.hex:
            print hexdump(data)
          else:
            print data
        elif args.delete:
          f.remove(args.delete[0])
        elif args.list is not None:
          print_dir_listing(f.readdir(args.list[0]))
        else:
          print "No command given, listing root directory:"
          print_dir_listing(f.readdir())
      except KeyboardInterrupt:
        pass
Beispiel #4
0
def main():
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    # Handler with context
    with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
      f = FileIO(link)

      try:
        if args.read:
          data = f.read(args.read[0])
          if args.hex:
            print hexdump(data)
          else:
            print data
        elif args.delete:
          f.remove(args.delete[0])
        elif args.list is not None:
          print_dir_listing(f.readdir(args.list[0]))
        else:
          print "No command given, listing root directory:"
          print_dir_listing(f.readdir())
      except KeyboardInterrupt:
        pass
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    # Handler with context
    with Handler(Framer(driver.read, driver.write)) as link:
      print "Resetting mask to 0xff"
      send_setting(link, "uart_ftdi", "sbp_message_mask", "65535")
      time.sleep(0.5)

      print "Resetting baudrate to 1Mbps"
      send_setting(link, "uart_ftdi", "baudrate", "1000000")
      time.sleep(0.5)

      print "Resetting mode to SBP"
      send_setting(link, "uart_ftdi", "mode", "SBP")
      time.sleep(0.5)

      print "Attempting to save settings"
      link.send(SBP_MSG_SETTINGS_SAVE, "")
      time.sleep(0.5)
      link.send(SBP_MSG_SETTINGS_SAVE, "")
      time.sleep(0.5)
      link.send(SBP_MSG_SETTINGS_SAVE, "")
      time.sleep(0.5)
      link.send(SBP_MSG_SETTINGS_SAVE, "")

      print "Sent Settings Reset message to return FTDI to defaults"
Beispiel #6
0
def main():
    """
  Get configuration, get driver, and build handler and start it.
  """
    port = args.port[0]
    baud = args.baud[0]
    # Driver with context
    with serial_link.get_driver(args.ftdi, port, baud) as driver:
        # Handler with context
        with Handler(driver.read, driver.write) as link:
            print "Resetting mask to 0xff"
            send_setting(link, "uart_ftdi", "sbp_message_mask", "65535")
            time.sleep(0.5)

            print "Resetting baudrate to 1Mbps"
            send_setting(link, "uart_ftdi", "baudrate", "1000000")
            time.sleep(0.5)

            print "Resetting mode to SBP"
            send_setting(link, "uart_ftdi", "mode", "SBP")
            time.sleep(0.5)

            print "Attempting to save settings"
            link.send(SBP_MSG_SETTINGS_SAVE, "")
            time.sleep(0.5)
            link.send(SBP_MSG_SETTINGS_SAVE, "")
            time.sleep(0.5)
            link.send(SBP_MSG_SETTINGS_SAVE, "")
            time.sleep(0.5)
            link.send(SBP_MSG_SETTINGS_SAVE, "")

            print "Sent Settings Reset message to return FTDI to defaults"
Beispiel #7
0
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  use_ftdi = args.ftdi
  use_m25 = args.m25
  use_stm = args.stm
  erase = args.erase
  # Driver with context
  with serial_link.get_driver(use_ftdi, port, baud) as driver:
    # Handler with context
    with Handler(Framer(driver.read, driver.write)) as link:
      link.add_callback(serial_link.log_printer, SBP_MSG_LOG)
      link.add_callback(serial_link.printer, SBP_MSG_PRINT_DEP)

      # Tell Bootloader we want to write to the flash.
      with Bootloader(link) as piksi_bootloader:
        print "Waiting for bootloader handshake message from Piksi ...",
        sys.stdout.flush()
        try:
          handshake_received = piksi_bootloader.handshake(args.timeout[0])
        except KeyboardInterrupt:
          return
        if not (handshake_received and piksi_bootloader.handshake_received):
          print "No handshake received."
          sys.exit(1) 
        print "received."
        print "Piksi Onboard Bootloader Version:", piksi_bootloader.version
        if piksi_bootloader.sbp_version > (0, 0):
          print "Piksi Onboard SBP Protocol Version:", piksi_bootloader.sbp_version

        # Catch all other errors and exit cleanly.
        try:
          import flash
          with flash.Flash(link, flash_type=("STM" if use_stm else "M25"),
                           sbp_version=piksi_bootloader.sbp_version) as piksi_flash:
            if erase:
              for s in range(1,12):
                print "\rErasing STM Sector", s,
                sys.stdout.flush()
                piksi_flash.erase_sector(s)
              print

            from intelhex import IntelHex
            ihx = IntelHex(args.file)
            piksi_flash.write_ihx(ihx, sys.stdout, mod_print=0x10)

            print "Bootloader jumping to application"
            piksi_bootloader.jump_to_app()
        except:
          import traceback
          traceback.print_exc()
Beispiel #8
0
def main():
    """
  Get configuration, get driver, and build handler and start it.
  """
    args = get_args()
    port = args.port[0]
    baud = args.baud[0]
    use_ftdi = args.ftdi
    use_m25 = args.m25
    use_stm = args.stm
    erase = args.erase
    # Driver with context
    with serial_link.get_driver(use_ftdi, port, baud) as driver:
        # Handler with context
        with Handler(driver.read, driver.write) as link:
            link.start()
            link.send(SBP_MSG_RESET, "")
            time.sleep(0.2)
            link.add_callback(serial_link.printer, SBP_MSG_PRINT)

            # Tell Bootloader we want to write to the flash.
            with Bootloader(link) as piksi_bootloader:
                print "Waiting for bootloader handshake message from Piksi ...",
                sys.stdout.flush()
                try:
                    piksi_bootloader.wait_for_handshake()
                except KeyboardInterrupt:
                    return
                piksi_bootloader.reply_handshake()
                print "received."
                print "Piksi Onboard Bootloader Version:", piksi_bootloader.version

                # Catch all other errors and exit cleanly.
                try:
                    import flash
                    with flash.Flash(link,
                                     flash_type=("STM" if use_stm else
                                                 "M25")) as piksi_flash:
                        if erase:
                            for s in range(1, 12):
                                print "\rErasing STM Sector", s,
                                sys.stdout.flush()
                                piksi_flash.erase_sector(s)
                            print

                        from intelhex import IntelHex
                        ihx = IntelHex(args.file)
                        piksi_flash.write_ihx(ihx, sys.stdout, mod_print=0x10)

                        print "Bootloader jumping to application"
                        piksi_bootloader.jump_to_app()
                except:
                    import traceback
                    traceback.print_exc()
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with Handler(driver.read, driver.write) as link:
      unique_id = STMUniqueID(link).get_id()
      print "STM Unique ID =", "0x" + ''.join(["%02x" % (b) for b in unique_id])
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with Handler(Framer(driver.read, driver.write)) as link:
      with STMUniqueID(link) as stm_unique_id:
        unique_id = stm_unique_id.get_id()
      print "STM Unique ID =", "0x" + ''.join(["%02x" % (b) for b in unique_id])
Beispiel #11
0
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  diagnostics_filename = args.diagnostics_filename[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with Handler(driver.read, driver.write) as link:
      diagnostics = Diagnostics(link).diagnostics
      with open(diagnostics_filename, 'w') as diagnostics_file:
        yaml.dump(diagnostics, diagnostics_file, default_flow_style=False)
Beispiel #12
0
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  diagnostics_filename = args.diagnostics_filename[0]
  # Driver with context
  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with Handler(Framer(driver.read, driver.write)) as link:
      diagnostics = Diagnostics(link).diagnostics
      with open(diagnostics_filename, 'w') as diagnostics_file:
        yaml.dump(diagnostics, diagnostics_file, default_flow_style=False)
        print "wrote diagnostics file"
Beispiel #13
0
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  use_ftdi = args.ftdi
  # Driver with context
  with serial_link.get_driver(use_ftdi, port, baud) as driver:
    # Handler with context
    with Handler(driver.read, driver.write) as link:
      link.add_callback(serial_link.printer, SBP_MSG_PRINT)
      acq_results = AcqResults(link)

      try:
        while True:
          print acq_results
          time.sleep(0.1)
      except KeyboardInterrupt:
        pass
Beispiel #14
0
def main():
    """
  Get configuration, get driver, and build handler and start it.
  """
    args = get_args()
    port = args.port[0]
    baud = args.baud[0]
    use_ftdi = args.ftdi
    # Driver with context
    with serial_link.get_driver(use_ftdi, port, baud) as driver:
        # Handler with context
        with Handler(driver.read, driver.write) as link:
            link.add_callback(serial_link.printer, SBP_MSG_PRINT)
            acq_results = AcqResults(link)
            link.start()

            try:
                while True:
                    print acq_results
                    time.sleep(0.1)
            except KeyboardInterrupt:
                pass
Beispiel #15
0
def main():
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  if args.tcp:
    try:
      host, port = port.split(':')
      selected_driver = TCPDriver(host, int(port))
    except:
      raise Exception('Invalid host and/or port')
  else:
    selected_driver = serial_link.get_driver(args.ftdi, port, baud)

  # Driver with context
  with selected_driver as driver:
    # Handler with context
    with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
      f = FileIO(link)

      try:
        if args.write:
          f.write(args.write[0], open(args.write[0]).read())
        elif args.read:
          data = f.read(args.read[0])
          if args.hex:
            print hexdump(data)
          else:
            print data
        elif args.delete:
          f.remove(args.delete[0])
        elif args.list is not None:
          print_dir_listing(f.readdir(args.list[0]))
        else:
          print "No command given, listing root directory:"
          print_dir_listing(f.readdir())
      except KeyboardInterrupt:
        pass
Beispiel #16
0
def main():
    args = get_args()
    port = args.port[0]
    baud = args.baud[0]
    if args.tcp:
        try:
            host, port = port.split(':')
            selected_driver = TCPDriver(host, int(port))
        except:
            raise Exception('Invalid host and/or port')
    else:
        selected_driver = serial_link.get_driver(args.ftdi, port, baud)

    # Driver with context
    with selected_driver as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write, args.verbose)) as link:
            f = FileIO(link)

            try:
                if args.write:
                    f.write(args.write[0], open(args.write[0]).read())
                elif args.read:
                    data = f.read(args.read[0])
                    if args.hex:
                        print hexdump(data)
                    else:
                        print data
                elif args.delete:
                    f.remove(args.delete[0])
                elif args.list is not None:
                    print_dir_listing(f.readdir(args.list[0]))
                else:
                    print "No command given, listing root directory:"
                    print_dir_listing(f.readdir())
            except KeyboardInterrupt:
                pass
Beispiel #17
0
def main():
    """
  Get configuration, get driver, and build handler and start it.
  """
    args = get_args()
    port = args.port[0]
    baud = args.baud[0]
    command = args.command

    with serial_link.get_driver(args.ftdi, port, baud) as driver:
        with Handler(Framer(driver.read, driver.write)) as link:
            settings = Settings(link)
            if command == 'write':
                settings.write(args.section, args.setting, args.value)
            elif command == 'read':
                settings.read(args.section, args.setting)
            elif command == 'all':
                settings.read_all()
            elif command == 'save':
                settings.save()
            elif command == 'reset':
                settings.reset()
            # Wait a few seconds for any relevant print messages
            settings.link.wait(MsgLog, 8)
Beispiel #18
0
def main():
  """
  Get configuration, get driver, and build handler and start it.
  """
  args = get_args()
  port = args.port[0]
  baud = args.baud[0]
  command = args.command

  with serial_link.get_driver(args.ftdi, port, baud) as driver:
    with Handler(Framer(driver.read, driver.write)) as link:
      settings = Settings(link)
      if command == 'write':
        settings.write(args.section, args.setting, args.value)
      elif command == 'read':
        settings.read(args.section, args.setting)
      elif command == 'all':
        settings.read_all()
      elif command == 'save':
        settings.save()
      elif command == 'reset':
        settings.reset()
      # Wait a few seconds for any relevant print messages
      settings.link.wait(MsgLog, 8)
Beispiel #19
0
def main():
    """
  Get configuration, get driver, and build handler and start it.
  """
    args = get_args()
    port = args.port[0]
    baud = args.baud[0]
    use_ftdi = args.ftdi
    use_m25 = args.m25
    use_stm = args.stm
    erase = args.erase
    # Driver with context
    with serial_link.get_driver(use_ftdi, port, baud) as driver:
        # Handler with context
        with Handler(Framer(driver.read, driver.write)) as link:
            link.add_callback(serial_link.log_printer, SBP_MSG_LOG)
            link.add_callback(serial_link.printer, SBP_MSG_PRINT_DEP)

            # Tell Bootloader we want to write to the flash.
            with Bootloader(link) as piksi_bootloader:
                print "Waiting for bootloader handshake message from Piksi ...",
                sys.stdout.flush()
                try:
                    handshake_received = piksi_bootloader.handshake(
                        args.timeout[0])
                except KeyboardInterrupt:
                    return
                if not (handshake_received
                        and piksi_bootloader.handshake_received):
                    print "No handshake received."
                    sys.exit(1)
                print "received."
                print "Piksi Onboard Bootloader Version:", piksi_bootloader.version
                if piksi_bootloader.sbp_version > (0, 0):
                    print "Piksi Onboard SBP Protocol Version:", piksi_bootloader.sbp_version

                # Catch all other errors and exit cleanly.
                try:
                    import flash
                    with flash.Flash(
                            link,
                            flash_type=("STM" if use_stm else "M25"),
                            sbp_version=piksi_bootloader.sbp_version,
                            max_queued_ops=int(
                                args.max_queued_ops[0])) as piksi_flash:
                        if erase:
                            for s in range(1, 12):
                                print "\rErasing STM Sector", s,
                                sys.stdout.flush()
                                piksi_flash.erase_sector(s)
                            print

                        from intelhex import IntelHex
                        ihx = IntelHex(args.file)
                        piksi_flash.write_ihx(ihx, sys.stdout, mod_print=0x10)

                        print "Bootloader jumping to application"
                        piksi_bootloader.jump_to_app()
                except:
                    import traceback
                    traceback.print_exc()