downloadUSDLogfile.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <boost/program_options.hpp>
4 #include <crazyflie_cpp/Crazyflie.h>
5 
6 int main(int argc, char **argv)
7 {
8 
9  std::string uri;
10  std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
11  bool verbose = false;
12 
13  namespace po = boost::program_options;
14 
15  po::options_description desc("Allowed options");
16  desc.add_options()
17  ("help", "produce help message")
18  ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
19  ("verbose,v", "verbose output")
20  ;
21 
22  try
23  {
24  po::variables_map vm;
25  po::store(po::parse_command_line(argc, argv, desc), vm);
26  po::notify(vm);
27 
28  if (vm.count("help")) {
29  std::cout << desc << "\n";
30  return 0;
31  }
32  verbose = vm.count("verbose");
33  }
34  catch(po::error& e)
35  {
36  std::cerr << e.what() << std::endl << std::endl;
37  std::cerr << desc << std::endl;
38  return 1;
39  }
40 
41  try
42  {
43  Crazyflie cf(uri);
44  cf.requestParamToc();
45 
46  const Crazyflie::ParamTocEntry* bcUSD = cf.getParamTocEntry("deck", "bcUSD");
47  const Crazyflie::ParamTocEntry* logging = cf.getParamTocEntry("usd", "logging");
48 
49  if (bcUSD && logging) {
50  if (cf.getParam<uint8_t>(bcUSD->id) != 1) {
51  std::cerr << "USD deck is not initialized!" << std::endl;
52  return 1;
53  }
54  if (cf.getParam<uint8_t>(logging->id) != 0) {
55  std::cout << "Logging still enabled. Disabling logging." << std::endl;
56  cf.setParam<uint8_t>(logging->id, 0);
57  // return 1;
58  }
59  } else {
60  std::cerr << "Could not find USD deck logging variables! Are you using the latest firmware?" << std::endl;
61  return 1;
62  }
63 
64  cf.requestMemoryToc();
65 
66  if (verbose) {
67  auto iter = cf.memoriesBegin();
68  const auto end = cf.memoriesEnd();
69  for (;iter != end; ++iter) {
70  if (iter->type == Crazyflie::MemoryTypeUSD) {
71  std::cout << "File is " << iter->size << " bytes." << std::endl;
72  break;
73  }
74  }
75  }
76 
77  std::vector<uint8_t> data;
78 
79  auto start = std::chrono::high_resolution_clock::now();
80  cf.readUSDLogFile(data);
81  auto end = std::chrono::high_resolution_clock::now();
82 
83  if (verbose) {
84  std::chrono::duration<double> duration = end-start;
85  double t = duration.count();
86 
87  std::cout << "read " << data.size() << " in " << t << " s. (" << data.size() / t << " B/s)." << std::endl;
88  }
89 
90  std::cout << "read " << data.size() << std::endl;
91 
92  std::ofstream out("output.log", std::ios::binary);
93  out.write(reinterpret_cast<const char*>(data.data()), data.size());
94 
95  return 0;
96  }
97  catch(std::exception& e)
98  {
99  std::cerr << e.what() << std::endl;
100  return 1;
101  }
102 }
std::vector< MemoryTocEntry >::const_iterator memoriesBegin() const
uint8_t error
const ParamTocEntry * getParamTocEntry(const std::string &group, const std::string &name) const
Definition: Crazyflie.cpp:1217
uint8_t data[29]
Definition: crtp.h:363
void requestParamToc(bool forceNoCache=false)
Definition: Crazyflie.cpp:696
void requestMemoryToc()
Definition: Crazyflie.cpp:857
float duration
Definition: Crazyflie.h:27
int main(int argc, char **argv)
std::vector< MemoryTocEntry >::const_iterator memoriesEnd() const
void setParam(uint16_t id, const T &value)
void readUSDLogFile(std::vector< uint8_t > &data)
Definition: Crazyflie.cpp:1478
T getParam(uint16_t id) const


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