123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #include <QCoreApplication>
- #include <QObject>
- #include <signal.h>
- #include "nvcan.h"
- #include "canctrl.h"
- #include <unistd.h>
- #include <thread>
- #include <iostream>
- #include <xmlparam.h>
- #include "ivversion.h"
- #include "ivexit.h"
- #include <signal.h>
- static canctrl * gpcanctrl;
- void exitfunc()
- {
- qDebug("enter exit func.");
- gpcanctrl->requestInterruption();
- QTime xTime;
- xTime.start();
- while(xTime.elapsed()<1000)
- {
- if(gpcanctrl->isFinished())
- {
- qDebug("canctrl complete.");
- delete gpcanctrl;
- break;
- }
- }
- }
- void signal_handler(int sig)
- {
- if(sig == SIGINT)
- {
- exitfunc();
- }
- }
- #ifdef TEST_PROG
- void threadtest()
- {
- QTimer xTimer;
- xTimer.setTimerType(Qt::PreciseTimer);
- void * pa = iv::modulecomm::RegisterSend("cansend0",100000,100);
- while(true)
- {
- iv::can::canmsg xmsg;
- xmsg.set_channel(0);
- xmsg.set_mstime(QDateTime::currentMSecsSinceEpoch());
- xmsg.set_index(0);
- int i;
- for(i=0;i<10;i++)
- {
- iv::can::canraw * pcanraw = xmsg.add_rawmsg();
- pcanraw->set_bext(false);
- pcanraw->set_id(11);
- pcanraw->set_bremote(false);
- char xdata[8];
- xdata[0] = 11;
- pcanraw->set_data(xdata,8);
- pcanraw->set_len(8);
- }
- int nbytesize = xmsg.ByteSize();
- std::shared_ptr<char> str_ptr = std::shared_ptr<char>(new char[nbytesize]);
- if(xmsg.SerializeToArray(str_ptr.get(),nbytesize))
- iv::modulecomm::ModuleSendMsg(pa,str_ptr.get(),nbytesize);
- // std::this_thread::sleep_for(std::chrono::milliseconds(1));
- std::this_thread::sleep_for(std::chrono::microseconds(5000));
- }
- }
- #endif
- int main(int argc, char *argv[])
- {
- showversion("driver_can_nvidia_agx");
- QCoreApplication a(argc, argv);
- QString strpath = QCoreApplication::applicationDirPath();
- if(argc < 2)
- strpath = strpath + "/driver_can_socket.xml";
- else
- strpath = argv[1];
- std::cout<<strpath.toStdString()<<std::endl;
- iv::xmlparam::Xmlparam xp(strpath.toStdString());
- std::string strmemsend0 = xp.GetParam("cansend0_agx","cansend0");
- std::string strmemrecv0 = xp.GetParam("canrecv0_agx","canrecv0");
- std::string strcanname = xp.GetParam("canname","can0");
- gpcanctrl = new canctrl(strmemsend0.data(),strmemrecv0.data(),strcanname.data());
- gpcanctrl->start();
- iv::ivexit::RegIVExitCall(exitfunc);
- signal(SIGINT,signal_handler);
- #ifdef TEST_PROG
- std::thread * pthread = new std::thread(threadtest);
- #endif
- // std::thread b(func);
- return a.exec();
- }
|