#include #include #include #include #include #include "console_colors.h" #include "GLOBALS.h" #include "hb_serial.h" void prog_opts(int ac, char* av[]) { namespace po = boost::program_options; using namespace std; using namespace habboy_hw_iface; try { po::options_description generic("CLI opts"); generic.add_options() ("help", "Display help message") ("wsport", po::value(), "websocket Port, example: --wsport 127.0.0.1:5565") ("serial", po::value(), "arduino serial port. defaults to /dev/ttyUSB0") ("baud", po::value(), "Serial Baud speed - defaults to 115200") ; po::options_description cli_options("Command Line Interface options"); cli_options.add(generic); string config_file; cli_options.add_options() ("config", po::value(&config_file), "Config file."); po::options_description file_options; file_options.add(generic); po::variables_map vm; store( po::command_line_parser(ac, av).options(cli_options).allow_unregistered().run(), vm ); notify(vm); if(vm.count("help")) { cout<(), match, std::regex(R"_(([\w\.]*)(\:?)(\d*))_") ); if(match.size() == 4) { if(match[2] == "" && match[3] == "") // special case when only port is given: --port 5565 { GLOBALS::get().par_.ws_port_ = stoi(match[1]); } else { if(match[1] != "") GLOBALS::get().par_.ws_host_ = match[1]; if(match[3] != "") GLOBALS::get().par_.ws_port_ = stoi(match[3]); } } } if (vm.count("serial")) { GLOBALS::get().par_.serial_ = vm["serial"].as(); } if (vm.count("baud")) { std::string b = vm["baud"].as(); if(b == "0") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b0; if(b == "50") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b50; if(b == "75") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b75; if(b == "110") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b110; if(b == "134") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b134; if(b == "150") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b150; if(b == "200") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b200; if(b == "300") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b300; if(b == "600") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b600; if(b == "1200") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b1200; if(b == "1800") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b1800; if(b == "2400") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b2400; if(b == "4800") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b4800; if(b == "9600") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b9600; if(b == "19200") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b19200; if(b == "38400") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b38400; if(b == "57600") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b57600; if(b == "115200") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b115200; if(b == "230400") GLOBALS::get().par_.baud_ = SerialConnection::Baud::b230400; } } catch(exception& e) { cout << e.what() << "\n"; } GLOBALS::DumpToFile("./habboy_hw_iface.opts"); }