scan.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <boost/program_options.hpp>
4 #include <crazyflie_cpp/Crazyradio.h>
5 #include <crazyflie_cpp/CrazyflieUSB.h>
6 
7 
8 int main(int argc, char **argv)
9 {
10 
11  std::string addressStr;
12  std::string defaultAddressStr("0xE7E7E7E7E7");
13  bool verbose = false;
14 
15  namespace po = boost::program_options;
16 
17  po::options_description desc("Allowed options");
18  desc.add_options()
19  ("help", "produce help message")
20  ("address", po::value<std::string>(&addressStr)->default_value(defaultAddressStr), "device address")
21  ("verbose,v", "verbose output")
22  ;
23 
24  try
25  {
26  po::variables_map vm;
27  po::store(po::parse_command_line(argc, argv, desc), vm);
28  po::notify(vm);
29 
30  if (vm.count("help")) {
31  std::cout << desc << "\n";
32  return 0;
33  }
34  verbose = vm.count("verbose");
35  }
36  catch(po::error& e)
37  {
38  std::cerr << e.what() << std::endl << std::endl;
39  std::cerr << desc << std::endl;
40  return 1;
41  }
42 
43  try
44  {
45  uint32_t numCrazyradios = Crazyradio::numDevices();
46  if (numCrazyradios > 0) {
47  uint64_t address;
48  std::stringstream sstr;
49  sstr << std::hex << addressStr;
50  sstr >> address;
51 
52  Crazyradio radio(0);
53  if (verbose) {
54  std::cout << "Found Crazyradio with version " << radio.version() << std::endl;
55  }
56  radio.setAddress(address);
57  size_t numCFsFound = 0;
58  for (uint8_t datarate = 0; datarate < 3; ++datarate) {
59  radio.setDatarate((Crazyradio::Datarate)datarate);
60  for (uint8_t channel = 0; channel <= 125; ++channel) {
61  radio.setChannel(channel);
62 
63  uint8_t test[] = {0xFF};
65  radio.sendPacket(test, sizeof(test), ack);
66  if (ack.ack) {
67  ++numCFsFound;
68  std::cout << "radio://0/" << (uint32_t)channel << "/";
69  switch(datarate) {
71  std::cout << "250K";
72  break;
74  std::cout << "1M";
75  break;
77  std::cout << "2M";
78  break;
79  }
80 
81  if (defaultAddressStr != addressStr) {
82  std::stringstream sstr;
83  sstr << std::hex << std::uppercase << address;
84  std::cout << "/" << sstr.str();
85  }
86  std::cout << std::endl;
87  }
88  }
89  }
90 
91  if ( numCFsFound == 0
92  && verbose) {
93  std::cout << "No Crazyflie found. Did you specify the correct address?" << std::endl;
94  }
95  } else if (verbose) {
96  std::cout << "No Crazyradio found." << std::endl;
97  }
98 
99  uint32_t numCFoverUSB = CrazyflieUSB::numDevices();
100  if (numCFoverUSB > 0) {
101  CrazyflieUSB cfusb(0);
102  if (verbose) {
103  std::cout << "Found Crazyflie connected via USB cable with version " << cfusb.version() << std::endl;
104  }
105 
106  for (uint32_t i = 0; i < numCFoverUSB; ++i) {
107  std::cout << "usb://" << i << std::endl;
108  }
109 
110  } else if (verbose) {
111  std::cout << "No Crazyflie connected via USB cable found." << std::endl;
112  }
113  return 0;
114  }
115  catch(std::exception& e)
116  {
117  std::cerr << e.what() << std::endl;
118  return 1;
119  }
120 }
uint8_t error
float version() const
uint8_t channel
Definition: crtp.h:33
virtual void sendPacket(const uint8_t *data, uint32_t length, ITransport::Ack &result)
Ack()
Definition: ITransport.h:1343
void setAddress(uint64_t address)
Definition: Crazyradio.cpp:57
uint16_t address
int main(int argc, char **argv)
Definition: scan.cpp:8
void setDatarate(Datarate datarate)
Definition: Crazyradio.cpp:84
static uint32_t numDevices()
static uint32_t numDevices()
Definition: Crazyradio.cpp:46
uint8_t ack
Definition: ITransport.h:1348
float version() const
void setChannel(uint8_t channel)
Definition: Crazyradio.cpp:51


crazyflie_tools
Author(s): Wolfgang Hoenig
autogenerated on Mon Sep 28 2020 03:40:15