#include "datasender.h" extern YT_UNIT_SHM *ytShm; DataSender::DataSender(QObject *parent, QString serverPath, QString id) : QObject(parent) { waitting = false; ServerPath = serverPath; SelfId = id; timer = new QTimer(this); connect(timer,SIGNAL(timeout()),this,SLOT(time_out())); queryManager = new QNetworkAccessManager(this); connect(queryManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(query_finishedSlot(QNetworkReply*))); timer->start(5000); } void DataSender::query_finishedSlot(QNetworkReply *reply) { if(reply->error()==QNetworkReply::NoError){ QByteArray qj = reply->readAll(); } waitting = false; } void DataSender::reply_timeout() { waitting = false; } void DataSender::time_out() { if(!waitting){ json_object *iotlist,*obj[5],*obj_list[5], *body, *json; int comm,adds,i; int count[5],alarm[5],out[5]; char tmp[256]; body = json_object_new_object(); json = json_object_new_object(); iotlist = json_object_new_array(); for(i=0;i<5;i++) { count[i]=0; alarm[i]=0; out[i]=0; obj[i] = json_object_new_object(); obj_list[i] = json_object_new_array(); } for(comm=0;comm<4;comm++) { if(ytShm->commList.comm[comm].ENABLED==0x01){ for(adds=0;adds<256;adds++) { if(ytShm->sPointList.sPoint[comm][adds].ENABLED==0x01) { json_object *sp = json_object_new_object(); for(i=0;i<5;i++) { if((ytShm->sPointList.sPoint[comm][adds].SUB_TYPE&(0x01<commStatusList.commStatus[comm].STATUS!=0x01) { if(ytShm->sPointList.sPoint[comm][adds].SUB_TYPE>0) { for(i=0;i<5;i++) { if((ytShm->sPointList.sPoint[comm][adds].SUB_TYPE&(0x01<spStatusList.spStatus[comm][adds].ALARM_STATUS!=0x00) { for(i=0;i<5;i++) { if((ytShm->sPointList.sPoint[comm][adds].SUB_TYPE&(0x01<sPointList.sPoint[comm][adds].NAME)); json_object_object_add(sp,"PNO_TYPE",json_object_new_int(ytShm->sPointList.sPoint[comm][adds].PNO_TYPE)); if(ytShm->sPointList.sPoint[comm][adds].PNO_TYPE==0x01){ if(ytShm->spStatusList.spStatus[comm][adds].REALTIME_VALUE==0.0) json_object_object_add(sp,"VALUE",json_object_new_string("0")); else json_object_object_add(sp,"VALUE",json_object_new_string("1")); }else{ sprintf(tmp,"%.2f",ytShm->spStatusList.spStatus[comm][adds].REALTIME_VALUE); json_object_object_add(sp,"VALUE",json_object_new_string(tmp)); } time_t t = ytShm->spStatusList.spStatus[comm][adds].REALTIME_TIMESTAMP; struct tm *loc_time = localtime(&t); sprintf(tmp,"%04d-%02d-%02d %02d:%02d:%02d", loc_time->tm_year+1900, loc_time->tm_mon+1, loc_time->tm_mday, loc_time->tm_hour, loc_time->tm_min, loc_time->tm_sec); json_object_object_add(sp,"TIME",json_object_new_string(tmp)); for(i=0;i<5;i++) { if((ytShm->sPointList.sPoint[comm][adds].SUB_TYPE&(0x01<setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded; charset=UTF-8"); req->setRawHeader("Accept","text/html, application/xhtml+xml, */*"); req->setRawHeader("Accept-Language","zh-CN"); req->setRawHeader("Connection","keep-alive"); req->setRawHeader("Cache-Control"," no-cache"); QByteArray postdata; postdata.append(QString::fromUtf8(json_object_to_json_string(json)).toUtf8()); req->setRawHeader("Content-Length",QString("%1").arg(postdata.length()).toUtf8()); QNetworkReply *reply = queryManager->post(*req,postdata); QReplayTimeout *pTimeout = new QReplayTimeout(reply,10000); connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout())); } }