listMemories.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include <boost/program_options.hpp>
00004 #include <crazyflie_cpp/Crazyflie.h>
00005 
00006 int main(int argc, char **argv)
00007 {
00008 
00009   std::string uri;
00010   std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
00011 
00012   namespace po = boost::program_options;
00013 
00014   po::options_description desc("Allowed options");
00015   desc.add_options()
00016     ("help", "produce help message")
00017     ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
00018   ;
00019 
00020   try
00021   {
00022     po::variables_map vm;
00023     po::store(po::parse_command_line(argc, argv, desc), vm);
00024     po::notify(vm);
00025 
00026     if (vm.count("help")) {
00027       std::cout << desc << "\n";
00028       return 0;
00029     }
00030   }
00031   catch(po::error& e)
00032   {
00033     std::cerr << e.what() << std::endl << std::endl;
00034     std::cerr << desc << std::endl;
00035     return 1;
00036   }
00037 
00038   try
00039   {
00040     Crazyflie cf(uri);
00041     cf.requestMemoryToc();
00042 
00043      std::for_each(cf.memoriesBegin(), cf.memoriesEnd(),
00044       [](const Crazyflie::MemoryTocEntry& entry)
00045       {
00046         std::cout << (int)entry.id << ": " << std::endl;
00047         std::cout << "  type: ";
00048         switch (entry.type) {
00049         case Crazyflie::MemoryTypeEEPROM:
00050           std::cout << "EEPROM";
00051           break;
00052         case Crazyflie::MemoryTypeOneWire:
00053           std::cout << "1-Wire";
00054           break;
00055         case Crazyflie::MemoryTypeLED12:
00056           std::cout << "LED12";
00057           break;
00058         case Crazyflie::MemoryTypeLOCO:
00059           std::cout << "LOCO";
00060           break;
00061         default:
00062           std::cout << "Unknown type!";
00063           break;
00064         }
00065         std::cout << std::endl;
00066         std::cout << "  size: " << entry.size << std::endl;
00067         std::cout << "  addr: " << entry.addr << std::endl;
00068       }
00069     );
00070 
00071     return 0;
00072   }
00073   catch(std::exception& e)
00074   {
00075     std::cerr << e.what() << std::endl;
00076     return 1;
00077   }
00078 }


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