scan.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <boost/program_options.hpp>
00004 #include <crazyflie_cpp/Crazyradio.h>
00005 #include <crazyflie_cpp/CrazyflieUSB.h>
00006 
00007 
00008 int main(int argc, char **argv)
00009 {
00010 
00011   std::string addressStr;
00012   std::string defaultAddressStr("0xE7E7E7E7E7");
00013   bool verbose = false;
00014 
00015   namespace po = boost::program_options;
00016 
00017   po::options_description desc("Allowed options");
00018   desc.add_options()
00019     ("help", "produce help message")
00020     ("address", po::value<std::string>(&addressStr)->default_value(defaultAddressStr), "device address")
00021     ("verbose,v", "verbose output")
00022   ;
00023 
00024   try
00025   {
00026     po::variables_map vm;
00027     po::store(po::parse_command_line(argc, argv, desc), vm);
00028     po::notify(vm);
00029 
00030     if (vm.count("help")) {
00031       std::cout << desc << "\n";
00032       return 0;
00033     }
00034     verbose = vm.count("verbose");
00035   }
00036   catch(po::error& e)
00037   {
00038     std::cerr << e.what() << std::endl << std::endl;
00039     std::cerr << desc << std::endl;
00040     return 1;
00041   }
00042 
00043   try
00044   {
00045     uint32_t numCrazyradios = Crazyradio::numDevices();
00046     if (numCrazyradios > 0) {
00047       uint64_t address;
00048       std::stringstream sstr;
00049       sstr << std::hex << addressStr;
00050       sstr >> address;
00051 
00052       Crazyradio radio(0);
00053       if (verbose) {
00054         std::cout << "Found Crazyradio with version " << radio.version() << std::endl;
00055       }
00056       radio.setAddress(address);
00057       size_t numCFsFound = 0;
00058       for (uint8_t datarate = 0; datarate < 3; ++datarate) {
00059         radio.setDatarate((Crazyradio::Datarate)datarate);
00060         for (uint8_t channel = 0; channel <= 125; ++channel) {
00061           radio.setChannel(channel);
00062 
00063           uint8_t test[] = {0xFF};
00064           Crazyradio::Ack ack;
00065           radio.sendPacket(test, sizeof(test), ack);
00066           if (ack.ack) {
00067             ++numCFsFound;
00068             std::cout << "radio://0/" << (uint32_t)channel << "/";
00069             switch(datarate) {
00070             case Crazyradio::Datarate_250KPS:
00071               std::cout << "250K";
00072               break;
00073             case Crazyradio::Datarate_1MPS:
00074               std::cout << "1M";
00075               break;
00076             case Crazyradio::Datarate_2MPS:
00077               std::cout << "2M";
00078               break;
00079             }
00080 
00081             if (defaultAddressStr != addressStr) {
00082               std::cout << "/" << addressStr.substr(2);
00083             }
00084             std::cout << std::endl;
00085           }
00086         }
00087       }
00088 
00089       if (   numCFsFound == 0
00090           && verbose) {
00091         std::cout << "No Crazyflie found. Did you specify the correct address?" << std::endl;
00092       }
00093     } else if (verbose) {
00094       std::cout << "No Crazyradio found." << std::endl;
00095     }
00096 
00097     uint32_t numCFoverUSB = CrazyflieUSB::numDevices();
00098     if (numCFoverUSB > 0) {
00099       CrazyflieUSB cfusb(0);
00100       if (verbose) {
00101         std::cout << "Found Crazyflie connected via USB cable with version " << cfusb.version() << std::endl;
00102       }
00103 
00104       for (uint32_t i = 0; i < numCFoverUSB; ++i) {
00105         std::cout << "usb://" << i << std::endl;
00106       }
00107 
00108     } else if (verbose) {
00109       std::cout << "No Crazyflie connected via USB cable found." << std::endl;
00110     }
00111     return 0;
00112   }
00113   catch(std::exception& e)
00114   {
00115     std::cerr << e.what() << std::endl;
00116     return 1;
00117   }
00118 }


crazyflie_tools
Author(s): Wolfgang Hoenig
autogenerated on Wed Jun 12 2019 19:20:48