#include #include #include #include #include #include #include #include #include #include #include #define DEBUG 0 using namespace std; using namespace net::lliurex::mrpdi; bool quit_requested=false; map settings_map; bool corrupted_settings=false; /** * loads calibration setup * */ void load_setup() { struct passwd * pwd; string path("/etc/mrpdi/settings.conf"); libconfig::Config cfg; ifstream myfile(path.c_str(),std::ifstream::in); if(myfile.good()) { myfile.close(); try { cfg.readFile(path.c_str()); libconfig::Setting & version = cfg.lookup("version"); std::string version_str=version; if(version_str!="2.0") { cout<<"Warning: Unknown format version: "<::iterator it; for(it=settings_map.begin();it!=settings_map.end();it++) { libconfig::Setting & device = devices.add(libconfig::Setting::TypeGroup); //id libconfig::Setting & id = device.add("id",libconfig::Setting::TypeInt); id.setFormat(libconfig::Setting::FormatHex); id=(int)it->first; //name libconfig::Setting & name = device.add("name",libconfig::Setting::TypeString); name=it->second.name; //calibration libconfig::Setting & calibration = device.add("calibration",libconfig::Setting::TypeArray); for(int n=0;n<8;n++) { libconfig::Setting & f = calibration.add(libconfig::Setting::TypeFloat); f=it->second.calibration[n]; } //params libconfig::Setting & params = device.add("params",libconfig::Setting::TypeList); std::map::iterator pit; for(pit=it->second.params.begin();pit!=it->second.params.end();pit++) { cout<<"* name:"<first<<" value:"<second<first; libconfig::Setting & pvalue = param.add("value",libconfig::Setting::TypeInt); pvalue=(int)pit->second; } } cfg.writeFile(path.c_str()); } void quit_handler(int sig) { #if DEBUG cout<<"[SIGNAL]:"< list; vector params; #if DEBUG cout<<"[mrpdi cli]: start"<init(); if(argc>1) { if(strcmp(argv[1],"--help")==0) { display_usage(); } if(strcmp(argv[1],"--list")==0) { core->update_devices(&list); cout<<"* Available devices:"<2) { bool found=false; unsigned int id; unsigned int address; string str(argv[2]); istringstream sp(str,istringstream::in); sp>>hex>>address; core->update_devices(&list); //device look up for(int n=0;nset_input_handler(handler); core->start(id,address); while(!quit_requested) { sleep(1); } core->stop(id,address); core->set_input_handler(NULL); delete handler; } else { cout<<"* Device not found, aborting"< params; load_setup(); handler = new input::InputHandler(); core->set_input_handler(handler); handler->set_settings(settings_map); while(!quit_requested) { core->update_devices(&list); if(list.size()>0) { cout<<"* Connecting to "<start(id,address); while(!quit_dev && !quit_requested) { core->update_devices(&list); found=false; for(int n=0;nstop(id,address); } sleep(1); } settings_map = handler->get_settings(); if(!corrupted_settings) save_setup(); delete handler; } } core->shutdown(); #if DEBUG cout<<"[mrpdi cli]: shutdown"<