reboot.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 enum Mode
00007 {
00008   RebootToFirmware,
00009   RebootToBootloader,
00010   SysOff,
00011   SysOn,
00012   AllOff,
00013 };
00014 
00015 std::istream& operator>>(std::istream& in, Mode& mode)
00016 {
00017   std::string token;
00018   in >> token;
00019   if (token == "firmware")
00020     mode = RebootToFirmware;
00021   else if (token == "bootloader")
00022     mode = RebootToBootloader;
00023   else if (token == "sysoff")
00024     mode = SysOff;
00025   else if (token == "syson")
00026     mode = SysOn;
00027   else if (token == "alloff")
00028     mode = AllOff;
00029   else throw boost::program_options::validation_error(boost::program_options::validation_error::invalid_option_value);
00030   return in;
00031 }
00032 
00033 int main(int argc, char **argv)
00034 {
00035 
00036   std::string uri;
00037   std::string defaultUri("radio://0/80/2M/E7E7E7E7E7");
00038   Mode mode = RebootToFirmware;
00039 
00040   namespace po = boost::program_options;
00041 
00042   po::options_description desc("Allowed options");
00043   desc.add_options()
00044     ("help", "produce help message")
00045     ("uri", po::value<std::string>(&uri)->default_value(defaultUri), "unique ressource identifier")
00046     ("mode", po::value<Mode>(&mode)->default_value(mode), "reboot mode {firmware,bootloader,sysoff,syson,alloff}")
00047   ;
00048 
00049   try
00050   {
00051     po::variables_map vm;
00052     po::store(po::parse_command_line(argc, argv, desc), vm);
00053     po::notify(vm);
00054 
00055     if (vm.count("help")) {
00056       std::cout << desc << "\n";
00057       return 0;
00058     }
00059   }
00060   catch(po::error& e)
00061   {
00062     std::cerr << e.what() << std::endl << std::endl;
00063     std::cerr << desc << std::endl;
00064     return 1;
00065   }
00066 
00067   try
00068   {
00069     Crazyflie cf(uri);
00070     switch (mode)
00071     {
00072       case RebootToFirmware:
00073         cf.reboot();
00074         break;
00075       case RebootToBootloader:
00076         cf.rebootToBootloader();
00077         break;
00078       case SysOff:
00079         cf.sysoff();
00080         break;
00081       case SysOn:
00082         cf.syson();
00083         break;
00084       case AllOff:
00085         cf.alloff();
00086         break;
00087     }
00088 
00089     return 0;
00090   }
00091   catch(std::exception& e)
00092   {
00093     std::cerr << e.what() << std::endl;
00094     return 1;
00095   }
00096 }


crazyflie_tools
Author(s): Wolfgang Hoenig
autogenerated on Sun Oct 8 2017 02:48:04