main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <QCoreApplication>
  2. #include <QObject>
  3. #include <signal.h>
  4. #include "nvcan.h"
  5. #include "canctrl.h"
  6. #include <unistd.h>
  7. #include <thread>
  8. #include <iostream>
  9. #include <xmlparam.h>
  10. #include "ivversion.h"
  11. #include "ivexit.h"
  12. #include <signal.h>
  13. static canctrl * gpcanctrl;
  14. void exitfunc()
  15. {
  16. qDebug("enter exit func.");
  17. gpcanctrl->requestInterruption();
  18. QTime xTime;
  19. xTime.start();
  20. while(xTime.elapsed()<1000)
  21. {
  22. if(gpcanctrl->isFinished())
  23. {
  24. qDebug("canctrl complete.");
  25. delete gpcanctrl;
  26. break;
  27. }
  28. }
  29. }
  30. void signal_handler(int sig)
  31. {
  32. if(sig == SIGINT)
  33. {
  34. exitfunc();
  35. }
  36. }
  37. #ifdef TEST_PROG
  38. void threadtest()
  39. {
  40. QTimer xTimer;
  41. xTimer.setTimerType(Qt::PreciseTimer);
  42. void * pa = iv::modulecomm::RegisterSend("cansend0",100000,100);
  43. return;
  44. while(true)
  45. {
  46. iv::can::canmsg xmsg;
  47. xmsg.set_channel(0);
  48. xmsg.set_mstime(QDateTime::currentMSecsSinceEpoch());
  49. xmsg.set_index(0);
  50. int i;
  51. for(i=0;i<10;i++)
  52. {
  53. iv::can::canraw * pcanraw = xmsg.add_rawmsg();
  54. pcanraw->set_bext(false);
  55. pcanraw->set_id(11);
  56. pcanraw->set_bremote(false);
  57. char xdata[8];
  58. xdata[0] = 11;
  59. pcanraw->set_data(xdata,8);
  60. pcanraw->set_len(8);
  61. }
  62. int nbytesize = xmsg.ByteSize();
  63. std::shared_ptr<char> str_ptr = std::shared_ptr<char>(new char[nbytesize]);
  64. if(xmsg.SerializeToArray(str_ptr.get(),nbytesize))
  65. iv::modulecomm::ModuleSendMsg(pa,str_ptr.get(),nbytesize);
  66. std::this_thread::sleep_for(std::chrono::milliseconds(5));
  67. // std::this_thread::sleep_for(std::chrono::microseconds(50000));
  68. }
  69. }
  70. #endif
  71. int main(int argc, char *argv[])
  72. {
  73. showversion("driver_can_nvidia_agx");
  74. QCoreApplication a(argc, argv);
  75. QString strpath = QCoreApplication::applicationDirPath();
  76. if(argc < 2)
  77. strpath = strpath + "/driver_can_socket.xml";
  78. else
  79. strpath = argv[1];
  80. std::cout<<strpath.toStdString()<<std::endl;
  81. iv::xmlparam::Xmlparam xp(strpath.toStdString());
  82. std::string strmemsend0 = xp.GetParam("cansend0_agx","cansend1");
  83. std::string strmemrecv0 = xp.GetParam("canrecv0_agx","canrecv1");
  84. std::string strcanname = xp.GetParam("canname","can1");
  85. gpcanctrl = new canctrl(strmemsend0.data(),strmemrecv0.data(),strcanname.data());
  86. gpcanctrl->start();
  87. iv::ivexit::RegIVExitCall(exitfunc);
  88. signal(SIGINT,signal_handler);
  89. #ifdef TEST_PROG
  90. std::thread * pthread = new std::thread(threadtest);
  91. #endif
  92. // std::thread b(func);
  93. return a.exec();
  94. }