|
@@ -0,0 +1,214 @@
|
|
|
+#include <QCoreApplication>
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <QDateTime>
|
|
|
+#include <math.h>
|
|
|
+
|
|
|
+#include <thread>
|
|
|
+#include <QElapsedTimer>
|
|
|
+#include "modulecomm.h"
|
|
|
+#include "xmlparam.h"
|
|
|
+#include "ivlog.h"
|
|
|
+#include "ivfault.h"
|
|
|
+#include "ivversion.h"
|
|
|
+
|
|
|
+iv::Ivlog * givlog;
|
|
|
+iv::Ivfault * givfault;
|
|
|
+
|
|
|
+#include "canmsg.pb.h"
|
|
|
+#include "bridge.pb.h"
|
|
|
+
|
|
|
+iv::bridge::reciver grecv;
|
|
|
+
|
|
|
+unsigned char dataToVision[8] = {0};
|
|
|
+unsigned char dataToArm[8] = {0};
|
|
|
+bool hasVisionCtrl = false;
|
|
|
+bool hasArmCtrl = false;
|
|
|
+int gnIndex = 0;
|
|
|
+void * gpa , * gpb;
|
|
|
+
|
|
|
+QElapsedTimer gTime;
|
|
|
+
|
|
|
+void ShareResult()
|
|
|
+{
|
|
|
+ char * str = new char[grecv.ByteSize()];
|
|
|
+ int nsize = grecv.ByteSize();
|
|
|
+ if(grecv.SerializeToArray(str,nsize))
|
|
|
+ {
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpa,str,nsize);
|
|
|
+ }
|
|
|
+ delete[] str;
|
|
|
+ str = nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+void ShareResultToCan()
|
|
|
+{
|
|
|
+ iv::can::canmsg xmsg;
|
|
|
+ iv::can::canraw xraw;
|
|
|
+
|
|
|
+ if(hasVisionCtrl){
|
|
|
+ xraw.set_id(0x7F);
|
|
|
+ xraw.set_data(dataToVision,8);
|
|
|
+ xraw.set_bext(false);
|
|
|
+ xraw.set_bremote(false);
|
|
|
+ xraw.set_len(8);
|
|
|
+ iv::can::canraw * pxraw = xmsg.add_rawmsg();
|
|
|
+ pxraw->CopyFrom(xraw);
|
|
|
+ xmsg.set_channel(0);
|
|
|
+ xmsg.set_index(gnIndex);
|
|
|
+ hasVisionCtrl = false;
|
|
|
+ dataToVision[0] = 0;
|
|
|
+ dataToVision[1] = 0;
|
|
|
+ }
|
|
|
+ if(hasArmCtrl){
|
|
|
+ xraw.set_id(0x7B);
|
|
|
+ xraw.set_data(dataToArm,8);
|
|
|
+ xraw.set_bext(false);
|
|
|
+ xraw.set_bremote(false);
|
|
|
+ xraw.set_len(8);
|
|
|
+ iv::can::canraw * pxraw1 = xmsg.add_rawmsg();
|
|
|
+ pxraw1->CopyFrom(xraw);
|
|
|
+ xmsg.set_channel(0);
|
|
|
+ xmsg.set_index(gnIndex);
|
|
|
+ hasArmCtrl = false;
|
|
|
+ dataToArm[0] = 0;
|
|
|
+ }
|
|
|
+ gnIndex++;
|
|
|
+ xmsg.set_mstime(QDateTime::currentMSecsSinceEpoch());
|
|
|
+ int ndatasize = xmsg.ByteSize();
|
|
|
+ char * strser = new char[ndatasize];
|
|
|
+ std::shared_ptr<char> pstrser;
|
|
|
+ pstrser.reset(strser);
|
|
|
+ if(xmsg.SerializeToArray(strser,ndatasize))
|
|
|
+ {
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpb,strser,ndatasize);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<"MainWindow::onTimer serialize error."<<std::endl;
|
|
|
+ }
|
|
|
+}
|
|
|
+void DecodeData(iv::can::canmsg xmsg)
|
|
|
+{
|
|
|
+ int type=0;
|
|
|
+ int color=0;
|
|
|
+ if(xmsg.rawmsg_size() < 1)return;
|
|
|
+
|
|
|
+ int i;
|
|
|
+ for(i=0;i<xmsg.rawmsg_size();i++)
|
|
|
+ {
|
|
|
+ iv::can::canraw canmsg = xmsg.rawmsg(i);
|
|
|
+
|
|
|
+ if(canmsg.id() == 0x7E)//精准识别=》自动驾驶系统
|
|
|
+ {
|
|
|
+ int data[8];
|
|
|
+ unsigned char cdata[8];
|
|
|
+ memcpy(cdata,canmsg.data().data(),8);
|
|
|
+
|
|
|
+ for(int j=0;j<8;j++)
|
|
|
+ data[j] = cdata[j];
|
|
|
+ grecv.set_stop(data[0]);//停车
|
|
|
+ grecv.set_pause(data[1]);//控制权移交
|
|
|
+ ShareResult();
|
|
|
+ }
|
|
|
+ else if(canmsg.id() == 0x7A)//机械控制=》自动驾驶系统
|
|
|
+ {
|
|
|
+
|
|
|
+ int data[8];
|
|
|
+ unsigned char cdata[8];
|
|
|
+ memcpy(cdata,canmsg.data().data(),8);
|
|
|
+
|
|
|
+ for(int j=0;j<8;j++)
|
|
|
+ data[j] = cdata[j];
|
|
|
+ grecv.set_st_rbshbox(data[0]);//垃圾箱回位状态1-》回位
|
|
|
+ ShareResult();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void Listencan0(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1)return;
|
|
|
+ iv::can::canmsg xmsg;
|
|
|
+
|
|
|
+ if(false == xmsg.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DecodeData(xmsg);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void ListenBrain(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1)return;
|
|
|
+ iv::bridge::sender xmsg;
|
|
|
+ unsigned char cdata[8];
|
|
|
+
|
|
|
+ if(false == xmsg.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(xmsg.has_camerastart())
|
|
|
+ {
|
|
|
+ hasVisionCtrl = true;
|
|
|
+ dataToVision[0] = xmsg.camerastart();
|
|
|
+ }
|
|
|
+ if(xmsg.has_carctrl())
|
|
|
+ {
|
|
|
+ hasVisionCtrl = true;
|
|
|
+ dataToVision[1] = xmsg.carctrl();
|
|
|
+ }
|
|
|
+ if(xmsg.has_rbshboxctrl())
|
|
|
+ {
|
|
|
+ hasArmCtrl = true;
|
|
|
+ dataToArm[0] = xmsg.rbshboxctrl();
|
|
|
+ }
|
|
|
+ ShareResultToCan();
|
|
|
+}
|
|
|
+
|
|
|
+void threadstate()
|
|
|
+{
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
+ }
|
|
|
+}
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ showversion("driver_vbox_gaohong");
|
|
|
+ QCoreApplication a(argc, argv);
|
|
|
+
|
|
|
+ gTime.start();
|
|
|
+
|
|
|
+ QString strpath = QCoreApplication::applicationDirPath();
|
|
|
+ if(argc < 2)
|
|
|
+ strpath = strpath + "/driver_agx_bridge.xml";
|
|
|
+ else
|
|
|
+ strpath = argv[1];
|
|
|
+ std::cout<<strpath.toStdString()<<std::endl;
|
|
|
+
|
|
|
+ iv::xmlparam::Xmlparam xp(strpath.toStdString());
|
|
|
+
|
|
|
+ std::string strmemcan = xp.GetParam("canrecv","canrecv1");
|
|
|
+ std::string strmemsend = xp.GetParam("cansend","cansend1");
|
|
|
+ std::string strmemBRec = xp.GetParam("bridgeRec","bridgeRec");
|
|
|
+ std::string strmemBSend = xp.GetParam("bridgeSend","bridgeSend");
|
|
|
+ std::string strmodulename = xp.GetParam("modulename","driver_agx_bridge");
|
|
|
+
|
|
|
+
|
|
|
+ givlog = new iv::Ivlog(strmodulename.data());
|
|
|
+ givfault = new iv::Ivfault(strmodulename.data());
|
|
|
+
|
|
|
+ givfault->SetFaultState(1,1,"初始化");
|
|
|
+ givlog->info("bridge","Initialized");
|
|
|
+
|
|
|
+ gpa = iv::modulecomm::RegisterSend(strmemBRec.data(),100000,3);//to brain
|
|
|
+ gpb = iv::modulecomm::RegisterSend(strmemsend.data(),100000,3);// to cansend1
|
|
|
+ iv::modulecomm::RegisterRecv(strmemcan.data(),Listencan0);// form canrecv1
|
|
|
+ iv::modulecomm::RegisterRecv(strmemBSend.data(),ListenBrain);//form brain
|
|
|
+
|
|
|
+ std::thread threadfault(threadstate);
|
|
|
+ return a.exec();
|
|
|
+}
|