Browse Source

大致的框架

Your Name 2 years ago
parent
commit
a867700f9f

+ 8 - 0
framework/core/include/UtilBase.hpp

@@ -6,6 +6,7 @@
 #include <memory>
 #include <vector>
 
+#include "SendDevice.h"
 #include "NonCopyAble.hpp"
 
 namespace gsd{
@@ -77,6 +78,13 @@ namespace gsd{
         };
 
         /**
+         * @description: 构建设备信息
+         * @param {SendDevice&} sendDevice
+         * @return {*}
+         */        
+        virtual void BuildDeviceInfo(SendDevice& sendDevice) {};
+
+        /**
          * @description: 常规控制
          * @param {string} _deviceId 设备Id
          * @param {uint8_t*} data 数据

+ 8 - 1
framework/request/include/BasicConfig.h

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-28 09:03:02
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 10:40:09
+ * @LastEditTime: 2022-08-23 16:01:50
  */
 #ifndef __BASICECONFIG_H_
 #define __BASICECONFIG_H_
@@ -54,6 +54,8 @@ public:
     
     std::string payServerIP = "10.81.160.141";
 
+    int filterLevel = 2;
+
 public:
     BasicConfig(){}
     ~BasicConfig(){}
@@ -181,6 +183,11 @@ public:
         if(end != doc.FindMember("payServerIP") && doc["payServerIP"].IsString()){
             payServerIP = doc["payServerIP"].GetString();
         }
+
+        if(end != doc.FindMember("filterLevel") && doc["filterLevel"].IsString()){
+            filterLevel = std::atoi(doc["filterLevel"].GetString());
+        }
+
         return true;
     }
 };

BIN
lib/libgsd_core.so


BIN
lib/libgsd_modules.so


BIN
lib/libgsd_plugins.so


+ 7 - 0
modules/Expel/include/DevicePlayerV1.hpp

@@ -107,6 +107,13 @@ namespace gsd{
         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);
     };
 };
 

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

@@ -19,9 +19,12 @@
 #include "DevicePlayerV4.hpp"
 #include "DeviceGasV1.hpp"
 #include "config.hpp"
-
+#include <iostream>
 #include "PlayerStatus.h"
+#include "uuid.hpp"
+#include "Notices.h"
 
+using namespace utility;
 using namespace toolkit;
 using namespace itas109;
 

+ 21 - 0
modules/Expel/src/DevicePlayerV1.cpp

@@ -186,4 +186,25 @@ namespace gsd
         data[9] = 0x0D;
         data[10] = 0x0A;
     }
+
+    /**
+     * @description: 构建设备信息
+     * @param {SendDevice&} sendDevice
+     * @return {*}
+     */    
+    void DevicePlayerV1::BuildDeviceInfo(SendDevice& sendDevice){
+        sendDevice.deviceId = atoi(this->getDeviceId().c_str());
+        sendDevice.commandCode = "1";
+        sendDevice.status = 1;
+        sendDevice.workStatus = 1;
+        sendDevice.powerStatus = 1;
+        sendDevice.batteryStatus = 1;
+        sendDevice.num  = 0;
+        sendDevice.oxyPressure  = 0;
+        sendDevice.gasPressure  = 0;
+        sendDevice.remark = "";
+        sendDevice.attr1 = std::to_string(this->getVoltage());     // 电压
+        sendDevice.attr2 = std::to_string(this->getCurent());     // 电流
+        sendDevice.attr3 = std::to_string(this->getPressure());    // 声压
+    }
 } // namespace gsd

+ 59 - 57
modules/Expel/src/Expel.cpp

@@ -19,32 +19,32 @@ namespace gsd
      * @return {*}
      */    
     void Expel::sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice){
-        // RecDeviceCommand recDeviceCommand;
-        // recDeviceCommand = nettyServerResultMsg.getData();
-        // std::string deviceId = to_string(recDeviceCommand.getDeviceId());
-        // int commandCode = atoi(recDeviceCommand.getCommandCode().c_str());
+        RecDeviceCommand recDeviceCommand;
+        recDeviceCommand = nettyServerResultMsg.getData();
+        std::string deviceId = to_string(recDeviceCommand.getDeviceId());
+        int commandCode = atoi(recDeviceCommand.getCommandCode().c_str());
 
-        // switch (commandCode)
-        // {
-        // // 查询
-        // case 1:
-        //     this->Status(expelDevice);
-        //     break;
-        // // 开启电源
-        // case 2:
-        //     this->Open(expelDevice);
-        //     break;
-        // // 关闭电源
-        // case 3:
-        //     this->Close(expelDevice);
-        //     break;
-        // // 开炮
-        // case 4:
-        //     this->Fire(expelDevice);
-        //     break;
-        // default:
-        //     break;
-        // }
+        switch (commandCode)
+        {
+        // 查询
+        case 1:
+            this->Status(expelDevice);
+            break;
+        // 开启电源
+        case 2:
+            this->Open(expelDevice);
+            break;
+        // 关闭电源
+        case 3:
+            this->Close(expelDevice);
+            break;
+        // 开炮
+        case 4:
+            this->Fire(expelDevice);
+            break;
+        default:
+            break;
+        }
     }
 
     /**
@@ -86,6 +86,9 @@ namespace gsd
         
         case DeviceType::DevicePlayerV3:
             deviceControl = std::make_shared<DevicePlayerV3>();
+            std::dynamic_pointer_cast<DevicePlayerV3>(deviceControl)->setServerCname(expelDevice.ServerCname);
+            std::dynamic_pointer_cast<DevicePlayerV3>(deviceControl)->setServerCpwd(expelDevice.ServerCpwd);
+            std::dynamic_pointer_cast<DevicePlayerV3>(deviceControl)->setServerIP(expelDevice.ServerIp);
             break;
 
         // case DeviceGasV3:
@@ -208,44 +211,42 @@ namespace gsd
     int32_t Expel::Control(std::shared_ptr<ContorlGear>& deviceControl, ExpelDevice& expelDevice, uint8_t* data, int& length, int type){
         std::lock_guard<mutex> gurad(m_mutex);
         deviceControl->setDeviceId(expelDevice.DeviceId);
-        // if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::serial){
-        //     CSerialPort ser;
-        //     config::Ptr m_config = config::getPtr();
-        //     if(m_config->debug) DebugL << "Serial control data:" << bytesToHexString(data, length) << endl;
-        //     ser.init(m_config->comPort.c_str());
-        //     ser.setBaudRate(deviceControl->getBaudRate());
-        //     if(!ser.open()){ 
-        //         ErrorL << "Open port falied!";
-        //         return -1;
-        //     }
-        //     if(ser.writeData((const char*)data, length) != length){
-        //         WarnL << "Control command failed" << endl;
-        //         return -1;
-        //     }
-        //     this->SerialReceive(ser, deviceControl);
-        //     ser.close();
-        //     return 0;
-       // }else if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::http){
-        if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::http){
+        if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::serial){
+            CSerialPort ser;
+            config::Ptr m_config = config::getPtr();
+            if(m_config->debug) DebugL << "Serial control data:" << bytesToHexString(data, length) << endl;
+            ser.init(m_config->comPort.c_str());
+            ser.setBaudRate(std::dynamic_pointer_cast<ContorlSerialBase>(deviceControl)->getBaudRate());
+            if(!ser.open()){ 
+                ErrorL << "Open port falied!";
+                return -1;
+            }
+            if(ser.writeData((const char*)data, length) != length){
+                WarnL << "Control command failed" << endl;
+                return -1;
+            }
+            this->SerialReceive(ser, deviceControl);
+            ser.close();
+            return 0;
+       }else if(deviceControl->getDeviceTool() == ContorlGear::DeviceTools::http){
             std::string serviceIP = "";
             if(config::getPtr()->getApp() == "gsd_SZX"){
                 serviceIP = config::getPtr()->payServerIP;
             }else{
                 serviceIP = expelDevice.ServerIp;
             }
-            
             if(serviceIP == ""){
                 ErrorL << "The device IP address is empty" << endl;
                 return -1;
             }
-            httplib::Client cli(expelDevice.ServerIp, config::getPtr()->ExpelPort);
+            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;
+                    // DebugL << res->body << endl;
                     return 0;
                 }else {
                     WarnL << res->body << endl;
@@ -288,16 +289,17 @@ namespace gsd
                         SendDevice sendDevice;
                         time_t timestamp;
                         NettyClientResultMsg<SendDevice> nettyClientResultMsg;
-                        // deviceControl->BuildDeviceInfo(sendDevice);
-                        // time(&timestamp);
-                        // sendDevice.msgTime = ctime(&timestamp);
-                        // std::string requestId;
-                        // requestId = uuid::generate();
-                        // nettyClientResultMsg.setRequestId(requestId);
-                        // nettyClientResultMsg.setDataType(NettyClientCommandEnum().device_info);
-                        // nettyClientResultMsg.setData(sendDevice);
-                        // nettyClientResultMsg.objectToJson(json);
-                        // NoticeCenter::Instance().emitEvent(NOTICE_DEVICEINFO, requestId ,json);
+                        deviceControl->BuildDeviceInfo(sendDevice);
+                        time(&timestamp);
+                        sendDevice.msgTime = ctime(&timestamp);
+                        std::string requestId;
+                        requestId = uuid::generate();
+                        nettyClientResultMsg.setRequestId(requestId);
+                        nettyClientResultMsg.setDataType(NettyClientCommandEnum().device_info);
+                        nettyClientResultMsg.setData(sendDevice);
+                        nettyClientResultMsg.objectToJson(json);
+
+                        NoticeCenter::Instance().emitEvent(NOTICE_DEVICEINFO, requestId ,json);
                     }
                     break;
                 }

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

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-02-23 09:32:08
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 15:01:24
+ * @LastEditTime: 2022-08-23 15:18:09
  */
 #include "HttpClient.hpp"
 
@@ -119,7 +119,7 @@ namespace gsd{
         };
         httplib::Params params;
         params.emplace("simCode", simCode);
-        if (auto res = m_httpClient->Post("/BMP-WEB/device/findBySimCode",headers, params)){
+        if (auto res = m_httpClient->Post("/BMP-BIRD/device/findBySimCode",headers, params)){
             if (res->status == 200) {
                 if(nettyHttpResultMsg.jsonToObject(res->body)){
                     return OK;

+ 11 - 5
modules/InfineFilter/include/InfineFilter.hpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-09 10:55:43
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 15:10:46
+ * @LastEditTime: 2022-08-23 16:04:10
  */
 #ifndef __INFINEFILTER_H_
 #define __INFINEFILTER_H_
@@ -53,6 +53,13 @@ namespace gsd
         //     超时时:舍弃历史记录
         int sensitivity = 2; // 灵敏度 
 
+        // 0 - 不过滤
+        // 1 - 参考上一个坐标、大小、数量, 如果类似则过滤
+        // 2 - 在1的基础上加入 时间间隔,如每2秒取一次结果
+        // 3 - 记录每一个结果,并设置超时机制,未超时时:判断当前推理结果与过去的坐标、大小、数量是否类似,类似则过滤
+        //     超时时:舍弃历史记录
+        int filterLevel = 2; // 过滤器等级
+
         int interval = 2000; // 时间间隔
 
         vector<HistoryData> HistoryDatas;
@@ -61,7 +68,6 @@ namespace gsd
         
         Timer::Ptr timer = nullptr;
 
-
     private:
         /**
          * @description: 跟上一次的判断结果
@@ -125,11 +131,11 @@ namespace gsd
         static std::shared_ptr<InfineFilter> getPtr();
 
         /**
-         * @description: 设置灵敏度
-         * @param {int} Sensitivity
+         * @description: 设置等级
+         * @param {int} FilterLevel
          * @return {*}
          */    
-        int8_t setSensitivity(int Sensitivity);
+        int8_t setFilterLevel(int FilterLevel);
 
         /**
          * @description: 设置时间间隔

+ 7 - 7
modules/InfineFilter/src/InfineFilter.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-09 10:58:34
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 15:11:34
+ * @LastEditTime: 2022-08-23 16:03:11
  */
 #include "InfineFilter.hpp"
 
@@ -32,7 +32,7 @@ namespace gsd
         // 过滤小目标
         MinBBoxFilter(cnStreamInferData);
 
-        switch (sensitivity)
+        switch (filterLevel)
         {
         case 0:
             result = OK;
@@ -94,13 +94,13 @@ namespace gsd
     }
 
     /**
-     * @description: 设置灵敏度
-     * @param {int} Sensitivity
+     * @description: 设置过滤器等级
+     * @param {int} FilterLevel
      * @return {*}
      */
-    int8_t InfineFilter::setSensitivity(int Sensitivity){
-        if(Sensitivity < 0 || Sensitivity > 3) return ERR;
-        this->sensitivity = Sensitivity;
+    int8_t InfineFilter::setFilterLevel(int FilterLevel){
+        if(FilterLevel < 0 || FilterLevel > 3) return ERR;
+        this->filterLevel = FilterLevel;
         return OK;
     }
 

+ 1 - 3
modules/TCPClient/src/TCPClient.cpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2021-09-14 09:12:25
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 10:24:11
+ * @LastEditTime: 2022-08-23 14:45:58
  */
 #include "TCPClient.hpp"
 
@@ -72,7 +72,6 @@ namespace gsd{
      * @return {*}
      */
     void TCPClient::sendRequest(std::string RequestId,std::string CommandEnum,  std::string& data,function<void(int, std::string)> t){
-        std::unique_lock<std::mutex> lk(m_mutex);
         if(CommandEnum != "heartbeat") InfoL << "requestId: " << RequestId + ", CommandEnum: " << CommandEnum  << endl;
         RequestAckTask acktask;
         acktask.ticker = std::make_shared<Ticker>();  // 创建滴答定时器
@@ -90,7 +89,6 @@ namespace gsd{
      * @return {*}
      */
     int TCPClient::requestAck(std::string& json){
-        std::unique_lock<std::mutex> lk(m_mutex);
         NettyServerResultMsg<RecLoginMsg> nettyServerResultMsg;   
         if(!nettyServerResultMsg.jsonToObject(json)) return Forbiddem;
         if(nettyServerResultMsg.getData().msg == "HeartBeat") return Ok;

+ 2 - 1
modules/config/include/config.hpp

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-07 11:52:08
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-22 14:01:46
+ * @LastEditTime: 2022-08-23 16:02:39
  */
 #ifndef __CONFIG_H_
 #define __CONFIG_H_
@@ -83,6 +83,7 @@ public:
 
     std::string payServerIP = "10.81.160.141";
 
+    int filterLevel = 2;
     
 protected:
     #ifdef RELEASE

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

@@ -4,7 +4,7 @@
  * @Autor: lishengyin
  * @Date: 2022-03-07 11:52:23
  * @LastEditors: lishengyin
- * @LastEditTime: 2022-08-23 10:41:38
+ * @LastEditTime: 2022-08-23 16:02:50
  */
 #include "config.hpp"
 #include "Shell.h"
@@ -174,6 +174,7 @@ bool config::getBasicConfig(){
                     this->ExpelPort = basicConfig.ExpelPort;
                     this->InferInterval = basicConfig.InferInterval;
                     this->payServerIP = basicConfig.payServerIP;
+                    this->filterLevel = basicConfig.filterLevel;
 
                     if(basicConfig.com_port != "") this->comPort = basicConfig.com_port;
 

+ 4 - 4
plugins/CMakeLists.txt

@@ -9,10 +9,10 @@ if(NOT COMPILER_SUPPORTS_CXX11)
 endif()
 
 # compile flags
-set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
+# set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-as-needed")
+# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O2")
+# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG -g")
+# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_REENTRANT -fPIC -Wall -Werror")
 
 # ---[ Options
 option(build_ExpelPlugin "build module ExpelPlugin" ON)

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

@@ -9,6 +9,8 @@
 #include <future>
 #include "Util/logger.h"
 #include "requests.hpp"
+#include "Expel.hpp"
+#include "InfineFilter.hpp"
 
 using namespace std;
 using namespace toolkit;
@@ -72,6 +74,14 @@ namespace gsd
         static void makeAddr(struct sockaddr *out,const char *ip,uint16_t port);
 
         /**
+         * @description: sendDeviceMsgCallback
+         * @param {NettyServerResultMsg<RecDeviceCommand>} &nettyServerResultMsg
+         * @param {ExpelDevice} expelDevice
+         * @return {*}
+         */        
+        void sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice);
+
+        /**
          * @description: ~ExpelPlugin
          * @return {*}
          */        
@@ -83,6 +93,7 @@ namespace gsd
     protected:  
         Socket::Ptr sockerUdp = nullptr;
         mutex m_mutex;
+        bool m_DevPowerState = false;
     };
 } // namespace gsd
 

+ 32 - 21
plugins/ExpelPlugin/src/ExpelPlugin.cpp

@@ -49,6 +49,7 @@ namespace gsd
             ErrorL << "Sockerudp cannot be created" << endl;
             return false;
         }
+
         // 数据接收
         this->sockerUdp->setOnRead([&](const Buffer::Ptr &buf, struct sockaddr *addr , int){
             this->UdpRecData(buf);
@@ -74,28 +75,28 @@ namespace gsd
             SqlWriter sqlSelete("SELECT DeviceId,DeviceToken,DeviceType, \
                 ServerIp,ServerCname,ServerCpwd FROM gsdDB.`DeviceList` WHERE ISDELETE = 0");
             sqlSelete << result;
+            Expel::getPtr()->UpdateDeviceList(result);
             
-            // Expel::getPtr()->UpdateDeviceList(result);
-            // InfineFilter::getPtr()->bboxSize = config::getPtr()->bboxSize;
-            // // 过滤小目标
-            // InfineFilter::getPtr()->MinBBoxFilter(cnstreamInferData);
-            // if(cnstreamInferData->Objects.size()){
-            //     if(ticker != nullptr) ticker->resetTime();
-            //     if(this -> m_DevPowerState == false){
-            //         // 控制驱鸟设备
-            //         Expel::getPtr() -> AllFire();
-            //         // 更新状态
-            //         this -> m_DevPowerState = true;
-            //     }
-            // }else{
-            //     if(ticker == nullptr) ticker = std::make_shared<Ticker>();
-            //     int time = config::getPtr()->ExpelInterval;
-            //     if(ticker->elapsedTime() > time && this->m_DevPowerState){
-            //         this->m_DevPowerState = false;
-            //         ticker = nullptr;
-            //         Expel::getPtr() -> AllClose();
-            //     }
-            // }
+            InfineFilter::getPtr()->bboxSize = config::getPtr()->bboxSize;
+            // 过滤小目标
+            InfineFilter::getPtr()->MinBBoxFilter(cnstreamInferData);
+            if(cnstreamInferData->Objects.size()){
+                if(ticker != nullptr) ticker->resetTime();
+                if(this -> m_DevPowerState == false){
+                    // 控制驱鸟设备
+                    Expel::getPtr() -> AllFire();
+                    // 更新状态
+                    this -> m_DevPowerState = true;
+                }
+            }else{
+                if(ticker == nullptr) ticker = std::make_shared<Ticker>();
+                int time = config::getPtr()->ExpelInterval;
+                if(ticker->elapsedTime() > time && this->m_DevPowerState){
+                    this->m_DevPowerState = false;
+                    ticker = nullptr;
+                    Expel::getPtr() -> AllClose();
+                }
+            }
         }
     }
 
@@ -113,4 +114,14 @@ namespace gsd
         servaddr.sin_addr.s_addr = inet_addr(ip);
         bzero(&(servaddr.sin_zero), sizeof servaddr.sin_zero);
     }
+
+    /**
+     * @description: sendDeviceMsgCallback
+     * @param {NettyServerResultMsg<RecDeviceCommand>} &nettyServerResultMsg
+     * @param {ExpelDevice} expelDevice
+     * @return {*}
+     */    
+    void ExpelPlugin::sendDeviceMsgCallback(NettyServerResultMsg<RecDeviceCommand> &nettyServerResultMsg, ExpelDevice expelDevice){
+        Expel::getPtr()->sendDeviceMsgCallback(nettyServerResultMsg, expelDevice);
+    }
 } // namespace gsd

+ 3 - 3
plugins/HttpPlugin/include/HttpPlugin.hpp

@@ -8,6 +8,8 @@
 #include "HttpClient.hpp"
 #include "requests.hpp"
 #include "ExpelDevice.h"
+#include "InfineFilter.hpp"
+
 
 using namespace std;
 using namespace toolkit;
@@ -29,9 +31,7 @@ namespace gsd
          * @description: CreateNew
          * @return {*}
          */        
-        static std::shared_ptr<HttpPlugin> CreateNew(){
-            return std::shared_ptr<HttpPlugin>(new HttpPlugin);
-        }
+        static std::shared_ptr<HttpPlugin> CreateNew();
 
         /**
          * @description: 初始化

+ 14 - 9
plugins/HttpPlugin/src/HttpPlugin.cpp

@@ -3,20 +3,20 @@
 namespace gsd
 {
 
-    // /**
-    //  * @description: CreateNew
-    //  * @return {*}
-    //  */    
-    // std::shared_ptr<HttpPlugin> HttpPlugin::CreateNew(){
-    //     return std::shared_ptr<HttpPlugin>(new HttpPlugin);
-    // }
+    /**
+     * @description: CreateNew
+     * @return {*}
+     */    
+    std::shared_ptr<HttpPlugin> HttpPlugin::CreateNew(){
+        return std::shared_ptr<HttpPlugin>(new HttpPlugin);
+    }
 
     /**
      * @description: 初始化
      * @return {*}
      */    
     bool HttpPlugin::Init(){
-        if(!config::getPtr()->debug) return true;
+        //if(!config::getPtr()->debug) return true;
         if(config::getPtr()->LowVersion) return true;
         if(this->m_httpClient == nullptr){
             this->m_httpClient = HttpClient::CreateNew();
@@ -38,6 +38,10 @@ namespace gsd
         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{
@@ -55,7 +59,7 @@ namespace gsd
      * @return {*}
      */    
     void HttpPlugin::Destroy(){
-
+        InfoL;
     }
 
     /**
@@ -98,6 +102,7 @@ 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;

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

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

+ 150 - 151
plugins/MonitorPlugin/src/MonitorPlugin.cpp

@@ -44,66 +44,65 @@ namespace gsd
      * @return {*}
      */
     void MonitorPlugin::MonitorProThrd(){
-        // FrameInferData::Ptr result = std::make_shared<FrameInferData>();
-        // if(!this->ConsumeData(result)) return;
-        // if(result->Num == 0) return;
-        // if(!app().getPlugin<TcpPlugin>()->getAlive()){
-        //     result->uuid = uuid::generate();
-        //     std::string sql = result->ObjectToSql();
-        //     SqlWriter insert(sql.c_str());
-        //     vector<vector<std::string>> ret;
-        //     insert << ret;
-        //     InfoL << "Save inferential Data, uuid:" << result->uuid << endl;
-        //     return;
-        // }
-
-        // config::Ptr m_config = config::getPtr();
-        // // 发送鸟情数据至后端  
-        // SendBird sendBird;
-        // sendBird.birdImageBase64 = "";
-        // if(!config::getPtr()->debug){
-        //     sendBird.birdImageBase64 = result->ImageBase64;
-        // }
-        // sendBird.birdNum = result->Num;
-        // sendBird.birdType = (NettyClientCommandEnum().bird_info);
+        FrameInferData::Ptr result = std::make_shared<FrameInferData>();
+        if(!this->ConsumeData(result)) return;
+        if(result->Num == 0) return;
+        if(!TcpPlugin::getPtr()->Alive()){
+            result->uuid = uuid::generate();
+            std::string sql = result->ObjectToSql();
+            SqlWriter insert(sql.c_str());
+            vector<vector<std::string>> ret;
+            insert << ret;
+            InfoL << "Save inferential Data, uuid:" << result->uuid << endl;
+            return;
+        }
+        config::Ptr m_config = config::getPtr();
+        // 发送鸟情数据至后端  
+        SendBird sendBird;
+        sendBird.birdImageBase64 = "";
+        if(!config::getPtr()->debug){
+            sendBird.birdImageBase64 = result->ImageBase64;
+        }
+        sendBird.birdNum = result->Num;
+        sendBird.birdType = (NettyClientCommandEnum().bird_info);
 
-        // if(!config::getPtr()->LowVersion) sendBird.deviceUuid = m_config->SimCode;
-        // else sendBird.deviceUuid = m_config->vpnIP;
+        if(!config::getPtr()->LowVersion) sendBird.deviceUuid = m_config->SimCode;
+        else sendBird.deviceUuid = m_config->vpnIP;
 
-        // sendBird.degree = 2;
-        // sendBird.remark = result->Remark;
-        // sendBird.heightRange = "0";
-        // sendBird.warningTime = result->WarningTime;
-        // sendBird.attr4 = result->VideoPath;
-        // sendBird.attr5 = "";
+        sendBird.degree = 2;
+        sendBird.remark = result->Remark;
+        sendBird.heightRange = "0";
+        sendBird.warningTime = result->WarningTime;
+        sendBird.attr4 = result->VideoPath;
+        sendBird.attr5 = "";
 
-        // HistoryVideo historyVideo;
-        // historyVideo.fileName = result->VideoPath;
-        // historyVideo.UpdateTime = result->WarningTime;
-        // this->SaveVideoRecord(historyVideo);
+        HistoryVideo historyVideo;
+        historyVideo.fileName = result->VideoPath;
+        historyVideo.UpdateTime = result->WarningTime;
+        this->SaveVideoRecord(historyVideo);
 
-        // NettyClientResultMsg <SendBird> nettyClientResultMsg;
-        // std::string RequestId = uuid::generate();
-        // result->uuid = RequestId;
-        // nettyClientResultMsg.setRequestId(RequestId);
-        // nettyClientResultMsg.setData(sendBird);
-        // nettyClientResultMsg.setDataType((NettyClientCommandEnum().bird_info));
+        NettyClientResultMsg <SendBird> nettyClientResultMsg;
+        std::string RequestId = uuid::generate();
+        result->uuid = RequestId;
+        nettyClientResultMsg.setRequestId(RequestId);
+        nettyClientResultMsg.setData(sendBird);
+        nettyClientResultMsg.setDataType((NettyClientCommandEnum().bird_info));
 
-        // std::string json;
-        // nettyClientResultMsg.objectToJson(json);
-        // json += "\r\n";
-        // std::string sql = result->ObjectToSql();
+        std::string json;
+        nettyClientResultMsg.objectToJson(json);
+        json += "\r\n";
+        std::string sql = result->ObjectToSql();
 
-        // if(app().getPlugin<TcpPlugin>()->getAlive()){
-        //     app().getPlugin<TcpPlugin>()->sendRequest(RequestId, NettyClientCommandEnum().bird_info, json, [&, sql](int status,std::string pbuf){
-        //         if(!config::getPtr()->LowVersion){
-        //             if(status == 200) return;
-        //             SqlWriter insert(sql.c_str());
-        //             vector<vector<std::string>> ret;
-        //             insert << ret;
-        //         }
-        //     });
-        // }
+        if(TcpPlugin::getPtr()->Alive()){
+            TcpPlugin::getPtr()->sendRequest(RequestId, NettyClientCommandEnum().bird_info, json, [&, sql](int status,std::string pbuf){
+                if(!config::getPtr()->LowVersion){
+                    if(status == 200) return;
+                    SqlWriter insert(sql.c_str());
+                    vector<vector<std::string>> ret;
+                    insert << ret;
+                }
+            });
+        }
     }
 
     /**
@@ -112,107 +111,106 @@ namespace gsd
     * @return {*}
     */
     bool MonitorPlugin::sendRequest(CNStreamInferData::Ptr data){
-        // FrameInferData::Ptr result = std::make_shared<FrameInferData>();
-        // InfineFilter::Ptr infineFilter = InfineFilter::getPtr();
-        // config::Ptr m_config = config::getPtr();
-
-        // if(!config::getPtr()->debug){
-        //     infineFilter->bboxSize = m_config->bboxSize;
-        //     // 设置
-        //     infineFilter->setSensitivity(m_config->sensitivity);
-        //     infineFilter->setInterval(m_config->interval);
-        //     infineFilter->setTimeOut(m_config->TimeOut);
-        //     if(infineFilter != nullptr) {
-        //         if(infineFilter->judgementResult(data) != OK){
-        //             return false;
-        //         }
-        //     }
-        // }
-
-        // rapidjson::StringBuffer buffer;
-        // rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
-        // writer.StartArray();
-        // for(auto &obj : data->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 = data->ImageBase64;
-        // result->Remark = buffer.GetString();
-        // result->Num = data->Objects.size();
-        // result->WarningTime = ctime;
-        // result->VideoPath = data->videoPath;
-        // if(result->Num == 0) return false;
+        FrameInferData::Ptr result = std::make_shared<FrameInferData>();
+        InfineFilter::Ptr infineFilter = InfineFilter::getPtr();
+        config::Ptr m_config = config::getPtr();
+        if(!config::getPtr()->debug){
+            infineFilter->bboxSize = m_config->bboxSize;
+            // 设置
+            infineFilter->setFilterLevel(m_config->filterLevel);
+            infineFilter->setInterval(m_config->interval);
+            infineFilter->setTimeOut(m_config->TimeOut);
+            if(infineFilter != nullptr) {
+                if(infineFilter->judgementResult(data) != OK){
+                    return false;
+                }
+            }
+        }
+        
+        rapidjson::StringBuffer buffer;
+        rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
+        writer.StartArray();
+        for(auto &obj : data->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 = data->ImageBase64;
+        result->Remark = buffer.GetString();
+        result->Num = data->Objects.size();
+        result->WarningTime = ctime;
+        result->VideoPath = data->videoPath;
+        if(result->Num == 0) return false;
         
-        // if(!app().getPlugin<TcpPlugin>()->getAlive()){
-        //     result->uuid = uuid::generate();
-        //     std::string sql = result->ObjectToSql();
-        //     SqlWriter insert(sql.c_str());
-        //     vector<vector<std::string>> ret;
-        //     insert << ret;
-        //     return true;
-        // }
-        // // 发送鸟情数据至后端  
-        // SendBird sendBird;
-        // sendBird.birdImageBase64 = "";
-        // if(!config::getPtr()->debug){
-        //     sendBird.birdImageBase64 = result->ImageBase64;
-        // }
-        // sendBird.birdNum = result->Num;
-        // sendBird.birdType = (NettyClientCommandEnum().bird_info);
-        // sendBird.deviceUuid = "";
+        if(!TcpPlugin::getPtr()->Alive()){
+            result->uuid = uuid::generate();
+            std::string sql = result->ObjectToSql();
+            SqlWriter insert(sql.c_str());
+            vector<vector<std::string>> ret;
+            insert << ret;
+            return true;
+        }
+        // 发送鸟情数据至后端  
+        SendBird sendBird;
+        sendBird.birdImageBase64 = "";
+        if(!config::getPtr()->debug){
+            sendBird.birdImageBase64 = result->ImageBase64;
+        }
+        sendBird.birdNum = result->Num;
+        sendBird.birdType = (NettyClientCommandEnum().bird_info);
+        sendBird.deviceUuid = "";
 
-        // if(!config::getPtr()->LowVersion) sendBird.deviceUuid = config::getPtr()->getSimCode();
-        // else sendBird.deviceUuid = config::getPtr()->vpnIP;
+        if(!config::getPtr()->LowVersion) sendBird.deviceUuid = config::getPtr()->getSimCode();
+        else sendBird.deviceUuid = config::getPtr()->vpnIP;
         
-        // sendBird.degree = 2;
-        // sendBird.remark = result->Remark;
-        // sendBird.heightRange = "0";
-        // sendBird.warningTime = result->WarningTime;
-        // sendBird.attr4 = result->VideoPath;
-        // sendBird.attr5 = "";
-        // HistoryVideo historyVideo;
-        // historyVideo.fileName = result->VideoPath;
-        // historyVideo.UpdateTime = result->WarningTime;
-        // this->SaveVideoRecord(historyVideo);
+        sendBird.degree = 2;
+        sendBird.remark = result->Remark;
+        sendBird.heightRange = "0";
+        sendBird.warningTime = result->WarningTime;
+        sendBird.attr4 = result->VideoPath;
+        sendBird.attr5 = "";
+        HistoryVideo historyVideo;
+        historyVideo.fileName = result->VideoPath;
+        historyVideo.UpdateTime = result->WarningTime;
+        this->SaveVideoRecord(historyVideo);
 
-        // NettyClientResultMsg <SendBird> nettyClientResultMsg;
-        // std::string RequestId = uuid::generate();
-        // result->uuid = RequestId;
-        // nettyClientResultMsg.setRequestId(RequestId);
-        // nettyClientResultMsg.setData(sendBird);
-        // nettyClientResultMsg.setDataType((NettyClientCommandEnum().bird_info));
-        // std::string json;
-        // nettyClientResultMsg.objectToJson(json);
-        // json += "\r\n";
-        // std::string sql = result->ObjectToSql();
-        // if(app().getPlugin<TcpPlugin>()->getAlive()){
-        //     app().getPlugin<TcpPlugin>()->sendRequest(RequestId, NettyClientCommandEnum().bird_info, json, [&, sql](int status,std::string pbuf){
-        //         if(!config::getPtr()->debug){
-        //             if(status == 200) return;
-        //             SqlWriter insert(sql.c_str());
-        //             vector<vector<std::string>> ret;
-        //             insert << ret;
-        //         }
-        //     });
-        // }else ErrorL;
+        NettyClientResultMsg <SendBird> nettyClientResultMsg;
+        std::string RequestId = uuid::generate();
+        result->uuid = RequestId;
+        nettyClientResultMsg.setRequestId(RequestId);
+        nettyClientResultMsg.setData(sendBird);
+        nettyClientResultMsg.setDataType((NettyClientCommandEnum().bird_info));
+        std::string json;
+        nettyClientResultMsg.objectToJson(json);
+        json += "\r\n";
+        std::string sql = result->ObjectToSql();
+        if(TcpPlugin::getPtr()->Alive()){
+            TcpPlugin::getPtr()->sendRequest(RequestId, NettyClientCommandEnum().bird_info, json, [&, sql](int status,std::string pbuf){
+                if(!config::getPtr()->debug){
+                    if(status == 200) return;
+                    SqlWriter insert(sql.c_str());
+                    vector<vector<std::string>> ret;
+                    insert << ret;
+                }
+            });
+        }else ErrorL;
         return true;
     }
 
@@ -252,6 +250,7 @@ namespace gsd
      * @return {*}
      */        
     void MonitorPlugin::Destroy(){
+        InfoL;
         stop_ = true;
     }
 

+ 10 - 1
plugins/TcpPlugin/include/TcpPlugin.hpp

@@ -8,6 +8,9 @@
 #include "config.hpp"
 #include "md5.h"
 #include "uuid.hpp"
+#include "ExpelDevice.h"
+#include "ExpelPlugin.hpp"
+#include "uuid.hpp"
 
 using namespace std;
 using namespace utility;
@@ -24,6 +27,12 @@ namespace gsd
         using Ptr = std::shared_ptr<TcpPlugin>;
         
         /**
+         * @description: getPtr
+         * @return {*}
+         */        
+        static std::shared_ptr<TcpPlugin> getPtr();
+
+        /**
          * @description: CreateNew
          * @return {*}
          */        
@@ -91,7 +100,7 @@ namespace gsd
         void sendRequest(std::string RequestId,std::string CommandEnum, std::string& data,function<void(int, std::string)> t);
 
     private:
-
+    
         // TCP对象
         TCPClient::Ptr tcpClient = nullptr;
         Timer::Ptr HeartbeatTimer = nullptr;

+ 46 - 25
plugins/TcpPlugin/src/TcpPlugin.cpp

@@ -11,15 +11,37 @@ namespace gsd
     }
 
     /**
+     * @description: 获取ptr
+     * @return {*}
+     */    
+    std::shared_ptr<TcpPlugin> TcpPlugin::getPtr(){
+        static std::shared_ptr<TcpPlugin> m_tcpplugin = nullptr;
+        if(m_tcpplugin == nullptr) m_tcpplugin = std::shared_ptr<TcpPlugin>(new TcpPlugin);
+        return m_tcpplugin;
+    }
+
+    /**
      * @description: 初始化
      * @return {*}
      */        
     bool TcpPlugin::Init(){
         this->tcpClient = std::shared_ptr<TCPClient>(new TCPClient);
+
+        // Netty数据
         NoticeCenter::Instance().addListener(0, NOTICE_NETTY,
             [&](const Buffer::Ptr &pBuf){
             this->ListenNettyData(pBuf);
         });
+
+        // 设备数据
+        NoticeCenter::Instance().addListener(0, NOTICE_DEVICEINFO,
+            [&](std::string requestId,std::string json){
+            if(this->Alive()){
+                json += "\r\n";
+                this->sendRequest(requestId, NettyClientCommandEnum().device_info, json,[&](int status,std::string buf){});
+            }
+        });
+
         this->pool = std::make_shared<ThreadPool>(1,ThreadPool::PRIORITY_HIGHEST, false);
         return true;
     }
@@ -48,6 +70,7 @@ namespace gsd
      * @return {*}
      */        
     void TcpPlugin::Destroy(){
+        InfoL;
     }
 
     /**
@@ -133,31 +156,29 @@ namespace gsd
         if(nettyServerResultMsg.jsonToObject(json)){
             if(config::getPtr()->debug) InfoL << "接收到控制指令" << endl;
             std::string deviceId = std::to_string(nettyServerResultMsg.getData().getDeviceId());
-            // ExpelDevice expelDevice;
-            // if(!config::getPtr()->LowVersion){
-            //     vector<vector<std::string>> results;
-            //     SqlWriter selete("SELECT DeviceToken,DeviceType,ServerIp,ServerCname,ServerCpwd FROM gsdDB.`DeviceList` WHERE DeviceId = '?' and ISDELETE=0");
-            //     selete << deviceId << results;
-            //     if(results.empty()){
-            //         WarnL << "No device is queried" << endl;
-            //         return;
-            //     }
-            //     expelDevice.DeviceId = deviceId;
-            //     expelDevice.deviceToken = (enum DeviceToken)std::atoi(results[0][0].c_str());
-            //     expelDevice.deviceType = (enum DeviceType)std::atoi(results[0][1].c_str());
-            //     expelDevice.ServerIp = results[0][2];
-            //     expelDevice.ServerCname = results[0][3];
-            //     expelDevice.ServerCpwd = results[0][4];
-            // }else{
-            //     expelDevice.DeviceId = deviceId;
-            //     expelDevice.deviceType = (enum DeviceType)config::getPtr()->deviceType;
-            //     expelDevice.deviceToken = serial;
-            // }
-            // this->pool->async([&,nettyServerResultMsg, expelDevice](){
-            //     NettyServerResultMsg<RecDeviceCommand> ResultMsg = nettyServerResultMsg;
-            //     Expel::getPtr() -> sendDeviceMsgCallback(ResultMsg, expelDevice);
-            // });
-            // this->pool->start();
+            ExpelDevice expelDevice;
+            if(!config::getPtr()->LowVersion){
+                vector<vector<std::string>> results;
+                SqlWriter selete("SELECT DeviceToken,DeviceType,ServerIp,ServerCname,ServerCpwd FROM gsdDB.`DeviceList` WHERE DeviceId = '?' and ISDELETE=0");
+                selete << deviceId << results;
+                if(results.empty()){
+                    WarnL << "No device is queried" << endl;
+                    return;
+                }
+                expelDevice.DeviceId = deviceId;
+                expelDevice.deviceType = (enum DeviceType)std::atoi(results[0][1].c_str());
+                expelDevice.ServerIp = results[0][2];
+                expelDevice.ServerCname = results[0][3];
+                expelDevice.ServerCpwd = results[0][4];
+            }else{
+                expelDevice.DeviceId = deviceId;
+                expelDevice.deviceType = (enum DeviceType)config::getPtr()->deviceType;
+            }
+            this->pool->async([&,nettyServerResultMsg, expelDevice](){
+                NettyServerResultMsg<RecDeviceCommand> ResultMsg = nettyServerResultMsg;
+                ExpelPlugin::getPtr() -> sendDeviceMsgCallback(ResultMsg, expelDevice);
+            });
+            this->pool->start();
         }else if(NettyServerResultMsgLogin.jsonToObject(json)){
             RecLoginMsg Loginmsg = NettyServerResultMsgLogin.getData();
             if(NettyServerResultMsgLogin.getDataType() == "client_conn_success"){

+ 1 - 2
source/UserApp/src/UserApp.cpp

@@ -41,7 +41,7 @@ namespace gsd
         }
 
         // TCPPlugin
-        if(this->m_TcpPlugin == nullptr) m_TcpPlugin = TcpPlugin::CreateNew();
+        if(this->m_TcpPlugin == nullptr) m_TcpPlugin = TcpPlugin::getPtr();
         if(this->m_TcpPlugin == nullptr){
             ErrorL << "TcpPlugin cannot be created" << endl;
             return false;
@@ -64,7 +64,6 @@ namespace gsd
             ErrorL << "MonitorPlugin init failed" << endl;
             return false;
         }
-
         return true;
     }
 

+ 3 - 0
source/src/main.cpp

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