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
00014 namespace po = boost::program_options;
00015
00016 po::options_description desc("Allowed options");
00017 desc.add_options()
00018 ("help", "produce help message")
00019 ("address", po::value<std::string>(&addressStr)->default_value(defaultAddressStr), "device address")
00020 ;
00021
00022 try
00023 {
00024 po::variables_map vm;
00025 po::store(po::parse_command_line(argc, argv, desc), vm);
00026 po::notify(vm);
00027
00028 if (vm.count("help")) {
00029 std::cout << desc << "\n";
00030 return 0;
00031 }
00032 }
00033 catch(po::error& e)
00034 {
00035 std::cerr << e.what() << std::endl << std::endl;
00036 std::cerr << desc << std::endl;
00037 return 1;
00038 }
00039
00040 try
00041 {
00042 uint32_t numCrazyradios = Crazyradio::numDevices();
00043 if (numCrazyradios > 0) {
00044 uint64_t address;
00045 std::stringstream sstr;
00046 sstr << std::hex << addressStr;
00047 sstr >> address;
00048
00049 Crazyradio radio(0);
00050 std::cout << "Found Crazyradio with version " << radio.version() << std::endl;
00051 radio.setAddress(address);
00052
00053 for (uint8_t datarate = 0; datarate < 3; ++datarate) {
00054 radio.setDatarate((Crazyradio::Datarate)datarate);
00055 for (uint8_t channel = 0; channel <= 125; ++channel) {
00056 radio.setChannel(channel);
00057
00058 uint8_t test[] = {0xFF};
00059 Crazyradio::Ack ack;
00060 radio.sendPacket(test, sizeof(test), ack);
00061 if (ack.ack) {
00062 std::cout << "radio://0/" << (uint32_t)channel << "/";
00063 switch(datarate) {
00064 case Crazyradio::Datarate_250KPS:
00065 std::cout << "250K";
00066 break;
00067 case Crazyradio::Datarate_1MPS:
00068 std::cout << "1M";
00069 break;
00070 case Crazyradio::Datarate_2MPS:
00071 std::cout << "2M";
00072 break;
00073 }
00074
00075 if (defaultAddressStr != addressStr) {
00076 std::cout << "/" << addressStr.substr(2);
00077 }
00078 std::cout << std::endl;
00079 }
00080 }
00081 }
00082 } else {
00083 std::cout << "No Crazyradio found." << std::endl;
00084 }
00085
00086 uint32_t numCFoverUSB = CrazyflieUSB::numDevices();
00087 if (numCFoverUSB > 0) {
00088 CrazyflieUSB cfusb(0);
00089 std::cout << "Found Crazyflie via USB with version " << cfusb.version() << std::endl;
00090
00091 for (uint32_t i = 0; i < numCFoverUSB; ++i) {
00092 std::cout << "usb://" << i << std::endl;
00093 }
00094
00095 } else {
00096 std::cout << "No Crazyflie over USB found." << std::endl;
00097 }
00098 return 0;
00099 }
00100 catch(std::exception& e)
00101 {
00102 std::cerr << e.what() << std::endl;
00103 return 1;
00104 }
00105 }