|
@@ -4,7 +4,7 @@ UdpReciver::UdpReciver(QObject *parent, QString localhost, int port) : QObject(p
|
|
|
{
|
|
|
m_thread = new QThread();
|
|
|
m_udpSocket = new QUdpSocket();
|
|
|
-// localhost = "";
|
|
|
+ // localhost = "";
|
|
|
init_port(localhost, port);
|
|
|
connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(readDatagrams()), Qt::DirectConnection);
|
|
|
this->moveToThread(m_thread);
|
|
@@ -33,8 +33,8 @@ void UdpReciver::readDatagrams()
|
|
|
{
|
|
|
m_data.resize(m_udpSocket->pendingDatagramSize());
|
|
|
m_udpSocket->readDatagram(m_data.data(), m_data.size(), &client_address);
|
|
|
-// QString strclient_address = client_address.toString();
|
|
|
-// deliverInfo(m_data, strclient_address);
|
|
|
+ // QString strclient_address = client_address.toString();
|
|
|
+ // deliverInfo(m_data, strclient_address);
|
|
|
qDebug() << "receive UDP data: " << m_data;
|
|
|
ReceiveDecode(m_data);
|
|
|
}
|
|
@@ -50,7 +50,6 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
|
|
|
}
|
|
|
// ##
|
|
|
char first;
|
|
|
- char second;
|
|
|
// 寻找报文开头
|
|
|
while (data.size() >= 10) {
|
|
|
while (1) {
|
|
@@ -64,43 +63,141 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- QJsonObject object;
|
|
|
- object = QJsonDocument::fromJson(data).object();
|
|
|
- QByteArray jsonData();
|
|
|
- if (object.contains("member")) {
|
|
|
- QJsonArray array = object.value("member").toArray();
|
|
|
- qDebug() << array[0].toString();
|
|
|
- qDebug() << array[1].toString();
|
|
|
- qDebug() << array[2].toString();
|
|
|
- }
|
|
|
-
|
|
|
int jsonSize = data[3]<<8 | data[4];
|
|
|
|
|
|
if(data[1] == 0x02) //LightsInfo
|
|
|
{
|
|
|
+ QByteArray jsonData;
|
|
|
+ int len = jsonSize;
|
|
|
+ jsonData.resize(len);
|
|
|
+
|
|
|
+ memcpy(jsonData.data(), &(data.data()[5]),jsonSize);
|
|
|
+ QJsonObject object = QJsonDocument::fromJson(jsonData).object();
|
|
|
+
|
|
|
+ if(object.contains("LightsStates"))
|
|
|
+ int lightState = object.value("LightsStates");
|
|
|
+
|
|
|
+ if (object.contains("LightsInfo")) {
|
|
|
+ QJsonArray array = object.value("LightsInfo").toArray();
|
|
|
+ int size = array.size();
|
|
|
+ qDebug("lightsInfo size %d", size);
|
|
|
+ for(int i = 0; i < size; i++){
|
|
|
+ qDebug() << array.at(0).toString();
|
|
|
+ QJsonObject lightInfo = array.at(0).toObject();
|
|
|
+
|
|
|
+ if(lightInfo.contains("function"))
|
|
|
+ {
|
|
|
+ int lightFuncValue = lightInfo.value("function");
|
|
|
+ qDebug("light fuction value: %d", lightFuncValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(lightInfo.contains("LightsColor"))
|
|
|
+ {
|
|
|
+ int lightColorValue = lightInfo.value("LightsColor");
|
|
|
+ qDebug("light Color value: %d", lightColorValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(lightInfo.contains("RemainingTime"))
|
|
|
+ {
|
|
|
+ int lightRemTimeValue = lightInfo.value("RemainingTime");
|
|
|
+ qDebug("light Remaining Time:%d", lightRemTimeValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
else if(data[1] == 0x04)
|
|
|
{
|
|
|
+ QByteArray jsonData();
|
|
|
+ memcpy(jsonData, &data[5],jsonSize);
|
|
|
+ QJsonObject object = QJsonDocument::fromJson(jsonData).object();
|
|
|
|
|
|
- }
|
|
|
+ if (object.contains("Obj_List")) {
|
|
|
+ QJsonArray array = object.value("Obj_List").toArray();
|
|
|
+ int size = array.size();
|
|
|
+ qDebug("Obj_List size %d", size);
|
|
|
+ for(int i = 0; i < size; i++){
|
|
|
+ qDebug() << array.at(0).toString();
|
|
|
+ QJsonObject obsObj = array.at(0).toObject();
|
|
|
|
|
|
+ if(obsObj.contains("ID"))
|
|
|
+ {
|
|
|
+ string objID = obsObj.value("ID");
|
|
|
+ qDebug("obs ID : %s", objID);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("PtcType"))
|
|
|
+ {
|
|
|
+ int ptcType = obsObj.value("PtcType");
|
|
|
+ qDebug("obs type value: %d", ptcType);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("VehL"))
|
|
|
+ {
|
|
|
+ double dVehL = obsObj.value("VehL");
|
|
|
+ qDebug("obs VehL :%f", dVehL);
|
|
|
+ }
|
|
|
+ if(obsObj.contains("VehW"))
|
|
|
+ {
|
|
|
+ double dVehW = obsObj.value("VehW");
|
|
|
+ qDebug("obs VehW :%f", dVehW);
|
|
|
+ }
|
|
|
+ if(obsObj.contains("VehH"))
|
|
|
+ {
|
|
|
+ double dVehH = obsObj.value("VehH");
|
|
|
+ qDebug("obs VehH :%f", dVehH);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("PtcLon"))
|
|
|
+ {
|
|
|
+ double dPtcLon = obsObj.value("PtcLon");
|
|
|
+ qDebug("obs PtcLon :%f", dPtcLon);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("PtcLat"))
|
|
|
+ {
|
|
|
+ double dPtcLat = obsObj.value("PtcLat");
|
|
|
+ qDebug("obs Ptc :%f", dPtcLat);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("PtcEle"))
|
|
|
+ {
|
|
|
+ double dPtcEle = obsObj.value("PtcEle");
|
|
|
+ qDebug("obs PtcEle :%f", dPtcEle);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("PtcSpeed"))
|
|
|
+ {
|
|
|
+ double dPtcSpeed = obsObj.value("PtcSpeed");
|
|
|
+ qDebug("obs PtcSpeed :%f", dPtcSpeed);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(obsObj.contains("PtcHeading"))
|
|
|
+ {
|
|
|
+ double dPtcHeading = obsObj.value("PtcHeading");
|
|
|
+ qDebug("obs PtcHeading :%f", dPtcHeading);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-// int high = data.at(22);
|
|
|
-// int low = data.at(23);
|
|
|
-// 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
|
|
|
+ // int high = data.at(22);
|
|
|
+ // int low = data.at(23);
|
|
|
+ // 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
|
|
|
}
|
|
|
}
|