|
@@ -0,0 +1,225 @@
|
|
|
+#include <QCoreApplication>
|
|
|
+
|
|
|
+#include <getopt.h>
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+#include "ivstdcolorout.h"
|
|
|
+
|
|
|
+#include <QFile>
|
|
|
+
|
|
|
+#include <OpenDrive/OpenDrive.h>
|
|
|
+#include <OpenDrive/OpenDriveXmlWriter.h>
|
|
|
+
|
|
|
+#include "ndsdataproc.h"
|
|
|
+
|
|
|
+static char gstr_vehiclepath[256];
|
|
|
+static char gstr_linepath[256];
|
|
|
+static char gstr_envpath[256];
|
|
|
+static char gstr_outputpath[256];
|
|
|
+
|
|
|
+
|
|
|
+ * @brief print_useage
|
|
|
+ */
|
|
|
+void print_useage()
|
|
|
+{
|
|
|
+ std::cout<<" -v --vehicle $vehiclefile : set vehicle file path. eq. -v /home/yuchuli/nds-sync-vehicle.csv"<<std::endl;
|
|
|
+ std::cout<<" -l --line $linefile : set line file path. eq. -l /home/yuchuli/nds-sync-line.csv"<<std::endl;
|
|
|
+ std::cout<<" -e --environment $Environmentfile: set Environment file . eq. -e /home/yuchuli/Environment.csv"<<std::endl;
|
|
|
+ std::cout<<" -o --output $outputfile : set output file. eq. -o /home/yuchuli/output.xodr"<<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;
|
|
|
+ (void)digit_optind;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ int option_index = 0;
|
|
|
+
|
|
|
+ const char *optstring = "v:l:e:o:h";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ struct option {
|
|
|
+ const char * name;
|
|
|
+ int has_arg;
|
|
|
+ int * flag;
|
|
|
+
|
|
|
+ int val;
|
|
|
+ };
|
|
|
+ 其中:
|
|
|
+ no_argument(即0),表明这个长参数不带参数(即不带数值,如:--name)
|
|
|
+ required_argument(即1),表明这个长参数必须带参数(即必须带数值,如:--name Bob)
|
|
|
+ optional_argument(即2),表明这个长参数后面带的参数是可选的,(即--name和--name Bob均可)
|
|
|
+ */
|
|
|
+ static struct option long_options[] = {
|
|
|
+ {"vehicle", required_argument, NULL, 'v'},
|
|
|
+ {"line", required_argument, NULL, 'l'},
|
|
|
+ {"environment", required_argument, NULL, 'e'},
|
|
|
+ {"output", required_argument, NULL, 'o'},
|
|
|
+ {"help", no_argument, NULL, 'h'},
|
|
|
+
|
|
|
+ {0, 0, 0, 0}
|
|
|
+ };
|
|
|
+
|
|
|
+ while ( (opt = getopt_long(argc,
|
|
|
+ argv,
|
|
|
+ optstring,
|
|
|
+ long_options,
|
|
|
+ &option_index)) != -1) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ switch(opt)
|
|
|
+ {
|
|
|
+ case 'v':
|
|
|
+ strncpy(gstr_vehiclepath,optarg,255);
|
|
|
+ break;
|
|
|
+ case 'l':
|
|
|
+ strncpy(gstr_linepath,optarg,255);
|
|
|
+ break;
|
|
|
+ case 'e':
|
|
|
+ strncpy(gstr_envpath,optarg,255);
|
|
|
+ break;
|
|
|
+ case 'o':
|
|
|
+ strncpy(gstr_outputpath,optarg,255);
|
|
|
+ break;
|
|
|
+ case 'h':
|
|
|
+ print_useage();
|
|
|
+ nRtn = 1;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return nRtn;
|
|
|
+}
|
|
|
+
|
|
|
+int GetLaneSet(const char * strenvpath, int & nleftlane, int & nrightlane)
|
|
|
+{
|
|
|
+ QFile xFile;
|
|
|
+ xFile.setFileName(strenvpath);
|
|
|
+ if(!xFile.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ ivstdcolorout("Can't Open Evniroment File.",iv::STDCOLOR_BOLDRED);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ QByteArray ba = xFile.readAll();
|
|
|
+ xFile.close();
|
|
|
+ QList<QByteArray> baline =ba.split('\n');
|
|
|
+ int nline = baline.size();
|
|
|
+ if(nline < 2)
|
|
|
+ {
|
|
|
+ ivstdcolorout("No Lane Line.",iv::STDCOLOR_BOLDRED);
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
+ QString x(baline[1]);
|
|
|
+ x = x.trimmed();
|
|
|
+
|
|
|
+ QStringList badata = x.split(QRegExp("[,]"));
|
|
|
+ if(badata.size()<7)
|
|
|
+ {
|
|
|
+ ivstdcolorout("No Lane Setting.",iv::STDCOLOR_BOLDRED);
|
|
|
+ return -3;
|
|
|
+ }
|
|
|
+ nleftlane = badata[5].toInt();
|
|
|
+ nrightlane = badata[6].toInt();
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ QCoreApplication a(argc, argv);
|
|
|
+
|
|
|
+ snprintf(gstr_vehiclepath,255," ");
|
|
|
+ snprintf(gstr_linepath,255," ");
|
|
|
+ snprintf(gstr_envpath,255," ");
|
|
|
+ snprintf(gstr_outputpath,255," ");
|
|
|
+
|
|
|
+ int nRtn = GetOptLong(argc,argv);
|
|
|
+ if(nRtn == 1)
|
|
|
+ {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if(strncmp(gstr_vehiclepath , " ",255) == 0)
|
|
|
+ {
|
|
|
+ ivstdcolorout("Please use -v set vehicle file path.",iv::STDCOLOR_BOLDRED);
|
|
|
+ print_useage();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ char strout[1000];
|
|
|
+ snprintf(strout,1000,"Vehicle File Path: %s",gstr_vehiclepath);
|
|
|
+ ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
|
|
|
+
|
|
|
+ if(strncmp(gstr_linepath , " ",255) == 0)
|
|
|
+ {
|
|
|
+ ivstdcolorout("Please use -l set line file path.",iv::STDCOLOR_BOLDRED);
|
|
|
+ print_useage();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ snprintf(strout,1000,"Line File Path: %s",gstr_linepath);
|
|
|
+ ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
|
|
|
+
|
|
|
+ if(strncmp(gstr_envpath , " ",255) == 0)
|
|
|
+ {
|
|
|
+ ivstdcolorout("Please use -e set environment file path.",iv::STDCOLOR_BOLDRED);
|
|
|
+ print_useage();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ snprintf(strout,1000,"Environment File Path: %s",gstr_envpath);
|
|
|
+ ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
|
|
|
+
|
|
|
+ if(strncmp(gstr_outputpath , " ",255) == 0)
|
|
|
+ {
|
|
|
+ ivstdcolorout("Please use -o set output file path.",iv::STDCOLOR_BOLDRED);
|
|
|
+ print_useage();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ snprintf(strout,1000,"Output File Path: %s",gstr_outputpath);
|
|
|
+ ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
|
|
|
+
|
|
|
+ int nleft = 0;
|
|
|
+ int nright = 0;
|
|
|
+ GetLaneSet(gstr_envpath,nleft,nright);
|
|
|
+
|
|
|
+ OpenDrive xxodr;
|
|
|
+
|
|
|
+ NDSDataProc ndp;
|
|
|
+ int nrtn = ndp.ProcNDSData(gstr_linepath,gstr_vehiclepath,&xxodr,nleft,nright);
|
|
|
+
|
|
|
+ std::cout<<"state: "<<ndp.mstrState<<std::endl;
|
|
|
+ if(nrtn == 0)
|
|
|
+ {
|
|
|
+ snprintf(strout,1000,"Convert OK. out file path: %s ",gstr_outputpath);
|
|
|
+ ivstdcolorout(strout,iv::STDCOLOR_BOLDGREEN);
|
|
|
+ OpenDriveXmlWriter x(&xxodr);
|
|
|
+ x.WriteFile(gstr_outputpath);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ snprintf(strout,1000," Convert Fail. Fail Code: %d ",nrtn);
|
|
|
+ ivstdcolorout(strout,iv::STDCOLOR_BOLDRED);
|
|
|
+ return nrtn;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|