Ver Fonte

加入纠察器

Your Name há 2 anos atrás
pai
commit
ce101ff1b3
41 ficheiros alterados com 852 adições e 148 exclusões
  1. 2 1
      .vscode/settings.json
  2. 46 1
      framework/core/include/UtilBase.hpp
  3. 25 2
      framework/request/include/BasicConfig.h
  4. 90 2
      framework/request/include/CNStreamInferData.h
  5. 2 1
      framework/request/include/ExpelDevice.h
  6. 8 3
      framework/request/include/HttpNull.hpp
  7. 5 1
      framework/request/include/HttpResultMsg.hpp
  8. 6 2
      framework/request/include/HttpToken.hpp
  9. 9 5
      framework/request/include/RecDeviceCommand.h
  10. BIN
      lib/libgsd_core.so
  11. BIN
      lib/libgsd_modules.so
  12. BIN
      lib/libgsd_plugins.so
  13. 1 0
      modules/Expel/include/Crc.h
  14. 98 0
      modules/Expel/include/DeviceGasV2.hpp
  15. 6 0
      modules/Expel/include/DevicePlayerV3.hpp
  16. 10 1
      modules/Expel/include/Expel.hpp
  17. 0 2
      modules/Expel/src/DeviceGasV1.cpp
  18. 124 0
      modules/Expel/src/DeviceGasV2.cpp
  19. 9 0
      modules/Expel/src/DevicePlayerV3.cpp
  20. 4 1
      modules/Expel/src/DevicePlayerV4.cpp
  21. 90 20
      modules/Expel/src/Expel.cpp
  22. 14 2
      modules/HttpClient/include/HttpClient.hpp
  23. 31 2
      modules/HttpClient/src/HttpClient.cpp
  24. 7 1
      modules/HttpServer/src/HttpServer.cpp
  25. 33 3
      modules/InfineFilter/include/InfineFilter.hpp
  26. 39 16
      modules/InfineFilter/src/InfineFilter.cpp
  27. 1 1
      modules/Monitor/include/Monitor.hpp
  28. 2 37
      modules/Monitor/src/Monitor.cpp
  29. 14 4
      modules/config/include/config.hpp
  30. 11 2
      modules/config/src/config.cpp
  31. 6 0
      plugins/ExpelPlugin/include/ExpelPlugin.hpp
  32. 8 1
      plugins/ExpelPlugin/src/ExpelPlugin.cpp
  33. 10 2
      plugins/HttpPlugin/include/HttpPlugin.hpp
  34. 38 22
      plugins/HttpPlugin/src/HttpPlugin.cpp
  35. 1 0
      plugins/MonitorPlugin/include/MonitorPlugin.hpp
  36. 58 3
      plugins/MonitorPlugin/src/MonitorPlugin.cpp
  37. 2 0
      plugins/TcpPlugin/include/TcpPlugin.hpp
  38. 21 1
      plugins/TcpPlugin/src/TcpPlugin.cpp
  39. 9 9
      source/UserApp/src/UserApp.cpp
  40. 2 0
      source/src/main.cpp
  41. 10 0
      tools/Deploy.sh

+ 2 - 1
.vscode/settings.json

@@ -70,6 +70,7 @@
         "csignal": "cpp",
         "codecvt": "cpp",
         "filesystem": "cpp",
-        "any": "cpp"
+        "any": "cpp",
+        "queue": "cpp"
     }
 }

+ 46 - 1
framework/core/include/UtilBase.hpp

@@ -8,6 +8,7 @@
 
 #include "SendDevice.h"
 #include "NonCopyAble.hpp"
+#include "httplib.h"
 
 namespace gsd{
 
@@ -32,10 +33,19 @@ namespace gsd{
             tcp = 2
         };
 
+        enum CommmandCodeGear{
+            _STATUS,
+            _OPEN,
+            _CLOSE,
+            _FIRE
+        };
+
     protected:
         std::string deviceId;
         std::string DeviceInfo = "";
         enum DeviceTools tool = DeviceTools::serial;
+        enum CommmandCodeGear code = CommmandCodeGear::_OPEN;
+        int TypeId;
 
     public:
         ContorlGear(){}
@@ -128,6 +138,23 @@ namespace gsd{
         std::string getDeviceInfo(){
             return DeviceInfo;
         }
+
+        /**
+         * @description: 获取类型
+         * @return {*}
+         */        
+        int getTypeId(){
+            return TypeId;
+        }
+
+        /**
+         * @description: 设置类型
+         * @param {int} typeId
+         * @return {*}
+         */        
+        void setTypeId(int typeId){
+            this->TypeId = typeId;
+        }
     };
 
     /**
@@ -162,7 +189,9 @@ namespace gsd{
         std::string serverIP;
         int port;
         std::string serverCname;
-        std::string serverCpwd;
+        std::string serverCpwd; 
+        int commandCode = 0;
+
     public:
         ContorlHttplBase(){}
         ~ContorlHttplBase(){}
@@ -178,6 +207,20 @@ namespace gsd{
         void setServerCpwd(std::string _serverCpwd){
             serverCpwd = _serverCpwd;
         }
+      
+        httplib::Params getParms(){
+            httplib::Params parms;
+            return parms;
+        }
+
+        httplib::Headers getHeaders(){
+            httplib::Headers headers;
+            return headers;
+        }
+         
+        std::string getUrl(){
+            return "";
+        }
     };
 
     /**
@@ -200,6 +243,8 @@ namespace gsd{
         void setPort(int _port){
             this->port = _port;
         }
+
+
     };
 
     /**

+ 25 - 2
framework/request/include/BasicConfig.h

@@ -3,8 +3,8 @@
  * @Version: 1.0
  * @Autor: lishengyin
  * @Date: 2022-03-28 09:03:02
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 16:01:50
+ * @LastEditors: Your Name lishengyin@sz-sunwin.com
+ * @LastEditTime: 2022-09-04 21:29:28
  */
 #ifndef __BASICECONFIG_H_
 #define __BASICECONFIG_H_
@@ -56,6 +56,13 @@ public:
 
     int filterLevel = 2;
 
+    int vpn = 0;
+
+    int InferChecker = 0;
+
+    std::string InferCheckerIP = "192.168.31.219";
+    int InferCheckerPort = 8860;
+
 public:
     BasicConfig(){}
     ~BasicConfig(){}
@@ -188,6 +195,22 @@ public:
             filterLevel = std::atoi(doc["filterLevel"].GetString());
         }
 
+        if(end != doc.FindMember("vpn") && doc["vpn"].IsString()){
+            vpn = std::atoi(doc["vpn"].GetString());
+        }
+        
+        if(end != doc.FindMember("InferChecker") && doc["InferChecker"].IsString()){
+            InferChecker = std::atoi(doc["InferChecker"].GetString());
+        }
+
+        if(end != doc.FindMember("InferCheckerIP") && doc["InferCheckerIP"].IsString()){
+            InferCheckerIP = doc["InferCheckerIP"].GetString();
+        }
+
+        if(end != doc.FindMember("InferCheckerPort") && doc["InferCheckerPort"].IsString()){
+            InferCheckerPort = std::atoi(doc["InferCheckerPort"].GetString());
+        }
+        
         return true;
     }
 };

+ 90 - 2
framework/request/include/CNStreamInferData.h

@@ -53,14 +53,45 @@ public:
         }
         return true;
     }
+
+
+    // std::string Label;
+    // double Score;
+    // InferBoundingBox BBox;
+
+    /**
+     * @description: objectToJson
+     * @return {*}
+     */    
+    void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
+        writer.StartObject();
+        writer.Key("Label");
+        writer.String(Label.c_str());
+
+        writer.Key("Score");
+        writer.Double(Score);
+
+        writer.Key("BBox");
+        writer.StartArray();
+
+        writer.Double(BBox.x);
+        writer.Double(BBox.y);
+        writer.Double(BBox.w);
+        writer.Double(BBox.h);
+
+        writer.EndArray();
+
+        writer.EndObject();
+    }
 };
 
 
 class CNStreamInferData
 {
 public:
+
     using Ptr = std::shared_ptr<CNStreamInferData>;
-    
+
     std::string StreamName;
     int FrameCount;
     int width;
@@ -71,6 +102,7 @@ public:
     std::string ImageBase64;
     std::string videoPath;
 
+
 public:
     CNStreamInferData() {}
     ~CNStreamInferData() {}
@@ -128,7 +160,63 @@ public:
         if (end != doc.FindMember("videoPath") && doc["videoPath"].IsString()) {
             videoPath = doc["videoPath"].GetString();
         } 
-        
+
         return true;
     }
+
+
+    /**
+     * @description: objectToJson
+     * @param {string&} str
+     * @return {*}
+     */    
+    void objectToJson(std::string& str){
+        rapidjson::StringBuffer strBuf;
+        rapidjson::Writer<rapidjson::StringBuffer> writer(strBuf);
+        this->objectToJson(writer);
+        str = strBuf.GetString();
+    }
+
+
+    
+    // std::string StreamName;
+    // int FrameCount;
+    // int width;
+    // int height;
+
+    // vector<InferInfo> Objects;
+    
+    // std::string ImageBase64;
+    // std::string videoPath;
+
+    /**
+     * @description: objectToJson
+     * @return {*}
+     */    
+    void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
+        writer.StartObject();
+        writer.Key("StreamName");
+        writer.String(StreamName.c_str());
+
+        writer.Key("FrameCount");
+        writer.Int(FrameCount);
+
+        writer.Key("width");
+        writer.Int(width);
+
+        writer.Key("height");
+        writer.Int(height);
+
+        writer.Key("Objects");
+        writer.StartArray();
+        for(auto iter = Objects.begin(); iter != Objects.end(); iter++){
+            iter->objectToJson(writer);
+        }
+        writer.EndArray();
+
+        writer.Key("videoPath");
+        writer.String(videoPath.c_str());
+
+        writer.EndObject();
+    }
 };

+ 2 - 1
framework/request/include/ExpelDevice.h

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-02-16 15:25:46
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 17:44:35
+ * @LastEditTime: 2022-09-09 09:38:52
  */
 #ifndef __EXPELDEVICE_H_
 #define __EXPELDEVICE_H_
@@ -29,6 +29,7 @@ enum DeviceType {
     DevicePlayerV2 = 2,
     DevicePlayerV3 = 3,
     DevicePlayerV4 = 4,
+    DeviceGasV2 = 5
 };
 
 class ExpelDevice

+ 8 - 3
framework/request/include/HttpNull.hpp

@@ -3,10 +3,12 @@
  * @Version: 1.0
  * @Autor: lishengyin
  * @Date: 2021-11-09 16:31:01
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 11:22:14
+ * @LastEditors: Your Name lishengyin@sz-sunwin.com
+ * @LastEditTime: 2022-09-04 21:27:03
  */
-#pragma once
+
+#ifndef __HTTPNULL_HPP_
+#define __HTTPNULL_HPP_
 
 #include <iostream>
 using namespace std;
@@ -15,6 +17,7 @@ using namespace std;
 #include <rapidjson/stringbuffer.h>
 #include <rapidjson/writer.h>
 
+
 class HttpNull
 {
 private:
@@ -38,3 +41,5 @@ public:
         writer.EndObject();
     }
 };
+
+#endif

+ 5 - 1
framework/request/include/HttpResultMsg.hpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2021-11-03 15:16:14
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 11:22:25
+ * @LastEditTime: 2022-09-09 14:46:09
  */
 #pragma once
 
@@ -116,6 +116,10 @@ public:
                 }
             }
         }
+
+        if (end != doc.FindMember("attr1") && doc["attr1"].IsString()) {
+            attr1 = doc["attr1"].GetString();
+        } 
         return true;
     }
 

+ 6 - 2
framework/request/include/HttpToken.hpp

@@ -3,10 +3,13 @@
  * @Version: 1.0
  * @Autor: lishengyin
  * @Date: 2021-11-04 09:39:46
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 11:22:35
+ * @LastEditors: Your Name lishengyin@sz-sunwin.com
+ * @LastEditTime: 2022-09-04 21:26:21
  */
 
+#ifndef __HTTPTOKEN_HPP_
+#define __HTTPTOKEN_HPP_
+
 #include <iostream>
 using namespace std;
 
@@ -57,4 +60,5 @@ public:
     }
 };
 
+#endif
 

+ 9 - 5
framework/request/include/RecDeviceCommand.h

@@ -59,12 +59,15 @@ public:
         const auto end = doc.MemberEnd();
 
         // json_type
-        if (end == doc.FindMember("deviceId") || !doc["deviceId"].IsInt()) {
+        if (end == doc.FindMember("deviceId")) {
             return false;
         } else {
-            deviceId = doc["deviceId"].GetInt();
+            if(doc["deviceId"].IsInt())
+                deviceId = doc["deviceId"].GetInt();
+            else if(doc["deviceId"].IsString())
+                deviceId = std::stoi(doc["deviceId"].GetString());
         }
-        
+
         if(end == doc.FindMember("commandCode") || !doc["commandCode"].IsString()) {
             return false;
         }else{
@@ -76,11 +79,12 @@ public:
     bool jsonToObject(const rapidjson::Value& object){
         const auto end = object.MemberEnd();
 
-        if(end == object.FindMember("deviceId") || !object["deviceId"].IsInt()){
+        if(end == object.FindMember("deviceId")){
             return false;
         }
         else{
-            deviceId = object["deviceId"].GetInt();
+            if(object["deviceId"].IsInt()) deviceId = object["deviceId"].GetInt();
+            else if(object["deviceId"].IsString()) deviceId = std::atoi(object["deviceId"].GetString());
         }
         if(end == object.FindMember("commandCode") || !object["commandCode"].IsString()){
             return false;

BIN
lib/libgsd_core.so


BIN
lib/libgsd_modules.so


BIN
lib/libgsd_plugins.so


+ 1 - 0
modules/Expel/include/Crc.h

@@ -48,6 +48,7 @@ public:
     Crc(/* args */){
     }
     ~Crc(){}
+
     static void crc_accumulate(uint8_t data, uint16_t* crcAccum)
     {
         *crcAccum = crc16_tab[(*crcAccum >> 8 ^ data) & 0xff] ^ (*crcAccum << 8);

+ 98 - 0
modules/Expel/include/DeviceGasV2.hpp

@@ -0,0 +1,98 @@
+#pragma once
+
+#include "UtilBase.hpp"
+
+namespace gsd
+{
+
+    class DeviceGasV2: public ContorlHttplBase
+    {
+    public:
+        DeviceGasV2():ContorlHttplBase(){
+            this->DeviceInfo = "合肥新桥机场 西安为开煤气炮驱动板协议";
+            this->tool = DeviceTools::http;
+        }
+
+        // 电压
+        float voltage = 0;
+        // 状态
+        int state = 0;
+        // 纬度
+        float latitude = 0;
+        // 经度
+        float longitude = 0;
+
+        std::string fuwuid = "551";
+        std::string key = "cc23a0046c2ba907f6cc779e67c7183b";
+
+        /**
+         * @description: 判定msg是否为status
+         * @param {int} &msg_id
+         * @return {*}
+         */    
+        bool getStatusMsg(int &msg_id);
+        
+        /**
+         * @description: 消费数据
+         * @param {uint8_t} *data
+         * @param {int} len
+         * @param {int} &msg_id
+         * @return {*}
+         */        
+        bool Consumer(uint8_t *data, int len, int &msg_id);
+
+        /**
+         * @description: 反序列化
+         * @param {uint8_t} *data
+         * @param {int} len
+         * @param {int} &msg_id
+         * @return {*}
+         */        
+        virtual bool deserialization(const uint8_t *data, int len, int &msg_id);
+
+        // 常规操作
+        int8_t Open(std::string _deviceId, uint8_t* data, int& length);
+        int8_t Close(std::string _deviceId, uint8_t* data, int&length);
+        int8_t Fire(std::string _deviceId, uint8_t* data, int& length);
+        int8_t Status(std::string _deviceId, uint8_t* data, int& length);
+
+        /**
+         * @description: 构建设备信息
+         * @param {SendDevice&} sendDevice
+         * @return {*}
+         */        
+        virtual void BuildDeviceInfo(SendDevice& sendDevice);
+
+        /**
+         * @description: 序列化
+         * @param {GasV1Control} gasV1Control
+         * @param {char} *data
+         * @return {*}
+         */        
+        static void serialization(const ControlerMsg gasV1Control,char *data);
+
+        /**
+         * @description: getParms
+         * @return {*}
+         */        
+        httplib::Params getParms();
+        
+        /**
+         * @description: getHeaders
+         * @return {*}
+         */        
+        httplib::Headers getHeaders();
+
+        /**
+         * @description: 
+         * @return {*}
+         */        
+        std::string getUrl();
+
+        ~DeviceGasV2(){}
+    };
+    
+
+
+} // namespace gsd
+

+ 6 - 0
modules/Expel/include/DevicePlayerV3.hpp

@@ -44,6 +44,12 @@ namespace gsd{
         int8_t Fire(std::string DeviceId, uint8_t* data, int& length);
 
         int8_t Status(std::string DeviceId, uint8_t* data, int& length);
+
+        /**
+         * @description: getUrl
+         * @return {*}
+         */        
+        std::string getUrl();
     };
 
 }

+ 10 - 1
modules/Expel/include/Expel.hpp

@@ -19,7 +19,9 @@
 #include "DevicePlayerV3.hpp"
 #include "DevicePlayerV3.hpp"
 #include "DevicePlayerV4.hpp"
+
 #include "DeviceGasV1.hpp"
+#include "DeviceGasV2.hpp"
 
 #include "config.hpp"
 #include <iostream>
@@ -129,6 +131,12 @@ namespace gsd{
          */
         int32_t Controler(std::string commandCode);
 
+        /**
+         * @description: getExpelInfo
+         * @return {*}
+         */        
+        std::string getExpelInfo();
+
         list<int> m_deviceIdList;
         list<ExpelDevice> m_deviceLists;
 
@@ -182,7 +190,8 @@ namespace gsd{
          * @return {*}
          */    
         int32_t Control(std::shared_ptr<ContorlGear>& deviceControl, ExpelDevice& expelDevice, uint8_t* data, int& length, int type);
-    
+
+
     protected:
         mutex m_mutex;
         std::shared_ptr<ThreadPool> pool = nullptr;

+ 0 - 2
modules/Expel/src/DeviceGasV1.cpp

@@ -146,8 +146,6 @@ namespace gsd
         return deserialization(_comm.data, _comm.dataCount, msg_id);
     }
 
-
-
     /**
      * @description: 打开
      * @param {int} deivceId

+ 124 - 0
modules/Expel/src/DeviceGasV2.cpp

@@ -0,0 +1,124 @@
+#include "DeviceGasV2.hpp"
+
+namespace gsd
+{
+    /**
+     * @description: 反序列化
+     * @param {uint8_t} *data
+     * @param {int} len
+     * @param {int} &msg_id
+     * @return {*}
+     */    
+    bool DeviceGasV2::deserialization(const uint8_t *data, int len, int &msg_id){
+        return true;
+    }
+
+    /**
+     * @description: 消费数据
+     * @param {uint8_t} *data
+     * @param {int} len
+     * @param {int} &msg_id
+     * @return {*}
+     */    
+    bool DeviceGasV2::Consumer(uint8_t *data, int len, int &msg_id)
+    {
+        return true;
+    }
+
+    /**
+     * @description: 打开
+     * @param {int} deivceId
+     * @return {*}
+     */    
+    int8_t DeviceGasV2::Open(std::string DeviceId, uint8_t* data, int& length){
+        return Fire(DeviceId, data, length);
+    }
+
+    /**
+     * @description: 关闭
+     * @param {int} deivceId
+     * @return {*}
+     */    
+    int8_t DeviceGasV2::Close(std::string DeviceId, uint8_t* data, int& length){
+        this->code = CommmandCodeGear::_CLOSE;
+        return 0;
+    }
+
+    /**
+     * @description: 开炮
+     * @param {int} deivceId
+     * @return {*}
+     */    
+    int8_t DeviceGasV2::Fire(std::string DeviceId, uint8_t* data, int& length){
+        this->code = CommmandCodeGear::_FIRE;
+        return 0;
+    }
+
+    /**
+     * @description: 状态
+     * @param {int} deivceId
+     * @return {*}
+     */    
+    int8_t DeviceGasV2::Status(std::string DeviceId, uint8_t* data, int& length){
+        this->code = CommmandCodeGear::_STATUS;
+        return 0;
+    }
+
+    /**
+     * @description: 判定msg是否为status
+     * @param {int} &msg_id
+     * @return {*}
+     */    
+    bool DeviceGasV2::getStatusMsg(int &msg_id){
+        return true;
+    }
+
+    /**
+     * @description: 构建设备信息
+     * @param {SendDevice&} sendDevice
+     * @return {*}
+     */    
+    void DeviceGasV2::BuildDeviceInfo(SendDevice& sendDevice){
+    }
+
+    /**
+     * @description: getParms
+     * @return {*}
+     */        
+    httplib::Params DeviceGasV2::getParms(){
+        httplib::Params params;
+        params.emplace("fuwuid", fuwuid);
+        params.emplace("number", deviceId);
+        params.emplace("key", key);
+        return params;
+    }
+
+    /**
+     * @description: getHeaders
+     * @return {*}
+     */        
+    httplib::Headers DeviceGasV2::getHeaders(){
+        httplib::Headers headers = {};
+        return headers;
+    }
+
+    /**
+     * @description: getUrl
+     * @return {*}
+     */    
+    std::string DeviceGasV2::getUrl(){
+        std::string url = "";
+        switch (code)
+        {
+        case CommmandCodeGear::_STATUS:
+            url = "/externalInterface/mqpInfo";
+            break;
+        case CommmandCodeGear::_FIRE:
+            url = "/externalInterface/mqpFireArtillery";
+            break;
+        default:
+            break;
+        }
+        return url;
+    }
+} // namespace gsd

+ 9 - 0
modules/Expel/src/DevicePlayerV3.cpp

@@ -89,4 +89,13 @@ namespace gsd
         length = json.length();
         return 0;
     }
+    
+    /**
+     * @description: getUrl
+     * @return {*}
+     */    
+    std::string DevicePlayerV3::getUrl(){
+        PlayerInquire playerInquire;
+        return playerInquire.getUrl();
+    }
 } // namespace gsd

+ 4 - 1
modules/Expel/src/DevicePlayerV4.cpp

@@ -106,7 +106,7 @@ namespace gsd
      */    
     bool DevicePlayerV4::deserialization(const uint8_t *data, int len, int &msg_id){
         if(len == 6 && data[5] == 0x01){
-            this->deviceId = data[3];
+            this->deviceId = std::to_string(data[3]);
             return true;
         }
         return false;
@@ -140,6 +140,7 @@ namespace gsd
     int8_t DevicePlayerV4::Open(std::string DeviceId, uint8_t* data, int& length){
         ControlerMsg gasControl;
         gasControl.deviceId = atoi(DeviceId.c_str());
+        if(gasControl.deviceId == 1) gasControl.deviceId = 0;
         gasControl.msgId = DEVICEGASV3_COMMAND_PLAY_NOW;
         gasControl.data = 0x00;
         length = 10;
@@ -156,6 +157,7 @@ namespace gsd
     int8_t DevicePlayerV4::Close(std::string DeviceId, uint8_t* data, int& length){
         ControlerMsg gasControl;
         gasControl.deviceId = atoi(DeviceId.c_str());
+        if(gasControl.deviceId == 1) gasControl.deviceId = 0;
         gasControl.msgId = DEVICEGASV3_COMMAND_STOP;
         gasControl.data = 0x00;
         length = 10;
@@ -171,6 +173,7 @@ namespace gsd
     int8_t DevicePlayerV4::Fire(std::string DeviceId, uint8_t* data, int& length){
         ControlerMsg gasControl;
         gasControl.deviceId = atoi(DeviceId.c_str());
+        if(gasControl.deviceId == 1) gasControl.deviceId = 0;
         gasControl.msgId = DEVICEGASV3_COMMAND_PLAY_NOW;
         gasControl.data = 0x00;
         length = 10;

+ 90 - 20
modules/Expel/src/Expel.cpp

@@ -44,6 +44,7 @@ namespace gsd
                 SendDevice sendDevice;
                 time_t timestamp;
                 NettyClientResultMsg<SendDevice> nettyClientResultMsg;
+                if(deviceControl->getDeviceId() == "0") deviceControl->setDeviceId("1");
                 deviceControl->BuildDeviceInfo(sendDevice);
                 time(&timestamp);
                 sendDevice.msgTime = ctime(&timestamp);
@@ -53,6 +54,7 @@ namespace gsd
                 nettyClientResultMsg.setDataType(NettyClientCommandEnum().device_info);
                 nettyClientResultMsg.setData(sendDevice);
                 nettyClientResultMsg.objectToJson(json);
+                if(config::getPtr()->debug) DebugL << json << endl;
                 NoticeCenter::Instance().emitEvent(NOTICE_DEVICEINFO, requestId ,json);
             }
         }
@@ -147,6 +149,13 @@ namespace gsd
         case 4:
             this->Fire(expelDevice);
             break;
+
+        case 18:
+            this->Open(expelDevice);
+            break;
+        case 19:
+            this->Close(expelDevice);
+            break;
         default:
             break;
         }
@@ -201,8 +210,12 @@ namespace gsd
             deviceControl = std::make_shared<DevicePlayerV4>();
             std::dynamic_pointer_cast<DevicePlayerV4>(deviceControl)->setServerIP(config::getPtr()->payServerIP);
             break;
-        }
 
+        case DeviceType::DeviceGasV2:
+            deviceControl = std::make_shared<gsd::DeviceGasV2>();
+            break;
+        }
+        deviceControl->setTypeId(expelDevice.deviceType);
         return deviceControl;
     }
 
@@ -324,7 +337,6 @@ namespace gsd
         std::lock_guard<mutex> gurad(m_mutex);
         deviceControl->setDeviceId(expelDevice.DeviceId);
         if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::serial){
-            DebugL;
             CSerialPort ser;
             config::Ptr m_config = config::getPtr();
             if(m_config->debug) DebugL << "Serial control data:" << bytesToHexString(data, length) << endl;
@@ -342,11 +354,11 @@ namespace gsd
             ser.close();
             return 0;
        }else if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::http){
-            DebugL;
             std::string serviceIP = "";
-            if(config::getPtr()->getApp() == "gsd_SZX"){
+            if(deviceControl->getTypeId() == DeviceType::DeviceGasV2 || deviceControl->getTypeId() == DeviceType::DevicePlayerV3){
                 serviceIP = config::getPtr()->payServerIP;
-            }else{
+            }
+            else{
                 serviceIP = expelDevice.ServerIp;
             }
             if(serviceIP == ""){
@@ -355,29 +367,50 @@ namespace gsd
             }
             httplib::Client cli(serviceIP, config::getPtr()->ExpelPort);
             std::string json;
-            json = (char*)data;
-            DebugL << "Http control data:" << json << endl;
-            PlayerInquire playerInquire;
-            if (auto res = cli.Post(playerInquire.getUrl().c_str(), json, "application/json")) {
-                if (res->status == 200) {
-                    // DebugL << res->body << endl;
-                    return 0;
-                }else {
-                    WarnL << res->body << endl;
+            if(json != ""){
+                json = (char*)data;
+                DebugL << "Http control data:" << json << endl;
+            }
+            if(deviceControl->getTypeId() == DeviceType::DevicePlayerV3){
+                if (auto res = cli.Post(std::dynamic_pointer_cast<DevicePlayerV3>(deviceControl)->getUrl().c_str(), json, "application/json")) {
+                    if (res->status == 200) {
+                        // DebugL << res->body << endl;
+                        return 0;
+                    }else {
+                        WarnL << res->body << endl;
+                        return -1;
+                    }
+                } else {
+                    auto err = res.error();
+                    ErrorL << "HTTP Service unavailable:" << err << endl;
+                    return -1;
+                }
+            }else if(deviceControl->getTypeId() == DeviceType::DeviceGasV2){
+                auto parms = std::dynamic_pointer_cast<DeviceGasV2>(deviceControl)->getParms();
+                auto headers = std::dynamic_pointer_cast<DeviceGasV2>(deviceControl)->getHeaders();
+                std::string url = std::dynamic_pointer_cast<DeviceGasV2>(deviceControl)->getUrl();
+                if(url == "") return 1;
+                if(auto res = cli.Get(url.c_str(), parms, headers)){
+                    if (res->status == 200) {
+                        DebugL << res->body << endl;
+                        return 0;
+                    }else {
+                        WarnL << res->body << endl;
+                        return -1;
+                    }
+                }else{
+                    auto err = res.error();
+                    ErrorL << "HTTP Service unavailable:" << err << endl;
                     return -1;
                 }
-            } else {
-                auto err = res.error();
-                ErrorL << "HTTP Service unavailable:" << err << endl;
-                return -1;
             }
         }else if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::tcp){
-            if(expelDevice.ServerIp == ""){
+            if(config::getPtr()->payServerIP_tcp == ""){
                 ErrorL << "The device IP address is empty" << endl;
                 return -1;
             }
             client->setDeviceControl(deviceControl);
-            if(!client->alive()) client->startConnect(expelDevice.ServerIp, config::getPtr()->ExpelPort);
+            if(!client->alive()) client->startConnect(config::getPtr()->payServerIP_tcp, config::getPtr()->payServerPort_tcp);
             if(config::getPtr()->debug) DebugL << "Serial control data:" << bytesToHexString(data, length) << endl;
             auto buf = BufferRaw::create();
             buf->assign((char*)data, length);
@@ -536,4 +569,41 @@ namespace gsd
             return config::getPtr()->DeviceIds.size();
         }
     }
+
+    /**
+     * @description: getExpelInfo
+     * @return {*}
+     */    
+    std::string Expel::getExpelInfo(){
+        std::string info;
+        rapidjson::StringBuffer strBuf;
+        rapidjson::Writer<rapidjson::StringBuffer> writer(strBuf);
+        if(!config::getPtr()->LowVersion){
+            writer.StartObject();
+            writer.Key("Num");
+            writer.Int(m_deviceLists.size());
+            writer.Key("datas");
+            writer.StartArray();
+            for(auto iter = m_deviceLists.begin(); iter != m_deviceLists.end(); iter++){
+                writer.StartObject();
+                writer.Key("DeviceId");
+                writer.String(iter->DeviceId.c_str());
+                writer.Key("DeviceType");
+                writer.Int(iter->deviceType);
+                writer.Key("DeviceTools");
+                writer.Int(iter->tool);
+                writer.EndObject();
+            }
+            writer.EndArray();
+            writer.EndObject();
+            info = strBuf.GetString();
+        }else{
+            writer.StartObject();
+            writer.Key("Num");
+            writer.Int(config::getPtr()->DeviceIds.size());
+
+        }
+        return info;
+    }
+
 } // namespace gsd

+ 14 - 2
modules/HttpClient/include/HttpClient.hpp

@@ -3,8 +3,8 @@
  * @Version: 1.0
  * @Autor: lishengyin
  * @Date: 2022-02-23 09:31:32
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 15:00:21
+ * @LastEditors: Your Name lishengyin@sz-sunwin.com
+ * @LastEditTime: 2022-09-04 21:32:43
  */
 #ifndef __HTTPCLIENT_H_
 #define __HTTPCLIENT_H_
@@ -31,8 +31,14 @@
 #include "NettyExpelDevInfo.h"
 #include "NettyHttpDicCode.h"
 
+#include "HttpNull.hpp"
+#include "HttpResultMsg.hpp"
+#include "HttpToken.hpp"
+
 #include "UtilBase.hpp"
 
+#include "config.hpp"
+
 using namespace std;
 
 namespace gsd{
@@ -121,6 +127,12 @@ namespace gsd{
         * @return {*}
         */    
         int32_t getHttpDicCode(std::string dictCode,NettyHttpResultMsg<NettyHttpDicCode,NettyHttpNull>& nettyHttpResultMsg);
+
+        /**
+         * @description: 送入判定器
+         * @return {*}
+         */        
+        std::pair<bool, std::string> getCheck(std::string& ImageBase64, std::string& datas);
     };
 };
 

+ 31 - 2
modules/HttpClient/src/HttpClient.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-02-23 09:32:08
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 15:18:09
+ * @LastEditTime: 2022-09-09 15:49:03
  */
 #include "HttpClient.hpp"
 
@@ -158,7 +158,6 @@ namespace gsd{
                     return OK;
                 }
             }
-            ErrorL << res->body << endl;
             return ERR;
         }else{
             auto err = res.error();
@@ -167,4 +166,34 @@ namespace gsd{
         }
         return OK;
     }
+
+    /**
+     * @description: 纠察器
+     * @param {string&} ImageBase64
+     * @param {string&} datas
+     * @return {*}
+     */    
+    std::pair<bool, std::string> HttpClient::getCheck(std::string& ImageBase64, std::string& datas){
+        static std::shared_ptr<httplib::Client> gsd_check = nullptr;
+        if(gsd_check == nullptr) gsd_check = std::make_shared<httplib::Client>(config::getPtr()->InferCheckerIP, config::getPtr()->InferCheckerPort);
+        httplib::Params params;
+        params.emplace("image", ImageBase64);
+        params.emplace("datas", datas);
+        std::pair<bool, std::string> result = std::make_pair<bool, std::string>(false, "");
+        if (auto res = gsd_check->Post("/apis/v1/check/Infer", params)){
+            HttpResultMsg<HttpNull, HttpNull> request;
+            if(res->status == 200){
+                if(request.jsonToObject(res->body)){
+                    if(request.msg == "成功") result.first = true;
+                    else if(request.msg == "失败") result.first = false;
+                    result.second = request.attr1;
+                    return result;
+                }
+            }
+            WarnL << "STATUS:" << res->status << ", " << res->body << endl;
+        }else{
+            ErrorL << "Service unavailable" << endl;
+        }
+        return result;
+    }
 };

+ 7 - 1
modules/HttpServer/src/HttpServer.cpp

@@ -25,6 +25,12 @@ namespace gsd
             res.set_content("version:" + config::getPtr()->getVersion(), "text/plain");
         });
 
+        // GET
+        this->m_server->Get("/api/v1/expelInfo", [](const httplib::Request& req, httplib::Response& res){
+            std::string info = Expel::getPtr()->getExpelInfo();
+            res.set_content(info, "text/plain");
+        });
+
         // Get
         this->m_server->Get("/api/v1/expeldev", [](const httplib::Request& req, httplib::Response& res){
             if(!req.has_param("DeviceID") || !req.has_param("command") || !req.has_param("type")){
@@ -44,7 +50,7 @@ namespace gsd
             std::string str = "usage : \r\n      http://" + config::getPtr()->localIP + ":9980" + "/[interface] \r\n" \
                             "interface: \r\n version: http://" + config::getPtr()->localIP + ":9980" + "/api/v1/version \r\n   params: null\r\n" \
                             "interface: \r\n expeldev: http://"+ config::getPtr()->localIP + ":9980" + "/api/v1/expeldev?DeviceID={?}&command={?}&type={?} \r\n    params(DeviceID), " \
-                            "command(Control type 1-open 2-close 3-fire 4-status), type(Equipment type 0-PKX 1-LHW 2-SZX 3-SZX 4-HFE)";
+                            "command(Control type 1-open 2-close 3-fire 4-status), type(Equipment type 0-PKX 1-LHW 2-PEK 3-SZX 4-HFE 5-HFE2)";
             res.set_content(str, "text/plain");
         });
 

+ 33 - 3
modules/InfineFilter/include/InfineFilter.hpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-09 10:55:43
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 16:04:10
+ * @LastEditTime: 2022-09-08 14:42:57
  */
 #ifndef __INFINEFILTER_H_
 #define __INFINEFILTER_H_
@@ -19,8 +19,8 @@
 #include "Poller/Timer.h"
 #include "CNStreamInferData.h"
 #include "config.hpp"
-
 #include <cmath>
+#include <queue>
 
 using namespace std;
 using namespace toolkit;
@@ -36,6 +36,14 @@ namespace gsd
             std::shared_ptr<Ticker> ticker = nullptr;
             std::shared_ptr<CNStreamInferData> CnStreamInferData = nullptr;
         };
+
+        // 相似数据
+        struct SimilarityData
+        {
+            std::shared_ptr<Ticker> ticker = nullptr;
+            InferInfo info;
+        };
+        
         
     private:
         InfineFilter(){
@@ -64,6 +72,10 @@ namespace gsd
 
         vector<HistoryData> HistoryDatas;
 
+        queue<HistoryData> LatestDatas;
+
+        vector<SimilarityData> SimilarityDatas;
+
         int TimeOut = 10 * 60 * 1000;
         
         Timer::Ptr timer = nullptr;
@@ -97,6 +109,18 @@ namespace gsd
          */    
         void HistoricalCheck();
 
+        /**
+         * @description: 相似度对比
+         * @return {*}
+         */        
+        int8_t SimilarityJudgment(std::shared_ptr<CNStreamInferData>& cnStreamInferData);
+
+        /**
+         * @description: 时间对比
+         * @return {*}
+         */        
+        void SimilarityCheck();
+
     public:
         using Ptr = std::shared_ptr<InfineFilter>;
 
@@ -121,7 +145,7 @@ namespace gsd
          * @param {InferInfo&} infer2
          * @return {*}
          */    
-        int8_t CalculateSimilarity(InferInfo& infer1, InferInfo& infer2);
+        int8_t CalculateSimilarity(InferInfo& infer1, InferInfo& infer2, std::shared_ptr<CNStreamInferData>& cnStreamInferData);
 
         /**
          * @description: 获取ptr
@@ -151,6 +175,12 @@ namespace gsd
          */    
         int8_t setTimeOut(int timeOut);
 
+        /**
+         * @description: getIou
+         * @return {*}
+         */    
+        float getIou(InferInfo infer1, InferInfo infer2, std::shared_ptr<CNStreamInferData>& cnStreamInferData);
+
     public:
         double bboxSize = 0.0;
     };

+ 39 - 16
modules/InfineFilter/src/InfineFilter.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-09 10:58:34
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 16:03:11
+ * @LastEditTime: 2022-09-09 15:25:51
  */
 #include "InfineFilter.hpp"
 
@@ -32,7 +32,7 @@ namespace gsd
         // 过滤小目标
         MinBBoxFilter(cnStreamInferData);
 
-        switch (filterLevel)
+        switch (sensitivity)
         {
         case 0:
             result = OK;
@@ -77,29 +77,30 @@ namespace gsd
      * @param {InferInfo} infer2
      * @return {*}
      */
-    int8_t InfineFilter::CalculateSimilarity(InferInfo& infer1, InferInfo& infer2){
+    int8_t InfineFilter::CalculateSimilarity(InferInfo& infer1, InferInfo& infer2, std::shared_ptr<CNStreamInferData>& cnStreamInferData){
         // Label
         if(infer1.Label != infer2.Label) return ERR;
         // Source
         // BBOX
-        double difference = fabs(infer1.BBox.x  - infer2.BBox.x);
-        if(difference > 10) return ERR;
-        difference = fabs(infer1.BBox.y  - infer2.BBox.y );
-        if(difference > 10) return ERR;
-        difference = fabs(infer1.BBox.w  - infer2.BBox.w );
-        if(difference > 10) return ERR;
-        difference = fabs(infer1.BBox.h  - infer2.BBox.h );
-        if(difference > 10) return ERR;
+        // double difference = fabs(infer1.BBox.x  - infer2.BBox.x);
+        // if(difference > 10) return ERR;
+        // difference = fabs(infer1.BBox.y  - infer2.BBox.y );
+        // if(difference > 10) return ERR;
+        // difference = fabs(infer1.BBox.w  - infer2.BBox.w );
+        // if(difference > 10) return ERR;
+        // difference = fabs(infer1.BBox.h  - infer2.BBox.h );
+        // if(difference > 10) return ERR;
+        if(this->getIou(infer1, infer2, cnStreamInferData) < 0.5) return ERR;
         return OK;
     }
 
     /**
-     * @description: 设置过滤器等级
+     * @description: 设置灵敏度
      * @param {int} FilterLevel
      * @return {*}
      */
     int8_t InfineFilter::setFilterLevel(int FilterLevel){
-        if(FilterLevel < 0 || FilterLevel > 3) return ERR;
+        if(filterLevel < 0 || filterLevel > 3) return ERR;
         this->filterLevel = FilterLevel;
         return OK;
     }
@@ -144,7 +145,7 @@ namespace gsd
             if(old->Objects.size() == cnStreamInferData->Objects.size()){
                 for(auto iter1 = old->Objects.begin(); iter1 != old->Objects.end(); iter1++){
                     for(auto iter2 = cnStreamInferData->Objects.begin(); iter2 != cnStreamInferData->Objects.end(); iter2++){
-                        if(CalculateSimilarity(*iter1, *iter2) == OK) num++;
+                        if(CalculateSimilarity(*iter1, *iter2, cnStreamInferData) == OK) num++;
                     }
                 }
             }
@@ -203,7 +204,7 @@ namespace gsd
             if(iter->CnStreamInferData->Objects.size() == cnStreamInferData->Objects.size()){
                 for(auto iter1 = iter->CnStreamInferData->Objects.begin(); iter1 != iter->CnStreamInferData->Objects.end(); iter1++){
                     for(auto iter2 = cnStreamInferData->Objects.begin(); iter2 != cnStreamInferData->Objects.end(); iter2++){
-                        if(CalculateSimilarity(*iter1, *iter2) == OK) num++;
+                        if(CalculateSimilarity(*iter1, *iter2, cnStreamInferData) == OK) num++;
                     }
                 }
             }
@@ -234,7 +235,29 @@ namespace gsd
             this->HistoryDatas.erase(*iter);
         }
     }
-    
+
+    /**
+     * @description: 获取Iou
+     * @return {*}
+     */
+    float InfineFilter::getIou(InferInfo infer1, InferInfo infer2,std::shared_ptr<CNStreamInferData>& cnStreamInferData){
+        
+        int max_x = std::max(infer1.BBox.x, infer2.BBox.x);
+        int min_x = std::min(infer1.BBox.x + infer1.BBox.w, infer2.BBox.x + infer2.BBox.w);
+        int max_y = std::max(infer1.BBox.y, infer2.BBox.y);
+        int min_y = std::min(infer1.BBox.y + infer1.BBox.h, infer2.BBox.y + infer2.BBox.h);
+        if(min_x <= max_x || min_y <= max_y) return 0;
+
+        float over_area = (min_x - max_x) * (min_y - max_y);  // 计算重叠面积
+        
+        float area_a = (infer1.BBox.w) * (infer1.BBox.h);
+        float area_b = (infer2.BBox.w) * (infer2.BBox.h);
+
+        float iou = over_area / (area_a + area_b - over_area);
+        return iou;
+    }
 } // namespace gsd
 
 
+
+

+ 1 - 1
modules/Monitor/include/Monitor.hpp

@@ -50,7 +50,7 @@ namespace gsd
          * @param {*}
          * @return {*}
          */    
-        bool ConsumeData(FrameInferData::Ptr& result);
+        bool ConsumeData(std::shared_ptr<CNStreamInferData>& cnstreamInferData);
 
     protected:
         std::shared_ptr<kafka_consumer_client> m_KafkaConsumer = nullptr; 

+ 2 - 37
modules/Monitor/src/Monitor.cpp

@@ -25,20 +25,18 @@ namespace gsd
     std::shared_ptr<Monitor> Monitor::CreateNew(std::string broker, std::string topic, std::string group){
         return std::shared_ptr<Monitor>(new Monitor(broker, topic, group));
     }
-
+    
     /**
      * @description: 消费数据
      * @param {Ptr&} result
      * @return {*}
      */    
-    bool Monitor::ConsumeData(FrameInferData::Ptr& result){
-        std::shared_ptr<CNStreamInferData> cnstreamInferData = std::make_shared<CNStreamInferData>();
+    bool Monitor::ConsumeData(std::shared_ptr<CNStreamInferData>& cnstreamInferData){
         std::string json = "";
         // 消费数据
         this->m_KafkaConsumer->ConsumeData(json, 5000);
         if(json == "") return false;
         cnstreamInferData->Objects.clear();
-        // 数据转换(TODO 优化) 
         if(cnstreamInferData->jsonToObject(json)){
             InfineFilter::Ptr infineFilter = InfineFilter::getPtr();
             config::Ptr m_config = config::getPtr();
@@ -52,39 +50,6 @@ namespace gsd
                     return false;
                 }
             }
-            // 解析数据成功
-            rapidjson::StringBuffer buffer;
-            rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
-            writer.StartArray();
-            for(auto &obj : cnstreamInferData->Objects)
-            {
-                writer.StartObject();
-                writer.Key("x");
-                writer.Double(obj.BBox.x * 1920);
-                writer.Key("y");
-                writer.Double(obj.BBox.y * 1080);
-                writer.Key("width");
-                writer.Double(obj.BBox.w * 1920);
-                writer.Key("height");
-                writer.Double(obj.BBox.h * 1080);
-                writer.EndObject();
-            }
-            writer.EndArray();
-
-            // 获取时间
-            char ctime[80];
-            time_t rawtime;
-            struct tm *info;
-            time(&rawtime);
-            info = localtime(&rawtime);
-            strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
-
-            result->ClassId = 1;
-            result->ImageBase64 = cnstreamInferData->ImageBase64;
-            result->Remark = buffer.GetString();
-            result->Num = cnstreamInferData->Objects.size();
-            result->WarningTime = ctime;
-            result->VideoPath = cnstreamInferData->videoPath;
             return true;
         }
         return false;

+ 14 - 4
modules/config/include/config.hpp

@@ -3,8 +3,8 @@
  * @Version: 1.0
  * @Autor: lishengyin
  * @Date: 2022-03-07 11:52:08
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 16:02:39
+ * @LastEditors: Your Name lishengyin@sz-sunwin.com
+ * @LastEditTime: 2022-09-04 21:31:21
  */
 #ifndef __CONFIG_H_
 #define __CONFIG_H_
@@ -24,7 +24,7 @@ using namespace inifile;
 
 #define GSD_MAJOR_VERSION 1
 #define GSD_MINOR_VERSION 0
-#define GSD_PATCH_VERSION 0
+#define GSD_PATCH_VERSION 5
 
 class config
 {
@@ -84,7 +84,17 @@ public:
     std::string payServerIP = "10.81.160.141";
 
     int filterLevel = 2;
-    
+
+    int vpn = 0;
+
+    std::string payServerIP_tcp = "192.168.1.102";
+    int payServerPort_tcp = 12500;
+
+    int InferChecker = 0;
+
+    std::string InferCheckerIP = "192.168.31.219";
+    int InferCheckerPort = 8860;
+
 protected:
     #ifdef RELEASE
         std::string configFile = "/etc/gsd/config.ini";

+ 11 - 2
modules/config/src/config.cpp

@@ -3,8 +3,8 @@
  * @Version: 1.0
  * @Autor: lishengyin
  * @Date: 2022-03-07 11:52:23
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-24 10:18:38
+ * @LastEditors: Your Name lishengyin@sz-sunwin.com
+ * @LastEditTime: 2022-09-04 21:31:30
  */
 #include "config.hpp"
 #include "Shell.h"
@@ -63,6 +63,9 @@ bool config::Update(){
     this->mysql_IP  = m_ini.getStringValue("Mysql", "mysql_IP", ret);
     this->mysql_port = m_ini.getIntValue("Mysql", "mysql_port", ret);
 
+    this->payServerIP_tcp = m_ini.getStringValue("payServer", "IP", ret);
+    this->payServerPort_tcp = m_ini.getIntValue("payServer", "Port", ret);
+
     this->SimCode = this->getSimCode();
     this->app = this->getApp();
     
@@ -79,6 +82,8 @@ bool config::Update(){
         this->deviceType = m_ini.getIntValue("Device", "DeviceType", ret);
         this->vpnIP = m_ini.getStringValue("vpn","vpn_ip", ret);
     }
+
+    if(this->vpn == 1) return false;
     this->HostIPs = this->getHostIP();
     int flag = 0;
     for(auto iter = HostIPs.begin(); iter != HostIPs.end(); iter++){
@@ -179,6 +184,10 @@ bool config::getBasicConfig(){
                     this->InferInterval = basicConfig.InferInterval;
                     this->payServerIP = basicConfig.payServerIP;
                     this->filterLevel = basicConfig.filterLevel;
+                    this->vpn = basicConfig.vpn;
+                    this->InferChecker = basicConfig.InferChecker;
+                    this->InferCheckerIP = basicConfig.InferCheckerIP;
+                    this->InferCheckerPort = basicConfig.InferCheckerPort;
 
                     if(basicConfig.com_port != "") this->comPort = basicConfig.com_port;
 

+ 6 - 0
plugins/ExpelPlugin/include/ExpelPlugin.hpp

@@ -82,6 +82,12 @@ namespace gsd
         void sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice);
 
         /**
+         * @description: getExpelSize
+         * @return {*}
+         */        
+        int32_t getExpelSize();
+
+        /**
          * @description: ~ExpelPlugin
          * @return {*}
          */        

+ 8 - 1
plugins/ExpelPlugin/src/ExpelPlugin.cpp

@@ -78,7 +78,6 @@ namespace gsd
                 ServerIp,ServerCname,ServerCpwd FROM gsdDB.`DeviceList` WHERE ISDELETE = 0");
             sqlSelete << result;
             Expel::getPtr()->UpdateDeviceList(result);
-            
             InfineFilter::getPtr()->bboxSize = config::getPtr()->bboxSize;
             // 过滤小目标
             InfineFilter::getPtr()->MinBBoxFilter(cnstreamInferData);
@@ -126,4 +125,12 @@ namespace gsd
     void ExpelPlugin::sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice){
         Expel::getPtr()->sendDeviceMsgCallback(nettyServerResultMsg, expelDevice);
     }
+
+    /**
+     * @description: getExpelSize
+     * @return {*}
+     */    
+    int32_t ExpelPlugin::getExpelSize(){
+        return Expel::getPtr()->getExpelSize();
+    }
 } // namespace gsd

+ 10 - 2
plugins/HttpPlugin/include/HttpPlugin.hpp

@@ -29,10 +29,10 @@ namespace gsd
         using Ptr = std::shared_ptr<HttpPlugin>;
 
         /**
-         * @description: CreateNew
+         * @description: getPtr
          * @return {*}
          */        
-        static std::shared_ptr<HttpPlugin> CreateNew();
+        static std::shared_ptr<HttpPlugin> getPtr();
 
         /**
          * @description: 初始化
@@ -65,6 +65,14 @@ namespace gsd
         bool Alive(){
             return true;
         }
+
+        /**
+         * @description: 纠察器
+         * @param {string&} ImageBase64
+         * @param {string&} datas
+         * @return {*}
+         */        
+        std::pair<bool, std::string> getCheck(std::string& ImageBase64, std::string& datas);
         
         ~HttpPlugin(){}
 

+ 38 - 22
plugins/HttpPlugin/src/HttpPlugin.cpp

@@ -7,8 +7,10 @@ namespace gsd
      * @description: CreateNew
      * @return {*}
      */    
-    std::shared_ptr<HttpPlugin> HttpPlugin::CreateNew(){
-        return std::shared_ptr<HttpPlugin>(new HttpPlugin);
+    std::shared_ptr<HttpPlugin> HttpPlugin::getPtr(){
+        static std::shared_ptr<HttpPlugin> HttpPlugin_ = nullptr;
+        if(HttpPlugin_ == nullptr) HttpPlugin_ = std::shared_ptr<HttpPlugin>(new HttpPlugin);
+        return HttpPlugin_;
     }
 
     /**
@@ -16,7 +18,9 @@ namespace gsd
      * @return {*}
      */    
     bool HttpPlugin::Init(){
-        //if(!config::getPtr()->debug) return true;
+        if(this->m_HttpServer == nullptr){
+            this->m_HttpServer = HttpServer::CreateNew();
+        }
         if(config::getPtr()->LowVersion) return true;
         if(this->m_httpClient == nullptr){
             this->m_httpClient = HttpClient::CreateNew();
@@ -27,10 +31,6 @@ namespace gsd
         }else{
             WarnL << "Netty login failed. Procedure" << endl;
         }
-
-        if(this->m_HttpServer == nullptr){
-            this->m_HttpServer = HttpServer::CreateNew();
-        }
         return true;
     }
 
@@ -40,23 +40,21 @@ namespace gsd
      */    
     bool HttpPlugin::StartTask(){
         this->timer0 = std::make_shared<Timer>(2.0f, [&](){
-            if(!config::getPtr()->debug) {
-                if(!config::getPtr()->LowVersion){
-                    if(this->m_httpClient == nullptr){
-                        this->m_httpClient = HttpClient::CreateNew();
-                        this->m_httpClient->Init(config::getPtr()->usr,  config::getPtr()->NettyIP, 80);
-                    }
-                    if(!this->m_httpClient->alive()){
-                        this->m_httpClient->LoginNetty();
-                    }else{
-                        this->getHttpInfo();
-                    }
+            if(!config::getPtr()->LowVersion){
+                if(this->m_httpClient == nullptr){
+                    this->m_httpClient = HttpClient::CreateNew();
+                    this->m_httpClient->Init(config::getPtr()->usr,  config::getPtr()->NettyIP, 80);
+                }
+                if(!this->m_httpClient->alive()){
+                    this->m_httpClient->LoginNetty();
+                }else{
+                    this->getHttpInfo();
                 }
             }
             return true;
         }, nullptr);
 
-        this->m_HttpServer->Init();
+        if(this->m_HttpServer != nullptr) this->m_HttpServer->Init();
         
         return true;
     }
@@ -67,7 +65,7 @@ namespace gsd
      */    
     void HttpPlugin::Destroy(){
         InfoL;
-        this->m_HttpServer->Destroy();
+        if(this->m_HttpServer != nullptr) this->m_HttpServer->Destroy();
     }
 
     /**
@@ -110,7 +108,6 @@ namespace gsd
                 std::string updateTime = ctime;
                 int i = 1;
                 vector<vector<std::string>> ret;
-
                 // 同步数据
                 for(auto iter = nettyHttpResultMsg.datas.begin(); iter != nettyHttpResultMsg.datas.end(); iter++){
                     expelDevice.DeviceId = iter->birdDeviceCode;
@@ -133,6 +130,16 @@ namespace gsd
                         // 派尔云
                         expelDevice.deviceType = DeviceType::DevicePlayerV3;
                         break;
+
+                    case 6:
+                        // 赛为驱鸟器
+                        expelDevice.deviceType = DeviceType::DevicePlayerV4;
+                        break;
+
+                    case 7:
+                        // 西安为开煤气炮
+                        expelDevice.deviceType = DeviceType::DeviceGasV2;
+                        break;
                     default:
                         // 协议不存在
                         return;
@@ -154,5 +161,14 @@ namespace gsd
             ErrorL << e.what() << '\n';
         }
     }
-
+    
+    /**
+     * @description: 纠察器
+     * @param {string&} ImageBase64
+     * @param {string&} datas
+     * @return {*}
+     */    
+    std::pair<bool, std::string> HttpPlugin::getCheck(std::string& ImageBase64, std::string& datas){
+        return this->m_httpClient->getCheck(ImageBase64, datas);
+    }
 } // namespace name

+ 1 - 0
plugins/MonitorPlugin/include/MonitorPlugin.hpp

@@ -8,6 +8,7 @@
 #include "HttpClient.hpp"
 #include "TcpPlugin.hpp"
 #include "InfineFilter.hpp"
+#include "HttpPlugin.hpp"
 
 using namespace std;
 

+ 58 - 3
plugins/MonitorPlugin/src/MonitorPlugin.cpp

@@ -112,7 +112,64 @@ namespace gsd
      * @return {*}
      */
     bool MonitorPlugin::ConsumeData(FrameInferData::Ptr& result){
-        return monitor->ConsumeData(result);
+        std::shared_ptr<CNStreamInferData> cnstreamInferData = std::make_shared<CNStreamInferData>();
+        if(monitor->ConsumeData(cnstreamInferData)){
+            // 纠察器
+            if(config::getPtr()->InferChecker){
+                CNStreamInferData data = *cnstreamInferData;
+                std::string _ImageBase64 = data.ImageBase64;
+                data.ImageBase64 = "";
+                std::string _json;
+                data.objectToJson(_json);
+                auto checkResultMsg = HttpPlugin::getPtr()->getCheck(_ImageBase64, _json);
+                if(checkResultMsg.first == false && checkResultMsg.second == "") {
+                    return false;
+                }
+                CNStreamInferData ChectResult;
+                if(ChectResult.jsonToObject(checkResultMsg.second)){
+                    if(ChectResult.Objects.empty()) {
+                        return false;
+                    }
+                    // 以纠察器的结果为准
+                    cnstreamInferData->Objects = ChectResult.Objects;
+                }
+            }
+            // 解析数据成功
+            rapidjson::StringBuffer buffer;
+            rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+            writer.StartArray();
+            for(auto &obj : cnstreamInferData->Objects)
+            {
+                writer.StartObject();
+                writer.Key("x");
+                writer.Double(obj.BBox.x * 1920);
+                writer.Key("y");
+                writer.Double(obj.BBox.y * 1080);
+                writer.Key("width");
+                writer.Double(obj.BBox.w * 1920);
+                writer.Key("height");
+                writer.Double(obj.BBox.h * 1080);
+                writer.EndObject();
+            }
+            writer.EndArray();
+
+            // 获取时间
+            char ctime[80];
+            time_t rawtime;
+            struct tm *info;
+            time(&rawtime);
+            info = localtime(&rawtime);
+            strftime(ctime, 80, "%Y-%m-%d %H:%M:%S", info);
+
+            result->ClassId = 1;
+            result->ImageBase64 = cnstreamInferData->ImageBase64;
+            result->Remark = buffer.GetString();
+            result->Num = cnstreamInferData->Objects.size();
+            result->WarningTime = ctime;
+            result->VideoPath = cnstreamInferData->videoPath;
+            return true;
+        }
+        return false;
     }
 
     /**
@@ -135,8 +192,6 @@ namespace gsd
         return true;
     }
 
-
-    
     /**
      * @description: 释放
      * @return {*}

+ 2 - 0
plugins/TcpPlugin/include/TcpPlugin.hpp

@@ -104,6 +104,8 @@ namespace gsd
         // TCP对象
         TCPClient::Ptr tcpClient = nullptr;
         Timer::Ptr HeartbeatTimer = nullptr;
+        Timer::Ptr NettyLoginTimer = nullptr;
+        
         bool TcpNettyLogin = false;
         // 线程池
         std::shared_ptr<ThreadPool> pool = nullptr;

+ 21 - 1
plugins/TcpPlugin/src/TcpPlugin.cpp

@@ -62,6 +62,13 @@ namespace gsd
             this->SendHeartbeatData();
             return true;
         }, nullptr);
+
+        // 登录定时器 每个一段时间发送一次登录信息
+        this->NettyLoginTimer = std::make_shared<Timer>(1200.0f, [&](){
+            this->TCPLoginNetty();
+            return true;
+        }, nullptr);
+
         return true;
     }
 
@@ -82,6 +89,15 @@ namespace gsd
             if(!this->TcpNettyLogin){
                 this->TCPLoginNetty();
             }
+            NettyClientResultMsg<SendHeartBeat> nettyClientResultMsg;
+            std::string RequestId = uuid::generate();
+            nettyClientResultMsg.setRequestId(RequestId);
+            nettyClientResultMsg.setDataType(NettyClientCommandEnum().heartbeat);
+            std::string json;
+            nettyClientResultMsg.objectToJson(json);
+            json += "\r\n";
+            this->sendRequest(RequestId, NettyClientCommandEnum().heartbeat, json, [&](int status,std::string buf){
+            });
         }
         else{
             this->tcpClient->startConnect(config::getPtr()->NettyIP, config::getPtr()->NettyPort);
@@ -100,7 +116,7 @@ namespace gsd
         sendLogin.setPwd(md5(m_config->usr + m_config->pwd));
         DebugL << "VPN_IP:" << m_config->vpnIP << endl;
         sendLogin.setCameraIp(m_config->vpnIP);
-        sendLogin.setSimCode(m_config->SimCode);
+        sendLogin.setSimCode(m_config->getSimCode());
         std::string str;
         DeviceInfo deviceInfo;
         deviceInfo.localIp = m_config->vpnIP;
@@ -150,6 +166,8 @@ namespace gsd
     void TcpPlugin::ListenNettyData(const Buffer::Ptr &buf)
     {
         std::string json = buf->toString();
+        // 避免Netty回复的数据粘连
+        json = json.substr(0, json.find("\r\n"));
         if(config::getPtr()->debug) DebugL << json << endl;
         NettyServerResultMsg<RecDeviceCommand> nettyServerResultMsg;
         NettyServerResultMsg<RecLoginMsg> NettyServerResultMsgLogin;
@@ -185,6 +203,8 @@ namespace gsd
                 InfoL << "连接Netty成功,发送登录信息" << endl;
                 this->TCPLoginNetty();
             }
+        }else{
+            WarnL;
         }
     }
 

+ 9 - 9
source/UserApp/src/UserApp.cpp

@@ -30,7 +30,7 @@ namespace gsd
         InfoL << "Starting Device, SN:" <<  config::getPtr()->getSimCode() << ",gsdApp:" <<  config::getPtr()->getApp() << ", Address:" <<  config::getPtr()->vpnIP << ", Version:" <<  config::getPtr()->getVersion() << ", Low:" <<  config::getPtr()->LowVersion << endl;
         
         // HttpPlugin
-        if(this->m_HttpPlugin == nullptr) m_HttpPlugin = HttpPlugin::CreateNew();
+        if(this->m_HttpPlugin == nullptr) m_HttpPlugin = HttpPlugin::getPtr();
         if(this->m_HttpPlugin == nullptr){
             ErrorL << "Httpplugin cannot be created" << endl;
             return false;
@@ -88,15 +88,15 @@ namespace gsd
                 return true;
             }, nullptr);
         }
-  
+
         // TCP启动任务
-        this->m_TcpPlugin->StartTask();
+        if(this->m_TcpPlugin != nullptr) this->m_TcpPlugin->StartTask();
         // Expel启动任务
-        this->m_ExpelPlugin->StartTask();
+        if(this->m_ExpelPlugin != nullptr) this->m_ExpelPlugin->StartTask();
         // Monitor启动任务
-        this->m_MonitorPlugin->StartTask();
+        if(this->m_MonitorPlugin != nullptr) this->m_MonitorPlugin->StartTask();
         // HTTP启动任务
-        this->m_HttpPlugin->StartTask();
+        if(this->m_HttpPlugin != nullptr) this->m_HttpPlugin->StartTask();
         
         return true;
     }  
@@ -107,9 +107,9 @@ namespace gsd
      * @return {*}
      */        
     void UserApp::Destroy(){
-        this->m_MonitorPlugin->Destroy();
-        this->m_TcpPlugin->Destroy();
-        this->m_HttpPlugin->Destroy();
+        if(this->m_MonitorPlugin != nullptr) this->m_MonitorPlugin->Destroy();
+        if(this->m_TcpPlugin != nullptr)  this->m_TcpPlugin->Destroy();
+        if(this->m_HttpPlugin != nullptr) this->m_HttpPlugin->Destroy();
     }
 
     /**

+ 2 - 0
source/src/main.cpp

@@ -39,6 +39,8 @@ int main(int argc, char* argv[]){
     // 启动任务
     app->StartTask();
     
+    sem.wait();
+
     InfoL << "app Destroy" << endl;
 
     app->Destroy();

+ 10 - 0
tools/Deploy.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+cp ../build/source/gsd ~/Desktop/Deploy/new/GSD/source/gsd/bin/
+cp ../lib/* ~/Desktop/Deploy/new/GSD/source/gsd/lib/
+
+sudo cp ~/Desktop/develop/GSD/GSD_CNStream/gsdv3.0/CNStream/lib/* /home/sunwin/Desktop/Deploy/new/GSD/source/CNStream/lib
+sudo cp ~/Desktop/develop/GSD/GSD_CNStream/gsdv3.0/CNStream/easydk/lib/* /home/sunwin/Desktop/Deploy/new/GSD/source/CNStream/lib
+sudo cp ~/Desktop/develop/GSD/GSD_CNStream/gsdv3.0/CNStream/3rdparty/live555/lib/* /home/sunwin/Desktop/Deploy/new/GSD/source/CNStream/lib
+sudo cp ~/Desktop/develop/GSD/GSD_CNStream/gsdv3.0/CNStream/3rdparty/libyuv/lib/*  /home/sunwin/Desktop/Deploy/new/GSD/source/CNStream/lib
+sudo cp ~/Desktop/develop/GSD/GSD_CNStream/gsdv3.0/CNStream/source/bin/main  /home/sunwin/Desktop/Deploy/new/GSD/source/CNStream/bin