소스 검색

新增新风系统模块,将共享内存同步逻辑全部移动看门狗程序中

james 1 년 전
부모
커밋
294513df3a
54개의 변경된 파일1611개의 추가작업 그리고 331개의 파일을 삭제
  1. 21 1
      AGBoxDog/agboxshm.h
  2. 28 2
      AGBoxDog/dogcore.cpp
  3. 1 1
      AGBoxDog/dogcore.h
  4. 50 0
      AGBoxDog/main.cpp
  5. 23 12
      agElevatorProcess/devinfotcpserver.cpp
  6. 2 0
      agElevatorProcess/devinfotcpserver.h
  7. 20 37
      agElevatorProcess/elevatorcore.cpp
  8. 3 0
      agElevatorProcess/elevatorcore.h
  9. 22 13
      agElevatorProcess/httpthread.cpp
  10. 2 0
      agElevatorProcess/httpthread.h
  11. 4 14
      agEnvironmentProcess/environmentcore.cpp
  12. 10 10
      agEnvironmentProcess/mqttpub.cpp
  13. 0 1
      agEnvironmentProcess/mqttsub.cpp
  14. 33 0
      agFreshAirProcess/agFreshAirProcess.pro
  15. 166 0
      agFreshAirProcess/core.cpp
  16. 54 0
      agFreshAirProcess/core.h
  17. 265 0
      agFreshAirProcess/httpthread.cpp
  18. 53 0
      agFreshAirProcess/httpthread.h
  19. 110 0
      agFreshAirProcess/jzmqttpub.cpp
  20. 45 0
      agFreshAirProcess/jzmqttpub.h
  21. 87 0
      agFreshAirProcess/jzmqttsub.cpp
  22. 35 0
      agFreshAirProcess/jzmqttsub.h
  23. 52 0
      agFreshAirProcess/logthread.cpp
  24. 28 0
      agFreshAirProcess/logthread.h
  25. 12 0
      agFreshAirProcess/main.cpp
  26. 119 0
      agFreshAirProcess/ytmqttpub.cpp
  27. 35 0
      agFreshAirProcess/ytmqttpub.h
  28. 62 0
      agFreshAirProcess/ytmqttsub.cpp
  29. 31 0
      agFreshAirProcess/ytmqttsub.h
  30. 9 9
      agGeneratorProcess/devinfotcpserver.cpp
  31. 0 46
      agGeneratorProcess/generatorcore.cpp
  32. 13 14
      agGeneratorProcess/httpthread.cpp
  33. 19 12
      agGuardProcess/devinfotcpserver.cpp
  34. 2 0
      agGuardProcess/devinfotcpserver.h
  35. 29 36
      agGuardProcess/guardcore.cpp
  36. 4 0
      agGuardProcess/guardcore.h
  37. 22 13
      agGuardProcess/httpthread.cpp
  38. 2 1
      agGuardProcess/httpthread.h
  39. 14 7
      agGuardProcess/tcpserver.cpp
  40. 2 1
      agGuardProcess/tcpserver.h
  41. 14 15
      agLightingProcess/clientthread.cpp
  42. 4 14
      agLightingProcess/lightingcore.cpp
  43. 0 2
      agVideoProcess/agVideoProcess.pro
  44. 19 12
      agVideoProcess/devinfotcpserver.cpp
  45. 2 0
      agVideoProcess/devinfotcpserver.h
  46. 13 7
      agVideoProcess/httpthread.cpp
  47. 2 0
      agVideoProcess/httpthread.h
  48. 14 7
      agVideoProcess/tcpserver.cpp
  49. 2 0
      agVideoProcess/tcpserver.h
  50. 14 7
      agVideoProcess/tcpserver1.cpp
  51. 2 0
      agVideoProcess/tcpserver1.h
  52. 30 36
      agVideoProcess/videocore.cpp
  53. 4 0
      agVideoProcess/videocore.h
  54. 2 1
      data-agbox.pro

+ 21 - 1
AGBoxDog/agboxshm.h

@@ -12,13 +12,33 @@
 #define SHM_PATH "/"
 
 
+typedef struct{
+    int device_type;
+    char product_code[50];
+    char attribute_name[60];
+    char attribute_code[20];
+    unsigned int Enabled;
+} ProductAttribute;
+
+typedef struct{
+    int device_type;
+    char device_code[50];
+    char device_id[50];
+    char product_code[50];
+    char device_gateway[50];
+    unsigned int lastTime;
+    unsigned int Enabled;
+}Device;
+
 typedef struct {
     uint t_time;
 }ProcessStatus;
 
 typedef struct {
     unsigned char Enabled;
-    ProcessStatus processStatus[16];
+    Device device[1024];
+    ProcessStatus processStatus[128];
+    ProductAttribute procuctattrbute[300];
 }AGBoxShm;
 
 

+ 28 - 2
AGBoxDog/dogcore.cpp

@@ -9,7 +9,7 @@ DogCore::DogCore(QObject *parent) : QObject(parent)
 
     timer = new QTimer(this);
     connect(timer,SIGNAL(timeout()),this,SLOT(time_out()));
-    for(int i=0;i<16;i++)
+    for(int i=0;i<128;i++)
         chkTime[i] = QDateTime::currentDateTime().toTime_t();
 }
 
@@ -204,6 +204,32 @@ void DogCore::time_out()
                 }
             }
         }
+		
+		if((chkTime1-chkTime[11])>300){
+            chkTime[11]=chkTime1;
+            if(chkrootprocmem("agDP0011")>200){
+                logThread->appendData(QString("[%1 agBoxDog %2] %3 chkrootprocmem(agDP0011): %4")
+                                      .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
+                                      .arg(chkTime1)
+                                      .arg(chkTime[11])
+                                      .arg(chkrootprocmem("agDP0011")));
+                system("killall agDP0011");
+                sleep(3);
+                system("/root/bin/agDP0011 &");
+            }
+        }
+        if((agBoxShm->processStatus[11].t_time>0)
+                &&(static_cast<int>(chkTime1-agBoxShm->processStatus[11].t_time)>90)){
+            if(system("killall agDP0011")!=-1){
+                sleep(3);
+                if(system("/root/bin/agDP0011 &")!=-1){
+                    logThread->appendData(QString("[%1 agBoxDog %2] agDP0011 time out: %3")
+                                          .arg(QDateTime::fromTime_t(chkTime1).toString("yyyy-MM-dd HH:mm:ss"))
+                                          .arg(chkTime1)
+                                          .arg(static_cast<int>(chkTime1-agBoxShm->processStatus[11].t_time)));
+                }
+            }
+        }
 
 
         isWorking = false;
@@ -214,7 +240,7 @@ void DogCore::time_out()
 
 void DogCore::start(){
     time_out();
-    timer->start(15000);
+    timer->start(30000);
 }
 
 

+ 1 - 1
AGBoxDog/dogcore.h

@@ -28,7 +28,7 @@ public slots:
 private:
     QTimer *timer;
     bool isWorking;
-    uint chkTime[16];
+    uint chkTime[128];
     LogThread *logThread;
 };
 

+ 50 - 0
AGBoxDog/main.cpp

@@ -3,9 +3,53 @@
 #include "dogcore.h"
 #include <QFile>
 #include <QDir>
+#include <QSqlDatabase>
+#include <QSqlQuery>
+
+QSqlDatabase db;
 
 AGBoxShm *agBoxShm;
 
+void shm_init(){
+    QSqlQuery qry;
+    int nrow = 0;
+    QString sql = QString("select device_code,device_id,device_type,product_code,device_gateway from yt_t_device");
+    qry = db.exec(sql);
+    while (qry.next()) {
+        if(nrow > 1023)
+            break;
+        agBoxShm->device[nrow].Enabled = 0x01;
+        sprintf(agBoxShm->device[nrow].device_code,"%s",qry.value(0).toString().toUtf8().data());
+        sprintf(agBoxShm->device[nrow].device_id,"%s",qry.value(1).toString().toUtf8().data());
+        agBoxShm->device[nrow].device_type = qry.value(2).toInt();
+        sprintf(agBoxShm->device[nrow].product_code,"%s",qry.value(3).toString().toUtf8().data());
+        sprintf(agBoxShm->device[nrow].device_gateway,"%s",qry.value(4).toString().toUtf8().data());
+        nrow++;
+    }
+    for(int i=nrow;i<1024;i++){
+        agBoxShm->device[i].Enabled = 0x00;
+    }
+    nrow = 0;
+    qry.clear();
+    sql.clear();
+    sql = QString("select device_type,product_code,attribute_name,attribute_code from yt_t_attribute");
+    qry = db.exec(sql);
+    while (qry.next()) {
+        if(nrow > 299)
+            break;
+        agBoxShm->procuctattrbute[nrow].Enabled = 0x01;
+        agBoxShm->procuctattrbute[nrow].device_type = qry.value(0).toInt();
+        sprintf(agBoxShm->procuctattrbute[nrow].product_code,"%s",qry.value(1).toString().toUtf8().data());
+        sprintf(agBoxShm->procuctattrbute[nrow].attribute_name,"%s",qry.value(2).toString().toUtf8().data());
+        sprintf(agBoxShm->procuctattrbute[nrow].attribute_code,"%s",qry.value(3).toString().toUtf8().data());
+        nrow++;
+    }
+    for(int i=nrow;i<300;i++){
+        agBoxShm->procuctattrbute[i].Enabled = 0x00;
+    }
+
+}
+
 bool shm_load(){
     int shmid;
     key_t key;
@@ -17,6 +61,7 @@ bool shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
+    shm_init();
     return true;
 }
 
@@ -28,6 +73,11 @@ int main(int argc, char *argv[])
         system("mkdir -p /opt/agBoxProcess");
         system("mkdir -p /opt/agBoxProcess/log");
     }
+    db = QSqlDatabase::addDatabase("QSQLITE","conf_db");
+    db.setDatabaseName(QString("/opt/db/yt_conf.db"));
+    if(!db.open()){
+        exit(1);
+    }
     if(shm_load()){
         DogCore *dogcore = new DogCore(nullptr);
         dogcore->start();

+ 23 - 12
agElevatorProcess/devinfotcpserver.cpp

@@ -1,5 +1,5 @@
 #include "devinfotcpserver.h"
-#include "../agVideoProcess/boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 DevInfoTcpServer::DevInfoTcpServer(QObject *parent) : QObject(parent)
 {
@@ -44,22 +44,26 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                     QJsonObject list_object = list_array.at(i).toObject();
                     QString device_code = list_object.value("indexCode").toString();
                     QString device_name = list_object.value("name").toString();
+                    QString productCode = "";
+                    int deviceType;
                     bool found = false;
                     for(int i=0;i<1024;i++){
-                        if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 503)){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 503)){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
+                                productCode = QString("%1").arg(agBoxShm->device[i].product_code);
+                                deviceType = agBoxShm->device[i].device_type;
                                 found = true;
-                                msg.append(QString("{\"product_id\": \"3\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 0},").arg(boxDeviceShm->device[i].device_id).arg(device_code).arg(device_name));
+                                msg.append(QString("{\"product_id\": \"3\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 0},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code).arg(device_name));
                                 break;
                             }
                         }
                     }
                     if(!found){
                         QString device_id = QCryptographicHash::hash(QString("3%1").arg(device_code).toUtf8(),QCryptographicHash::Md5).toHex();
-                        QString sql = QString("insert into yt_t_device values('%1','%2',503,'10000001',null);").arg(device_code).arg(device_id);
+                        QString sql = QString("insert into yt_t_device values('%1','%2',%3,'%4',null);").arg(device_code).arg(device_id).arg(deviceType).arg(productCode);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"3\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 1},").arg(device_id).arg(device_code).arg(device_name));
+                        msg.append(QString("{\"product_id\": \"3\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 1},").arg(agBoxShm->device[i].product_code).arg(device_id).arg(device_code).arg(device_name));
                     }
                     devTcpList.append(device_code);
                 }
@@ -67,9 +71,9 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
 
 
             for(int i=0;i<1024;i++){
-                if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 503)){
+                if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 503)){
                     bool found1 = false;
-                    QString device_code = QString(boxDeviceShm->device[i].device_code);
+                    QString device_code = QString(agBoxShm->device[i].device_code);
                     if(devTcpList.size() > 0){
                         for(int j=0;j<devTcpList.size();j++){
                             if(device_code.compare(devTcpList.at(j))==0){
@@ -83,7 +87,7 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                         QString sql = QString("delete from yt_t_device where device_code = '%1';").arg(device_code);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"3\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"\",\"flag\": -1},").arg(boxDeviceShm->device[i].device_id).arg(device_code));
+                        msg.append(QString("{\"product_id\": \"3\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"\",\"flag\": -1},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code));
                     }
 
                 }
@@ -108,6 +112,13 @@ void DevInfoTcpServer::new_incomming()
 
 }
 
+void DevInfoTcpServer::app_info(QString url, QString key, QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void DevInfoTcpServer::read_data()
 {
     QString str = QString::fromUtf8(so->readAll());
@@ -137,13 +148,13 @@ void DevInfoTcpServer::read_data()
         if(regions.length() > 1){
             regions = regions.left(regions.length()-1);
             QNetworkRequest *req = new QNetworkRequest();
-            req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/resource/v2/ecsDevice/search"));
+            req->setUrl(QUrl(url));
             req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
             req->setRawHeader("Accept","*/*");
             req->setRawHeader("Connection","keep-alive");
             req->setRawHeader("Cache-Control"," no-cache");
-            req->setRawHeader("X-Ca-Key","27997984");
-            req->setRawHeader("X-Ca-Signature","rYhzIwbT3nxb6OMmn8kwj/5aKYur8qTcQWet96GTrbk=");
+            req->setRawHeader("X-Ca-Key",key);
+            req->setRawHeader("X-Ca-Signature",signature);
             req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
             config = req->sslConfiguration();
             config.setPeerVerifyMode(QSslSocket::VerifyNone);

+ 2 - 0
agElevatorProcess/devinfotcpserver.h

@@ -23,6 +23,7 @@ class DevInfoTcpServer : public QObject
 public:
     explicit DevInfoTcpServer(QObject *parent = nullptr);
     void start();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void tcp_log(QString log);
@@ -39,6 +40,7 @@ private:
 
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
+    QString url, key, signature;
 
 };
 

+ 20 - 37
agElevatorProcess/elevatorcore.cpp

@@ -1,8 +1,6 @@
 #include "elevatorcore.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 AGBoxShm *agBoxShm;
-BoxDeviceShm *boxDeviceShm;
 
 void ElevatorCore::shm_init(){
     QSqlQuery qry;
@@ -14,41 +12,32 @@ void ElevatorCore::shm_init(){
         username = qry.value(2).toString();
         password = qry.value(3).toString();
     }
-    qry.clear();
-    int nrow = 0;
     sql.clear();
-    sql = QString("select device_code,device_id,device_type,company_code,device_gateway from yt_t_device");
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'ladder-search-hk'");
     qry = db.exec(sql);
     while (qry.next()) {
-        if(nrow > 1023)
-            break;
-        boxDeviceShm->device[nrow].Enabled = 0x01;
-        sprintf(boxDeviceShm->device[nrow].device_code,"%s",qry.value(0).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_id,"%s",qry.value(1).toString().toUtf8().data());
-        boxDeviceShm->device[nrow].device_type = qry.value(2).toInt();
-        sprintf(boxDeviceShm->device[nrow].company_code,"%s",qry.value(3).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_gateway,"%s",qry.value(4).toString().toUtf8().data());
-        nrow++;
+        devinfourl = qry.value(0).toString();
+        devinfokey = qry.value(1).toString();
+        devinfosignature = qry.value(2).toString();
     }
-    for(int i=nrow;i<1024;i++){
-        boxDeviceShm->device[i].Enabled = 0x00;
-    }
-    nrow = 0;
-    qry.clear();
     sql.clear();
-    sql = QString("select device_type,attribute_name,attribute_code from yt_t_attribute");
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'ladder-record-hk'");
     qry = db.exec(sql);
     while (qry.next()) {
-        if(nrow > 299)
-            break;
-        boxDeviceShm->procuctattrbute[nrow].Enabled = 0x01;
-        boxDeviceShm->procuctattrbute[nrow].device_type = qry.value(0).toInt();
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_name,"%s",qry.value(1).toString().toUtf8().data());
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_code,"%s",qry.value(2).toString().toUtf8().data());
-        nrow++;
+       httpurl = qry.value(0).toString();
+       httpkey = qry.value(1).toString();
+       httpsignature = qry.value(2).toString();
     }
-    for(int i=nrow;i<300;i++){
-        boxDeviceShm->procuctattrbute[i].Enabled = 0x00;
+    sql.clear();
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'ladder-state-hk'");
+    qry = db.exec(sql);
+    while (qry.next()) {
+        httpurl1 = qry.value(0).toString();
+        httpkey1 = qry.value(1).toString();
+        httpsignature1 = qry.value(2).toString();
     }
 
 }
@@ -64,14 +53,6 @@ bool ElevatorCore::shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
-    if((key=ftok(VIDEO_PATH,static_cast<int>(VIDEO_PORT)))==-1){
-        return false;
-    }
-    if((shmid=shmget(key,sizeof(BoxDeviceShm),IPC_CREAT|0666))==-1){
-        return false;
-    }
-    boxDeviceShm = static_cast<BoxDeviceShm *>(shmat(shmid,nullptr,0));
-
     shm_init();
     return true;
 }
@@ -106,10 +87,12 @@ ElevatorCore::ElevatorCore(QObject *parent) : QObject(parent)
     connect(httpthread,&HttpThread::dataLog,this,&ElevatorCore::dataLog);
     connect(httpthread,&HttpThread::mqttData,this,&ElevatorCore::mqtt_data);
     connect(httpthread,&HttpThread::mqttEvent,this,&ElevatorCore::mqtt_event);
+    httpthread->app_info(httpurl,httpkey,httpsignature,httpurl1,httpkey1,httpsignature1);
 
     devinfoserver = new DevInfoTcpServer(this);
     connect(devinfoserver,&DevInfoTcpServer::tcp_log,this,&ElevatorCore::dataLog);
     connect(devinfoserver,&DevInfoTcpServer::append_sql,this,&ElevatorCore::appendSql);
+    devinfoserver->app_info(devinfourl,devinfokey,devinfosignature);
 
 }
 

+ 3 - 0
agElevatorProcess/elevatorcore.h

@@ -42,6 +42,9 @@ private:
     QSqlDatabase db;
     quint16 mqttIdx,mqttEventIdx;
     QString ip,port,username,password;
+    QString devinfourl,devinfokey,devinfosignature;
+    QString httpurl,httpkey,httpsignature;
+    QString httpurl1,httpkey1,httpsignature1;
 
 signals:
 

+ 22 - 13
agElevatorProcess/httpthread.cpp

@@ -1,5 +1,4 @@
 #include "httpthread.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 #include "../AGBoxDog/boxshm.h"
 
 HttpThread::HttpThread(QObject *parent) : QObject(parent)
@@ -59,10 +58,10 @@ void  HttpThread::finishedSlot(QNetworkReply *reply)
                     QDateTime date1 = QDateTime::fromString(list_object.value("receiveTime").toString(), "yyyy-MM-ddTHH:mm:ss.zzz+08:00");
                     QString receiveTime = date.toLocalTime().toString("yyyy-MM-dd HH:mm:ss");
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttEvent(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"device_id\":\"%5\",\"device_code\":\"%6\",\"device_name\":\"%7\",\"lift_name\":\"%8\",\"event_id\":\"%9\",\"event_name\":\"%10\",\"event_time\":\"%11\",\"person_id\":\"%12\",\"card_no\":\"%13\",\"person_name\":\"%14\",\"org_id\":\"%15\",\"org_name\":\"%16\",\"receive_time\":\"%17\"},\"metrics\":{\"event_type\":%18},\"device_type\":\"%19-lc\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(deviceName).arg(liftName).arg(eventId).arg(eventName).arg(eventTime).arg(personId).arg(cardNo).arg(personName).arg(orgId).arg(orgName).arg(receiveTime).arg(eventType).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(deviceName).arg(liftName).arg(eventId).arg(eventName).arg(eventTime).arg(personId).arg(cardNo).arg(personName).arg(orgId).arg(orgName).arg(receiveTime).arg(eventType).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }
@@ -116,10 +115,10 @@ void  HttpThread::finishedSlot1(QNetworkReply *reply)
                     int deviceStatus = list_object.value("online").toInt();
 
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"device_status\":%5},\"device_type\":\"%6-lc\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(deviceStatus).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(deviceStatus).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }
@@ -150,6 +149,16 @@ void HttpThread::reply_timeout1()
     isWaiting1 = false;
 }
 
+void HttpThread::app_info(QString url, QString key, QString signature, QString url1, QString key1, QString signature1)
+{
+    url = url;
+    key = key;
+    signature = signature;
+    url1 = url1;
+    key1 = key1;
+    signature1 = signature1;
+}
+
 void HttpThread::time_out()
 {
     agBoxShm->processStatus[3].t_time=QDateTime::currentDateTime().toTime_t();
@@ -166,13 +175,13 @@ void HttpThread::time_out()
         if(!isWaiting){
             isWaiting = true;
             QNetworkRequest *req = new QNetworkRequest();
-            req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/ecs/v1/access_events/search"));
+            req->setUrl(QUrl(url));
             req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
             req->setRawHeader("Accept","*/*");
             req->setRawHeader("Connection","keep-alive");
             req->setRawHeader("Cache-Control"," no-cache");
-            req->setRawHeader("X-Ca-Key","27997984");
-            req->setRawHeader("X-Ca-Signature","suViBsEUVHh0kaTWjZgGYvYuezrYoA0sJRchgMkJGSQ=");
+            req->setRawHeader("X-Ca-Key",key);
+            req->setRawHeader("X-Ca-Signature",signature);
             req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
             config = req->sslConfiguration();
             config.setPeerVerifyMode(QSslSocket::VerifyNone);
@@ -193,13 +202,13 @@ void HttpThread::time_out()
       if(!isWaiting1 && ((minute1==00)||(minute1==30))){
           isWaiting1 = true;
           QNetworkRequest *req = new QNetworkRequest();
-          req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/nms/v1/online/ladder_controller/get"));
+          req->setUrl(QUrl(url1));
           req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
           req->setRawHeader("Accept","*/*");
           req->setRawHeader("Connection","keep-alive");
           req->setRawHeader("Cache-Control"," no-cache");
-          req->setRawHeader("X-Ca-Key","27997984");
-          req->setRawHeader("X-Ca-Signature","dY38jPrLDZGBz0JSowveMsRcnt8aAiEM5sjBTn9FP2k=");
+          req->setRawHeader("X-Ca-Key",key1);
+          req->setRawHeader("X-Ca-Signature",signature1);
           req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
           config = req->sslConfiguration();
           config.setPeerVerifyMode(QSslSocket::VerifyNone);

+ 2 - 0
agElevatorProcess/httpthread.h

@@ -22,6 +22,7 @@ public:
     explicit HttpThread(QObject *parent = nullptr);
     void run();
     void stop();
+    void app_info(QString url,QString key,QString signature,QString url1,QString key1,QString signature1);
 
 signals:
     void dataLog(QString log);
@@ -44,6 +45,7 @@ private:
     QNetworkAccessManager *networkManager,*networkManager1;
     QSslConfiguration config;
     QTimer *timer;
+    QString url, key, signature, url1, key1, signature1;
 
 
 };

+ 4 - 14
agEnvironmentProcess/environmentcore.cpp

@@ -1,8 +1,6 @@
 #include "environmentcore.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 AGBoxShm *agBoxShm;
-BoxDeviceShm *boxDeviceShm;
 
 void EnvironmentCore::shm_init(){
     QSqlQuery qry;
@@ -30,14 +28,6 @@ bool EnvironmentCore::shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
-    if((key=ftok(VIDEO_PATH,static_cast<int>(VIDEO_PORT)))==-1){
-        return false;
-    }
-    if((shmid=shmget(key,sizeof(BoxDeviceShm),IPC_CREAT|0666))==-1){
-        return false;
-    }
-    boxDeviceShm = static_cast<BoxDeviceShm *>(shmat(shmid,nullptr,0));
-
     shm_init();
     return true;
 }
@@ -98,12 +88,12 @@ void EnvironmentCore::time_out()
     agBoxShm->processStatus[5].t_time=QDateTime::currentDateTime().toTime_t();
 
     for(int i=0;i<1024;i++){
-        if((boxDeviceShm->device[i].Enabled == 0x01)&&(boxDeviceShm->device[i].device_type == 509)){
+        if((agBoxShm->device[i].Enabled == 0x01)&&(agBoxShm->device[i].device_type == 509)){
             uint curTime = QDateTime::currentDateTime().toTime_t();
-            if((curTime - boxDeviceShm->device[i].lastTime)>7200){
-                boxDeviceShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
+            if((curTime - agBoxShm->device[i].lastTime)>7200){
+                agBoxShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
                 this->mqtt_data(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"device_status\":0},\"device_type\":\"%5-ev\"}")
-                              .arg(boxDeviceShm->device[i].device_id).arg(boxDeviceShm->device[i].device_code).arg(boxDeviceShm->device[i].company_code).arg(curTime).arg(boxDeviceShm->device[i].device_type));
+                              .arg(agBoxShm->device[i].device_id).arg(agBoxShm->device[i].device_code).arg(agBoxShm->device[i].product_code).arg(curTime).arg(agBoxShm->device[i].device_type));
             }
         }
     }

+ 10 - 10
agEnvironmentProcess/mqttpub.cpp

@@ -1,5 +1,5 @@
 #include "mqttpub.h"
-#include "../agVideoProcess/boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 MqttPub::MqttPub(QObject *parent) : QThread(parent)
 {
@@ -49,13 +49,13 @@ void MqttPub::run()
                             QString deviceCode = sn + "-" + obj_dev.value("dev").toString();
                             printf("deviceCode: %s\n",deviceCode.toUtf8().data());
                             for(int i=0;i<1024;i++){
-                                if(boxDeviceShm->device[i].Enabled == 0x01){
-                                    if(deviceCode.compare(QString(boxDeviceShm->device[i].device_code))==0){
-                                        boxDeviceShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
-                                        deviceId = QString(boxDeviceShm->device[i].device_id);
-                                        companyCode = QString(boxDeviceShm->device[i].company_code);
-                                        deviceType = QString::number(boxDeviceShm->device[i].device_type);
-                                        boxDeviceShm->device->lastTime = QDateTime::currentDateTime().toTime_t();
+                                if(agBoxShm->device[i].Enabled == 0x01){
+                                    if(deviceCode.compare(QString(agBoxShm->device[i].device_code))==0){
+                                        agBoxShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
+                                        deviceId = QString(agBoxShm->device[i].device_id);
+                                        companyCode = QString(agBoxShm->device[i].product_code);
+                                        deviceType = QString::number(agBoxShm->device[i].device_type);
+                                        agBoxShm->device->lastTime = QDateTime::currentDateTime().toTime_t();
                                         break;
                                     }
                                 }
@@ -71,8 +71,8 @@ void MqttPub::run()
                                         double value = list_object.value("v").toDouble();
 
                                         for(int i=0;i<300;i++){
-                                            if(name.compare(QString(boxDeviceShm->procuctattrbute[i].attribute_name))==0){
-                                                nodeInfo.append(QString("\"%1\":%2,").arg(QString(boxDeviceShm->procuctattrbute[i].attribute_code)).arg(value));
+                                            if(name.compare(QString(agBoxShm->procuctattrbute[i].attribute_name))==0){
+                                                nodeInfo.append(QString("\"%1\":%2,").arg(QString(agBoxShm->procuctattrbute[i].attribute_code)).arg(value));
                                                 break;
                                             }
                                         }

+ 0 - 1
agEnvironmentProcess/mqttsub.cpp

@@ -1,6 +1,5 @@
 #include "mqttsub.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 
 MqttSub::MqttSub(QObject *parent) : QThread(parent)
 {

+ 33 - 0
agFreshAirProcess/agFreshAirProcess.pro

@@ -0,0 +1,33 @@
+QT += core sql network
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+TARGET = agDP0011
+
+
+SOURCES += \
+        main.cpp \
+    logthread.cpp \
+    httpthread.cpp \
+    core.cpp \
+    jzmqttsub.cpp \
+    jzmqttpub.cpp \
+    ytmqttsub.cpp \
+    ytmqttpub.cpp
+
+INCLUDEPATH += ../qmqtt-master/src/mqtt/
+
+HEADERS += \
+    logthread.h \
+    core.h \
+    jzmqttsub.h \
+    jzmqttpub.h \
+    ../QReplyTimeout.h \
+    httpthread.h \
+    ytmqttsub.h \
+    ytmqttpub.h
+
+
+LIBS += -lQt5Qmqtt

+ 166 - 0
agFreshAirProcess/core.cpp

@@ -0,0 +1,166 @@
+#include "core.h"
+#include "../AGBoxDog/boxshm.h"
+AGBoxShm *agBoxShm;
+
+void Core::shm_init(){
+    QSqlQuery qry;
+    QString sql = QString("select mqtt_ip,mqtt_port,user_name,pass_word from yt_t_mqtt where item_name = 'data-agbox'");
+    qry = db.exec(sql);
+    while (qry.next()) {
+        ip = qry.value(0).toString();
+        port = qry.value(1).toString();
+        username = qry.value(2).toString();
+        password = qry.value(3).toString();
+    }
+
+}
+
+bool Core::shm_load(){
+    key_t key;
+    int shmid;
+    if((key=ftok(SHM_PATH,static_cast<int>(SHM_PORT)))==-1){
+        return false;
+    }
+    if((shmid=shmget(key,sizeof(AGBoxShm),IPC_CREAT|0666))==-1){
+        return false;
+    }
+    agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
+
+    shm_init();
+    return true;
+}
+
+Core::Core(QObject *parent) : QObject(parent)
+{
+    logthread = new LogThread(this);
+    logthread->start();
+
+    db = QSqlDatabase::addDatabase("QSQLITE","conf_db");
+    db.setDatabaseName(QString("/opt/db/yt_conf.db"));
+    if(!db.open()){
+        logthread->appendData(QString("[agMqttProcess] open yt_conf.db failed"));
+    }
+    if(shm_load()){
+        logthread->appendData(QString("[agMqttProcess] shm load success"));
+    }
+
+    mqttIdx = 1;
+    mqttIdx1 = 1;
+    mqttIdx2 = 1;
+    m_client = new QMQTT::Client(QHostAddress(ip),static_cast<quint16>(port.toInt()),this);
+    connect(m_client,&QMQTT::Client::connected,this,&Core::onConnected);
+    m_client->setUsername(username);
+    m_client->setPassword(password.toLatin1());
+    m_client->setCleanSession(true);
+    m_client->connectToHost();
+
+    jzmqttsub = new JZMqttSub(this);
+    connect(jzmqttsub,&JZMqttSub::sendMqttData,this,&Core::receiveDevData);
+
+    jzmqttpub = new JZMqttPub(this);
+    connect(jzmqttpub,&JZMqttPub::mqttData,this,&Core::mqtt_data);
+    connect(jzmqttpub,&JZMqttPub::dataListLog,this,&Core::dataLog);
+
+    httpthread = new HttpThread(this);
+    connect(httpthread,&HttpThread::dataLog,this,&Core::dataLog);
+    connect(httpthread,&HttpThread::mqttData,this,&Core::mqtt_data1);
+
+    ytmqttsub = new YTMqttSub(this);
+    connect(ytmqttsub,&YTMqttSub::sendMqttData,this,&Core::receiveYtDevData);
+
+    ytmqttpub = new YTMqttPub(this);
+    connect(ytmqttpub,&YTMqttPub::mqttData,this,&Core::mqtt_data2);
+    connect(ytmqttpub,&YTMqttPub::mqttLog,this,&Core::dataLog);
+
+    timer = new QTimer(this);
+    connect(timer,&QTimer::timeout,this,&Core::time_out);
+    timer->start(1000);
+
+}
+
+
+Core::~Core()
+{
+    logthread->stop();
+    jzmqttpub->stop();
+
+}
+
+void Core::start()
+{
+    jzmqttsub->start();
+    jzmqttsub->mqtt_conf(ip,port,username,password);
+
+    jzmqttpub->start();
+
+    ytmqttsub->start();
+    ytmqttsub->mqtt_conf(ip,port,username,password);
+
+    ytmqttpub->start();
+}
+
+void Core::time_out()
+{
+    agBoxShm->processStatus[1].t_time=QDateTime::currentDateTime().toTime_t();
+
+
+}
+
+void Core::onConnected()
+{
+    logthread->appendData(QString("mqtt onConnected"));
+}
+
+void Core::dataLog(QString log)
+{
+    logthread->appendData(log);
+}
+
+void Core::mqtt_data(QString mqtt_msg)
+{
+    printf("test1111 [%s]\n",mqtt_msg.toUtf8().data());
+    logthread->appendData(QString("[%1] jz mqtt %2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(mqtt_msg));
+    if((m_client->connectionState()==QMQTT::STATE_INIT)||(m_client->connectionState()==QMQTT::STATE_DISCONNECTED)){
+        m_client->connectToHost();
+    }
+    m_client->publish(QMQTT::Message(mqttIdx++,"data-collector",mqtt_msg.toUtf8()));
+    if(mqttIdx > 9999){
+        mqttIdx = 1;
+    }
+}
+
+void Core::mqtt_data1(QString mqtt_msg)
+{
+    printf("test2222 [%s]\n",mqtt_msg.toUtf8().data());
+    logthread->appendData(QString("[%1] fj&ali http  %2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(mqtt_msg));
+    if((m_client->connectionState()==QMQTT::STATE_INIT)||(m_client->connectionState()==QMQTT::STATE_DISCONNECTED)){
+        m_client->connectToHost();
+    }
+    m_client->publish(QMQTT::Message(mqttIdx1++,"data-collector",mqtt_msg.toUtf8()));
+    if(mqttIdx1 > 9999){
+        mqttIdx1 = 1;
+    }
+}
+
+void Core::mqtt_data2(QString mqtt_msg)
+{
+    printf("test3333 [%s]\n",mqtt_msg.toUtf8().data());
+    logthread->appendData(QString("[%1] yt mqtt %2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")).arg(mqtt_msg));
+    if((m_client->connectionState()==QMQTT::STATE_INIT)||(m_client->connectionState()==QMQTT::STATE_DISCONNECTED)){
+        m_client->connectToHost();
+    }
+    m_client->publish(QMQTT::Message(mqttIdx2++,"data-collector",mqtt_msg.toUtf8()));
+    if(mqttIdx2 > 9999){
+        mqttIdx2 = 1;
+    }
+}
+
+void Core::receiveDevData(QString topic,QByteArray data)
+{
+    jzmqttpub->devMessage(MqttData(topic,data));
+}
+
+void Core::receiveYtDevData(QString topic,QByteArray data)
+{
+    ytmqttpub->devMessage(MqttData(topic,data));
+}

+ 54 - 0
agFreshAirProcess/core.h

@@ -0,0 +1,54 @@
+#ifndef CORE_H
+#define CORE_H
+
+#include <QObject>
+#include <qmqtt.h>
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include <QDateTime>
+#include <QTimer>
+#include "logthread.h"
+#include "jzmqttpub.h"
+#include "jzmqttsub.h"
+#include "httpthread.h"
+#include "ytmqttpub.h"
+#include "ytmqttsub.h"
+
+class Core : public QObject
+{
+    Q_OBJECT
+public:
+    explicit Core(QObject *parent = nullptr);
+    ~Core();
+    void start();
+    void shm_init();
+    bool shm_load();
+
+signals:
+
+public slots:
+    void onConnected();
+    void dataLog(QString log);
+    void receiveDevData(QString topic,QByteArray data);
+    void receiveYtDevData(QString topic,QByteArray data);
+    void mqtt_data(QString mqtt_msg);
+    void mqtt_data1(QString mqtt_msg);
+    void mqtt_data2(QString mqtt_msg);
+    void time_out();
+
+private:
+    LogThread *logthread;
+    JZMqttPub *jzmqttpub;
+    JZMqttSub *jzmqttsub;
+    HttpThread *httpthread;
+    YTMqttPub *ytmqttpub;
+    YTMqttSub *ytmqttsub;
+
+    QMQTT::Client *m_client;
+    QSqlDatabase db;
+    quint16 mqttIdx,mqttIdx1,mqttIdx2;
+    QString ip,port,username,password;
+    QTimer *timer;
+};
+
+#endif // CORE_H

+ 265 - 0
agFreshAirProcess/httpthread.cpp

@@ -0,0 +1,265 @@
+#include "httpthread.h"
+#include "../AGBoxDog/boxshm.h"
+
+HttpThread::HttpThread(QObject *parent) : QObject(parent)
+{
+    minute = 255;
+    minute1 = 255;
+    hour = 25;
+    roomList.clear();
+    keep = false;
+    isWaiting = false;
+    networkManager = new QNetworkAccessManager(this); //3-12层房间设备列表心跳数据
+    connect(networkManager,SIGNAL(finished(QNetworkReply *)),this,SLOT(finishedSlot(QNetworkReply *)));
+    isWaiting1 = false;
+    networkManager1 = new QNetworkAccessManager(this); //阿里天气接口
+    connect(networkManager1,SIGNAL(finished(QNetworkReply *)),this,SLOT(finishedSlot1(QNetworkReply *)));
+
+    timer = new QTimer(this);
+    connect(timer,&QTimer::timeout,this,&HttpThread::time_out);
+    timer->start(5000);
+
+}
+
+void HttpThread::stop()
+{
+    keep = false;
+}
+
+void  HttpThread::finishedSlot(QNetworkReply *reply)
+{
+    if(reply->error()==QNetworkReply::NoError){
+        QString data = QString::fromUtf8(reply->readAll());
+        QByteArray ba = data.toLocal8Bit();
+        ba = QString::fromLocal8Bit(ba).toUtf8();
+        QJsonParseError parseError;
+        QJsonDocument doc = QJsonDocument::fromJson(ba,&parseError);
+        printf("event parseError.error %d\n",parseError.error);
+        if(parseError.error == QJsonParseError::NoError){
+            QJsonArray list_array = doc.array();
+            QString device_code = "";
+            QString nodeInfo = "";
+            double wd=0.00,sd=0.00,pm2_5=0.00,co2=0.00;
+            int voc= 0;
+            int fan_status = 0;
+//            int ts = (QDateTime::fromString(QDateTime::currentDateTime().toString("yyyy-MM-dd HH")+":00:00","yyyy-MM-dd HH:mm:ss")).toTime_t();
+            int ts = QDateTime::currentDateTime().toTime_t();
+            for(int i=0;i<list_array.size();i++){
+                QJsonObject list_object = list_array.at(i).toObject();
+                device_code = list_object.value("roomNo").toString();
+                QString attribute_name = list_object.value("name").toString();
+                //printf("222  list_object.value(eventTime).toString() %s, eventTime %s \n",list_object.value("eventTime").toString().toUtf8().data(),eventTime.toUtf8().data());
+                if(attribute_name.compare("新风系统-室内温度")==0){
+                    wd = list_object.value("value").toDouble();
+                    nodeInfo.append(QString("\"wd\":%1,").arg(wd));
+                }
+                if(attribute_name.compare("新风系统-室内湿度")==0){
+                    sd = list_object.value("value").toDouble();
+                    nodeInfo.append(QString("\"sd\":%1,").arg(sd));
+                }
+                if(attribute_name.compare("新风系统-室内PM2.5")==0){
+                    pm2_5 = list_object.value("value").toDouble();
+                    nodeInfo.append(QString("\"pm2_5\":%1,").arg(pm2_5));
+                }
+                if(attribute_name.compare("新风系统-室内CO2")==0){
+                    co2 = list_object.value("value").toDouble();
+                    nodeInfo.append(QString("\"co2\":%1,").arg(co2));
+                }
+                if(attribute_name.compare("新风系统-室内VOC等级")==0){
+                    voc = list_object.value("value").toInt();
+                    nodeInfo.append(QString("\"voc\":%1,").arg(voc));
+                }
+                if(attribute_name.contains("排气扇")){
+                    fan_status = list_object.value("value").toInt();
+                    nodeInfo.append(QString("\"fan_status\":%1,").arg(fan_status));
+
+                }
+
+            }
+            nodeInfo = nodeInfo.left(nodeInfo.length()-1);
+
+            for(int i=0;i<1024;i++){
+                if(agBoxShm->device[i].Enabled == 0x01){
+                    if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
+                        emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{%5},\"device_type\":\"%6-xf\"}")
+                                                                          .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(ts).arg(nodeInfo).arg(agBoxShm->device[i].device_type));
+                        break;
+                    }
+                }
+            }
+
+
+        }else{
+            emit dataLog(QString("http room QJson Parse  Error  %1").arg(parseError.error));
+        }
+
+        emit dataLog(QString("[%1] http room QNetworkReply Status %2").arg(QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t()).toString("yyyy-MM-dd HH:mm:ss")).arg(data));
+    }else{
+        emit dataLog(QString("[%1] http room QNetworkReply Status Err  %2").arg(QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t()).toString("yyyy-MM-dd HH:mm:ss")).arg(reply->error()));
+    }
+
+    isWaiting = false;
+    roomList.removeFirst();
+    reply->abort();
+    reply->deleteLater();
+}
+
+void HttpThread::reply_timeout()
+{
+    printf("[%s] room reply_timeout\n",QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss").toUtf8().data());
+    isWaiting = false;
+    roomList.removeFirst();
+}
+
+void  HttpThread::finishedSlot1(QNetworkReply *reply)
+{
+    if(reply->error()==QNetworkReply::NoError){
+        QString data = QString::fromUtf8(reply->readAll());
+        QByteArray ba = data.toLocal8Bit();
+        ba = QString::fromLocal8Bit(ba).toUtf8();
+        QJsonParseError parseError;
+        QJsonDocument doc = QJsonDocument::fromJson(ba,&parseError);
+        printf("status parseError.error %d\n",parseError.error);
+        if(parseError.error == QJsonParseError::NoError){
+            QJsonObject obj_doc = doc.object();
+            QJsonValue data_value = obj_doc.value("showapi_res_body");
+
+            QJsonObject data_object = data_value.toObject();
+            QJsonValue list_value = data_object.value("now");
+            QJsonObject list_object = list_value.toObject();
+            double wd = list_object.value("temperature").toString().toDouble();
+            QString sdStr = list_object.value("sd").toString();
+            double sd = sdStr.left(sdStr.length()-1).toDouble();
+
+            QJsonValue aqi_detail = list_object.value("aqiDetail");
+            QJsonObject detail_object = aqi_detail.toObject();
+            double pm2_5 = detail_object.value("pm2_5").toString().toDouble();
+            QString qual = detail_object.value("quality").toString();
+
+            int quality = 0;
+            if(qual.compare("优质")==0){
+                quality = 1;
+            }else if(qual.compare("良好")==0){
+                quality = 2;
+            }else if(qual.compare("轻度污染")==0){
+                quality = 3;
+            }else if(qual.compare("中度污染")==0){
+                quality = 4;
+            }else if(qual.compare("重度污染")==0){
+                quality = 5;
+            }else if(qual.compare("严重污染")==0){
+                quality = 6;
+            }
+
+            emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"wd\":%5,\"sd\":%6,\"pm2_5\":%7,\"quality\":%8},\"device_type\":\"%9-xf\"}")
+                          .arg(QString("weather0001")).arg(QString("weather0001")).arg(QString("511_XFFJ")).arg(QDateTime::fromString(QDateTime::currentDateTime().toString("yyyy-MM-dd HH")+":00:00","yyyy-MM-dd HH:mm:ss").toTime_t()).arg(wd).arg(sd).arg(pm2_5).arg(quality).arg(511));
+
+
+        }else{
+            emit dataLog(QString("ali weather QJson Parse  Error  %1").arg(parseError.error));
+        }
+
+        emit dataLog(QString("[%1] ali weather QNetworkReply Status %2").arg(QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t()).toString("yyyy-MM-dd HH:mm:ss")).arg(data));
+    }else{
+        emit dataLog(QString("[%1] ali weather QNetworkReply Status Err  %2").arg(QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t()).toString("yyyy-MM-dd HH:mm:ss")).arg(reply->error()));
+    }
+
+    isWaiting1 = false;
+    reply->abort();
+    reply->deleteLater();
+}
+
+void HttpThread::reply_timeout1()
+{
+    printf("[%s] ali weather reply_timeout\n",QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss").toUtf8().data());
+    isWaiting1 = false;
+}
+
+void HttpThread::time_out()
+{
+    agBoxShm->processStatus[11].t_time=QDateTime::currentDateTime().toTime_t();
+
+//    if(hour != QDateTime::currentDateTime().time().hour()){
+//        hour = QDateTime::currentDateTime().time().hour();
+//        for(int i=0;i<1024;i++){
+//            if(QString("http").compare(QString(agBoxShm->device[i].device_gateway))==0){
+//                roomList.append(QString(agBoxShm->device[i].device_code));
+//            }
+//        }
+
+//        //每小时获取一次阿里天气数据
+//        if(!isWaiting1){
+//            isWaiting1 = true;
+//            QNetworkRequest *req = new QNetworkRequest();
+//            QString url = QString("https://weather01.market.alicloudapi.com/area-to-weather?area=历城区");
+//            req->setUrl(QUrl(url));
+//            req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
+//            req->setRawHeader("Accept","*/*");
+//            req->setRawHeader("Connection","keep-alive");
+//            req->setRawHeader("Cache-Control"," no-cache");
+//            req->setRawHeader("Authorization","APPCODE 0f2b7fce6e104ba8835358b7b59b4fb6");
+//            QNetworkReply *reply = networkManager1->get(*req);
+//            QReplayTimeout *pTimeout = new QReplayTimeout(reply,10000);
+//            connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout1()));
+
+//        }
+
+//    }
+
+    if(hour != QDateTime::currentDateTime().time().hour()){
+        hour = QDateTime::currentDateTime().time().hour();
+
+        //每小时获取一次阿里天气数据
+        if(!isWaiting1){
+            isWaiting1 = true;
+            QNetworkRequest *req = new QNetworkRequest();
+            QString url = QString("https://weather01.market.alicloudapi.com/area-to-weather?area=历城区");
+            req->setUrl(QUrl(url));
+            req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
+            req->setRawHeader("Accept","*/*");
+            req->setRawHeader("Connection","keep-alive");
+            req->setRawHeader("Cache-Control"," no-cache");
+            req->setRawHeader("Authorization","APPCODE 0f2b7fce6e104ba8835358b7b59b4fb6");
+            QNetworkReply *reply = networkManager1->get(*req);
+            QReplayTimeout *pTimeout = new QReplayTimeout(reply,10000);
+            connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout1()));
+
+        }
+
+    }
+
+    if(QDateTime::currentDateTime().time().minute()%10 == 0){
+        for(int i=0;i<1024;i++){
+            if(QString("http").compare(QString(agBoxShm->device[i].device_gateway))==0){
+                roomList.append(QString(agBoxShm->device[i].device_code));
+            }
+        }
+    }
+
+    if(!isWaiting && roomList.length() > 0){  //每小时获取3-12层每个房间设备列表心跳数据一次
+        isWaiting = true;
+        QString roomNo = roomList.first();
+        QNetworkRequest *req = new QNetworkRequest();
+        QString url = QString("http://www.limark.net:81/api/hotel/control/device/list.do?hotelCode=ff80808179c6599a0179c65caf9a0001&roomNo=%1").arg(roomNo);
+        req->setUrl(QUrl(url));
+        req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
+        req->setRawHeader("Accept","*/*");
+        req->setRawHeader("Connection","keep-alive");
+        req->setRawHeader("Cache-Control"," no-cache");
+        req->setRawHeader("api-key","ff1930560ed8405382d49c6991861e75");
+        QNetworkReply *reply = networkManager->get(*req);
+        QReplayTimeout *pTimeout = new QReplayTimeout(reply,10000);
+        connect(pTimeout, SIGNAL(net_timeout()),this,SLOT(reply_timeout()));
+
+    }
+
+}
+
+
+
+
+
+
+
+
+

+ 53 - 0
agFreshAirProcess/httpthread.h

@@ -0,0 +1,53 @@
+#ifndef HTTPTHREAD_H
+#define HTTPTHREAD_H
+
+#include <QObject>
+#include <QDateTime>
+#include <QTimer>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QSslConfiguration>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QJsonParseError>
+#include "../QReplyTimeout.h"
+
+class HttpThread : public QObject
+{
+    Q_OBJECT
+public:
+    explicit HttpThread(QObject *parent = nullptr);
+    void run();
+    void stop();
+
+signals:
+    void dataLog(QString log);
+    void mqttData(QString mqtt_msg);
+    void mqttEvent(QString mqtt_event);
+    void appendSql(QString sql);
+
+public slots:
+    void time_out();
+    void finishedSlot(QNetworkReply *reply);
+    void finishedSlot1(QNetworkReply *reply);
+    void reply_timeout();
+    void reply_timeout1();
+
+private:
+    bool isWaiting,isWaiting1;
+    bool keep;
+    int minute,hour,minute1;
+    QList<QString> roomList;
+    QString startTime;
+    QString endTime;
+    QNetworkAccessManager *networkManager,*networkManager1;
+    QSslConfiguration config;
+    QTimer *timer;
+
+
+};
+
+#endif // HTTPTHREAD_H

+ 110 - 0
agFreshAirProcess/jzmqttpub.cpp

@@ -0,0 +1,110 @@
+#include "jzmqttpub.h"
+#include "../AGBoxDog/boxshm.h"
+
+JZMqttPub::JZMqttPub(QObject *parent) : QThread(parent)
+{
+    keep = false;
+    mqttDataList.clear();
+
+
+}
+
+void JZMqttPub::stop()
+{
+    keep = false;
+
+}
+
+
+void JZMqttPub::run()
+{
+    keep = true;
+    while (keep) {
+        if(mqttDataList.length()>0){
+            while (mqttDataList.length()>0) {
+                MqttData md = mqttDataList.first();
+                QString topic = md.topic;
+                QByteArray data = md.data;
+
+
+                QJsonParseError parseErr;
+                QJsonDocument doc = QJsonDocument::fromJson(data,&parseErr);
+                printf("jz device parseErr.error %d\n",parseErr.error);
+                if(parseErr.error==QJsonParseError::NoError){
+                    QString nodeInfo = "";
+                    QString deviceId = "";
+                    QString productCode = "";
+                    QString deviceType = "";
+                    QJsonObject obj_doc = doc.object();
+                    int ts = obj_doc.value("ts").toInt();
+                    QDateTime datatime = QDateTime::fromTime_t(ts);
+                    int minute = datatime.time().minute();
+                    QJsonValue dev_value = obj_doc.value("devs");
+                    if(dev_value.isArray() && (minute == 00)){
+                        int ts = QDateTime::fromString(datatime.toString("yyyy-MM-dd HH")+":00:00","yyyy-MM-dd HH:mm:ss").toTime_t();
+
+                        QJsonArray list_array = dev_value.toArray();
+                        for(int i=0;i<list_array.size();i++){
+                            QJsonObject obj_dev = list_array.at(i).toObject();
+                            QString deviceCode = obj_dev.value("dev").toString();
+                            printf("deviceCode: %s\n",deviceCode.toUtf8().data());
+                            for(int j=0;j<1024;j++){
+                                if(agBoxShm->device[j].Enabled == 0x01){
+                                    if(deviceCode.compare(QString(agBoxShm->device[j].device_code))==0){
+                                        deviceId = QString(agBoxShm->device[j].device_id);
+                                        productCode = QString(agBoxShm->device[j].product_code);
+                                        deviceType = QString::number(agBoxShm->device[j].device_type);
+                                        break;
+                                    }
+                                }
+                            }
+
+                            QJsonValue d_value = obj_dev.value("d");
+                            if(d_value.isArray()){
+                                QJsonArray d_array = d_value.toArray();
+                                if(d_array.size() > 0){
+                                    nodeInfo.append(QString("\"on_line\":1"));
+                                    emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{%5},\"device_type\":\"%6-xf\"}")
+                                                  .arg(deviceId).arg(deviceCode).arg(productCode).arg(ts).arg(nodeInfo).arg(deviceType));
+
+                                }
+                            }
+
+                        }
+                    }
+
+                }
+
+
+                mqttDataList.removeFirst();
+                usleep(1000);
+            }
+        }
+
+
+        usleep(50000);
+    }
+}
+
+void JZMqttPub::devMessage(MqttData dev)
+{
+    mqttDataList.append(dev);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 45 - 0
agFreshAirProcess/jzmqttpub.h

@@ -0,0 +1,45 @@
+#ifndef MQTTPUB_H
+#define MQTTPUB_H
+
+#include <QThread>
+#include <QDateTime>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QJsonParseError>
+#include <QVariantMap>
+
+class MqttData{
+public:
+    explicit MqttData(QString t="",QByteArray d=""){
+        topic = t;
+        data = d;
+    }
+    QString topic;
+    QByteArray data;
+};
+
+
+class JZMqttPub : public QThread
+{
+    Q_OBJECT
+public:
+    explicit JZMqttPub(QObject *parent = nullptr);
+    void run();
+    void stop();
+    void devMessage(MqttData dev);
+
+
+signals:
+    void mqttData(QString mqtt_msg);
+    void dataListLog(QString msg);
+
+public slots:
+
+private:
+    bool keep;
+    QList<MqttData> mqttDataList;
+};
+
+#endif // MQTTPUB_H

+ 87 - 0
agFreshAirProcess/jzmqttsub.cpp

@@ -0,0 +1,87 @@
+#include "jzmqttsub.h"
+#include "../AGBoxDog/boxshm.h"
+
+JZMqttSub::JZMqttSub(QObject *parent) : QThread(parent)
+{
+    minute = 255;
+
+    timer = new QTimer(this);
+    connect(timer,&QTimer::timeout,this,&JZMqttSub::time_out);
+}
+
+void JZMqttSub::run()
+{
+
+}
+
+void JZMqttSub::time_out()
+{
+    if((m_client->connectionState()==QMQTT::STATE_DISCONNECTED)||(m_client->connectionState()==QMQTT::STATE_INIT)){
+        m_client->connectToHost();
+    }
+
+}
+
+void JZMqttSub::mqtt_conf(QString ip,QString port,QString username,QString password)
+{
+    mqtt_ip = ip;
+    mqtt_port = port;
+    mqtt_username = username;
+    mqtt_passwd = password;
+
+
+//    m_client = new QMQTT::Client(QHostAddress(mqtt_ip),static_cast<quint16>(mqtt_port.toInt()),this);
+//    m_client->setUsername(mqtt_username);
+//    m_client->setPassword(mqtt_passwd.toLatin1());
+    m_client = new QMQTT::Client(QHostAddress("10.108.34.2"),1883,this);
+    m_client->setUsername("usky");
+    m_client->setPassword("usky");
+    m_client->setCleanSession(true);
+    connect(m_client,&QMQTT::Client::connected,this,&JZMqttSub::onConnected);
+    connect(m_client,&QMQTT::Client::received,this,&JZMqttSub::onReceived);
+    m_client->connectToHost();
+
+
+    timer->start(1000);
+}
+
+void JZMqttSub::onConnected()
+{
+    printf("xfjz onConnected\n");
+    m_client->subscribe("/edge/baInfo/091267EB9CF743D8857330E22DF8EC2D/rtg",0);
+    m_client->subscribe("/edge/baInfo/F3D0A204C7594361A308018307E8C349/rtg",0);
+    m_client->subscribe("/edge/baInfo/3D25E5054A01457AA66466FEE1BCFA6E/rtg",0);
+    m_client->subscribe("/edge/baInfo/340D46C186DB42C0BD2F1A99AC5E63F2/rtg",0);
+    m_client->subscribe("/edge/baInfo/D9F69465CCE74E82BC38F61821D3E6BE/rtg",0);
+    m_client->subscribe("/edge/baInfo/FB0CB2D69D214E8487BDA518C8726F56/rtg",0);
+    m_client->subscribe("/edge/baInfo/207DE156F8844A92901449DDF0B4C76C/rtg",0);
+    m_client->subscribe("/edge/baInfo/EC18DF7F35F14163B232E0B1EF55DDCE/rtg",0);
+    m_client->subscribe("/edge/baInfo/8118A064BCA3458BAD020EC9DA12265D/rtg",0);
+    m_client->subscribe("/edge/baInfo/67DF1D8A6471432591FC0ED10D3A7FC6/rtg",0);
+    m_client->subscribe("/edge/baInfo/08D86E3BCA4D44B594AEF4150AB41F9B/rtg",0);
+    m_client->subscribe("/edge/baInfo/5657148CD58C43159170E1960A72242F/rtg",0);
+    m_client->subscribe("/edge/baInfo/21981D16C19842078E6E5DD326835B00/rtg",0);
+    m_client->subscribe("/edge/baInfo/7C1CE5AEE4BF4706AFEA77BB2C35E57B/rtg",0);
+    m_client->subscribe("/edge/baInfo/AA075EC348654E3690665AAD22C9FA75/rtg",0);
+    m_client->subscribe("/edge/baInfo/162CDC71F7F74E7FA5CCED83EF3ECF05/rtg",0);
+
+}
+
+void JZMqttSub::onReceived(const QMQTT::Message &message)
+{
+    agBoxShm->processStatus[11].t_time=QDateTime::currentDateTime().toTime_t();
+
+    QString topic = message.topic();
+    QByteArray data = message.payload();
+
+    emit sendMqttData(topic,data);
+
+}
+
+
+
+
+
+
+
+

+ 35 - 0
agFreshAirProcess/jzmqttsub.h

@@ -0,0 +1,35 @@
+#ifndef MQTTSUB_H
+#define MQTTSUB_H
+
+#include <QThread>
+#include <qmqtt.h>
+#include <QDateTime>
+#include <QTimer>
+
+class JZMqttSub : public QThread
+{
+    Q_OBJECT
+public:
+    explicit JZMqttSub(QObject *parent = nullptr);
+    void run();
+    void mqtt_conf(QString ip,QString port,QString username,QString password);
+
+signals:
+    void mq_log(QString log);
+    void sendMqttData(QString topic,QByteArray data);
+
+public slots:
+    void time_out();
+    void onConnected();
+    void onReceived(const QMQTT::Message &message);
+
+private:
+    QString mqtt_ip,mqtt_port,mqtt_username,mqtt_passwd;
+    QTimer *timer;
+
+    QMQTT::Client *m_client;
+    int minute;
+
+};
+
+#endif // MQTTSUB_H

+ 52 - 0
agFreshAirProcess/logthread.cpp

@@ -0,0 +1,52 @@
+#include "logthread.h"
+
+LogThread::LogThread(QObject *parent) :
+    QThread(parent)
+{
+    keep = false;
+    dataList.clear();
+    QDir path("/usky/data-agbox/agmqttprocess/log");
+    if(!path.exists()){
+        system("mkdir -p /usky/data-agbox/agmqttprocess/log/");
+    }
+    file = new QFile("/usky/data-agbox/agmqttprocess/log/mqttprocess-"+QDate::currentDate().toString("yyyyMMdd")+".log");
+    day = QDate::currentDate().day();
+}
+
+void LogThread::appendData(QString data)
+{
+    dataList.append(data);
+}
+
+void LogThread::stop()
+{
+    keep = false;
+}
+
+void LogThread::run()
+{
+    printf("log thread start\n");
+    if(file->open(QIODevice::ReadWrite|QIODevice::Append|QIODevice::Text)){
+        file->write(QString("agMqttProcess start at %1.\r\n").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz")).toUtf8());
+        file->close();
+    }
+    keep = true;
+    while(keep){
+        if(dataList.length()>0){
+            if(day!=QDate::currentDate().day()){
+                day = QDate::currentDate().day();
+                file = new QFile("/usky/data-agbox/agmqttprocess/log/mqttprocess-"+QDate::currentDate().toString("yyyyMMdd")+".log");
+            }
+            if(file->open(QIODevice::ReadWrite|QIODevice::Append|QIODevice::Text)){
+                while(dataList.length()>0){
+                    file->write(dataList.first().toUtf8());
+                    file->write("\r\n");
+                    dataList.removeFirst();
+                    usleep(1000);
+                }
+                file->close();
+            }
+        }
+        usleep(50000);
+    }
+}

+ 28 - 0
agFreshAirProcess/logthread.h

@@ -0,0 +1,28 @@
+#ifndef LOGTHREAD_H
+#define LOGTHREAD_H
+
+#include <QThread>
+#include <QStringList>
+#include <QDate>
+#include <QDir>
+#include <QFile>
+
+class LogThread : public QThread
+{
+    Q_OBJECT
+public:
+    explicit LogThread(QObject *parent = nullptr);
+    void appendData(QString data);
+    void run();
+    void stop();
+signals:
+
+public slots:
+private:
+    QFile *file;
+    QStringList dataList;
+    int day;
+    bool keep;
+};
+
+#endif // LOGTHREAD_H

+ 12 - 0
agFreshAirProcess/main.cpp

@@ -0,0 +1,12 @@
+#include <QCoreApplication>
+#include "core.h"
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    Core *core = new Core(nullptr);
+    core->start();
+
+    return a.exec();
+}

+ 119 - 0
agFreshAirProcess/ytmqttpub.cpp

@@ -0,0 +1,119 @@
+#include "ytmqttpub.h"
+#include "../AGBoxDog/boxshm.h"
+
+YTMqttPub::YTMqttPub(QObject *parent) : QThread(parent)
+{
+    keep = false;
+    mqttDataList.clear();
+}
+
+void YTMqttPub::run()
+{
+    keep = true;
+    while (keep) {
+        if(mqttDataList.length()>0){
+            while (mqttDataList.length()>0) {
+                MqttData md = mqttDataList.first();
+                QString topic = md.topic;
+                QByteArray data = md.data;
+
+
+                QJsonParseError parseErr;
+                QJsonDocument doc = QJsonDocument::fromJson(data,&parseErr);
+                printf("yts device parseErr.error %d\n",parseErr.error);
+                if(parseErr.error==QJsonParseError::NoError){
+                    QString nodeInfo = "";
+                    QString deviceId = "";
+                    QString productCode = "";
+                    QString deviceType = "";
+                    QJsonObject obj_doc = doc.object();
+                    int ts = obj_doc.value("ts").toInt();
+                    QDateTime datatime = QDateTime::fromTime_t(ts);
+                    int minute = datatime.time().minute();
+                    QJsonValue dev_value = obj_doc.value("devs");
+                    if(dev_value.isArray() && (minute == 00)){
+                        int ts = QDateTime::fromString(datatime.toString("yyyy-MM-dd HH")+":00:00","yyyy-MM-dd HH:mm:ss").toTime_t();
+
+                        QJsonArray list_array = dev_value.toArray();
+                        for(int i=0;i<list_array.size();i++){
+                            QJsonObject obj_dev = list_array.at(i).toObject();
+
+                            QJsonValue d_value = obj_dev.value("d");
+                            if(d_value.isArray()){
+                                QJsonArray d_array = d_value.toArray();
+                                if(d_array.size() > 0){
+
+                                    QString deviceCode = d_array.at(0).toObject().value("m").toString().mid(0,6);
+                                    printf("yts deviceCode: %s\n",deviceCode.toUtf8().data());
+                                    for(int j=0;j<1024;j++){
+                                        if(agBoxShm->device[j].Enabled == 0x01){
+                                            if(deviceCode.compare(QString(agBoxShm->device[j].device_code))==0){
+                                                deviceId = QString(agBoxShm->device[j].device_id);
+                                                productCode = QString(agBoxShm->device[j].product_code);
+                                                deviceType = QString::number(agBoxShm->device[j].device_type);
+                                                for(int k=0;k<d_array.size();k++){
+                                                    QJsonObject obj_d = d_array.at(k).toObject();
+                                                    QString name = obj_d.value("m").toString();
+                                                    QList<QString> nameList = name.split("_");
+                                                    int value = obj_d.value("v").toInt();
+                                                    if(QString(nameList.at(2)).compare("CO2")==0){
+                                                        nodeInfo.append(QString("\"co2\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("FLDW")==0){
+                                                        nodeInfo.append(QString("\"fldw\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("PM2")==0){
+                                                        nodeInfo.append(QString("\"pm2_5\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("SNSD")==0){
+                                                        nodeInfo.append(QString("\"sd\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("SNWD")==0){
+                                                        nodeInfo.append(QString("\"wd\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("VOC")==0){
+                                                        nodeInfo.append(QString("\"voc\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("YXMS")==0){
+                                                        nodeInfo.append(QString("\"yxms\":%1,").arg(value));
+                                                    }else if(QString(nameList.at(2)).compare("YXZT")==0){
+                                                        nodeInfo.append(QString("\"yxzt\":%1,").arg(value));
+                                                    }
+
+                                                }
+
+                                                nodeInfo = nodeInfo.left(nodeInfo.length()-1);
+                                                emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{%5},\"device_type\":\"%6-xf\"}")
+                                                              .arg(deviceId).arg(deviceCode).arg(productCode).arg(ts).arg(nodeInfo).arg(deviceType));
+
+                                                break;
+                                            }
+                                        }
+                                    }
+
+
+                                }
+                            }
+
+
+
+                        }
+                    }
+
+                }
+
+
+                mqttDataList.removeFirst();
+                usleep(1000);
+            }
+        }
+
+
+        usleep(50000);
+    }
+
+}
+
+void YTMqttPub::stop()
+{
+    keep = false;
+}
+
+void YTMqttPub::devMessage(MqttData dev)
+{
+    mqttDataList.append(dev);
+}

+ 35 - 0
agFreshAirProcess/ytmqttpub.h

@@ -0,0 +1,35 @@
+#ifndef YTMQTTPUB_H
+#define YTMQTTPUB_H
+
+#include <QThread>
+#include <QJsonArray>
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QJsonParseError>
+#include <QVariantMap>
+#include "jzmqttpub.h"
+
+
+
+class YTMqttPub : public QThread
+{
+    Q_OBJECT
+public:
+    explicit YTMqttPub(QObject *parent = nullptr);
+    void run();
+    void stop();
+    void devMessage(MqttData dev);
+
+signals:
+    void mqttData(QString msg);
+    void mqttLog(QString msg_log);
+
+public slots:
+
+private:
+    bool keep;
+    QList<MqttData> mqttDataList;
+};
+
+#endif // YTMQTTPUB_H

+ 62 - 0
agFreshAirProcess/ytmqttsub.cpp

@@ -0,0 +1,62 @@
+#include "ytmqttsub.h"
+#include "../AGBoxDog/boxshm.h"
+
+YTMqttSub::YTMqttSub(QObject *parent) : QThread(parent)
+{
+    timer = new QTimer(this);
+    connect(timer,&QTimer::timeout,this,&YTMqttSub::time_out);
+
+}
+
+void YTMqttSub::run()
+{
+
+}
+
+void YTMqttSub::time_out()
+{
+    if(m_client->connectionState() == QMQTT::STATE_INIT || m_client->connectionState() == QMQTT::STATE_DISCONNECTED){
+        m_client->connectToHost();
+    }
+
+}
+
+void YTMqttSub::mqtt_conf(QString ip, QString port, QString username, QString passwd)
+{
+//    m_client = new QMQTT::Client(QHostAddress(ip),static_cast<quint16>(port.toInt()),this);
+//    m_client->setUsername(username);
+//    m_client->setPassword(passwd.toLatin1());
+    m_client = new QMQTT::Client(QHostAddress("10.108.34.2"),1883,this);
+    m_client->setUsername("usky");
+    m_client->setPassword("usky");
+    m_client->setCleanSession(true);
+    connect(m_client,&QMQTT::Client::connected,this,&YTMqttSub::onConnected);
+    connect(m_client,&QMQTT::Client::received,this,&YTMqttSub::onReceived);
+    m_client->connectToHost();
+
+    timer->start(1000);
+}
+
+void YTMqttSub::onConnected()
+{
+    printf("xfyt mqtt onConnected\n");
+    m_client->subscribe("/edge/baInfo/B3E523F1D0E8402F818C30833C4F1C6F/rtg",0);
+    m_client->subscribe("/edge/baInfo/E68D8A289878474D963D43F5FC624E34/rtg",0);
+    m_client->subscribe("/edge/baInfo/3CC454CC33B74714BB7B8D8C83C72304/rtg",0);
+    m_client->subscribe("/edge/baInfo/3932C85C53964902A0A426B03A4EBB42/rtg",0);
+    m_client->subscribe("/edge/baInfo/ED2059D345D145DCBEB6B5E3B4CFCAD8/rtg",0);
+    m_client->subscribe("/edge/baInfo/E4C82427D44D40E5B398002CA5A1EF42/rtg",0);
+    m_client->subscribe("/edge/baInfo/0344B9CD3B6A468E87551B25BC679A96/rtg",0);
+    m_client->subscribe("/edge/baInfo/2F0C601E76E9444997F5E72EAB86856F/rtg",0);
+
+}
+
+void YTMqttSub::onReceived(const QMQTT::Message &message)
+{
+    agBoxShm->processStatus[11].t_time=QDateTime::currentDateTime().toTime_t();
+    QString topic = message.topic();
+    QByteArray data = message.payload();
+
+    emit sendMqttData(topic,data);
+
+}

+ 31 - 0
agFreshAirProcess/ytmqttsub.h

@@ -0,0 +1,31 @@
+#ifndef YTMQTTSUB_H
+#define YTMQTTSUB_H
+
+#include <QThread>
+#include <qmqtt.h>
+#include <QDateTime>
+#include <QTimer>
+
+class YTMqttSub : public QThread
+{
+    Q_OBJECT
+public:
+    explicit YTMqttSub(QObject *parent = nullptr);
+    void run();
+    void mqtt_conf(QString ip, QString port, QString username, QString passwd);
+
+signals:
+    void mq_log(QString log);
+    void sendMqttData(QString topic, QByteArray data);
+
+public slots:
+    void time_out();
+    void onConnected();
+    void onReceived(const QMQTT::Message &message);
+
+private:
+    QTimer *timer;
+    QMQTT::Client *m_client;
+};
+
+#endif // YTMQTTSUB_H

+ 9 - 9
agGeneratorProcess/devinfotcpserver.cpp

@@ -1,5 +1,5 @@
 #include "devinfotcpserver.h"
-#include "../agVideoProcess/boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 DevInfoTcpServer::DevInfoTcpServer(QObject *parent) : QObject(parent)
 {
@@ -46,20 +46,20 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                     QString device_name = list_object.value("name").toString();
                     bool found = false;
                     for(int i=0;i<1024;i++){
-                        if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 504)){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 504)){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 found = true;
-                                msg.append(QString("{\"product_id\": \"4\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 0},").arg(boxDeviceShm->device[i].device_id).arg(device_code).arg(device_name));
+                                msg.append(QString("{\"product_id\": \"4\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 0},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code).arg(device_name));
                                 break;
                             }
                         }
                     }
                     if(!found){
                         QString device_id = QCryptographicHash::hash(QString("4%1").arg(device_code).toUtf8(),QCryptographicHash::Md5).toHex();
-                        QString sql = QString("insert into yt_t_device values('%1','%2',504,'10000001',null);").arg(device_code).arg(device_id);
+                        QString sql = QString("insert into yt_t_device values('%1','%2',504,'504_gr',null);").arg(device_code).arg(device_id);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"4\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 1},").arg(device_id).arg(device_code).arg(device_name));
+                        msg.append(QString("{\"product_id\": \"4\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 1},").arg(agBoxShm->device[i].product_code).arg(device_id).arg(device_code).arg(device_name));
                     }
                     devTcpList.append(device_code);
                 }
@@ -67,9 +67,9 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
 
 
             for(int i=0;i<1024;i++){
-                if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 504)){
+                if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 504)){
                     bool found1 = false;
-                    QString device_code = QString(boxDeviceShm->device[i].device_code);
+                    QString device_code = QString(agBoxShm->device[i].device_code);
                     if(devTcpList.size() > 0){
                         for(int j=0;j<devTcpList.size();j++){
                             if(device_code.compare(devTcpList.at(j))==0){
@@ -83,7 +83,7 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                         QString sql = QString("delete from yt_t_device where device_code = '%1';").arg(device_code);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"4\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"\",\"flag\": -1},").arg(boxDeviceShm->device[i].device_id).arg(device_code));
+                        msg.append(QString("{\"product_id\": \"4\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"\",\"flag\": -1},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code));
                     }
 
                 }

+ 0 - 46
agGeneratorProcess/generatorcore.cpp

@@ -1,8 +1,6 @@
 #include "generatorcore.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 AGBoxShm *agBoxShm;
-BoxDeviceShm *boxDeviceShm;
 
 void GeneratorCore::shm_init(){
     QSqlQuery qry;
@@ -14,42 +12,6 @@ void GeneratorCore::shm_init(){
         username = qry.value(2).toString();
         password = qry.value(3).toString();
     }
-    qry.clear();
-    int nrow = 0;
-    sql.clear();
-    sql = QString("select device_code,device_id,device_type,company_code,device_gateway from yt_t_device");
-    qry = db.exec(sql);
-    while (qry.next()) {
-        if(nrow > 1023)
-            break;
-        boxDeviceShm->device[nrow].Enabled = 0x01;
-        sprintf(boxDeviceShm->device[nrow].device_code,"%s",qry.value(0).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_id,"%s",qry.value(1).toString().toUtf8().data());
-        boxDeviceShm->device[nrow].device_type = qry.value(2).toInt();
-        sprintf(boxDeviceShm->device[nrow].company_code,"%s",qry.value(3).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_gateway,"%s",qry.value(4).toString().toUtf8().data());
-        nrow++;
-    }
-    for(int i=nrow;i<1024;i++){
-        boxDeviceShm->device[i].Enabled = 0x00;
-    }
-    nrow = 0;
-    qry.clear();
-    sql.clear();
-    sql = QString("select device_type,attribute_name,attribute_code from yt_t_attribute");
-    qry = db.exec(sql);
-    while (qry.next()) {
-        if(nrow > 299)
-            break;
-        boxDeviceShm->procuctattrbute[nrow].Enabled = 0x01;
-        boxDeviceShm->procuctattrbute[nrow].device_type = qry.value(0).toInt();
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_name,"%s",qry.value(1).toString().toUtf8().data());
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_code,"%s",qry.value(2).toString().toUtf8().data());
-        nrow++;
-    }
-    for(int i=nrow;i<300;i++){
-        boxDeviceShm->procuctattrbute[i].Enabled = 0x00;
-    }
 
 }
 
@@ -64,14 +26,6 @@ bool GeneratorCore::shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
-    if((key=ftok(VIDEO_PATH,static_cast<int>(VIDEO_PORT)))==-1){
-        return false;
-    }
-    if((shmid=shmget(key,sizeof(BoxDeviceShm),IPC_CREAT|0666))==-1){
-        return false;
-    }
-    boxDeviceShm = static_cast<BoxDeviceShm *>(shmat(shmid,nullptr,0));
-
     shm_init();
     return true;
 }

+ 13 - 14
agGeneratorProcess/httpthread.cpp

@@ -1,5 +1,4 @@
 #include "httpthread.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 #include "../AGBoxDog/boxshm.h"
 
 HttpThread::HttpThread(QObject *parent) : QObject(parent)
@@ -55,11 +54,11 @@ void  HttpThread::finishedSlot(QNetworkReply *reply)
                 QString device_code = QString::number(list_object0.value("node_id").toInt());
                 printf("attribute data device_code %s\n",device_code.toUtf8().data());
                 for(int i=0;i<1024;i++){
-                    if(boxDeviceShm->device[i].Enabled == 0x01){
-                        if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
-                            deviceId = QString(boxDeviceShm->device[i].device_id);
-                            companyCode = QString(boxDeviceShm->device[i].company_code);
-                            deviceType = QString::number(boxDeviceShm->device[i].device_type);
+                    if(agBoxShm->device[i].Enabled == 0x01){
+                        if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
+                            deviceId = QString(agBoxShm->device[i].device_id);
+                            companyCode = QString(agBoxShm->device[i].product_code);
+                            deviceType = QString::number(agBoxShm->device[i].device_type);
                             break;
                         }
                     }
@@ -71,8 +70,8 @@ void  HttpThread::finishedSlot(QNetworkReply *reply)
                     double value = list_object.value("sdata").toDouble();
 
                     for(int j=0;j<300;j++){
-                        if(name.compare(QString(boxDeviceShm->procuctattrbute[j].attribute_name))==0){
-                            nodeInfo.append(QString("\"%1\":%2,").arg(QString(boxDeviceShm->procuctattrbute[j].attribute_code)).arg(value));
+                        if(name.compare(QString(agBoxShm->procuctattrbute[j].attribute_name))==0){
+                            nodeInfo.append(QString("\"%1\":%2,").arg(QString(agBoxShm->procuctattrbute[j].attribute_code)).arg(value));
                             break;
                         }
                     }
@@ -134,10 +133,10 @@ void  HttpThread::finishedSlot1(QNetworkReply *reply)
                         deviceStatus = 0;
                     }
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"device_status\":%5},\"device_type\":\"%6-gr\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(deviceStatus).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(deviceStatus).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }
@@ -217,10 +216,10 @@ void  HttpThread::finishedSlot2(QNetworkReply *reply)
                     QString alarmTime = list_object.value("atimestr").toString();
                     double alarmValue = list_object.value("sdata").toDouble();
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttAlarm(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"device_id\":\"%5\",\"device_code\":\"%6\",\"device_name\":\"%7\",\"alarm_type\":\"%8\",\"alarm_desc\":\"%9\",\"alarm_time\":\"%10\"},\"metrics\":{\"alarm_value\":%11,\"handling_status\":%12},\"device_type\":\"%13-gr\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(device_name).arg(alarmLevel).arg(alarmDesc).arg(alarmTime).arg(alarmValue).arg(handlingStatus).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(device_name).arg(alarmLevel).arg(alarmDesc).arg(alarmTime).arg(alarmValue).arg(handlingStatus).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }

+ 19 - 12
agGuardProcess/devinfotcpserver.cpp

@@ -1,5 +1,5 @@
 #include "devinfotcpserver.h"
-#include "../agVideoProcess/boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 DevInfoTcpServer::DevInfoTcpServer(QObject *parent) : QObject(parent)
 {
@@ -46,20 +46,20 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                     QString device_name = list_object.value("name").toString();
                     bool found = false;
                     for(int i=0;i<1024;i++){
-                        if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 502)){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 502)){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 found = true;
-                                msg.append(QString("{\"product_id\": \"2\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 0},").arg(boxDeviceShm->device[i].device_id).arg(device_code).arg(device_name));
+                                msg.append(QString("{\"product_id\": \"2\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 0},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code).arg(device_name));
                                 break;
                             }
                         }
                     }
                     if(!found){
                         QString device_id = QCryptographicHash::hash(QString("2%1").arg(device_code).toUtf8(),QCryptographicHash::Md5).toHex();
-                        QString sql = QString("insert into yt_t_device values('%1','%2',502,'10000001',null);").arg(device_code).arg(device_id);
+                        QString sql = QString("insert into yt_t_device values('%1','%2',502,'502_eg',null);").arg(device_code).arg(device_id);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"2\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 1},").arg(device_id).arg(device_code).arg(device_name));
+                        msg.append(QString("{\"product_id\": \"2\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 1},").arg(agBoxShm->device[i].product_code).arg(device_id).arg(device_code).arg(device_name));
                     }
                     devTcpList.append(device_code);
                 }
@@ -67,9 +67,9 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
 
 
             for(int i=0;i<1024;i++){
-                if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 502)){
+                if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 502)){
                     bool found1 = false;
-                    QString device_code = QString(boxDeviceShm->device[i].device_code);
+                    QString device_code = QString(agBoxShm->device[i].device_code);
                     if(devTcpList.size() > 0){
                         for(int j=0;j<devTcpList.size();j++){
                             if(device_code.compare(devTcpList.at(j))==0){
@@ -83,7 +83,7 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                         QString sql = QString("delete from yt_t_device where device_code = '%1';").arg(device_code);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"2\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"\",\"flag\": -1},").arg(boxDeviceShm->device[i].device_id).arg(device_code));
+                        msg.append(QString("{\"product_id\": \"2\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"\",\"flag\": -1},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code));
                     }
 
                 }
@@ -108,6 +108,13 @@ void DevInfoTcpServer::new_incomming()
 
 }
 
+void DevInfoTcpServer::app_info(QString url,QString key,QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void DevInfoTcpServer::read_data()
 {
     QString str = QString::fromUtf8(so->readAll());
@@ -137,13 +144,13 @@ void DevInfoTcpServer::read_data()
         if(regions.length() > 1){
             regions = regions.left(regions.length()-1);
             QNetworkRequest *req = new QNetworkRequest();
-            req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/resource/v2/door/search"));
+            req->setUrl(QUrl(url));
             req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
             req->setRawHeader("Accept","*/*");
             req->setRawHeader("Connection","keep-alive");
             req->setRawHeader("Cache-Control"," no-cache");
-            req->setRawHeader("X-Ca-Key","27997984");
-            req->setRawHeader("X-Ca-Signature","jXp3h2tlRF5cuqEtKCajSRhiwWGPFMjdkKaxqBtAMS8=");
+            req->setRawHeader("X-Ca-Key",key);
+            req->setRawHeader("X-Ca-Signature",signature);
             req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
             config = req->sslConfiguration();
             config.setPeerVerifyMode(QSslSocket::VerifyNone);

+ 2 - 0
agGuardProcess/devinfotcpserver.h

@@ -23,6 +23,7 @@ class DevInfoTcpServer : public QObject
 public:
     explicit DevInfoTcpServer(QObject *parent = nullptr);
     void start();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void tcp_log(QString log);
@@ -39,6 +40,7 @@ private:
 
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
+    QString url, key, signature;
 
 };
 

+ 29 - 36
agGuardProcess/guardcore.cpp

@@ -1,8 +1,6 @@
 #include "guardcore.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 AGBoxShm *agBoxShm;
-BoxDeviceShm *boxDeviceShm;
 
 void GuardCore::shm_init(){
     QSqlQuery qry;
@@ -14,41 +12,41 @@ void GuardCore::shm_init(){
         username = qry.value(2).toString();
         password = qry.value(3).toString();
     }
-    qry.clear();
-    int nrow = 0;
     sql.clear();
-    sql = QString("select device_code,device_id,device_type,company_code,device_gateway from yt_t_device");
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'door-search-hk'");
     qry = db.exec(sql);
     while (qry.next()) {
-        if(nrow > 1023)
-            break;
-        boxDeviceShm->device[nrow].Enabled = 0x01;
-        sprintf(boxDeviceShm->device[nrow].device_code,"%s",qry.value(0).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_id,"%s",qry.value(1).toString().toUtf8().data());
-        boxDeviceShm->device[nrow].device_type = qry.value(2).toInt();
-        sprintf(boxDeviceShm->device[nrow].company_code,"%s",qry.value(3).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_gateway,"%s",qry.value(4).toString().toUtf8().data());
-        nrow++;
-    }
-    for(int i=nrow;i<1024;i++){
-        boxDeviceShm->device[i].Enabled = 0x00;
+        devinfourl = qry.value(0).toString();
+        devinfokey = qry.value(1).toString();
+        devinfosignature = qry.value(2).toString();
     }
-    nrow = 0;
+    sql.clear();
     qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'door-event-hk'");
+    qry = db.exec(sql);
+    while (qry.next()) {
+       httpurl = qry.value(0).toString();
+       httpkey = qry.value(1).toString();
+       httpsignature = qry.value(2).toString();
+    }
     sql.clear();
-    sql = QString("select device_type,attribute_name,attribute_code from yt_t_attribute");
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'door-state-hk'");
     qry = db.exec(sql);
     while (qry.next()) {
-        if(nrow > 299)
-            break;
-        boxDeviceShm->procuctattrbute[nrow].Enabled = 0x01;
-        boxDeviceShm->procuctattrbute[nrow].device_type = qry.value(0).toInt();
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_name,"%s",qry.value(1).toString().toUtf8().data());
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_code,"%s",qry.value(2).toString().toUtf8().data());
-        nrow++;
+        httpurl1 = qry.value(0).toString();
+        httpkey1 = qry.value(1).toString();
+        httpsignature1 = qry.value(2).toString();
     }
-    for(int i=nrow;i<300;i++){
-        boxDeviceShm->procuctattrbute[i].Enabled = 0x00;
+    sql.clear();
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'door-control-hk'");
+    qry = db.exec(sql);
+    while (qry.next()) {
+       tcpserverurl = qry.value(0).toString();
+       tcpserverkey = qry.value(1).toString();
+       tcpserversignature = qry.value(2).toString();
     }
 
 }
@@ -64,14 +62,6 @@ bool GuardCore::shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
-    if((key=ftok(VIDEO_PATH,static_cast<int>(VIDEO_PORT)))==-1){
-        return false;
-    }
-    if((shmid=shmget(key,sizeof(BoxDeviceShm),IPC_CREAT|0666))==-1){
-        return false;
-    }
-    boxDeviceShm = static_cast<BoxDeviceShm *>(shmat(shmid,nullptr,0));
-
     shm_init();
     return true;
 }
@@ -106,13 +96,16 @@ GuardCore::GuardCore(QObject *parent) : QObject(parent)
     connect(httpthread,&HttpThread::dataLog,this,&GuardCore::dataLog);
     connect(httpthread,&HttpThread::mqttData,this,&GuardCore::mqtt_data);
     connect(httpthread,&HttpThread::mqttEvent,this,&GuardCore::mqtt_event);
+    httpthread->app_info(httpurl,httpkey,httpsignature,httpurl1,httpkey1,httpsignature);
 
     tcpserver = new TcpServer(this);
     connect(tcpserver,&TcpServer::tcp_log,this,&GuardCore::dataLog);
+    tcpserver->app_info(tcpserverurl,tcpserverkey,tcpserversignature);
 
     devinfoserver = new DevInfoTcpServer(this);
     connect(devinfoserver,&DevInfoTcpServer::tcp_log,this,&GuardCore::dataLog);
     connect(devinfoserver,&DevInfoTcpServer::append_sql,this,&GuardCore::appendSql);
+    devinfoserver->app_info(devinfourl,devinfokey,devinfosignature);
 
 }
 

+ 4 - 0
agGuardProcess/guardcore.h

@@ -41,6 +41,10 @@ private:
     QSqlDatabase db;
     quint16 mqttIdx,mqttEventIdx;
     QString ip,port,username,password;
+    QString devinfourl,devinfokey,devinfosignature;
+    QString httpurl,httpkey,httpsignature;
+    QString httpurl1,httpkey1,httpsignature1;
+    QString tcpserverurl,tcpserverkey,tcpserversignature;
 };
 
 #endif // GUARDCORE_H

+ 22 - 13
agGuardProcess/httpthread.cpp

@@ -1,5 +1,4 @@
 #include "httpthread.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 #include "../AGBoxDog/boxshm.h"
 
 HttpThread::HttpThread(QObject *parent) : QObject(parent)
@@ -55,10 +54,10 @@ void  HttpThread::finishedSlot(QNetworkReply *reply)
                     QString eventTime = date.toLocalTime().toString("yyyy-MM-dd HH:mm:ss");
                     //printf("222  list_object.value(eventTime).toString() %s, eventTime %s \n",list_object.value("eventTime").toString().toUtf8().data(),eventTime.toUtf8().data());
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttEvent(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"device_id\":\"%5\",\"device_code\":\"%6\",\"device_name\":\"%7\",\"install_address\":\"\",\"person_name\":\"%8\",\"card_no\":\"%9\",\"org_name\":\"%10\",\"event_time\":\"%11\"},\"metrics\":{\"event_type\": %12,\"in_out_type\": %13},\"device_type\":\"%14-eg\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(doorName).arg(personName).arg(cardNo).arg(orgName).arg(eventTime).arg(eventType).arg(inAndOutType).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(doorName).arg(personName).arg(cardNo).arg(orgName).arg(eventTime).arg(eventType).arg(inAndOutType).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }
@@ -117,10 +116,10 @@ void  HttpThread::finishedSlot1(QNetworkReply *reply)
                         deviceStatus = 1;
                     }
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"device_status\":%5,\"door_status\":%6},\"device_type\":\"%7-eg\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(deviceStatus).arg(doorState).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(deviceStatus).arg(doorState).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }
@@ -151,6 +150,16 @@ void HttpThread::reply_timeout1()
     isWaiting1 = false;
 }
 
+void HttpThread::app_info(QString url,QString key,QString signature,QString url1,QString key1,QString signature1)
+{
+    url = url;
+    key = key;
+    signature = signature;
+    url1 = url1;
+    key1 = key1;
+    signature1 = signature1;
+}
+
 void HttpThread::time_out()
 {
     agBoxShm->processStatus[2].t_time=QDateTime::currentDateTime().toTime_t();
@@ -167,13 +176,13 @@ void HttpThread::time_out()
         if(!isWaiting){
             isWaiting = true;
             QNetworkRequest *req = new QNetworkRequest();
-            req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/acs/v1/door/events"));
+            req->setUrl(QUrl(url));
             req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
             req->setRawHeader("Accept","*/*");
             req->setRawHeader("Connection","keep-alive");
             req->setRawHeader("Cache-Control"," no-cache");
-            req->setRawHeader("X-Ca-Key","27997984");
-            req->setRawHeader("X-Ca-Signature","zocGT3eKtbbUyljDBPf4yoQPoFdN97+Mg4fCc9Ki4jE=");
+            req->setRawHeader("X-Ca-Key",key);
+            req->setRawHeader("X-Ca-Signature",signature);
             req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
             config = req->sslConfiguration();
             config.setPeerVerifyMode(QSslSocket::VerifyNone);
@@ -194,13 +203,13 @@ void HttpThread::time_out()
       if(!isWaiting1 && ((minute1==00)||(minute1==30))){
           isWaiting1 = true;
           QNetworkRequest *req = new QNetworkRequest();
-          req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/acs/v1/door/states"));
+          req->setUrl(QUrl(url1));
           req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
           req->setRawHeader("Accept","*/*");
           req->setRawHeader("Connection","keep-alive");
           req->setRawHeader("Cache-Control"," no-cache");
-          req->setRawHeader("X-Ca-Key","27997984");
-          req->setRawHeader("X-Ca-Signature","FZRWBzzvzp8mDxFSpLHGdtNaot1PfNvpMbCaoT+dDLw=");
+          req->setRawHeader("X-Ca-Key",key1);
+          req->setRawHeader("X-Ca-Signature",signature1);
           req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
           config = req->sslConfiguration();
           config.setPeerVerifyMode(QSslSocket::VerifyNone);

+ 2 - 1
agGuardProcess/httpthread.h

@@ -22,6 +22,7 @@ public:
     explicit HttpThread(QObject *parent = nullptr);
     void run();
     void stop();
+    void app_info(QString url,QString key,QString signature,QString url1,QString key1,QString signature1);
 
 signals:
     void dataLog(QString log);
@@ -45,7 +46,7 @@ private:
     QNetworkAccessManager *networkManager,*networkManager1;
     QSslConfiguration config;
     QTimer *timer;
-
+    QString url, key, signature, url1, key1, signature1;
 
 };
 

+ 14 - 7
agGuardProcess/tcpserver.cpp

@@ -1,5 +1,5 @@
 #include "tcpserver.h"
-#include "../agVideoProcess/boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 TcpServer::TcpServer(QObject *parent) : QObject(parent)
 {
@@ -45,6 +45,13 @@ void TcpServer::finishedSlot(QNetworkReply *reply)
     reply->deleteLater();
 }
 
+void TcpServer::app_info(QString url, QString key, QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void TcpServer::read_data()
 {
     QString str = QString::fromUtf8(so->readAll());
@@ -66,23 +73,23 @@ void TcpServer::read_data()
         QString deviceId = param_obj.value("device_id").toString();
         int controlType = param_obj.value("controlType").toInt();
         for(int i=0;i<1024;i++){
-            if(boxDeviceShm->device[i].Enabled == 0x01){
-                if(deviceId.compare(QString(boxDeviceShm->device[i].device_id))==0){
+            if(agBoxShm->device[i].Enabled == 0x01){
+                if(deviceId.compare(QString(agBoxShm->device[i].device_id))==0){
                     QNetworkRequest *req = new QNetworkRequest();
-                    req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/acs/v1/door/doControl"));
+                    req->setUrl(QUrl(url));
                     req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
                     req->setRawHeader("Accept","*/*");
                     req->setRawHeader("Connection","keep-alive");
                     req->setRawHeader("Cache-Control"," no-cache");
-                    req->setRawHeader("X-Ca-Key","27997984");
-                    req->setRawHeader("X-Ca-Signature","azbiDyuW3AhipLvGYQQnU015ah2EVVofkBX19GRaZ1g=");
+                    req->setRawHeader("X-Ca-Key",key);
+                    req->setRawHeader("X-Ca-Signature",signature);
                     req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
                     config = req->sslConfiguration();
                     config.setPeerVerifyMode(QSslSocket::VerifyNone);
                     config.setProtocol(QSsl::TlsV1_0OrLater);
                     req->setSslConfiguration(config);
                     QString postdata = QString("{\"doorIndexCodes\": [\"%1\"],\"controlType\": %2}")
-                            .arg(boxDeviceShm->device[i].device_code).arg(controlType);
+                            .arg(agBoxShm->device[i].device_code).arg(controlType);
                     req->setRawHeader("Content_Length",QString("%1").arg(postdata.length()).toUtf8());
                     networkManager->post(*req,postdata.toUtf8());
                     break;

+ 2 - 1
agGuardProcess/tcpserver.h

@@ -21,6 +21,7 @@ class TcpServer : public QObject
 public:
     explicit TcpServer(QObject *parent = nullptr);
     void start();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void tcp_log(QString log);
@@ -36,7 +37,7 @@ private:
 
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
-
+    QString url, key, signature;
 };
 
 #endif // TCPSERVER_H

+ 14 - 15
agLightingProcess/clientthread.cpp

@@ -1,6 +1,5 @@
 #include "clientthread.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 
 ClientThread::ClientThread(QObject *parent) : QThread(parent)
 {
@@ -18,7 +17,7 @@ void ClientThread::stop()
 void ClientThread::deviceStatus()
 {
     for(int i=0;i<1024;i++){
-        if((boxDeviceShm->device[i].Enabled == 0x01)&&(boxDeviceShm->device[i].device_type == 510)){
+        if((agBoxShm->device[i].Enabled == 0x01)&&(agBoxShm->device[i].device_type == 510)){
             int cur=0;
             unsigned char data[256];
             data[cur++] = 0x00;
@@ -30,9 +29,9 @@ void ClientThread::deviceStatus()
             data[cur++] = 0x01;
             data[cur++] = 0x03;
 
-            QByteArray deviceCode = QByteArray::fromHex(QString(boxDeviceShm->device[i].device_code).toLatin1());
-            emit dataListLog(QString("deviceCode %1").arg(boxDeviceShm->device[i].device_code));
-            printf("deviceCode %s\n",boxDeviceShm->device[i].device_code);
+            QByteArray deviceCode = QByteArray::fromHex(QString(agBoxShm->device[i].device_code).toLatin1());
+            emit dataListLog(QString("deviceCode %1").arg(agBoxShm->device[i].device_code));
+            printf("deviceCode %s\n",agBoxShm->device[i].device_code);
             data[cur++] = deviceCode.at(0)&0xff;
             data[cur++] = deviceCode.at(1)&0xff;
             data[cur++] = 0x00;
@@ -64,10 +63,10 @@ void ClientThread::controlData(QString deviceId,int switchStatus)
     data[cur++] = 0x10;
 
     for(int i=0;i<1024;i++){
-        if(deviceId.compare(boxDeviceShm->device[i].device_id)==0){
-            QByteArray deviceCode = QByteArray::fromHex(QString(boxDeviceShm->device[i].device_code).toLatin1());
-            emit dataListLog(QString("deviceCode %1").arg(boxDeviceShm->device[i].device_code));
-            printf("deviceCode %s\n",boxDeviceShm->device[i].device_code);
+        if(deviceId.compare(agBoxShm->device[i].device_id)==0){
+            QByteArray deviceCode = QByteArray::fromHex(QString(agBoxShm->device[i].device_code).toLatin1());
+            emit dataListLog(QString("deviceCode %1").arg(agBoxShm->device[i].device_code));
+            printf("deviceCode %s\n",agBoxShm->device[i].device_code);
             data[cur++] = deviceCode.at(0)&0xff;
             data[cur++] = deviceCode.at(1)&0xff;
             break;
@@ -108,20 +107,20 @@ void ClientThread::readData(QTcpSocket *so,QString devCode)
 
     if((Rtn.at(7)&0xff) == 0x03){
         for(int i=0;i<1024;i++){
-            if(devCode.compare(boxDeviceShm->device[i].device_code)==0){
+            if(devCode.compare(agBoxShm->device[i].device_code)==0){
                 int switchStatus = ((Rtn.at(9)&0x00ff)<<8)|(Rtn.at(10)&0x00ff);
-                boxDeviceShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
+                agBoxShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
                 emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"switch_status\":%5,\"device_status\":1},\"device_type\":\"%6-lg\"}")
-                              .arg(boxDeviceShm->device[i].device_id).arg(boxDeviceShm->device[i].device_code).arg(boxDeviceShm->device[i].company_code).arg(QDateTime::currentDateTime().toTime_t()).arg(switchStatus).arg(boxDeviceShm->device[i].device_type));
+                              .arg(agBoxShm->device[i].device_id).arg(agBoxShm->device[i].device_code).arg(agBoxShm->device[i].product_code).arg(QDateTime::currentDateTime().toTime_t()).arg(switchStatus).arg(agBoxShm->device[i].device_type));
                 break;
             }
         }
     }else if((Rtn.at(7)&0xff) == 0x10){
         for(int i=0;i<1024;i++){
-            if(devCode.compare(boxDeviceShm->device[i].device_code)==0){
-                boxDeviceShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
+            if(devCode.compare(agBoxShm->device[i].device_code)==0){
+                agBoxShm->device[i].lastTime = QDateTime::currentDateTime().toTime_t();
                 emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"switch_status\":%5,\"device_status\":1},\"device_type\":\"%6-lg\"}")
-                              .arg(boxDeviceShm->device[i].device_id).arg(boxDeviceShm->device[i].device_code).arg(boxDeviceShm->device[i].company_code).arg(QDateTime::currentDateTime().toTime_t()).arg(switch_status).arg(boxDeviceShm->device[i].device_type));
+                              .arg(agBoxShm->device[i].device_id).arg(agBoxShm->device[i].device_code).arg(agBoxShm->device[i].product_code).arg(QDateTime::currentDateTime().toTime_t()).arg(switch_status).arg(agBoxShm->device[i].device_type));
                 emit responseMsg(QString("{\"code\":\"0\",\"msg\":\"success\",\"data\":\"\"}"));
                 break;
             }

+ 4 - 14
agLightingProcess/lightingcore.cpp

@@ -1,8 +1,6 @@
 #include "lightingcore.h"
 #include "../AGBoxDog/boxshm.h"
-#include "../agVideoProcess/boxdeviceshm.h"
 AGBoxShm *agBoxShm;
-BoxDeviceShm *boxDeviceShm;
 
 void LightingCore::shm_init(){
     QSqlQuery qry;
@@ -30,14 +28,6 @@ bool LightingCore::shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
-    if((key=ftok(VIDEO_PATH,static_cast<int>(VIDEO_PORT)))==-1){
-        return false;
-    }
-    if((shmid=shmget(key,sizeof(BoxDeviceShm),IPC_CREAT|0666))==-1){
-        return false;
-    }
-    boxDeviceShm = static_cast<BoxDeviceShm *>(shmat(shmid,nullptr,0));
-
     shm_init();
     return true;
 }
@@ -106,12 +96,12 @@ void LightingCore::time_out()
 
     clientthread->deviceStatus();
     for(int i=0;i<1024;i++){
-        if((boxDeviceShm->device[i].Enabled == 0x01)&&(boxDeviceShm->device[i].device_type == 510)){
+        if((agBoxShm->device[i].Enabled == 0x01)&&(agBoxShm->device[i].device_type == 510)){
             uint curTime = QDateTime::currentDateTime().toTime_t();
-            if((curTime - boxDeviceShm->device[i].lastTime)>120){
-                boxDeviceShm->device[i].lastTime = curTime;
+            if((curTime - agBoxShm->device[i].lastTime)>120){
+                agBoxShm->device[i].lastTime = curTime;
                 this->mqtt_data(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"device_status\":0},\"device_type\":\"%5-lg\"}")
-                              .arg(boxDeviceShm->device[i].device_id).arg(boxDeviceShm->device[i].device_code).arg(boxDeviceShm->device[i].company_code).arg(curTime).arg(boxDeviceShm->device[i].device_type));
+                              .arg(agBoxShm->device[i].device_id).arg(agBoxShm->device[i].device_code).arg(agBoxShm->device[i].product_code).arg(curTime).arg(agBoxShm->device[i].device_type));
             }
         }
     }

+ 0 - 2
agVideoProcess/agVideoProcess.pro

@@ -24,8 +24,6 @@ INCLUDEPATH += ../qmqtt-master/src/mqtt/
 HEADERS += \
     httpthread.h \
     ../QReplyTimeout.h \
-    agboxdeviceshm.h \
-    boxdeviceshm.h \
     logthread.h \
     videocore.h \
     tcpserver.h \

+ 19 - 12
agVideoProcess/devinfotcpserver.cpp

@@ -1,5 +1,5 @@
 #include "devinfotcpserver.h"
-#include "boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 DevInfoTcpServer::DevInfoTcpServer(QObject *parent) : QObject(parent)
 {
@@ -46,20 +46,20 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                     QString device_name = list_object.value("name").toString();
                     bool found = false;
                     for(int i=0;i<1024;i++){
-                        if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 501)){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 501)){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 found = true;
-                                msg.append(QString("{\"product_id\": \"1\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 0},").arg(boxDeviceShm->device[i].device_id).arg(device_code).arg(device_name));
+                                msg.append(QString("{\"product_id\": \"1\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 0},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code).arg(device_name));
                                 break;
                             }
                         }
                     }
                     if(!found){
                         QString device_id = QCryptographicHash::hash(QString("1%1").arg(device_code).toUtf8(),QCryptographicHash::Md5).toHex();
-                        QString sql = QString("insert into yt_t_device values('%1','%2',501,'10000001',null);").arg(device_code).arg(device_id);
+                        QString sql = QString("insert into yt_t_device values('%1','%2',501,'501_vd',null);").arg(device_code).arg(device_id);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"1\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"%3\",\"flag\": 1},").arg(device_id).arg(device_code).arg(device_name));
+                        msg.append(QString("{\"product_id\": \"1\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"%4\",\"flag\": 1},").arg(agBoxShm->device[i].product_code).arg(device_id).arg(device_code).arg(device_name));
                     }
                     devTcpList.append(device_code);
                 }
@@ -67,9 +67,9 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
 
 
             for(int i=0;i<1024;i++){
-                if((boxDeviceShm->device[i].Enabled == 0x01) && (boxDeviceShm->device[i].device_type == 501)){
+                if((agBoxShm->device[i].Enabled == 0x01) && (agBoxShm->device[i].device_type == 501)){
                     bool found1 = false;
-                    QString device_code = QString(boxDeviceShm->device[i].device_code);
+                    QString device_code = QString(agBoxShm->device[i].device_code);
                     if(devTcpList.size() > 0){
                         for(int j=0;j<devTcpList.size();j++){
                             if(device_code.compare(devTcpList.at(j))==0){
@@ -83,7 +83,7 @@ void DevInfoTcpServer::finishedSlot(QNetworkReply *reply)
                         QString sql = QString("delete from yt_t_device where device_code = '%1';").arg(device_code);
                         emit append_sql(sql);
 
-                        msg.append(QString("{\"product_id\": \"1\",\"company_code\": \"10000001\",\"device_id\": \"%1\",\"device_code\": \"%2\",\"device_name\": \"\",\"flag\": -1},").arg(boxDeviceShm->device[i].device_id).arg(device_code));
+                        msg.append(QString("{\"product_id\": \"1\",\"product_code\": \"%1\",\"device_id\": \"%2\",\"device_code\": \"%3\",\"device_name\": \"\",\"flag\": -1},").arg(agBoxShm->device[i].product_code).arg(agBoxShm->device[i].device_id).arg(device_code));
                     }
 
                 }
@@ -108,6 +108,13 @@ void DevInfoTcpServer::new_incomming()
 
 }
 
+void DevInfoTcpServer::app_info(QString url,QString key,QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void DevInfoTcpServer::read_data()
 {
     QString str = QString::fromUtf8(so->readAll());
@@ -137,13 +144,13 @@ void DevInfoTcpServer::read_data()
         if(regions.length() > 1){
             regions = regions.left(regions.length()-1);
             QNetworkRequest *req = new QNetworkRequest();
-            req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/resource/v2/camera/search"));
+            req->setUrl(QUrl(url));
             req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
             req->setRawHeader("Accept","*/*");
             req->setRawHeader("Connection","keep-alive");
             req->setRawHeader("Cache-Control"," no-cache");
-            req->setRawHeader("X-Ca-Key","27997984");
-            req->setRawHeader("X-Ca-Signature","/f3F+ekIwc5hFwP2edSOdAU2zVoowOogCMSRPNxKmKE=");
+            req->setRawHeader("X-Ca-Key",key);
+            req->setRawHeader("X-Ca-Signature",signature);
             req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
             config = req->sslConfiguration();
             config.setPeerVerifyMode(QSslSocket::VerifyNone);

+ 2 - 0
agVideoProcess/devinfotcpserver.h

@@ -23,6 +23,7 @@ class DevInfoTcpServer : public QObject
 public:
     explicit DevInfoTcpServer(QObject *parent = nullptr);
     void start();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void tcp_log(QString log);
@@ -39,6 +40,7 @@ private:
 
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
+    QString url, key, signature;
 
 };
 

+ 13 - 7
agVideoProcess/httpthread.cpp

@@ -1,5 +1,4 @@
 #include "httpthread.h"
-#include "boxdeviceshm.h"
 #include "../AGBoxDog/boxshm.h"
 
 HttpThread::HttpThread(QObject *parent) : QObject(parent)
@@ -44,10 +43,10 @@ void  HttpThread::finishedSlot(QNetworkReply *reply)
                     QString device_code = list_object.value("indexCode").toString();
                     int device_status = list_object.value("online").toInt();
                     for(int i=0;i<1024;i++){
-                        if(boxDeviceShm->device[i].Enabled == 0x01){
-                            if(device_code.compare(QString(boxDeviceShm->device[i].device_code))==0){
+                        if(agBoxShm->device[i].Enabled == 0x01){
+                            if(device_code.compare(QString(agBoxShm->device[i].device_code))==0){
                                 emit mqttData(QString("{\"device_id\":\"%1\",\"device_code\":\"%2\",\"product_id\":\"%3\",\"timestamp\":%4,\"tags\":{\"conn_type\":\"\",\"type\":\"\"},\"metrics\":{\"device_status\":%5},\"device_type\":\"%6-vd\"}")
-                                              .arg(QString(boxDeviceShm->device[i].device_id)).arg(device_code).arg(QString(boxDeviceShm->device[i].company_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(device_status).arg(boxDeviceShm->device[i].device_type));
+                                              .arg(QString(agBoxShm->device[i].device_id)).arg(device_code).arg(QString(agBoxShm->device[i].product_code)).arg(QDateTime::currentDateTime().toTime_t()).arg(device_status).arg(agBoxShm->device[i].device_type));
                                 break;
                             }
                         }
@@ -78,6 +77,13 @@ void HttpThread::reply_timeout()
     isWaiting = false;
 }
 
+void HttpThread::app_info(QString url,QString key,QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void HttpThread::time_out()
 {
     agBoxShm->processStatus[1].t_time=QDateTime::currentDateTime().toTime_t();
@@ -88,13 +94,13 @@ void HttpThread::time_out()
         if(!isWaiting && ((minute==00)||(minute==30))){
             isWaiting = true;
             QNetworkRequest *req = new QNetworkRequest();
-            req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/nms/v1/online/camera/get"));
+            req->setUrl(QUrl(url));
             req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
             req->setRawHeader("Accept","*/*");
             req->setRawHeader("Connection","keep-alive");
             req->setRawHeader("Cache-Control"," no-cache");
-            req->setRawHeader("X-Ca-Key","27997984");
-            req->setRawHeader("X-Ca-Signature","a9kzGHD938rFhCfWVlGB6eO0bZ0SQbhzSwXlT+FMh+Q=");
+            req->setRawHeader("X-Ca-Key",key);
+            req->setRawHeader("X-Ca-Signature",signature);
             req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
             config = req->sslConfiguration();
             config.setPeerVerifyMode(QSslSocket::VerifyNone);

+ 2 - 0
agVideoProcess/httpthread.h

@@ -22,6 +22,7 @@ public:
     explicit HttpThread(QObject *parent = nullptr);
     void run();
     void stop();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void dataLog(QString log);
@@ -39,6 +40,7 @@ private:
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
     QTimer *timer;
+    QString url, key, signature;
 
 
 };

+ 14 - 7
agVideoProcess/tcpserver.cpp

@@ -1,5 +1,5 @@
 #include "tcpserver.h"
-#include "boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 TcpServer::TcpServer(QObject *parent) : QObject(parent)
 {
@@ -39,6 +39,13 @@ void TcpServer::new_incomming()
     connect(so,SIGNAL(readyRead()),this,SLOT(read_data()));
 }
 
+void TcpServer::app_info(QString url,QString key,QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void TcpServer::read_data()
 {
     QString str = QString::fromUtf8(so->readAll());
@@ -62,23 +69,23 @@ void TcpServer::read_data()
         QString protocol = param_obj.value("protocol").toString();
         int transMode = param_obj.value("transmode").toInt();
         for(int i=0;i<1024;i++){
-            if(boxDeviceShm->device[i].Enabled == 0x01){
-                if(deviceId.compare(QString(boxDeviceShm->device[i].device_id))==0){
+            if(agBoxShm->device[i].Enabled == 0x01){
+                if(deviceId.compare(QString(agBoxShm->device[i].device_id))==0){
                     QNetworkRequest *req = new QNetworkRequest();
-                    req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/video/v1/cameras/previewURLs"));
+                    req->setUrl(QUrl(url));
                     req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
                     req->setRawHeader("Accept","*/*");
                     req->setRawHeader("Connection","keep-alive");
                     req->setRawHeader("Cache-Control"," no-cache");
-                    req->setRawHeader("X-Ca-Key","27997984");
-                    req->setRawHeader("X-Ca-Signature","DGavOjaJIV81XPQUMz7F3UwpSWMYy+s9jYOzHKkbk6o=");
+                    req->setRawHeader("X-Ca-Key",key);
+                    req->setRawHeader("X-Ca-Signature",signature);
                     req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
                     config = req->sslConfiguration();
                     config.setPeerVerifyMode(QSslSocket::VerifyNone);
                     config.setProtocol(QSsl::TlsV1_0OrLater);
                     req->setSslConfiguration(config);
                     QString postdata = QString("{\"cameraIndexCode\": \"%1\",\"streamType\": %2,\"protocol\":\"%3\",\"transmode\":%4}")
-                            .arg(boxDeviceShm->device[i].device_code).arg(streamType).arg(protocol).arg(transMode);
+                            .arg(agBoxShm->device[i].device_code).arg(streamType).arg(protocol).arg(transMode);
                     req->setRawHeader("Content_Length",QString("%1").arg(postdata.length()).toUtf8());
                     networkManager->post(*req,postdata.toUtf8());
                     break;

+ 2 - 0
agVideoProcess/tcpserver.h

@@ -22,6 +22,7 @@ class TcpServer : public QObject
 public:
     explicit TcpServer(QObject *parent = nullptr);
     void start();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void tcp_log(QString log);
@@ -37,6 +38,7 @@ private:
 
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
+    QString url, key, signature;
 };
 
 #endif // TCPSERVER_H

+ 14 - 7
agVideoProcess/tcpserver1.cpp

@@ -1,5 +1,5 @@
 #include "tcpserver1.h"
-#include "boxdeviceshm.h"
+#include "../AGBoxDog/boxshm.h"
 
 TcpServer1::TcpServer1(QObject *parent) : QObject(parent)
 {
@@ -40,6 +40,13 @@ void TcpServer1::new_incomming()
     connect(so,SIGNAL(readyRead()),this,SLOT(read_data()));
 }
 
+void TcpServer1::app_info(QString url,QString key,QString signature)
+{
+    url = url;
+    key = key;
+    signature = signature;
+}
+
 void TcpServer1::read_data()
 {
     QString str = QString::fromUtf8(so->readAll());
@@ -63,23 +70,23 @@ void TcpServer1::read_data()
         int speed = param_obj.value("speed").toInt();
         int presetIndex = param_obj.value("presetIndex").toInt();
         for(int i=0;i<1024;i++){
-            if(boxDeviceShm->device[i].Enabled == 0x01){
-                if(deviceId.compare(QString(boxDeviceShm->device[i].device_id))==0){
+            if(agBoxShm->device[i].Enabled == 0x01){
+                if(deviceId.compare(QString(agBoxShm->device[i].device_id))==0){
                     QNetworkRequest *req = new QNetworkRequest();
-                    req->setUrl(QUrl("https://172.17.200.250:443/artemis/api/video/v1/ptzs/controlling"));
+                    req->setUrl(QUrl(url));
                     req->setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
                     req->setRawHeader("Accept","*/*");
                     req->setRawHeader("Connection","keep-alive");
                     req->setRawHeader("Cache-Control"," no-cache");
-                    req->setRawHeader("X-Ca-Key","27997984");
-                    req->setRawHeader("X-Ca-Signature","C/1aEVkfDZhGXuCH64tGv1vfySvDMTSMkqKd5PXgOM8=");
+                    req->setRawHeader("X-Ca-Key",key);
+                    req->setRawHeader("X-Ca-Signature",signature);
                     req->setRawHeader("X-Ca-Signature-Headers","x-ca-key");
                     config = req->sslConfiguration();
                     config.setPeerVerifyMode(QSslSocket::VerifyNone);
                     config.setProtocol(QSsl::TlsV1_0OrLater);
                     req->setSslConfiguration(config);
                     QString postdata = QString("{\"cameraIndexCode\": \"%1\",\"action\": %2,\"command\":\"%3\",\"speed\":%4,\"presetIndex\":%5}")
-                            .arg(boxDeviceShm->device[i].device_code).arg(action).arg(command).arg(speed).arg(presetIndex);
+                            .arg(agBoxShm->device[i].device_code).arg(action).arg(command).arg(speed).arg(presetIndex);
                     req->setRawHeader("Content_Length",QString("%1").arg(postdata.length()).toUtf8());
                     networkManager->post(*req,postdata.toUtf8());
                     break;

+ 2 - 0
agVideoProcess/tcpserver1.h

@@ -22,6 +22,7 @@ class TcpServer1 : public QObject
 public:
     explicit TcpServer1(QObject *parent = nullptr);
     void start();
+    void app_info(QString url,QString key,QString signature);
 
 signals:
     void tcp_log(QString log);
@@ -37,6 +38,7 @@ private:
 
     QNetworkAccessManager *networkManager;
     QSslConfiguration config;
+    QString url, key, signature;
 
 };
 

+ 30 - 36
agVideoProcess/videocore.cpp

@@ -1,8 +1,6 @@
 #include "videocore.h"
 #include "../AGBoxDog/boxshm.h"
-#include "boxdeviceshm.h"
 AGBoxShm *agBoxShm;
-BoxDeviceShm *boxDeviceShm;
 
 void VideoCore::shm_init(){
     QSqlQuery qry;
@@ -14,41 +12,41 @@ void VideoCore::shm_init(){
         username = qry.value(2).toString();
         password = qry.value(3).toString();
     }
-    qry.clear();
-    int nrow = 0;
     sql.clear();
-    sql = QString("select device_code,device_id,device_type,company_code,device_gateway from yt_t_device");
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'video-search-hk'");
     qry = db.exec(sql);
     while (qry.next()) {
-        if(nrow > 1023)
-            break;
-        boxDeviceShm->device[nrow].Enabled = 0x01;
-        sprintf(boxDeviceShm->device[nrow].device_code,"%s",qry.value(0).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_id,"%s",qry.value(1).toString().toUtf8().data());
-        boxDeviceShm->device[nrow].device_type = qry.value(2).toInt();
-        sprintf(boxDeviceShm->device[nrow].company_code,"%s",qry.value(3).toString().toUtf8().data());
-        sprintf(boxDeviceShm->device[nrow].device_gateway,"%s",qry.value(4).toString().toUtf8().data());
-        nrow++;
-    }
-    for(int i=nrow;i<1024;i++){
-        boxDeviceShm->device[i].Enabled = 0x00;
+        devinfourl = qry.value(0).toString();
+        devinfokey = qry.value(1).toString();
+        devinfosignature = qry.value(2).toString();
     }
-    nrow = 0;
+    sql.clear();
     qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'video-get-hk'");
+    qry = db.exec(sql);
+    while (qry.next()) {
+       httpurl = qry.value(0).toString();
+       httpkey = qry.value(1).toString();
+       httpsignature = qry.value(2).toString();
+    }
     sql.clear();
-    sql = QString("select device_type,attribute_name,attribute_code from yt_t_attribute");
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'video-preview-hk'");
     qry = db.exec(sql);
     while (qry.next()) {
-        if(nrow > 299)
-            break;
-        boxDeviceShm->procuctattrbute[nrow].Enabled = 0x01;
-        boxDeviceShm->procuctattrbute[nrow].device_type = qry.value(0).toInt();
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_name,"%s",qry.value(1).toString().toUtf8().data());
-        sprintf(boxDeviceShm->procuctattrbute[nrow].attribute_code,"%s",qry.value(2).toString().toUtf8().data());
-        nrow++;
+       tcpserverurl = qry.value(0).toString();
+       tcpserverkey = qry.value(1).toString();
+       tcpserversignature = qry.value(2).toString();
     }
-    for(int i=nrow;i<300;i++){
-        boxDeviceShm->procuctattrbute[i].Enabled = 0x00;
+    sql.clear();
+    qry.clear();
+    sql = QString("select url,app_key,app_signature from yt_t_platforminfo where type = 'video-control-hk'");
+    qry = db.exec(sql);
+    while (qry.next()) {
+       tcpserver1url = qry.value(0).toString();
+       tcpserver1key = qry.value(1).toString();
+       tcpserver1signature = qry.value(2).toString();
     }
 }
 
@@ -63,14 +61,6 @@ bool VideoCore::shm_load(){
     }
     agBoxShm = static_cast<AGBoxShm *>(shmat(shmid,nullptr,0));
 
-    if((key=ftok(VIDEO_PATH,static_cast<int>(VIDEO_PORT)))==-1){
-        return false;
-    }
-    if((shmid=shmget(key,sizeof(BoxDeviceShm),IPC_CREAT|0666))==-1){
-        return false;
-    }
-    boxDeviceShm = static_cast<BoxDeviceShm *>(shmat(shmid,nullptr,0));
-
     shm_init();
     return true;
 }
@@ -104,16 +94,20 @@ VideoCore::VideoCore(QObject *parent) : QObject(parent)
     httpthread = new HttpThread(this);
     connect(httpthread,&HttpThread::dataLog,this,&VideoCore::dataLog);
     connect(httpthread,&HttpThread::mqttData,this,&VideoCore::mqtt_data);
+    httpthread->app_info(httpurl,httpkey,httpsignature);
 
     tcpserver = new TcpServer(this);
     connect(tcpserver,&TcpServer::tcp_log,this,&VideoCore::dataLog);
+    tcpserver->app_info(tcpserverurl,tcpserverkey,tcpserversignature);
 
     tcpserver1 = new TcpServer1(this);
     connect(tcpserver1,&TcpServer1::tcp_log,this,&VideoCore::dataLog);
+    tcpserver1->app_info(tcpserver1url,tcpserver1key,tcpserver1signature);
 
     devinfoserver = new DevInfoTcpServer(this);
     connect(devinfoserver,&DevInfoTcpServer::tcp_log,this,&VideoCore::dataLog);
     connect(devinfoserver,&DevInfoTcpServer::append_sql,this,&VideoCore::appendSql);
+    devinfoserver->app_info(devinfourl,devinfokey,devinfosignature);
 
     dbthread = new DatabaseThread(this,&db);
     connect(dbthread,&DatabaseThread::dbdata_log,this,&VideoCore::dataLog);

+ 4 - 0
agVideoProcess/videocore.h

@@ -43,6 +43,10 @@ private:
     QSqlDatabase db;
     quint16 mqttIdx;
     QString ip,port,username,password;
+    QString devinfourl,devinfokey,devinfosignature;
+    QString httpurl,httpkey,httpsignature;
+    QString tcpserverurl,tcpserverkey,tcpserversignature;
+    QString tcpserver1url,tcpserver1key,tcpserver1signature;
 };
 
 #endif // VIDEOCORE_H

+ 2 - 1
data-agbox.pro

@@ -7,4 +7,5 @@ SUBDIRS += \
     agGeneratorProcess \
     agEnvironmentProcess \
     agLightingProcess \
-    AGBoxDog
+    AGBoxDog \
+    agFreshAirProcess