main.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <vector>
  4. #include <yaml-cpp/yaml.h>
  5. #include <QDebug>
  6. #include "moduleunit.h"
  7. #include "QtDBus/QDBusConnection"
  8. #include "I
  9. std::vector<moduleunit> gvecmodule;
  10. void dec_yaml(const char * stryamlpath)
  11. {
  12. YAML::Node config;
  13. try
  14. {
  15. config = YAML::LoadFile(stryamlpath);
  16. }
  17. catch(YAML::BadFile e)
  18. {
  19. qDebug("load error.");
  20. return;
  21. }
  22. int i;
  23. int nmodulesize;
  24. std::vector<std::string> vecmodulename;
  25. if(config["module"])
  26. {
  27. qDebug("have module size is %d",config["module"].size());
  28. nmodulesize = config["module"].size();
  29. for(i=0;i<nmodulesize;i++)
  30. {
  31. std::string strname = config["module"][i].as<std::string>();
  32. vecmodulename.push_back(strname);
  33. }
  34. }
  35. else
  36. {
  37. return;
  38. }
  39. if(nmodulesize <1)return;
  40. std::string strmodulename;
  41. std::string strmoduletitle;
  42. for(i=0;i<nmodulesize;i++)
  43. {
  44. if(config[vecmodulename[i].data()])
  45. {
  46. if((config[vecmodulename[i].data()]["modulename"])&&(config[vecmodulename[i].data()]["title"]))
  47. {
  48. strmodulename = config[vecmodulename[i].data()]["modulename"].as<std::string>();
  49. strmoduletitle = config[vecmodulename[i].data()]["title"].as<std::string>();
  50. moduleunit mu;
  51. mu.mstrmodulename = strmodulename;
  52. mu.mstrmoduletitle = strmoduletitle;
  53. gvecmodule.push_back(mu);
  54. // iv::radar_data xradardata;
  55. // xradardata.foff_x = atof(stroffset_x.data());
  56. // xradardata.foff_y = atof(stroffset_y.data());
  57. // xradardata.frotation = atof(strrotation.data()) * M_PI/180.0;
  58. // strncpy(xradardata.strmemname,strmemname.data(),255);
  59. // gvectorradar.push_back(xradardata);
  60. // qDebug("name is %s ",strmemname.data());
  61. }
  62. }
  63. }
  64. return;
  65. }
  66. int main(int argc, char *argv[])
  67. {
  68. QApplication a(argc, argv);
  69. //获取可执行程序的绝对路径
  70. char abs_path[256];
  71. int cnt = readlink("/proc/self/exe", abs_path, 256);
  72. for(int i = cnt; i >= 0; --i)
  73. {
  74. if(abs_path[i]=='/')
  75. {
  76. abs_path[i + 1]='\0';
  77. break;
  78. }
  79. }
  80. qDebug()<<"路径: "<<abs_path;
  81. char yaml_name[] = "ivdiagnosis.yaml";
  82. char *abs_ymlpath = new char[strlen(abs_path)+strlen(yaml_name)+1];
  83. if (abs_ymlpath == NULL) exit (1);
  84. strcpy(abs_ymlpath, abs_path);
  85. strcat(abs_ymlpath, yaml_name);
  86. //add tjc
  87. QDBusConnection::sessionBus().connect(QString(),"/catarc/adc", "adciv.sys.interface","ivdiagnosis",&a,SLOT(quit()));
  88. char stryamlpath[256];
  89. if(argc<2)
  90. {
  91. // snprintf(stryamlpath,255,"ivdiagnosis.yaml");
  92. strncpy(stryamlpath,abs_ymlpath,255);
  93. }
  94. else
  95. {
  96. strncpy(stryamlpath,argv[1],255);
  97. }
  98. dec_yaml(stryamlpath);
  99. MainWindow w;
  100. w.show();
  101. return a.exec();
  102. }