|
@@ -21,6 +21,7 @@ Radio::Radio()
|
|
|
//shareMem:send
|
|
|
mpmem_radio_send_addr = iv::modulecomm::RegisterSend("v2r_send",100,1);
|
|
|
m_sVin="A1000000CATARCS02";
|
|
|
+ m_bEnReceive=false;
|
|
|
/////////////////////////////
|
|
|
}
|
|
|
Radio::~Radio()
|
|
@@ -179,11 +180,12 @@ void Radio::closeSerial()
|
|
|
}
|
|
|
void Radio::heartBeat()
|
|
|
{
|
|
|
+ m_bEnReceive=true;
|
|
|
if(m_bEnConnect) {
|
|
|
if(m_bSerialOpen==false) {
|
|
|
openSerial();
|
|
|
} else {
|
|
|
- //upDataStream();
|
|
|
+ upDataStream();
|
|
|
//if no answer,shake hands three times
|
|
|
if(m_iResponse!=-1) {
|
|
|
m_iResponse++;
|
|
@@ -224,6 +226,7 @@ void Radio::heartBeat()
|
|
|
closeSerial();
|
|
|
}
|
|
|
}
|
|
|
+ m_bEnReceive=false;
|
|
|
}
|
|
|
void Radio::upDataStream()
|
|
|
{
|
|
@@ -392,18 +395,51 @@ int Radio::PackagetHeadInfo( unsigned char featureID,unsigned char commendID, un
|
|
|
}
|
|
|
void Radio::receiveData()
|
|
|
{
|
|
|
+
|
|
|
+
|
|
|
qint64 rLen = m_serialPort_Radio->bytesAvailable();
|
|
|
+
|
|
|
+ if (rLen < 50) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
qDebug() << "rLen:"<<rLen;
|
|
|
- if (rLen <= 38) {
|
|
|
+ char *headdata = new char[1];
|
|
|
+ if (headdata == NULL) {
|
|
|
return;
|
|
|
}
|
|
|
- char *_data = new char[rLen + 1];
|
|
|
+ memset(headdata, 0, 1);
|
|
|
+ int ret;
|
|
|
+ char first;
|
|
|
+
|
|
|
+ for(int i=0;i++;i<rLen-4)
|
|
|
+ {
|
|
|
+ ret= m_serialPort_Radio->read(headdata, 1);
|
|
|
+ if(ret <= 0)
|
|
|
+ {
|
|
|
+ qDebug() << "read error";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ QByteArray data(headdata, ret);
|
|
|
+ first = data[i];
|
|
|
+ if (first == '$') {
|
|
|
+ delete [] headdata;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ rLen = m_serialPort_Radio->bytesAvailable();
|
|
|
+ if (rLen < 40) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ char *_data = new char[rLen + 2];
|
|
|
if (_data == NULL) {
|
|
|
return;
|
|
|
}
|
|
|
- memset(_data, 0, rLen + 1);
|
|
|
+ memset(_data, 0, rLen + 2);
|
|
|
+ _data[0]=0x24;
|
|
|
//socket_mutex.lock();
|
|
|
- int ret = m_serialPort_Radio->read(_data, rLen);
|
|
|
+ ret = m_serialPort_Radio->read(_data+1, rLen);
|
|
|
//socket_mutex.unlock();
|
|
|
if(ret <= 0)
|
|
|
{
|
|
@@ -416,6 +452,7 @@ void Radio::receiveData()
|
|
|
// 数据拆开
|
|
|
ReceiveDecode(data);
|
|
|
replyMessage();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
char Radio::BCCEncode(char sbuf[],int len)//计算校验
|
|
@@ -497,10 +534,11 @@ void Radio::replyMessage()
|
|
|
}
|
|
|
case CollisionEarlyWarning: {
|
|
|
collisionEarlyWarningMessage collisionWarning;
|
|
|
- std::string *str;
|
|
|
+ char *str=new char[17];
|
|
|
memcpy(str, recvBuf+18, 17);
|
|
|
collisionWarning.isEnable=true;
|
|
|
- collisionWarning.vin=*str;
|
|
|
+ collisionWarning.vin=str;
|
|
|
+ delete []str;
|
|
|
collisionWarning.warningType=recvBuf[35];
|
|
|
collisionWarning.speedLimit=recvBuf[36];
|
|
|
if(collisionWarning.vin==m_sVin) {
|
|
@@ -517,10 +555,11 @@ void Radio::replyMessage()
|
|
|
}
|
|
|
case CongestionIdentification: {
|
|
|
congestionIdentificationMessage congestionIdenti;
|
|
|
- std::string *str;
|
|
|
+ char *str=new char[17];
|
|
|
memcpy(str, recvBuf+18, 17);
|
|
|
congestionIdenti.isEnable=true;
|
|
|
- congestionIdenti.vin=*str;
|
|
|
+ congestionIdenti.vin=str;
|
|
|
+ delete []str;
|
|
|
congestionIdenti.openCommand=recvBuf[35];
|
|
|
if(congestionIdenti.vin==m_sVin) {
|
|
|
qDebug() << "[RADIO]:receive congestion identification message "<<endl;
|