#include #include #include #include "modulecomm.h" #include "ivversion.h" #include "ivbacktrace.h" #include "ivfault.h" #include "ivlog.h" #include "ivexit.h" #include "canmsg.pb.h" #ifndef NUM_OF_SENSOR_MAX #define NUM_OF_SENSOR_MAX 12 #endif #include "decode_cfg.h" #include "iv_msgunit.h" #include "can_producer_consumer.h" #include "canrecv_consumer.h" #include "cansend_consumer.h" #include "cansend_producer.h" QCoreApplication * gApp; iv::Ivfault *gfault = nullptr; iv::Ivlog *givlog = nullptr; setupConfig_t setupConfig; iv::msgunit shmCANRecv; iv::msgunit shmCANSend; iv::msgunit shmSonar; CAN_Producer_Consumer CANRecv(4096); CAN_Producer_Consumer CANSend(4096); CANSend_Producer* can_send_producer; CANSend_Consumer* can_send_consumer; CANRecv_Consumer* can_recv_consumer; void ListenCANMsg(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname) { if(nSize<1) { std::cout<<"radar ListenCANMsg data empty."<error("radar Listencanmsg fail"); gfault->SetFaultState(1, 0, "radar Listencanmsg error"); std::cout<<"radar ListenCANMsg parse fail."<quit(); std::this_thread::sleep_for(std::chrono::milliseconds(500)); } void signal_handler(int sig) { if(sig == SIGINT) { ExitFunc(); } } int main(int argc, char *argv[]) { RegisterIVBackTrace(); showversion("driver_ultrasonic_dauxi_KS136A"); QCoreApplication a(argc, argv); gApp = &a; givlog = new iv::Ivlog("driver_ultrasonic_dauxi_KS136A"); gfault = new iv::Ivfault("driver_ultrasonic_dauxi_KS136A"); signal(SIGINT,signal_handler); QString strpath = QCoreApplication::applicationDirPath(); if(argc < 2) strpath = strpath + "/driver_ultrasonic_dauxi_KS136A.xml"; else strpath = argv[1]; DecodeSonarCfgFromXML(setupConfig,strpath.toStdString()); strncpy(shmCANSend.mstrmsgname,setupConfig.strMemCANSend.data(),255); shmCANSend.mnBufferSize = 100000; shmCANSend.mnBufferCount = 3; shmCANSend.mpa = iv::modulecomm::RegisterSend(shmCANSend.mstrmsgname,shmCANSend.mnBufferSize,shmCANSend.mnBufferCount); strncpy(shmSonar.mstrmsgname,setupConfig.strMemSonar.data(),255); shmSonar.mnBufferSize = 100000; shmSonar.mnBufferCount = 1; shmSonar.mpa = iv::modulecomm::RegisterSend(shmSonar.mstrmsgname,shmSonar.mnBufferSize,shmSonar.mnBufferCount); strncpy(shmCANRecv.mstrmsgname,setupConfig.strMemCANRecv.data(),255); shmCANRecv.mnBufferSize = 100000; shmCANRecv.mnBufferCount = 3; shmCANRecv.mpa = iv::modulecomm::RegisterRecv(shmCANRecv.mstrmsgname,ListenCANMsg); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); can_send_consumer = new CANSend_Consumer(&CANSend); can_send_consumer->start(); can_send_producer = new CANSend_Producer(&CANSend); can_recv_consumer = new CANRecv_Consumer(&CANRecv); qRegisterMetaType("uint8_t"); QObject::connect(can_send_producer,&CANSend_Producer::Enable_DecodeResult,can_recv_consumer,&CANRecv_Consumer::Enable_DecodeResult_Slot); QObject::connect(can_recv_consumer,&CANRecv_Consumer::Enable_Ask,can_send_producer,&CANSend_Producer::Enable_Ask_Slot); can_send_producer->start(); can_recv_consumer->start(); int rtn = a.exec(); can_send_producer->terminate(); //function "terminate" can not be used in other position. it is dangerous. can_send_consumer->terminate(); //function "terminate" can not be used in other position. it is dangerous. can_recv_consumer->terminate(); //function "terminate" can not be used in other position. it is dangerous. if(gfault != nullptr)delete gfault; if(givlog != nullptr)delete givlog; if(shmCANRecv.mpa != nullptr)iv::modulecomm::Unregister(shmCANRecv.mpa); if(shmCANSend.mpa != nullptr)iv::modulecomm::Unregister(shmCANSend.mpa); if(shmSonar.mpa != nullptr)iv::modulecomm::Unregister(shmSonar.mpa); return rtn; }