From 50af73c5938b2114808f4c582251fc507d8dc8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AE=87=E8=A1=A1?= Date: Thu, 1 Jun 2023 17:17:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=A4=A7=E5=8D=8Esd?= =?UTF-8?q?k=E7=9A=84=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F=20=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E4=BA=86=E5=A4=A7=E5=8D=8E=E6=8E=A5=E5=8F=A3=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CommonCamera/include/DaHua.h | 16 ++++++++++--- CommonCamera/include/HikVision.h | 1 - CommonCamera/src/DaHuaImpl.cpp | 24 +++++++++---------- CommonCamera/src/HikVisionImpl.cpp | 1 + .../{include => src}/dahua/avglobal.h | 0 .../{include => src}/dahua/dhconfigsdk.h | 0 .../{include => src}/dahua/dhnetsdk.h | 0 .../{include => src}/hikvision/DataType.h | 0 .../hikvision/DecodeCardSdk.h | 0 .../{include => src}/hikvision/HCNetSDK.h | 0 .../{include => src}/hikvision/plaympeg4.h | 0 tests/main.cpp | 5 ++-- 12 files changed, 29 insertions(+), 18 deletions(-) rename CommonCamera/{include => src}/dahua/avglobal.h (100%) rename CommonCamera/{include => src}/dahua/dhconfigsdk.h (100%) rename CommonCamera/{include => src}/dahua/dhnetsdk.h (100%) rename CommonCamera/{include => src}/hikvision/DataType.h (100%) rename CommonCamera/{include => src}/hikvision/DecodeCardSdk.h (100%) rename CommonCamera/{include => src}/hikvision/HCNetSDK.h (100%) rename CommonCamera/{include => src}/hikvision/plaympeg4.h (100%) diff --git a/CommonCamera/include/DaHua.h b/CommonCamera/include/DaHua.h index 7cadcca..34cbe3f 100644 --- a/CommonCamera/include/DaHua.h +++ b/CommonCamera/include/DaHua.h @@ -6,7 +6,7 @@ #include #include "Camera.h" -#include "dahua/dhnetsdk.h" + #define DH_CHANNEL 0 @@ -23,6 +23,8 @@ private: std::mutex usable_mutex_; std::mutex operate_mutex_; + bool connected_ = false; + public: typedef std::shared_ptr Ptr; @@ -39,6 +41,16 @@ public: ~DaHua() override; public: + bool connected() { + std::lock_guard lock(usable_mutex_); + return connected_; + } + + void set_connect(bool connected) { + std::lock_guard lock(usable_mutex_); + connected_ = connected; + } + PTZ_INFO::Ptr get_ptz_range() override; PTZ_INFO::Ptr get_ptz() override; @@ -113,8 +125,6 @@ private: void login(); void logout(); - - fDisConnect dis_connect_callback_ = nullptr; }; } // namespace CC \ No newline at end of file diff --git a/CommonCamera/include/HikVision.h b/CommonCamera/include/HikVision.h index 3273e98..a287fc0 100644 --- a/CommonCamera/include/HikVision.h +++ b/CommonCamera/include/HikVision.h @@ -6,7 +6,6 @@ #include #include "Camera.h" -#include "hikvision/HCNetSDK.h" #include #include diff --git a/CommonCamera/src/DaHuaImpl.cpp b/CommonCamera/src/DaHuaImpl.cpp index c27a88a..7d082b4 100644 --- a/CommonCamera/src/DaHuaImpl.cpp +++ b/CommonCamera/src/DaHuaImpl.cpp @@ -3,6 +3,7 @@ // #include "DaHua.h" +#include "dahua/dhnetsdk.h" #include #include #include @@ -63,7 +64,13 @@ bool DaHua::snapshot(const std::string &path) { DaHua::DaHua(std::string ip, std::string username, std::string password) : ip_(std::move(ip)), username_(std::move(username)), password_(std::move(password)) { - CLIENT_Init(dis_connect_callback_, (LDWORD)this); + CLIENT_Init( + [](LLONG lLoginID, char *ip, LONG port, LDWORD dwUser) { + // 断线重连 + ((DaHua *)dwUser)->set_connect(false); + ((DaHua *)dwUser)->login(); + }, + (LDWORD)this); login(); } @@ -80,6 +87,9 @@ void DaHua::login() { out_param.dwSize = sizeof(out_param); login_handle_ = CLIENT_LoginWithHighLevelSecurity(&in_param, &out_param); + if (login_handle_ > 0) { + set_connect(true); + } } void DaHua::move_up(float speed) { @@ -140,17 +150,7 @@ void DaHua::move_up() { } bool DaHua::usable() { - std::unique_lock lock(usable_mutex_); - if (login_handle_ > 0) { - // 如果已经是登录过的重新尝试登录避免因为超时导致的操作失败 - logout(); - login(); - } - if (login_handle_ <= 0) { - login(); - return false; - } - return true; + return connected() && login_handle_ > 0; } PTZ_INFO::Ptr DaHua::get_ptz_range() { diff --git a/CommonCamera/src/HikVisionImpl.cpp b/CommonCamera/src/HikVisionImpl.cpp index a2ac0d4..326cda7 100644 --- a/CommonCamera/src/HikVisionImpl.cpp +++ b/CommonCamera/src/HikVisionImpl.cpp @@ -4,6 +4,7 @@ #include "HikVision.h" +#include "hikvision/HCNetSDK.h" namespace CC { diff --git a/CommonCamera/include/dahua/avglobal.h b/CommonCamera/src/dahua/avglobal.h similarity index 100% rename from CommonCamera/include/dahua/avglobal.h rename to CommonCamera/src/dahua/avglobal.h diff --git a/CommonCamera/include/dahua/dhconfigsdk.h b/CommonCamera/src/dahua/dhconfigsdk.h similarity index 100% rename from CommonCamera/include/dahua/dhconfigsdk.h rename to CommonCamera/src/dahua/dhconfigsdk.h diff --git a/CommonCamera/include/dahua/dhnetsdk.h b/CommonCamera/src/dahua/dhnetsdk.h similarity index 100% rename from CommonCamera/include/dahua/dhnetsdk.h rename to CommonCamera/src/dahua/dhnetsdk.h diff --git a/CommonCamera/include/hikvision/DataType.h b/CommonCamera/src/hikvision/DataType.h similarity index 100% rename from CommonCamera/include/hikvision/DataType.h rename to CommonCamera/src/hikvision/DataType.h diff --git a/CommonCamera/include/hikvision/DecodeCardSdk.h b/CommonCamera/src/hikvision/DecodeCardSdk.h similarity index 100% rename from CommonCamera/include/hikvision/DecodeCardSdk.h rename to CommonCamera/src/hikvision/DecodeCardSdk.h diff --git a/CommonCamera/include/hikvision/HCNetSDK.h b/CommonCamera/src/hikvision/HCNetSDK.h similarity index 100% rename from CommonCamera/include/hikvision/HCNetSDK.h rename to CommonCamera/src/hikvision/HCNetSDK.h diff --git a/CommonCamera/include/hikvision/plaympeg4.h b/CommonCamera/src/hikvision/plaympeg4.h similarity index 100% rename from CommonCamera/include/hikvision/plaympeg4.h rename to CommonCamera/src/hikvision/plaympeg4.h diff --git a/tests/main.cpp b/tests/main.cpp index b3f9051..fca3fa5 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -5,9 +5,10 @@ int main() { auto cam = CC::make_dahua_camera("192.168.163.4", "admin", "eccom123"); - std::cout<get_ptz_info()->str()<get_fov_info()->str()<zoom(50); std::this_thread::sleep_for(std::chrono::milliseconds (10000)); - std::cout<get_ptz_info()->str()<zoom(0); + std::cout<get_fov_info()->str()<