PDA

View Full Version : QNetworkAccessManager and data acquisition from several sensors on a network



johann57
18th May 2011, 10:18
Hi,

I'm developing a QT application where I have to request data regularly (each second) to several sensors on a network. The request are sent in XML-RPC.

I'm using QNetworkAccessManager and QNetworkReply.

I have structured my program with a main function and an endless loop, like described here :


int main(int argc, char *argv[])
{
//------------
//Time variable
QTime qtSensorRequestDataTimePrev = QDateTime::currentDateTime().time();
/*!< Previous time when we requested data from the sensors */


QDateTime qdtCurDateTime;
QStringList qzslIP;

qzslIP.append("http://10.8.4.151:8008/rpc");
qzslIP.append("http://10.8.4.152:8008/rpc");

XmlRpc::XmlRpcRequest request;


//-------------------------------------------------------------------------
//Main event loop
QApplication a(argc, argv);

gulSensNb = 2;


while(gslQuit == 0)
{
QCoreApplication::processEvents(QEventLoop::AllEve nts);


//Start timing
qdtCurDateTime = QDateTime::currentDateTime();

//Get FW and BW information + time, mode and DTC
if((qtSensorRequestDataTimePrev.secsTo(qdtCurDateT ime.time())> 1)
{

qtSensorRequestDataTimePrev = qdtCurDateTime.time();
//-------------------------------------------------------------
request.setMethod(QString("MyMethodName1"));

QList<QVariant> paramList;


paramList.append("param1");
paramList.append("param2");

request.setParams(paramList);
//-------------------------------------------------------------
//Request "MyMethodName1" to all sensors
for(i=0;i<gulSensNb;i++)
{
MyXmlRpcCom.XmlRpcCon->setUrl(qzslIP[i].trimmed());
MyXmlRpcCom.XmlRpcCon->query(request);
}
//-------------------------------------------------------------
request.setMethod(QString("MyMethodName2"));

QList<QVariant> paramList;


paramList.append("param3");
paramList.append("param4");

request.setParams(paramList);
//--------------------------------------------------------------
//Request "MyMethodName2" data to all sensors
for(i=0;i<gulSensNb;i++)
{
MyXmlRpcCom.XmlRpcCon->setUrl(qzslIP[i].trimmed());
MyXmlRpcCom.XmlRpcCon->query(request);
}
}

}

}

void XmlRpcCom::rpcQueryCompleted(XmlRpc::XmlRpcRespons e *response)
{

if (response->error())

qDebug()<<"error"<<response->errorString();
else
qDebug()<<response->returnValue();


response->deleteLater();
}



XmlRpcCom::XmlRpcCom()
{
XmlRpcCon = new XmlRpc::XmlRpcConnection(this);

connect(XmlRpcCon, SIGNAL(finished(XmlRpc::XmlRpcResponse*)),
this, SLOT(rpcQueryCompleted(XmlRpc::XmlRpcResponse*)));

}

XmlRpcCom::~XmlRpcCom()
{
delete XmlRpcCon;
}

The program is able to send the request and receive them however I have some synchronization issues.
Normally, the sequence should be :

MyMethodName1 sent to sensor 1
MyMethodName1 sent to sensor 2
MyMethodName2 sent to sensor 1
MyMethodName2 sent to sensor 2

This sequence should be repeated constantly in the while loop.

However, when I check with a network analyzer tool, I don't have this sequence, but have it in a random way.

Any ideas, suggestions on how to structure the program in order to have the sequence always in the right order?

Thanks.