123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- #include <QCoreApplication>
- #include <iostream>
- #include <QDateTime>
- #include <math.h>
- #include <thread>
- #include "modulecomm.h"
- #include "xmlparam.h"
- #include "ivlog.h"
- #include "ivfault.h"
- #include "ivversion.h"
- #include "ivbacktrace.h"
- iv::Ivlog * givlog;
- iv::Ivfault * givfault;
- #include "canmsg.pb.h"
- #include "canraw.pb.h"
- #include "decodechassis.h"
- void * gpa ;
- QTime gTime;
- namespace iv {
- enum VehicleTypeDef {GE3,VV7,MIDCAR,PROBLUE,MIDBUS,HAPO,UNKNOWN, YUHESEN,SHENLAN,SHENLAN_CANFD} gVehicleType; //车辆类型
- }
- int gnRadarState = 0;
- /**
- * @brief Listencan0
- * Listen CAN Message
- * @param strdata pointer to module communication buffer
- * @param nSize Message Size
- * @param index Message index
- * @param dt Share DateTime
- * @param strmemname Message Name of Share
- * @retval
- **/
- void Listencan0(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- {
- (void)index;
- (void)dt;
- (void)strmemname;
- if(nSize<1)return;
- iv::can::canmsg xmsg;
- if(false == xmsg.ParseFromArray(strdata,nSize))
- {
- std::cout<<"esr Listencan0 fail."<<std::endl;
- return;
- }
- int nRtn = 0;
- switch (iv::gVehicleType) {
- case iv::GE3:
- nRtn = ProcGE3Chassis(gpa,&xmsg);
- break;
- case iv::VV7:
- nRtn = ProcVV7Chassis(gpa,&xmsg);
- break;
- case iv::PROBLUE:
- nRtn = ProcPROBLUEChassis(gpa,&xmsg);
- break;
- case iv::MIDCAR:
- nRtn = ProcMIDCARChassis(gpa,&xmsg);
- break;
- case iv::MIDBUS:
- nRtn = ProcMIDBUSChassis(gpa,&xmsg);
- break;
- case iv::HAPO:
- nRtn = ProcHAPOChassis(gpa,&xmsg);
- break;
- case iv::YUHESEN:
- nRtn = ProcYUHESENChassis(gpa,&xmsg);
- break;
- case iv::SHENLAN:
- nRtn = ProcShenLanChassis(gpa,&xmsg);
- case iv::SHENLAN_CANFD:
- nRtn = ProcShenLanCANFDChassis(gpa,&xmsg);
- break;
- default:
- break;
- }
- if(nRtn == 1)gnRadarState = 100;
- // DecodeRadar(xmsg);
- // qDebug("can size is %d",xmsg.rawmsg_size());
- // xt = QDateTime::currentMSecsSinceEpoch();
- // qDebug("latence = %ld ",xt-pic.time());
- }
- /**
- * @brief threadstate
- * Update Fault State
- * @retval
- **/
- void threadstate()
- {
- while(1)
- {
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- if(gnRadarState > -100)gnRadarState--;
- if(gnRadarState > 0)
- {
- givfault->SetFaultState(0,0,"OK");
- }
- else
- {
- if(gnRadarState > -100)
- {
- givfault->SetFaultState(1,1,"无底盘数据");
- }
- else
- {
- givfault->SetFaultState(1,2,"底盘无响应");
- }
- }
- }
- }
- int main(int argc, char *argv[])
- {
- RegisterIVBackTrace();
- showversion("detection_chassis");
- QCoreApplication a(argc, argv);
- gTime.start();
- QString strpath = QCoreApplication::applicationDirPath();
- if(argc < 2)
- strpath = strpath + "/detection_chassis.xml";
- else
- strpath = argv[1];
- std::cout<<strpath.toStdString()<<std::endl;
- iv::xmlparam::Xmlparam xp(strpath.toStdString());
- std::string strmemcan = xp.GetParam("canrecv","canrecv0");
- std::string strvehicletype = xp.GetParam("vehicletype","GE3");
- std::string strmodulename = xp.GetParam("modulename","chassis"); //chassismsgname
- std::string strchassismsgname = xp.GetParam("chassismsgname","chassis");
- iv::gVehicleType = iv::UNKNOWN;
- if(strncmp(strvehicletype.data(),"GE3",255) == 0)
- {
- iv::gVehicleType = iv::GE3;
- }
- if(strncmp(strvehicletype.data(),"VV7",255) == 0)
- {
- iv::gVehicleType = iv::VV7;
- }
- if(strncmp(strvehicletype.data(),"PROBLUE",255) == 0)
- {
- iv::gVehicleType = iv::PROBLUE;
- }
- if(strncmp(strvehicletype.data(),"MIDCAR",255) == 0)
- {
- iv::gVehicleType = iv::MIDCAR;
- }
- if(strncmp(strvehicletype.data(),"MIDBUS",255) == 0)
- {
- iv::gVehicleType = iv::MIDBUS;
- }
- if(strncmp(strvehicletype.data(),"HAPO",255) == 0)
- {
- iv::gVehicleType = iv::HAPO;
- }
- if(strncmp(strvehicletype.data(),"YUHESEN",255) == 0)
- {
- iv::gVehicleType = iv::YUHESEN;
- }
- if(strncmp(strvehicletype.data(),"SHENLAN",255) == 0)
- {
- iv::gVehicleType = iv::SHENLAN;
- }
- if(strncmp(strvehicletype.data(),"SHENLAN_CANFD",255) == 0)
- {
- iv::gVehicleType = iv::SHENLAN_CANFD;
- }
- //iv::gVehicleType = iv::MIDBUS;
- givlog = new iv::Ivlog(strmodulename.data());
- givfault = new iv::Ivfault(strmodulename.data());
- givfault->SetFaultState(1,1,"初始化");
- givlog->info("Initialized");
- gpa = iv::modulecomm::RegisterSend(strchassismsgname.data(),1000,1);
- void * pa = iv::modulecomm::RegisterRecv(strmemcan.data(),Listencan0);
- std::thread threadfault(threadstate);
- return a.exec();
- }
|