From 002d24e2b07cead369fad523a72196236cf8ce23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=B8=85=E9=94=9F?= <811096647@qq.com> Date: Tue, 22 Oct 2024 15:20:51 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=B7=BB=E5=8A=A0=20=E8=8E=B7=E5=8F=96=20?= =?UTF-8?q?Nvr=20=E4=B8=8E=20UTC=20=E4=B9=8B=E9=97=B4=E7=9A=84=E6=8F=92?= =?UTF-8?q?=E6=9B=B2=E6=8E=A5=E5=8F=A3=202.=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?=E7=90=83=E6=9C=BA=E8=81=9A=E7=84=A6=E6=8E=A5=E5=8F=A3=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E9=94=99=E8=AF=AF=203.=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20PTZ=20=E8=B7=B3=E8=BD=AC=E5=88=B0=E6=8C=87=E5=AE=9A=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=20Action=20=E5=8F=82=E6=95=B0=E6=A0=87=E5=87=86?= =?UTF-8?q?=E6=B5=B7=E5=BA=B7=E6=8E=A5=E5=8F=A3=E4=B8=8B=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98,=E4=BB=A5=E5=8F=8A=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=AE=BE=E7=BD=AEZ=E5=80=BC=204.=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=20GetBallCameraByName=205.=20=E6=B7=BB=E5=8A=A0=20PointPair=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hikvision.go | 7 +++---- Type.go | 42 +++++++++++++++++++++--------------------- include/library.h | 1 + library.cpp | 5 +++++ src/HIKBallCamera.cpp | 13 +++++++------ src/HIKNvr.cpp | 5 ++--- src/HIKNvr.h | 2 +- 7 files changed, 40 insertions(+), 35 deletions(-) diff --git a/Hikvision.go b/Hikvision.go index 2783425..0990990 100644 --- a/Hikvision.go +++ b/Hikvision.go @@ -163,13 +163,12 @@ func (h *HIKBallCamera) PTZ2FullView() (Point, error) { if !h.PTZGet(&ptz.P, &ptz.T, &ptz.Z) { return Point{}, fmt.Errorf("PTZ Get Error") } - h.WarpingPtByHomography(h.BallCameraCfg.Matrix.InvMatrix, Point{ + return h.WarpingPtByHomography(h.BallCameraCfg.Matrix.InvMatrix, Point{ X: h.mapping(h.BallCameraCfg.Matrix.PStart, h.BallCameraCfg.Matrix.PMax, float64(ptz.P), h.BallCameraCfg.Matrix.PPositiveDirection, ""), - Y: h.mapping(h.BallCameraCfg.Matrix.TStart, h.BallCameraCfg.Matrix.TMax, float64(ptz.T), h.BallCameraCfg.Matrix.TPositiveDirection, "")}) - return Point{}, nil + Y: h.mapping(h.BallCameraCfg.Matrix.TStart, h.BallCameraCfg.Matrix.TMax, float64(ptz.T), h.BallCameraCfg.Matrix.TPositiveDirection, "")}), nil } -func (hikBC *HIKBallCamera) invert3x3() bool { +func (hikBC *HIKBallCamera) Invert3x3() bool { a := hikBC.BallCameraCfg.Matrix.Matrix[0] b := hikBC.BallCameraCfg.Matrix.Matrix[1] diff --git a/Type.go b/Type.go index 6398287..3d3847a 100644 --- a/Type.go +++ b/Type.go @@ -3,25 +3,25 @@ package HikNetSDK import "encoding/json" type HikCfg struct { - Nvr []Nvr `json:"Nvr"` - BallCamera []BallCamera `json:"BallCamera"` + Nvr map[string]Nvr `json:"Nvr"` + BallCamera map[string]BallCamera `json:"BallCamera"` } type Nvr struct { - Name string `json:"name"` - Ip string `json:"ip"` - Port string `json:"port"` - User string `json:"user"` + Name string `json:"Name"` + Ip string `json:"Ip"` + Port string `json:"Port"` + User string `json:"User"` Password string `json:"Password"` Channel int `json:"Channel"` } type BallCamera struct { Type string `json:"Type"` - Name string `json:"name"` - Ip string `json:"ip"` - Port string `json:"port"` - User string `json:"user"` + Name string `json:"Name"` + Ip string `json:"Ip"` + Port string `json:"Port"` + User string `json:"User"` Password string `json:"Password"` RtspUrl string `json:"RtspUrl"` Matrix Matrix `json:"Matrix"` @@ -37,8 +37,17 @@ type Matrix struct { TPositiveDirection string `json:"T_Positive_Direction"` Matrix []float64 `json:"Matrix"` InvMatrix []float64 `json:"InvMatrix"` + PointSet map[string]PointPair `json:"PointSet"` } +type PointPair struct { + X float64 `json:"X"` + Y float64 `json:"Y"` + P float64 `json:"P"` + T float64 `json:"T"` +} + + type PTZ struct { P float32 `json:"P"` T float32 `json:"T"` @@ -50,8 +59,8 @@ type MoveCfg struct { Direction int `json:"Direction"` } type Point struct { - X float64 `json:"x"` - Y float64 `json:"y"` + X float64 `json:"X"` + Y float64 `json:"Y"` } func (h *HikCfg) Json() []byte { @@ -61,12 +70,3 @@ func (h *HikCfg) Json() []byte { } return marshal } - -func (h *HikCfg) GetBallCameraByName(name string) *BallCamera { - for i, camera := range h.BallCamera { - if camera.Name == name { - return &h.BallCamera[i] - } - } - return nil -} diff --git a/include/library.h b/include/library.h index 98fe317..d1146f5 100644 --- a/include/library.h +++ b/include/library.h @@ -29,6 +29,7 @@ extern "C" { Omnimatrix bool InitNvr(void* PtrHIKNvr,char* ip, char* port, char* username, char* password, int channel); Omnimatrix char* CheckTimeRegionWithMonth(void* PtrHIKNvr,int year,int month); Omnimatrix char* CheckTimeRegionWithDay(void* PtrHIKNvr,int year,int month,int day); + Omnimatrix int NvrUTCDiff(); #ifdef __cplusplus } diff --git a/library.cpp b/library.cpp index 981da3c..f843071 100644 --- a/library.cpp +++ b/library.cpp @@ -83,4 +83,9 @@ char* CheckTimeRegionWithDay(void* PtrHIKNvr,int year,int month,int day){ char* cString = new char[res.size() + 1]; std::strcpy(cString,res.c_str()); return cString; +} + +int NvrUTCDiff(void* PtrHIKNvr){ + auto* HIKNvrObj = (HIKNvr*)PtrHIKNvr; + return HIKNvrObj->GetNvrUTCDiff(); } \ No newline at end of file diff --git a/src/HIKBallCamera.cpp b/src/HIKBallCamera.cpp index c84cae3..db35f15 100644 --- a/src/HIKBallCamera.cpp +++ b/src/HIKBallCamera.cpp @@ -148,7 +148,7 @@ bool HIKBallCamera::PtzControlFocusAdd(int speed,int state){ SerialSend(PrepareHexString("ff 01 01 00 00 00 02")); return true; }else{ - return PtzControl(ZOOM_OUT, state, speed); + return PtzControl(FOCUS_FAR, state, speed); } } @@ -158,7 +158,7 @@ bool HIKBallCamera::PtzControlFocusSub(int speed,int state){ SerialSend(PrepareHexString("ff 01 00 80 00 00 81")); return true; }else{ - return PtzControl(ZOOM_OUT, state, speed); + return PtzControl(FOCUS_NEAR, state, speed); } } @@ -283,7 +283,8 @@ bool HIKBallCamera::PtzGotoPut(int Action, float P, float T, float Z) NET_DVR_PTZPOS ptzPosCurrent; ptzPosCurrent.wPanPos = DEC2HEX(P); ptzPosCurrent.wTiltPos = DEC2HEX(T); - ptzPosCurrent.wAction = 5; + ptzPosCurrent.wZoomPos = DEC2HEX(Z); + ptzPosCurrent.wAction = Action; bool b = NET_DVR_SetDVRConfig(LoginID, NET_DVR_SET_PTZPOS, m_Channel, &ptzPosCurrent, sizeof(NET_DVR_PTZPOS)); return b; @@ -315,9 +316,9 @@ bool HIKBallCamera::PtzGet(float* posP, float* posT, float* posZ) { float P = HEX2DEC(ptzPosCurrent.wPanPos); float T = HEX2DEC(ptzPosCurrent.wTiltPos); float Z = HEX2DEC(ptzPosCurrent.wZoomPos); - posP = &P; - posT = &T; - posZ = &Z; + *posP = P; + *posT = T; + *posZ = Z; return b; } } diff --git a/src/HIKNvr.cpp b/src/HIKNvr.cpp index 50746a2..bd1fdbf 100644 --- a/src/HIKNvr.cpp +++ b/src/HIKNvr.cpp @@ -27,15 +27,14 @@ bool HIKNvr::InitNvr(std::string ip, std::string port, std::string username, std return false; } -bool HIKNvr::GetNvrUTCDiff(){ +int HIKNvr::GetNvrUTCDiff(){ NET_DVR_NETAPPCFG struNAC = {0}; DWORD ZoneSize = 0; NET_DVR_GetDVRConfig(LoginID, NET_DVR_GET_NETAPPCFG, 0, &struNAC, sizeof(NET_DVR_NETAPPCFG), &ZoneSize); int nDiffHour = struNAC.struNtpClientParam.cTimeDifferenceH; int nDiffMin = struNAC.struNtpClientParam.cTimeDifferenceM; - nDiffTotalMin = (nDiffHour < 0 ? -1 : 1) * (abs(nDiffHour) * 60 + nDiffMin); - return true; + return (nDiffHour < 0 ? -1 : 1) * (abs(nDiffHour) * 60 + nDiffMin); } /** diff --git a/src/HIKNvr.h b/src/HIKNvr.h index 99d23a9..d50414a 100644 --- a/src/HIKNvr.h +++ b/src/HIKNvr.h @@ -42,7 +42,7 @@ public: //though input SelectTime get the time region bool GetTimeRegion(DateTime select_time,int value ,DateTime &time_start,DateTime &time_end); - bool GetNvrUTCDiff(); + int GetNvrUTCDiff(); int nDiffTotalMin; public: