Explorar o código

radio test proto

HAPO-9# %!s(int64=3) %!d(string=hai) anos
pai
achega
e7ce122ac2

+ 2 - 0
src/v2x/CommunicatePlatform/mainwindow.cpp

@@ -155,6 +155,7 @@ void MainWindow::on_pushButton_vinChange_clicked()
 {
         std::string str=ui->lineEdit_VIN->text().toStdString();
         m_tbox->setTboxNewVin(str);
+        m_radio->setVin(str);
 }
 void MainWindow::on_checkBox_trafficBroadcast_stateChanged(int arg1)
 {
@@ -325,6 +326,7 @@ void MainWindow::UpdateUI(const char * strdata,const unsigned int nSize,const un
         std::string str=xhmi.vin();
         ui->lineEdit_VIN->setText(QString::fromStdString(str));
         m_tbox->setTboxNewVin(str);
+        m_radio->setVin(str);
     }
     if(xhmi.has_rodeinfoen()) {
         bool enRadioBroadcast = xhmi.rodeinfoen();

+ 58 - 20
src/v2x/CommunicatePlatform/radio.cpp

@@ -10,6 +10,7 @@ Radio::Radio()
     timer->start(1000);
     m_iResponse = -1;
     m_iVirtualVehicle = -1;
+    m_iResponseRealtimeTraffic=-1;
     m_bEnTrafficBroadcast=false;
     m_bEnCollisionWarning=false;
     m_bEnBusyRoad=false;
@@ -19,6 +20,7 @@ Radio::Radio()
     mivlog = new iv::Ivlog("v2r");
     //shareMem:send
     mpmem_radio_send_addr = iv::modulecomm::RegisterSend("v2r_send",100,1);
+    m_sVin="A1000000CATARCS02";
     /////////////////////////////
 }
 Radio::~Radio()
@@ -95,7 +97,7 @@ void Radio::setGpsImuMemory(gpsImuM m)
 void Radio::sendResponseMessage(int type)
 {
     m_responseType=type&0xFF;
-    upRespondMessage();
+    upRespondMessageRealtimeTraffic();
 }
 void Radio::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
 {
@@ -103,6 +105,9 @@ void Radio::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
         iv::v2r::v2r_send protobuf;
         double lat=((double)realtimeTraffic.lat)/1000000.0;
         double lon=((double)realtimeTraffic.lng)/1000000.0;
+        qDebug()<<"[Radio]:real time traffic lat is "<<lat<<". lng is "<<lon
+               <<".scope is "<<realtimeTraffic.scope<<".traffic info is "<<realtimeTraffic.trafficInfo
+              <<". speed limit is "<<realtimeTraffic.speedLimit<<endl;
         protobuf.set_radiobroadcastgpslat(lat);
         protobuf.set_radiobroadcastgpslon(lon);
         protobuf.set_radiobroadcastrange(realtimeTraffic.scope);
@@ -118,6 +123,7 @@ void Radio::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
         iv::v2r::v2r_send protobuf;
         protobuf.set_radiowarningtype(collisionWarning.warningType);
         protobuf.set_radiowarningspeedlimit(collisionWarning.speedLimit);
+        qDebug()<<"[Radio]:warning type is "<<collisionWarning.warningType<<".speed limit is:"<<collisionWarning.speedLimit<<endl;
         sendProto(protobuf);
     }
 }
@@ -127,6 +133,7 @@ void Radio::outCongestionIdenti(congestionIdentificationMessage congestionIdenti
     if(m_bEnBusyRoad) {
         iv::v2r::v2r_send protobuf;
         protobuf.set_radioidentistart(congestionIdenti.openCommand);
+        qDebug()<<"[Radio]:congestion identi open command is "<<congestionIdenti.openCommand<<endl;
         sendProto(protobuf);
     }
 }
@@ -145,9 +152,9 @@ void Radio::serialPortInit()
 //    }
 
     m_serialPort_Radio = new QSerialPort();
-    //m_serialPort_Radio->setPortName("/dev/ttyUSB1");
-    m_serialPort_Radio->setPortName("/dev/pts/1");
-    m_serialPort_Radio->setBaudRate(QSerialPort::Baud115200);
+    m_serialPort_Radio->setPortName("/dev/ttyUSB1");
+    //m_serialPort_Radio->setPortName("/dev/pts/1");
+    m_serialPort_Radio->setBaudRate(QSerialPort::Baud9600);
     m_serialPort_Radio->setParity(QSerialPort::NoParity);
     m_serialPort_Radio->setDataBits(QSerialPort::Data8);
     m_serialPort_Radio->setStopBits(QSerialPort::OneStop);
@@ -176,12 +183,12 @@ void Radio::heartBeat()
         if(m_bSerialOpen==false) {
             openSerial();
         } else {
-            upDataStream();
+            //upDataStream();
             //if no answer,shake hands three times
             if(m_iResponse!=-1) {
                 m_iResponse++;
                 if((m_iResponse==3)||(m_iResponse==6)||(m_iResponse==9)) {
-                    upRespondMessageRaw();
+                    upRespondMessageRaw(0x02);
                 }
                 if(m_iResponse>=9) {
                     m_iResponse = -1;
@@ -196,6 +203,15 @@ void Radio::heartBeat()
                     m_iVirtualVehicle = -1;
                 }
             }
+            if(m_iResponseRealtimeTraffic!=-1) {
+                m_iResponseRealtimeTraffic++;
+                if((m_iResponseRealtimeTraffic==3)||(m_iResponseRealtimeTraffic==6)||(m_iResponseRealtimeTraffic==9)) {
+                    upRespondMessageRaw(0x01);
+                }
+                if(m_iResponseRealtimeTraffic>=9) {
+                    m_iResponseRealtimeTraffic = -1;
+                }
+            }
             ///////////////////////////////////////////////////////
             if(m_bEnUpRespond) {
                 upRespondMessage();
@@ -246,7 +262,7 @@ void Radio::upDataStream()
     int iele = int(fele);
     unsigned char electrical=(iele)&0xff;
     carFormationInfo.electricalVoltage=electrical;
-    float faccx=m_structMGpsImu.accx*10.0;
+    float faccx=(m_structMGpsImu.accx+6)*10.0;
     int iaccx=int(faccx);
     carFormationInfo.acc_x=(iaccx)&0xff;
     float faccy=m_structMGpsImu.accy*10.0;
@@ -255,19 +271,21 @@ void Radio::upDataStream()
     unsigned char error=m_structMControl.error;
     carFormationInfo.error=error;
     int dataLen = sizeof(upVehicleBaseInfo )/sizeof(unsigned char);
-    int headLen = PackagetHeadInfo(0x00,VehicleBaseInfo,comment,dataLen);//jiaolili,featureID need clear
+    int headLen = PackagetHeadInfo(0x05,VehicleBaseInfo,comment,dataLen);
     memcpy(sendBuf,&packageDataHead,headLen);
     memcpy(sendBuf+headLen,&carFormationInfo,dataLen);
     sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
     m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
     m_serialPort_Radio->flush();
     //m_serialPort_Radio->write("sendBuf");
+    qDebug() << "[RADIO]:up vehicle message "<<endl;
 }
 void Radio::upVirtualVehicle(virtualVehicleM virtualVehicle)
 {
-    m_iVirtualVehicle=-1;
+    m_iVirtualVehicle=0;
     m_structMVirtualVehicle=virtualVehicle;
     upVirtualVehicleRaw();
+    qDebug() << "[RADIO]:up virtual vehicle message "<<endl;
 }
 void Radio::upVirtualVehicleRaw()
 {
@@ -303,7 +321,7 @@ void Radio::upVirtualVehicleRaw()
     virtualVehicleInfo.yaw[3] = (yaw)&0xff;
 
     int dataLen = sizeof(upVirtualVehicleInfo)/sizeof(unsigned char);
-    int headLen = PackagetHeadInfo(0x00,VirtualVehicle,comment,dataLen);//jiaolili,featureID need clear
+    int headLen = PackagetHeadInfo(0x02,VirtualVehicle,comment,dataLen);
     memcpy(sendBuf,&packageDataHead,headLen);
     memcpy(sendBuf+headLen,&virtualVehicleInfo,dataLen);
     sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
@@ -313,11 +331,19 @@ void Radio::upVirtualVehicleRaw()
 }
 void Radio::upRespondMessage()
 {
+    qDebug() << "[RADIO]:up response message "<<endl;
     m_iResponse=0;
-    upRespondMessageRaw();
+    upRespondMessageRaw(0x02);
 }
-void Radio::upRespondMessageRaw()
+void Radio::upRespondMessageRealtimeTraffic()
 {
+    qDebug() << "[RADIO]:up response real time traffic message "<<endl;
+    m_iResponseRealtimeTraffic=0;
+    upRespondMessageRaw(0x01);
+}
+
+void Radio::upRespondMessageRaw(unsigned char featureId)
+{    
     char sendBuf[100];
     memset(sendBuf,0,100);
     upResponseInfo responseInfo;
@@ -325,7 +351,13 @@ void Radio::upRespondMessageRaw()
     vin.copy(responseInfo.vin, vin.length(), 0);
     responseInfo.reponseType = m_responseType;
     int dataLen = sizeof(upResponseInfo)/sizeof(unsigned char);
-    int headLen = PackagetHeadInfo(0x00,ResponseMessage,comment,dataLen);//jiaolili,featureID need clear
+    int headLen;
+    if(featureId==0x02) {
+        headLen = PackagetHeadInfo(0x02,ResponseMessage,comment,dataLen);
+    } else if (featureId==0x01) {
+        headLen = PackagetHeadInfo(0x01,ResponseMessage,comment,dataLen);
+    }
+
     memcpy(sendBuf,&packageDataHead,headLen);
     memcpy(sendBuf+headLen,&responseInfo,dataLen);
     sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
@@ -335,10 +367,10 @@ void Radio::upRespondMessageRaw()
 }
 int Radio::PackagetHeadInfo( unsigned char featureID,unsigned char commendID, unsigned char respondID,int dataLen)
 {
-    packageDataHead.startSymbol1 = '$';
-    packageDataHead.startSymbol2 = '$';
-    packageDataHead.driveTestSysSymbol[0]=0xFF;//jiaolili,need clear when testing
-    packageDataHead.driveTestSysSymbol[1]=0xFF;//jiaolili,need clear when testing
+    packageDataHead.startSymbol1 = 0x24;//
+    packageDataHead.startSymbol2 = 0x24;
+    packageDataHead.driveTestSysSymbol[0]=0x01;//jiaolili,need clear when testing
+    packageDataHead.driveTestSysSymbol[1]=0x00;//jiaolili,need clear when testing
     packageDataHead.featureSymbol = featureID;
     packageDataHead.commentSymbol  = commendID;
     packageDataHead.responseSymbol = respondID;
@@ -362,7 +394,7 @@ void Radio::receiveData()
 {
     qint64 rLen = m_serialPort_Radio->bytesAvailable();
     qDebug() << "rLen:"<<rLen;
-    if (rLen <= 0) {
+    if (rLen <= 38) {
         return;
     }
     char *_data = new char[rLen + 1];
@@ -448,6 +480,7 @@ void Radio::replyMessage()
             lightMessage light;
             light.lightType=recvBuf[18];
             light.timeRemaining=(((recvBuf[19]<<8)&0xFF00)|((recvBuf[20])&0xFF));
+            qDebug() << "[RADIO]:receive light type is "<<int(light.lightType)<<" and remaining is "<<light.timeRemaining;
             outLight(light);
             break;
         }
@@ -458,6 +491,7 @@ void Radio::replyMessage()
             realtimeTraffic.scope=(((recvBuf[26]<<8)&0xFF00)|((recvBuf[27])&0xFF));
             realtimeTraffic.trafficInfo=recvBuf[28];
             realtimeTraffic.speedLimit=(recvBuf[29]&0xFF);
+            qDebug() << "[RADIO]:receive real time traffic message "<<endl;
             outRealtimeTraffic(realtimeTraffic);
             break;
         }
@@ -470,6 +504,7 @@ void Radio::replyMessage()
             collisionWarning.warningType=recvBuf[35];
             collisionWarning.speedLimit=recvBuf[36];
             if(collisionWarning.vin==m_sVin) {
+                qDebug() << "[RADIO]:receive collisionEarlyWarning message "<<endl;
                 outCollisionWarning(collisionWarning);
                 responseCollisionEarlyWarning(collisionWarning);
                 m_responseType=collisionWarning.warningType;
@@ -488,6 +523,7 @@ void Radio::replyMessage()
             congestionIdenti.vin=*str;
             congestionIdenti.openCommand=recvBuf[35];
             if(congestionIdenti.vin==m_sVin) {
+                qDebug() << "[RADIO]:receive congestion identification message "<<endl;
                 responseCongestionIdentification(congestionIdenti);
                 outCongestionIdenti(congestionIdenti);
             } else {
@@ -496,10 +532,12 @@ void Radio::replyMessage()
             break;
         }
         case ResponseMessage: {
+            qDebug() << "[RADIO]:receive answer Response Message "<<endl;
             m_iResponse = -1;
             break;
         }
         case VirtualVehicle: {
+            qDebug() << "[RADIO]:receive answer VirtualVehicle "<<endl;
             m_iVirtualVehicle = -1;
             break;
         }
@@ -517,7 +555,7 @@ void Radio::responseCollisionEarlyWarning(collisionEarlyWarningMessage collision
     responseCollisionWarningInfo.warningType = collisionWarning.warningType;
     responseCollisionWarningInfo.speedLimit = (collisionWarning.speedLimit)&0xFF;
     int dataLen = sizeof(responseCollisionEarlyWarningInfo)/sizeof(unsigned char);
-    int headLen = PackagetHeadInfo(0x00,CollisionEarlyWarning,resuccess,dataLen);//jiaolili,featureID need clear
+    int headLen = PackagetHeadInfo(0x02,CollisionEarlyWarning,resuccess,dataLen);//jiaolili,featureID need clear
     memcpy(sendBuf,&packageDataHead,headLen);
     memcpy(sendBuf+headLen,&responseCollisionWarningInfo,dataLen);
     sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
@@ -535,7 +573,7 @@ void Radio::responseCongestionIdentification(congestionIdentificationMessage con
     responseCongestionInfo.openCommand = congestionIdenti.openCommand;
 
     int dataLen = sizeof(responseCongestionIdentificationInfo)/sizeof(unsigned char);
-    int headLen = PackagetHeadInfo(0x00,CongestionIdentification,resuccess,dataLen);//jiaolili,featureID need clear
+    int headLen = PackagetHeadInfo(0x03,CongestionIdentification,resuccess,dataLen);//jiaolili,featureID need clear
     memcpy(sendBuf,&packageDataHead,headLen);
     memcpy(sendBuf+headLen,&responseCongestionInfo,dataLen);
     sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);

+ 3 - 1
src/v2x/CommunicatePlatform/radio.h

@@ -132,8 +132,9 @@ public:
     void closeSerial();
     void upDataStream();
     void upVirtualVehicle(virtualVehicleM virtualVehicle);
+    void upRespondMessageRaw(unsigned char);
     void upRespondMessage();
-
+    void upRespondMessageRealtimeTraffic();
     void responseCollisionEarlyWarning(collisionEarlyWarningMessage collisionWarning);
     void responseCongestionIdentification(congestionIdentificationMessage congestionIdenti);
     char BCCEncode(char sbuf[],int len);//计算校验
@@ -164,6 +165,7 @@ private:
     radioDataPackageHead packageDataHead;
     int m_iResponse;
     int m_iVirtualVehicle;
+    int m_iResponseRealtimeTraffic;
     std::string m_sVin;
     gpsImuM m_structMGpsImu;
     controlM m_structMControl;

+ 1 - 1
src/v2x/CommunicatePlatform/tbox.cpp

@@ -16,7 +16,7 @@ Tbox::Tbox()
 }
 void Tbox::heartBeat()
 {
-    qDebug()<<"消息:Into hearbeat!"<<endl;
+    //qDebug()<<"消息:Into hearbeat!"<<endl;
     if(m_bEnConnect) {
         if(!m_bEnablePlatform) {
             connectPlatform();