|
|
@@ -1,11 +1,14 @@
|
|
|
#include "coreobject.h"
|
|
|
#include <unistd.h>
|
|
|
-
|
|
|
+//公司这边生产环境的内网和外网ip
|
|
|
#define iServerIP "172.19.198.166"
|
|
|
#define oServerIP "47.103.74.123"
|
|
|
-
|
|
|
-//#define iServerIP "172.19.198.168"
|
|
|
-//#define oServerIP "101.133.214.75"
|
|
|
+//伍继158对应的内网和外网ip
|
|
|
+//#define iServerIP "192.168.0.31"
|
|
|
+//#define oServerIP "124.70.160.158"
|
|
|
+//伍继91对应的内网和外网ip
|
|
|
+//#define iServerIP "192.168.0.149"
|
|
|
+//#define oServerIP "124.71.175.91"
|
|
|
|
|
|
#define UN_REFERENCED_PARAMETER(x) {(x) = (x);}
|
|
|
|
|
|
@@ -31,6 +34,9 @@ CoreObject::CoreObject(QObject *parent) :
|
|
|
{
|
|
|
infomqttIdx=1;
|
|
|
alarmmqttIdx=1;
|
|
|
+ statusIdx=1;
|
|
|
+ statusStr="";
|
|
|
+ hour = 255;
|
|
|
nopic_count = 0;
|
|
|
processList.clear();
|
|
|
sqlList.clear();
|
|
|
@@ -40,12 +46,29 @@ CoreObject::CoreObject(QObject *parent) :
|
|
|
alarmListenHandle = -1;
|
|
|
start_time = QDateTime::currentDateTime().toTime_t();
|
|
|
had_reg = false;
|
|
|
+
|
|
|
+ netAccessManager = new QNetworkAccessManager(this);
|
|
|
+ connect(netAccessManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(finishedSlot(QNetworkReply*)));
|
|
|
+
|
|
|
timer = new QTimer();
|
|
|
+ //公司187生产环境对应的数据库配置
|
|
|
db = QSqlDatabase::addDatabase("QMYSQL","conf_db");
|
|
|
db.setDatabaseName("jdxf");
|
|
|
db.setHostName("47.98.201.187");
|
|
|
db.setUserName("root");
|
|
|
db.setPassword("Yt2018IoT");
|
|
|
+ //伍继158环境对应的数据库配置
|
|
|
+// db = QSqlDatabase::addDatabase("QMYSQL","conf_db");
|
|
|
+// db.setDatabaseName("smart_electricity");
|
|
|
+// db.setHostName("124.70.160.158");
|
|
|
+// db.setUserName("root");
|
|
|
+// db.setPassword("Y48hD&Eg");
|
|
|
+ //伍继91环境对应的数据库配置
|
|
|
+// db = QSqlDatabase::addDatabase("QMYSQL","conf_db");
|
|
|
+// db.setDatabaseName("smart_electricity");
|
|
|
+// db.setHostName("192.168.0.206");
|
|
|
+// db.setUserName("electric");
|
|
|
+// db.setPassword("Y48hD&Eg");
|
|
|
|
|
|
QString ip="",port="",name="",passwd="";
|
|
|
db.open();
|
|
|
@@ -130,6 +153,8 @@ CoreObject::~CoreObject()
|
|
|
NET_ECMS_Fini();
|
|
|
NET_ESTREAM_Fini();
|
|
|
NET_EALARM_Fini();
|
|
|
+
|
|
|
+ netAccessManager->deleteLater();
|
|
|
}
|
|
|
|
|
|
void CoreObject::mqconnected()
|
|
|
@@ -346,6 +371,98 @@ bool CoreObject::checkAlarmDevTime(QString deviceid){
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+void CoreObject::finishedSlot(QNetworkReply *reply)
|
|
|
+{
|
|
|
+ QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
|
|
|
+
|
|
|
+ if(status_code == 200){
|
|
|
+ if(reply->error() == QNetworkReply::NoError){
|
|
|
+ QString message = QString::fromUtf8(reply->readAll());
|
|
|
+ QByteArray data = message.toLatin1();
|
|
|
+ QJsonParseError json_err;
|
|
|
+ QJsonDocument jsondoc(QJsonDocument::fromJson(data,&json_err));
|
|
|
+ //printf("json_err.error = %d\n ",json_err.error);
|
|
|
+ if(json_err.error==QJsonParseError::NoError){
|
|
|
+ QJsonObject root = jsondoc.object();
|
|
|
+ QJsonObject obj = root.value("RESULT").toObject();
|
|
|
+ QString num = "";
|
|
|
+ int t = 0;
|
|
|
+
|
|
|
+ QJsonValue list_value = obj.value("LIST");
|
|
|
+ if(list_value.isArray()){
|
|
|
+ QJsonArray list_array = list_value.toArray();
|
|
|
+ for(int i=0;i<list_array.size();i++){
|
|
|
+ QJsonObject obj1 = list_array.at(i).toObject();
|
|
|
+ QString devid = obj1.value("DEVICE").toString();
|
|
|
+ int linevalue = obj1.value("ALIVEVALUE").toInt();
|
|
|
+ printf("[%d] devid: %s, linevalue: %d\n",i,devid.toUtf8().data(),linevalue);
|
|
|
+
|
|
|
+
|
|
|
+ QString companyCode="",deviceType="",deviceName="",value="";
|
|
|
+ for(int i=0;i<DEVICES_COUNT;i++){
|
|
|
+ QString devicecode = QString(ytShm->eHomeDevice[i].deviceID);
|
|
|
+ if(QString::compare(devid,devicecode)==0){
|
|
|
+ companyCode = QString(ytShm->eHomeDevice[i].rtsppath);
|
|
|
+ //deviceType.append(QString("%1").arg((ytShm->eHomeDevice[i].io[8]&0xff),2,16,QChar('0')));
|
|
|
+ //deviceName = QString(ytMqShm->eHomeDeviceMq[i].deviceName);
|
|
|
+ //value = QString(ytShm->eHomeDeviceFtp[i].filePath);
|
|
|
+ if(linevalue == 3){
|
|
|
+ if((m_client->connectionState()==QMQTT::STATE_DISCONNECTED)||(m_client->connectionState()==QMQTT::STATE_INIT)){
|
|
|
+ m_client->connectToHost();
|
|
|
+ }
|
|
|
+ if(m_client->connectionState()==QMQTT::STATE_CONNECTED){
|
|
|
+
|
|
|
+ statusStr.append(QString("{\"devId\":\"%1\",\"devicestatus\":0,\"type\":\"STATUS\",\"timestamp\":\"%2\"}").arg(devid).arg(QDateTime::currentDateTime().toTime_t()));
|
|
|
+
|
|
|
+ QString topic1 = QString("/usky/ytCamCore/%1/%2/status").arg(companyCode).arg(devid);
|
|
|
+ m_client->publish(QMQTT::Message(statusIdx++,topic1,statusStr.toUtf8()));
|
|
|
+ statusStr.clear();
|
|
|
+ if(statusIdx>9999)
|
|
|
+ statusIdx = 1;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if((m_client->connectionState()==QMQTT::STATE_DISCONNECTED)||(m_client->connectionState()==QMQTT::STATE_INIT)){
|
|
|
+ m_client->connectToHost();
|
|
|
+ }
|
|
|
+ if(m_client->connectionState()==QMQTT::STATE_CONNECTED){
|
|
|
+
|
|
|
+ statusStr.append(QString("{\"devId\":\"%1\",\"devicestatus\":75,\"type\":\"STATUS\",\"timestamp\":\"%2\"}").arg(devid).arg(QDateTime::currentDateTime().toTime_t()));
|
|
|
+
|
|
|
+ QString topic1 = QString("/usky/ytCamCore/%1/%2/status").arg(companyCode).arg(devid);
|
|
|
+ m_client->publish(QMQTT::Message(statusIdx++,topic1,statusStr.toUtf8()));
|
|
|
+ statusStr.clear();
|
|
|
+ if(statusIdx>9999)
|
|
|
+ statusIdx = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ reply->abort();
|
|
|
+ reply->close();
|
|
|
+ reply->deleteLater();
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
void CALLBACK fnPREVIEW_DATA_CB(LONG lPreviewHandle, NET_EHOME_PREVIEW_CB_MSG *pPreviewCBMsg, void *pUserData)
|
|
|
{
|
|
|
ytShm->workingTime[0] = QDateTime::currentDateTime().toTime_t();
|
|
|
@@ -773,6 +890,20 @@ void CoreObject::time_out()
|
|
|
isWorking = true;
|
|
|
if(synchour!=t.time().hour())
|
|
|
chkPhoneList();
|
|
|
+
|
|
|
+ if(hour != t.time().hour()){
|
|
|
+ hour = t.time().hour();
|
|
|
+
|
|
|
+ QByteArray post_data;
|
|
|
+ post_data.append(QString("queryJson={\"CMD\":%1}").arg(1));
|
|
|
+ QNetworkRequest *req = new QNetworkRequest();
|
|
|
+ req->setUrl(QUrl("https://fire.usky.cn:8443/YtIoT/cgi-bin/demo2.cgi"));
|
|
|
+ req->setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
|
|
|
+ req->setHeader(QNetworkRequest::ContentLengthHeader,post_data.length());
|
|
|
+ QNetworkReply* reply = netAccessManager->post(*req,post_data);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
t = QDateTime::currentDateTime();
|
|
|
ytShm->workingTime[0] = t.toTime_t();
|
|
|
for(int i=0;i<DEVICES_COUNT;i++){
|