|
@@ -0,0 +1,537 @@
|
|
|
|
+#include "radio.h"
|
|
|
|
+//#include <string.h>
|
|
|
|
+Radio::Radio()
|
|
|
|
+{
|
|
|
|
+ m_bSerialOpen = false;
|
|
|
|
+ m_bEnConnect=false;
|
|
|
|
+ serialPortInit();
|
|
|
|
+ timer = new QTimer(this);
|
|
|
|
+ connect(timer,SIGNAL(timeout()),SLOT(heartBeat()));
|
|
|
|
+ timer->start(1000);
|
|
|
|
+ m_iResponse = -1;
|
|
|
|
+ m_iVirtualVehicle = -1;
|
|
|
|
+ m_bEnTrafficBroadcast=false;
|
|
|
|
+ m_bEnCollisionWarning=false;
|
|
|
|
+ m_bEnBusyRoad=false;
|
|
|
|
+ m_bEnDangerDrive=false;
|
|
|
|
+ m_bEnUpRespond=false;
|
|
|
|
+}
|
|
|
|
+Radio::~Radio()
|
|
|
|
+{
|
|
|
|
+ if (m_serialPort_Radio->isOpen())
|
|
|
|
+ {
|
|
|
|
+ m_serialPort_Radio->close();
|
|
|
|
+ }
|
|
|
|
+ delete m_serialPort_Radio;
|
|
|
|
+}
|
|
|
|
+void Radio::setVin(std::string vin)
|
|
|
|
+{
|
|
|
|
+ m_sVin=vin;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::getTrafficBroadcast(bool en)
|
|
|
|
+{
|
|
|
|
+ m_bEnTrafficBroadcast=en;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::getCollisonWarning(bool en)
|
|
|
|
+{
|
|
|
|
+ m_bEnCollisionWarning=en;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::getBusyRoad(bool en)
|
|
|
|
+{
|
|
|
|
+ m_bEnBusyRoad=en;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::getDangerDrive(bool en)
|
|
|
|
+{
|
|
|
|
+ m_bEnDangerDrive=en;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::outLight(lightMessage light)
|
|
|
|
+{
|
|
|
|
+ if(m_bEnBusyRoad|m_bEnCollisionWarning|m_bEnDangerDrive|m_bEnTrafficBroadcast) {
|
|
|
|
+ //protobuffer ui
|
|
|
|
+ }
|
|
|
|
+ //protobuffer control
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::outRealtimeTraffic(realtimeTrafficMessage realtimeTraffic)
|
|
|
|
+{
|
|
|
|
+ if(m_bEnTrafficBroadcast) {
|
|
|
|
+ //protobuffer ui
|
|
|
|
+ }
|
|
|
|
+ //protobuffer control
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::outCollisionWarning(collisionEarlyWarningMessage collisionWarning)
|
|
|
|
+{
|
|
|
|
+ if(m_bEnCollisionWarning) {
|
|
|
|
+ //protobuffer ui
|
|
|
|
+ }
|
|
|
|
+ //protobuffer control
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::outCongestionIdenti(congestionIdentificationMessage congestionIdenti)
|
|
|
|
+{
|
|
|
|
+ if(m_bEnBusyRoad) {
|
|
|
|
+ //protobuffer ui
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Radio::setEnConnect(bool en)
|
|
|
|
+{
|
|
|
|
+ m_bEnConnect=en;
|
|
|
|
+}
|
|
|
|
+void Radio::serialPortInit()
|
|
|
|
+{
|
|
|
|
+// QStringList m_serialPortName;
|
|
|
|
+// foreach(const QSerialPortInfo &info,QSerialPortInfo::availablePorts())
|
|
|
|
+// {
|
|
|
|
+// m_serialPortName << info.portName();
|
|
|
|
+// qDebug()<<"serialPortName:"<<info.portName();
|
|
|
|
+// }
|
|
|
|
+
|
|
|
|
+ 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->setParity(QSerialPort::NoParity);
|
|
|
|
+ m_serialPort_Radio->setDataBits(QSerialPort::Data8);
|
|
|
|
+ m_serialPort_Radio->setStopBits(QSerialPort::OneStop);
|
|
|
|
+ m_serialPort_Radio->setFlowControl(QSerialPort::NoFlowControl);
|
|
|
|
+ m_serialPort_Radio->setReadBufferSize(0);
|
|
|
|
+ connect(m_serialPort_Radio,SIGNAL(readyRead()),this,SLOT(receiveData()));
|
|
|
|
+}
|
|
|
|
+void Radio::openSerial()
|
|
|
|
+{
|
|
|
|
+ if(m_serialPort_Radio->open(QSerialPort::ReadWrite)) {
|
|
|
|
+ m_bSerialOpen = true;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+void Radio::closeSerial()
|
|
|
|
+{
|
|
|
|
+ if(m_serialPort_Radio->isOpen())//如果串口已经打开了
|
|
|
|
+ {
|
|
|
|
+ m_serialPort_Radio->clear();
|
|
|
|
+ m_serialPort_Radio->close();
|
|
|
|
+ m_bSerialOpen = false;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+void Radio::heartBeat()
|
|
|
|
+{
|
|
|
|
+ if(m_bEnConnect) {
|
|
|
|
+ if(m_bSerialOpen==false) {
|
|
|
|
+ openSerial();
|
|
|
|
+ } else {
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+ if(m_iResponse>=9) {
|
|
|
|
+ m_iResponse = -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(m_iVirtualVehicle!=-1) {
|
|
|
|
+ m_iVirtualVehicle++;
|
|
|
|
+ if((m_iVirtualVehicle==3)||(m_iVirtualVehicle==6)||(m_iVirtualVehicle==9)) {
|
|
|
|
+ upVirtualVehicleRaw();
|
|
|
|
+ }
|
|
|
|
+ if(m_iVirtualVehicle>=9) {
|
|
|
|
+ m_iVirtualVehicle = -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ///////////////////////////////////////////////////////
|
|
|
|
+ if(m_bEnUpRespond) {
|
|
|
|
+ upRespondMessage();
|
|
|
|
+ m_bEnUpRespond=false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if(m_bSerialOpen) {
|
|
|
|
+ closeSerial();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+void Radio::upDataStream()
|
|
|
|
+{
|
|
|
|
+ char sendBuf[100];
|
|
|
|
+ memset(sendBuf,0,100);
|
|
|
|
+ upVehicleBaseInfo carFormationInfo;
|
|
|
|
+ std::string vin=m_sVin;
|
|
|
|
+ vin.copy(carFormationInfo.vin, vin.length(), 0);
|
|
|
|
+
|
|
|
|
+ carFormationInfo.vehicleType=0x01;//0x01:轿车;0x02:货车;0x03:客车;0x04:挂车;0x05:摩托车;“0xFE”表示异常,“0xFF”表示无效
|
|
|
|
+ float flng,flat;
|
|
|
|
+ flng = (m_structMGpsImu.gps_lng*1000000);
|
|
|
|
+ flat = (m_structMGpsImu.gps_lat*1000000);
|
|
|
|
+ int lng,lat;
|
|
|
|
+ lng=int(flng);
|
|
|
|
+ lat=int(flat);
|
|
|
|
+ carFormationInfo.lng[0] = (lng>>24)&0xff;
|
|
|
|
+ carFormationInfo.lng[1] = (lng>>16)&0xff;
|
|
|
|
+ carFormationInfo.lng[2] = (lng>>8)&0xff;
|
|
|
|
+ carFormationInfo.lng[3] = (lng)&0xff;
|
|
|
|
+
|
|
|
|
+ carFormationInfo.lat[0] = (lat>>24)&0xff;
|
|
|
|
+ carFormationInfo.lat[1] = (lat>>16)&0xff;
|
|
|
|
+ carFormationInfo.lat[2] = (lat>>8)&0xff;
|
|
|
|
+ carFormationInfo.lat[3] = (lat)&0xff;
|
|
|
|
+ int ispeed;
|
|
|
|
+ ispeed = int(m_structMGpsImu.speed);
|
|
|
|
+ unsigned char speed=(ispeed)&0xff;
|
|
|
|
+ carFormationInfo.speed = speed;
|
|
|
|
+ int yaw=int(m_structMGpsImu.yaw);
|
|
|
|
+ carFormationInfo.yaw[0] = (yaw>>24)&0xff;
|
|
|
|
+ carFormationInfo.yaw[1] = (yaw>>16)&0xff;
|
|
|
|
+ carFormationInfo.yaw[2] = (yaw>>8)&0xff;
|
|
|
|
+ carFormationInfo.yaw[3] = (yaw)&0xff;
|
|
|
|
+ float fele=m_structMControl.eleVoltage*100.0;
|
|
|
|
+ int iele = int(fele);
|
|
|
|
+ unsigned char electrical=(iele)&0xff;
|
|
|
|
+ carFormationInfo.electricalVoltage=electrical;
|
|
|
|
+ float faccx=m_structMGpsImu.accx*10.0;
|
|
|
|
+ int iaccx=int(faccx);
|
|
|
|
+ carFormationInfo.acc_x=(iaccx)&0xff;
|
|
|
|
+ float faccy=m_structMGpsImu.accy*10.0;
|
|
|
|
+ int iaccy=int(faccy);
|
|
|
|
+ carFormationInfo.acc_y=(iaccy)&0xff;
|
|
|
|
+ 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
|
|
|
|
+ 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");
|
|
|
|
+}
|
|
|
|
+void Radio::upVirtualVehicle(virtualVehicleM virtualVehicle)
|
|
|
|
+{
|
|
|
|
+ m_iVirtualVehicle=-1;
|
|
|
|
+ m_structMVirtualVehicle=virtualVehicle;
|
|
|
|
+ upVirtualVehicleRaw();
|
|
|
|
+}
|
|
|
|
+void Radio::upVirtualVehicleRaw()
|
|
|
|
+{
|
|
|
|
+ char sendBuf[100];
|
|
|
|
+ memset(sendBuf,0,100);
|
|
|
|
+ upVirtualVehicleInfo virtualVehicleInfo;
|
|
|
|
+ std::string vin=m_structMVirtualVehicle.vin;
|
|
|
|
+ vin.copy(virtualVehicleInfo.vin, 17, 0);
|
|
|
|
+
|
|
|
|
+ float flng,flat;
|
|
|
|
+ flng = (m_structMVirtualVehicle.gps_lng*1000000);
|
|
|
|
+ flat = (m_structMVirtualVehicle.gps_lat*1000000);
|
|
|
|
+ int lng,lat;
|
|
|
|
+ lng=int(flng);
|
|
|
|
+ lat=int(flat);
|
|
|
|
+ virtualVehicleInfo.lng[0] = (lng>>24)&0xff;
|
|
|
|
+ virtualVehicleInfo.lng[1] = (lng>>16)&0xff;
|
|
|
|
+ virtualVehicleInfo.lng[2] = (lng>>8)&0xff;
|
|
|
|
+ virtualVehicleInfo.lng[3] = (lng)&0xff;
|
|
|
|
+
|
|
|
|
+ virtualVehicleInfo.lat[0] = (lat>>24)&0xff;
|
|
|
|
+ virtualVehicleInfo.lat[1] = (lat>>16)&0xff;
|
|
|
|
+ virtualVehicleInfo.lat[2] = (lat>>8)&0xff;
|
|
|
|
+ virtualVehicleInfo.lat[3] = (lat)&0xff;
|
|
|
|
+ int ispeed;
|
|
|
|
+ ispeed = int(m_structMVirtualVehicle.speed);
|
|
|
|
+ unsigned char speed=(ispeed)&0xff;
|
|
|
|
+ virtualVehicleInfo.speed = speed;
|
|
|
|
+ int yaw=int(m_structMVirtualVehicle.yaw);
|
|
|
|
+ virtualVehicleInfo.yaw[0] = (yaw>>24)&0xff;
|
|
|
|
+ virtualVehicleInfo.yaw[1] = (yaw>>16)&0xff;
|
|
|
|
+ virtualVehicleInfo.yaw[2] = (yaw>>8)&0xff;
|
|
|
|
+ virtualVehicleInfo.yaw[3] = (yaw)&0xff;
|
|
|
|
+
|
|
|
|
+ int dataLen = sizeof(upVirtualVehicleInfo)/sizeof(unsigned char);
|
|
|
|
+ int headLen = PackagetHeadInfo(0x00,VirtualVehicle,comment,dataLen);//jiaolili,featureID need clear
|
|
|
|
+ memcpy(sendBuf,&packageDataHead,headLen);
|
|
|
|
+ memcpy(sendBuf+headLen,&virtualVehicleInfo,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");
|
|
|
|
+}
|
|
|
|
+void Radio::upRespondMessage()
|
|
|
|
+{
|
|
|
|
+ m_iResponse=-1;
|
|
|
|
+ upRespondMessageRaw();
|
|
|
|
+}
|
|
|
|
+void Radio::upRespondMessageRaw()
|
|
|
|
+{
|
|
|
|
+ char sendBuf[100];
|
|
|
|
+ memset(sendBuf,0,100);
|
|
|
|
+ upResponseInfo responseInfo;
|
|
|
|
+ std::string vin=m_sVin;
|
|
|
|
+ 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
|
|
|
|
+ memcpy(sendBuf,&packageDataHead,headLen);
|
|
|
|
+ memcpy(sendBuf+headLen,&responseInfo,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");
|
|
|
|
+}
|
|
|
|
+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.featureSymbol = featureID;
|
|
|
|
+ packageDataHead.commentSymbol = commendID;
|
|
|
|
+ packageDataHead.responseSymbol = respondID;
|
|
|
|
+ packageDataHead.encryptionType = 0x01;
|
|
|
|
+ //秒级时间戳(十位)
|
|
|
|
+ long timestamp = QDateTime::currentMSecsSinceEpoch() / 1000;
|
|
|
|
+ packageDataHead.timeStamp[0]=(timestamp>>56)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[1]=(timestamp>>48)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[2]=(timestamp>>40)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[3]=(timestamp>>32)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[4]=(timestamp>>24)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[5]=(timestamp>>16)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[6]=(timestamp>>8)&0xff;
|
|
|
|
+ packageDataHead.timeStamp[7]=(timestamp)&0xff;
|
|
|
|
+ packageDataHead.dataLength[0] = (dataLen >> 8) & 0xFF;
|
|
|
|
+ packageDataHead.dataLength[1] = dataLen & 0xFF;
|
|
|
|
+ int headLen = sizeof(packageDataHead)/sizeof(unsigned char);
|
|
|
|
+ return headLen;
|
|
|
|
+}
|
|
|
|
+void Radio::receiveData()
|
|
|
|
+{
|
|
|
|
+ qint64 rLen = m_serialPort_Radio->bytesAvailable();
|
|
|
|
+ qDebug() << "rLen:"<<rLen;
|
|
|
|
+ if (rLen <= 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ char *_data = new char[rLen + 1];
|
|
|
|
+ if (_data == NULL) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ memset(_data, 0, rLen + 1);
|
|
|
|
+ //socket_mutex.lock();
|
|
|
|
+ int ret = m_serialPort_Radio->read(_data, rLen);
|
|
|
|
+ //socket_mutex.unlock();
|
|
|
|
+ if(ret <= 0)
|
|
|
|
+ {
|
|
|
|
+ qDebug() << "read error";
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ QByteArray data(_data, ret);
|
|
|
|
+
|
|
|
|
+ delete [] _data;
|
|
|
|
+ // 数据拆开
|
|
|
|
+ ReceiveDecode(data);
|
|
|
|
+ replyMessage();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char Radio::BCCEncode(char sbuf[],int len)//计算校验
|
|
|
|
+{
|
|
|
|
+ if(sbuf == NULL || len < 4)
|
|
|
|
+ return false;
|
|
|
|
+ char BBCcode;
|
|
|
|
+ BBCcode = sbuf[2];
|
|
|
|
+ for (int i = 3; i < len; i++) {
|
|
|
|
+ BBCcode = BBCcode^sbuf[i];
|
|
|
|
+ }
|
|
|
|
+ return BBCcode;
|
|
|
|
+}
|
|
|
|
+bool Radio::BCCDecode(char sbuf[], int len)
|
|
|
|
+{
|
|
|
|
+ if(sbuf == NULL || len < 4)
|
|
|
|
+ return false;
|
|
|
|
+ char BBCcode;
|
|
|
|
+ BBCcode = sbuf[2];
|
|
|
|
+ for (int i = 3; i < len-1; i++) {
|
|
|
|
+ BBCcode = BBCcode^sbuf[i];
|
|
|
|
+ }
|
|
|
|
+ if (BBCcode == sbuf[len-1])
|
|
|
|
+ return true;
|
|
|
|
+ else
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
+void Radio::replyMessage()
|
|
|
|
+{
|
|
|
|
+ //queue_mutex.lock();
|
|
|
|
+ if(readData.isEmpty())
|
|
|
|
+ {
|
|
|
|
+ //queue_mutex.unlock();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ QByteArray data = readData.dequeue();
|
|
|
|
+ //queue_mutex.unlock();
|
|
|
|
+
|
|
|
|
+ int len = data.size();
|
|
|
|
+
|
|
|
|
+ char *recvBuf = data.data();
|
|
|
|
+ if(len < 21 || recvBuf == NULL)
|
|
|
|
+ {
|
|
|
|
+ qDebug() << "len error";
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ qDebug() <<"len:"<<len;
|
|
|
|
+ qDebug() <<"recvBuf: "<<recvBuf;
|
|
|
|
+
|
|
|
|
+ bool is_checkok = false;
|
|
|
|
+ is_checkok = BCCDecode(recvBuf,len);
|
|
|
|
+ if(is_checkok==false) {
|
|
|
|
+ qDebug() << "check error";
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ qDebug() << "check ok";
|
|
|
|
+ }
|
|
|
|
+ switch(recvBuf[5]) {
|
|
|
|
+ case TrafficLight: {
|
|
|
|
+ lightMessage light;
|
|
|
|
+ light.lightType=recvBuf[18];
|
|
|
|
+ light.timeRemaining=(((recvBuf[19]<<8)&0xFF00)|((recvBuf[20])&0xFF));
|
|
|
|
+ outLight(light);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case RealtimeTraffic: {
|
|
|
|
+ realtimeTrafficMessage realtimeTraffic;
|
|
|
|
+ realtimeTraffic.lng=(((recvBuf[18]<<24)&0xFF000000)|((recvBuf[19]<<16)&0xFF0000)|((recvBuf[20]<<8)&0xFF00)|((recvBuf[21])&0xFF));
|
|
|
|
+ realtimeTraffic.lat=(((recvBuf[22]<<24)&0xFF000000)|((recvBuf[23]<<16)&0xFF0000)|((recvBuf[24]<<8)&0xFF00)|((recvBuf[25])&0xFF));
|
|
|
|
+ realtimeTraffic.scope=(((recvBuf[26]<<8)&0xFF00)|((recvBuf[27])&0xFF));
|
|
|
|
+ realtimeTraffic.trafficInfo=recvBuf[28];
|
|
|
|
+ realtimeTraffic.speedLimit=(recvBuf[29]&0xFF);
|
|
|
|
+ outRealtimeTraffic(realtimeTraffic);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case CollisionEarlyWarning: {
|
|
|
|
+ collisionEarlyWarningMessage collisionWarning;
|
|
|
|
+ std::string *str;
|
|
|
|
+ memcpy(str, recvBuf+18, 17);
|
|
|
|
+ collisionWarning.isEnable=true;
|
|
|
|
+ collisionWarning.vin=*str;
|
|
|
|
+ collisionWarning.warningType=recvBuf[35];
|
|
|
|
+ collisionWarning.speedLimit=recvBuf[36];
|
|
|
|
+ if(collisionWarning.vin==m_sVin) {
|
|
|
|
+ outCollisionWarning(collisionWarning);
|
|
|
|
+ responseCollisionEarlyWarning(collisionWarning);
|
|
|
|
+ m_responseType=collisionWarning.warningType;
|
|
|
|
+ m_bEnUpRespond=true;
|
|
|
|
+ //upRespondMessage();
|
|
|
|
+ } else {
|
|
|
|
+ qDebug()<<"[CollisionEarlyWarning] vin error"<<endl;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case CongestionIdentification: {
|
|
|
|
+ congestionIdentificationMessage congestionIdenti;
|
|
|
|
+ std::string *str;
|
|
|
|
+ memcpy(str, recvBuf+18, 17);
|
|
|
|
+ congestionIdenti.isEnable=true;
|
|
|
|
+ congestionIdenti.vin=*str;
|
|
|
|
+ congestionIdenti.openCommand=recvBuf[35];
|
|
|
|
+ if(congestionIdenti.vin==m_sVin) {
|
|
|
|
+ responseCongestionIdentification(congestionIdenti);
|
|
|
|
+ outCongestionIdenti(congestionIdenti);
|
|
|
|
+ } else {
|
|
|
|
+ qDebug()<<"[CongestionIdentification] vin error"<<endl;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case ResponseMessage: {
|
|
|
|
+ m_iResponse = -1;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ case VirtualVehicle: {
|
|
|
|
+ m_iVirtualVehicle = -1;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+void Radio::responseCollisionEarlyWarning(collisionEarlyWarningMessage collisionWarning)
|
|
|
|
+{
|
|
|
|
+ char sendBuf[100];
|
|
|
|
+ memset(sendBuf,0,100);
|
|
|
|
+ responseCollisionEarlyWarningInfo responseCollisionWarningInfo;
|
|
|
|
+ std::string vin=m_sVin;
|
|
|
|
+ vin.copy(responseCollisionWarningInfo.vin, vin.length(), 0);
|
|
|
|
+ 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
|
|
|
|
+ memcpy(sendBuf,&packageDataHead,headLen);
|
|
|
|
+ memcpy(sendBuf+headLen,&responseCollisionWarningInfo,dataLen);
|
|
|
|
+ sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
|
|
|
|
+ m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
|
|
|
|
+ m_serialPort_Radio->flush();
|
|
|
|
+}
|
|
|
|
+void Radio::responseCongestionIdentification(congestionIdentificationMessage congestionIdenti)
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ char sendBuf[100];
|
|
|
|
+ memset(sendBuf,0,100);
|
|
|
|
+ responseCongestionIdentificationInfo responseCongestionInfo;
|
|
|
|
+ std::string vin=m_sVin;
|
|
|
|
+ vin.copy(responseCongestionInfo.vin, vin.length(), 0);
|
|
|
|
+ responseCongestionInfo.openCommand = congestionIdenti.openCommand;
|
|
|
|
+
|
|
|
|
+ int dataLen = sizeof(responseCongestionIdentificationInfo)/sizeof(unsigned char);
|
|
|
|
+ int headLen = PackagetHeadInfo(0x00,CongestionIdentification,resuccess,dataLen);//jiaolili,featureID need clear
|
|
|
|
+ memcpy(sendBuf,&packageDataHead,headLen);
|
|
|
|
+ memcpy(sendBuf+headLen,&responseCongestionInfo,dataLen);
|
|
|
|
+ sendBuf[headLen+dataLen] = BCCEncode(sendBuf,headLen+dataLen);
|
|
|
|
+ m_serialPort_Radio->write(sendBuf,headLen+dataLen+1);
|
|
|
|
+ m_serialPort_Radio->flush();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+void Radio::ReceiveDecode(QByteArray &data)
|
|
|
|
+{
|
|
|
|
+ static int BATH_LENTH = 21;
|
|
|
|
+ // 防包太大
|
|
|
|
+ if (data.size() > 2048) {
|
|
|
|
+ qDebug() << "size too large";
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // ##
|
|
|
|
+ char first;
|
|
|
|
+ char second;
|
|
|
|
+ // 寻找报文开头
|
|
|
|
+ while (data.size() >= BATH_LENTH) {
|
|
|
|
+ while (1) {
|
|
|
|
+ first = data[0];
|
|
|
|
+ second = data[1];
|
|
|
|
+ if (first == '$' && second == '$') {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ // 删除一个字符
|
|
|
|
+ data.remove(0, 1);
|
|
|
|
+ if (data.size() < BATH_LENTH)
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ int high = data.at(16);
|
|
|
|
+ int low = data.at(17);
|
|
|
|
+ int dataLen = (high << 8) | low;
|
|
|
|
+ qDebug() << "dataLen:" << dataLen;
|
|
|
|
+ // 长度不对
|
|
|
|
+ if ((dataLen + sizeof(packageDataHead)) > data.size()) {
|
|
|
|
+ qDebug() << "message len error";
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ QByteArray temp = data.left(sizeof(packageDataHead) + dataLen + 1);
|
|
|
|
+ //queue_mutex.lock();
|
|
|
|
+ readData.enqueue(temp);
|
|
|
|
+ //queue_mutex.unlock();
|
|
|
|
+ data.remove(0, sizeof(packageDataHead) + dataLen + 1);//need check,20210915,jiaolili
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|