|
@@ -1,10 +1,92 @@
|
|
|
#include "udpreciver.h"
|
|
|
+#include "vbox.pb.h"
|
|
|
+
|
|
|
+iv::vbox::vbox_light gobjl;
|
|
|
+iv::vbox::vbox_obj_arr gobja;
|
|
|
+
|
|
|
+void * gpLight , * gpObj;
|
|
|
+
|
|
|
+void UdpReciver::ShareResultLights()
|
|
|
+{
|
|
|
+ lightLock.lock();
|
|
|
+ char * str = new char[gobja.ByteSize()];
|
|
|
+ int nsize = gobja.ByteSize();
|
|
|
+ if(gobja.SerializeToArray(str,nsize))
|
|
|
+ {
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpObj,str,nsize);
|
|
|
+ }
|
|
|
+ gobjl.Clear();
|
|
|
+ lightLock.unlock();
|
|
|
+ delete[] str;
|
|
|
+ str = nullptr;
|
|
|
+}
|
|
|
+
|
|
|
+void UdpReciver::ShareResultObs()
|
|
|
+{
|
|
|
+ obsLock.lock();
|
|
|
+ char * str = new char[gobjl.ByteSize()];
|
|
|
+ int nsize = gobjl.ByteSize();
|
|
|
+ if(gobjl.SerializeToArray(str,nsize))
|
|
|
+ {
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpLight,str,nsize);
|
|
|
+ }
|
|
|
+ gobja.Clear();
|
|
|
+ obsLock.unlock();
|
|
|
+
|
|
|
+ delete[] str;
|
|
|
+ str = nullptr;
|
|
|
+}
|
|
|
|
|
|
UdpReciver::UdpReciver(QObject *parent, QString localhost, int port) : QObject(parent)
|
|
|
{
|
|
|
m_thread = new QThread();
|
|
|
m_udpSocket = new QUdpSocket();
|
|
|
// localhost = "";
|
|
|
+
|
|
|
+ iv::vbox::vbox_light x;
|
|
|
+ x.set_st_straight(0);
|
|
|
+ x.set_st_left(0);
|
|
|
+ x.set_st_right(0);
|
|
|
+ x.set_st_turn(0);
|
|
|
+ x.set_time_straight(0);
|
|
|
+ x.set_time_left(0);
|
|
|
+ x.set_time_right(0);
|
|
|
+ x.set_time_turn(0);
|
|
|
+
|
|
|
+
|
|
|
+ gobjl.CopyFrom(x);
|
|
|
+
|
|
|
+ iv::vbox::vbox_obj_arr y;
|
|
|
+ iv::vbox::vbox_obj *obj;
|
|
|
+ obj = y.add_obj();
|
|
|
+ obj->set_allocated_id("");
|
|
|
+ obj->set_objtype(4);
|
|
|
+ obj->set_vehh(0);
|
|
|
+ obj->set_vehw(0);
|
|
|
+ obj->set_vehl(0);
|
|
|
+ obj->set_lon(0);
|
|
|
+ obj->set_lat(0);
|
|
|
+ obj->set_ele(0);
|
|
|
+ obj->set_speed(0);
|
|
|
+ obj->set_heading(0);
|
|
|
+ gobja.CopyFrom(y);
|
|
|
+
|
|
|
+ QString strpath = QCoreApplication::applicationDirPath();
|
|
|
+ if(argc < 2)
|
|
|
+ strpath = strpath + "/obuUdpClient.xml";
|
|
|
+ else
|
|
|
+ strpath = argv[1];
|
|
|
+ std::cout<<strpath.toStdString()<<std::endl;
|
|
|
+
|
|
|
+ iv::xmlparam::Xmlparam xp(strpath.toStdString());
|
|
|
+
|
|
|
+ std::string strmemsend_obj = xp.GetParam("vboxObj","vobxObj");
|
|
|
+ std::string strmemvbox_light = xp.GetParam("vboxLight","vboxLight");
|
|
|
+ std::string strmodulename = xp.GetParam("modulename","vbox_gaohong_net");
|
|
|
+
|
|
|
+ gpLight = iv::modulecomm::RegisterSend(strmemvbox_light.data(),100000,3);
|
|
|
+ gpObj = iv::modulecomm::RegisterSend(strmemsend_obj.data(),100000,1);
|
|
|
+
|
|
|
init_port(localhost, port);
|
|
|
connect(m_udpSocket, SIGNAL(readyRead()), this, SLOT(readDatagrams()), Qt::DirectConnection);
|
|
|
this->moveToThread(m_thread);
|
|
@@ -43,6 +125,12 @@ void UdpReciver::readDatagrams()
|
|
|
void UdpReciver::ReceiveDecode(QByteArray &data)
|
|
|
{
|
|
|
static int BATH_LENTH = 10;
|
|
|
+
|
|
|
+ iv::vbox::vbox_light objl;
|
|
|
+ iv::vbox::vbox_obj_arr obja;
|
|
|
+ iv::vbox::vbox_obj *obj;
|
|
|
+
|
|
|
+
|
|
|
// 防包太大
|
|
|
if (data.size() > 2048) {
|
|
|
//qDebug() << "size too large";
|
|
@@ -75,35 +163,76 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
|
|
|
QJsonObject object = QJsonDocument::fromJson(jsonData).object();
|
|
|
|
|
|
if(object.contains("LightsStates"))
|
|
|
+ {
|
|
|
int lightState = object.value("LightsStates");
|
|
|
+ }
|
|
|
|
|
|
- if (object.contains("LightsInfo")) {
|
|
|
+ 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();
|
|
|
-
|
|
|
+ int lightFuncValue = 0;
|
|
|
if(lightInfo.contains("function"))
|
|
|
{
|
|
|
- int lightFuncValue = lightInfo.value("function");
|
|
|
+ lightFuncValue = lightInfo.value("function");
|
|
|
qDebug("light fuction value: %d", lightFuncValue);
|
|
|
}
|
|
|
|
|
|
if(lightInfo.contains("LightsColor"))
|
|
|
{
|
|
|
int lightColorValue = lightInfo.value("LightsColor");
|
|
|
+ switch (lightFuncValue)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ objl.set_st_right(lightColorValue);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ objl.set_st_straight(lightColorValue);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ objl.set_st_turn(lightColorValue);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ objl.set_st_left(lightColorValue);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
qDebug("light Color value: %d", lightColorValue);
|
|
|
}
|
|
|
|
|
|
if(lightInfo.contains("RemainingTime"))
|
|
|
{
|
|
|
int lightRemTimeValue = lightInfo.value("RemainingTime");
|
|
|
+ switch (lightFuncValue)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ objl.set_time_right(lightRemTimeValue);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ objl.set_time_straight(lightRemTimeValue);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ objl.set_time_turn(lightRemTimeValue);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ objl.set_time_left(lightRemTimeValue);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
qDebug("light Remaining Time:%d", lightRemTimeValue);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ lightLock.lock();
|
|
|
+ gobjl.CopyFrom(objl);
|
|
|
+ lightLock.unlock();
|
|
|
+ ShareResultLights();
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -121,6 +250,7 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
|
|
|
qDebug() << array.at(0).toString();
|
|
|
QJsonObject obsObj = array.at(0).toObject();
|
|
|
|
|
|
+ obj = obja.add_obj();
|
|
|
if(obsObj.contains("ID"))
|
|
|
{
|
|
|
string objID = obsObj.value("ID");
|
|
@@ -130,56 +260,70 @@ void UdpReciver::ReceiveDecode(QByteArray &data)
|
|
|
if(obsObj.contains("PtcType"))
|
|
|
{
|
|
|
int ptcType = obsObj.value("PtcType");
|
|
|
+ obj->set_objtype(4);
|
|
|
qDebug("obs type value: %d", ptcType);
|
|
|
}
|
|
|
|
|
|
if(obsObj.contains("VehL"))
|
|
|
{
|
|
|
double dVehL = obsObj.value("VehL");
|
|
|
+ obj->set_vehl(0);
|
|
|
qDebug("obs VehL :%f", dVehL);
|
|
|
}
|
|
|
if(obsObj.contains("VehW"))
|
|
|
{
|
|
|
double dVehW = obsObj.value("VehW");
|
|
|
+ obj->set_vehw(0);
|
|
|
qDebug("obs VehW :%f", dVehW);
|
|
|
}
|
|
|
if(obsObj.contains("VehH"))
|
|
|
{
|
|
|
double dVehH = obsObj.value("VehH");
|
|
|
+ obj->set_vehh(0);
|
|
|
qDebug("obs VehH :%f", dVehH);
|
|
|
}
|
|
|
|
|
|
if(obsObj.contains("PtcLon"))
|
|
|
{
|
|
|
double dPtcLon = obsObj.value("PtcLon");
|
|
|
+ obj->set_lon(0);
|
|
|
qDebug("obs PtcLon :%f", dPtcLon);
|
|
|
}
|
|
|
|
|
|
if(obsObj.contains("PtcLat"))
|
|
|
{
|
|
|
double dPtcLat = obsObj.value("PtcLat");
|
|
|
+ obj->set_lat(0);
|
|
|
qDebug("obs Ptc :%f", dPtcLat);
|
|
|
}
|
|
|
|
|
|
if(obsObj.contains("PtcEle"))
|
|
|
{
|
|
|
double dPtcEle = obsObj.value("PtcEle");
|
|
|
+ obj->set_ele(0);
|
|
|
qDebug("obs PtcEle :%f", dPtcEle);
|
|
|
}
|
|
|
|
|
|
if(obsObj.contains("PtcSpeed"))
|
|
|
{
|
|
|
double dPtcSpeed = obsObj.value("PtcSpeed");
|
|
|
+ obj->set_speed(0);
|
|
|
qDebug("obs PtcSpeed :%f", dPtcSpeed);
|
|
|
}
|
|
|
|
|
|
if(obsObj.contains("PtcHeading"))
|
|
|
{
|
|
|
double dPtcHeading = obsObj.value("PtcHeading");
|
|
|
+ obj->set_heading(0);
|
|
|
qDebug("obs PtcHeading :%f", dPtcHeading);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ obsLock.lock();
|
|
|
+ gobja.CopyFrom(obja);
|
|
|
+ obsLock.unlock();
|
|
|
+ ShareResultObs();
|
|
|
}
|
|
|
|
|
|
}
|