示例#1
0
文件: main.go 项目: samofly/cflie
func Main() {
	flags.Parse(flag.Args()[1:])

	log.Printf("Connecting to bootloader, please, restart Crazyflie...")
	dev, info, err := boot.Cold()
	if err != nil {
		log.Fatal(err)
	}
	defer dev.Close()
	log.Printf("Connected to bootloader")
	log.Printf("Info: %+v", info)

	log.Printf("Downloading the contents of Crazyflie Flash memory...")
	var fromPage, toPage int
	if *full {
		toPage = info.FlashPages
	} else {
		fromPage = info.FlashStart
		toPage = boot.ConfigPageIndex
	}
	mem, err := boot.Dump(dev, info, fromPage, toPage)
	if err != nil {
		log.Fatal(err)
	}
	if err = ioutil.WriteFile(*output, mem, 0644); err != nil {
		log.Fatalf("Unable to dump memory to file %s: %v", *output, err)
	}
	log.Printf("OK - Memory dump saved to %s", *output)
}
示例#2
0
文件: main.go 项目: samofly/cflie
func Main() {
	log.Printf("Connecting to bootloader, please, restart Crazyflie...")
	dev, info, err := boot.Cold()
	if err != nil {
		log.Fatal(err)
	}
	defer dev.Close()

	conf, err := boot.ReadConfig(dev, info)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Config block: %+v", conf)
}
示例#3
0
文件: main.go 项目: samofly/cflie
func Main() {
	flags.Parse(flag.Args()[2:])

	log.Printf("Connecting to bootloader, please, restart Crazyflie...")
	dev, info, err := boot.Cold()
	if err != nil {
		log.Fatal(err)
	}
	defer dev.Close()

	conf, err := boot.ReadConfig(dev, info)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Config block: %+v", conf)

	if *channel != 0 {
		if *channel > cflie.MaxChannel {
			log.Fatal("Max channel: %d", cflie.MaxChannel)
		}
		if *channel <= 0 {
			log.Fatal("Channel must be positive")
		}
		conf.Channel = byte(*channel)
	}

	if *speed > 2 {
		log.Fatal("Max speed: 2")
	}
	if *speed >= 0 {
		conf.Speed = byte(*speed)
	}

	if err = boot.WriteConfig(dev, info, conf); err != nil {
		log.Fatal("WriteConfig: ", err)
	}
	log.Printf("Config updated, validating")

	conf2, err := boot.ReadConfig(dev, info)
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("Config block: %+v", conf2)

	if conf != conf2 {
		log.Fatal("Config block update failed. Want: %+v, got: %+v", conf, conf2)
	}
	log.Printf("OK")
}
示例#4
0
文件: main.go 项目: samofly/cflie
func Main() {
	flags.Parse(flag.Args()[1:])
	log.Printf("flags.Args: %+v", flags.Args())

	if *image == "" {
		log.Printf("Error: -image is not specified\n")
		flag.PrintDefaults()
		os.Exit(1)
	}

	data, err := ioutil.ReadFile(*image)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Connecting to bootloader, please, restart Crazyflie...")
	dev, info, err := boot.Cold()
	if err != nil {
		log.Fatal(err)
	}
	defer dev.Close()
	log.Printf("Connected to bootloader")
	log.Printf("Info: %+v", info)

	padding := make([]byte, (info.PageSize-len(data)%info.PageSize)%info.PageSize)
	mem := append(data, padding...)

	log.Printf("Writing the image to Crazyflie Flash memory...")
	fromPage := info.FlashStart
	toPage := fromPage + len(mem)/info.PageSize
	if toPage > boot.ConfigPageIndex {
		log.Fatal("Image is too large: %d bytes. Must not exceed %d bytes",
			len(data), (boot.ConfigPageIndex-info.FlashStart)*info.PageSize)
	}
	for page := fromPage; page < toPage; page++ {
		index := (page - fromPage) * info.PageSize
		err := boot.FlashPage(dev, info, page, mem[index:index+info.PageSize])
		if err != nil {
			log.Fatalf("Failed to flash page #%d (image spans from #%d to #%d): %v",
				page, fromPage, toPage, err)
		}
	}
	log.Printf("OK - %s has been successfully flashed", *image)
}