修改了大华sdk的实现方式

提高了大华接口的调用速度
This commit is contained in:
张宇衡 2023-06-01 17:17:41 +08:00
parent 005ce8cb29
commit 50af73c593
12 changed files with 29 additions and 18 deletions

View File

@ -6,7 +6,7 @@
#include <utility>
#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<DaHua> Ptr;
@ -39,6 +41,16 @@ public:
~DaHua() override;
public:
bool connected() {
std::lock_guard<std::mutex> lock(usable_mutex_);
return connected_;
}
void set_connect(bool connected) {
std::lock_guard<std::mutex> 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

View File

@ -6,7 +6,6 @@
#include <utility>
#include "Camera.h"
#include "hikvision/HCNetSDK.h"
#include <cmath>
#include <iostream>

View File

@ -3,6 +3,7 @@
//
#include "DaHua.h"
#include "dahua/dhnetsdk.h"
#include <cmath>
#include <iostream>
#include <thread>
@ -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<std::mutex> 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() {

View File

@ -4,6 +4,7 @@
#include "HikVision.h"
#include "hikvision/HCNetSDK.h"
namespace CC {

View File

@ -5,9 +5,10 @@
int main() {
auto cam = CC::make_dahua_camera("192.168.163.4", "admin", "eccom123");
std::cout<<cam->get_ptz_info()->str()<<std::endl;
std::cout<<cam->get_fov_info()->str()<<std::endl;
cam->zoom(50);
std::this_thread::sleep_for(std::chrono::milliseconds (10000));
std::cout<<cam->get_ptz_info()->str()<<std::endl;
cam->zoom(0);
std::cout<<cam->get_fov_info()->str()<<std::endl;
return 0;
}