123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #include <QCoreApplication>
- #include "ivdriver_lidar.h"
- #include <signal.h>
- #include <getopt.h>
- #include <iostream>
- #include <iostream>
- #include <fstream>
- #include <yaml-cpp/yaml.h>
- iv::ivmodule * gpivmodule;
- QCoreApplication * gpapp;
- void sigint_handler(int sig){
- if(sig == SIGINT){
-
- delete gpivmodule;
- gpapp->exit(0);
- }
- }
- char gstr_memname[256];
- char gstr_rollang[256];
- char gstr_inclinationang_yaxis[256];
- char gstr_inclinationang_xaxis[256];
- char gstr_hostip[256];
- char gstr_port[256];
- char gstr_yaml[256];
- void print_useage()
- {
- std::cout<<" -m --memname $memname : share memory name. eq. -m lidar_pc"<<std::endl;
- std::cout<<" -r --rollang $rollang : roll angle. eq. -r 10.0"<<std::endl;
- std::cout<<" -x --inclinationang_xaxis $inclinationang_xaxis : inclination angle from x axis. eq. -x 0.0"<<std::endl;
- std::cout<<" -y --inclinationang_yaxis $inclinationang_yaxis : inclination angle from y axis. eq. -y 0.0"<<std::endl;
- std::cout<<" -o --hostip $hostip : host ip. eq. -o 192.168.1.111"<<std::endl;
- std::cout<<" -p --port $port : port . eq. -p 2368"<<std::endl;
- std::cout<<" -s --setyaml $yaml : port . eq. -s rs1.yaml"<<std::endl;
- std::cout<<" -h --help print help"<<std::endl;
- }
- int GetOptLong(int argc, char *argv[]) {
- int nRtn = 0;
- int opt;
- int digit_optind = 0;
-
-
- int option_index = 0;
-
- const char *optstring = "m:r:x:y:o:p:s:h";
-
-
- static struct option long_options[] = {
- {"memname", required_argument, NULL, 'm'},
- {"rollang", required_argument, NULL, 'r'},
- {"inclinationang_xaxis", required_argument, NULL, 'x'},
- {"inclinationang_yaxis", required_argument, NULL, 'y'},
- {"hostip", required_argument, NULL, 'o'},
- {"port", required_argument, NULL, 'p'},
- {"setyaml", required_argument, NULL, 's'},
- {"help", no_argument, NULL, 'h'},
-
- {0, 0, 0, 0}
- };
- while ( (opt = getopt_long(argc,
- argv,
- optstring,
- long_options,
- &option_index)) != -1) {
- switch(opt)
- {
- case 'm':
- strncpy(gstr_memname,optarg,255);
- break;
- case 'r':
- strncpy(gstr_rollang,optarg,255);
- break;
- case 'x':
- strncpy(gstr_inclinationang_xaxis,optarg,255);
- break;
- case 'y':
- strncpy(gstr_inclinationang_yaxis,optarg,255);
- break;
- case 'o':
- strncpy(gstr_hostip,optarg,255);
- break;
- case 'p':
- strncpy(gstr_port,optarg,255);
- break;
- case 's':
- strncpy(gstr_yaml,optarg,255);
- break;
- case 'h':
- print_useage();
- nRtn = 1;
- break;
- default:
- break;
- }
- }
- return nRtn;
- }
- void decodeyaml(const char * stryaml)
- {
- YAML::Node config;
- try
- {
- config = YAML::LoadFile(stryaml);
- }
- catch(YAML::BadFile e)
- {
- qDebug("load yaml error.");
- return;
- }
- if(config["memname"])
- {
- strncpy(gstr_memname,config["memname"].as<std::string>().data(),255);
- }
- if(config["rollang"])
- {
- strncpy(gstr_rollang,config["rollang"].as<std::string>().data(),255);
- }
- if(config["inclinationang_xaxis"])
- {
- strncpy(gstr_inclinationang_xaxis,config["inclinationang_xaxis"].as<std::string>().data(),255);
- }
- if(config["inclinationang_yaxis"])
- {
- strncpy(gstr_inclinationang_yaxis,config["inclinationang_yaxis"].as<std::string>().data(),255);
- }
- if(config["hostip"])
- {
- strncpy(gstr_hostip,config["hostip"].as<std::string>().data(),255);
- }
- if(config["port"])
- {
- strncpy(gstr_port,config["port"].as<std::string>().data(),255);
- }
- }
- int lidarmain(iv::ivdriver_lidar * pivm,int argc, char *argv[],QCoreApplication * pa,const char * strmodulename)
- {
- int nRtn = GetOptLong(argc,argv);
- if(nRtn == 1)
- {
- return 0;
- }
- if(strnlen(gstr_yaml,255)>0)
- {
- decodeyaml(gstr_yaml);
- }
- strncpy(pivm->mstr_memname,gstr_memname,256);
- strncpy(pivm->mstr_hostip,gstr_hostip,256);
- strncpy(pivm->mstr_port,gstr_port,256);
- pivm->mfrollang = atof(gstr_rollang)*M_PI/180.0;
- pivm->mfinclinationang_xaxis = atof(gstr_inclinationang_xaxis)*M_PI/180.0;
- pivm->mfinclinationang_yaxis = atof(gstr_inclinationang_yaxis)*M_PI/180.0;
- iv::ivmodule * pivmodule = pivm;
- signal(SIGINT, sigint_handler);
- gpivmodule = pivmodule;
- pivmodule->start();
- gpapp = pa;
- return 1;
- }
|