1. 导出Core包
This commit is contained in:
parent
3124c12f67
commit
666ed24e73
@ -10,7 +10,7 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.com/kunmeng/HikNetSDKPkg/core"
|
||||
"gitea.com/kunmeng/HikNetSDKPkg/Core"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
@ -161,15 +161,15 @@ var HikPTZEnum = struct {
|
||||
}
|
||||
|
||||
type BallCamera struct {
|
||||
userId core.LONG
|
||||
userId Core.LONG
|
||||
_type uint8
|
||||
deviceInfo core.NET_DVR_DEVICEINFO_V30
|
||||
deviceInfo Core.NET_DVR_DEVICEINFO_V30
|
||||
mu sync.Mutex
|
||||
expectedType byte
|
||||
}
|
||||
|
||||
func NewBallCamera(Ip string, Port int, Username, Password string, Type uint8) (*BallCamera, error) {
|
||||
UserId, DeviceInfo, err := core.Login(Ip, Port, Username, Password)
|
||||
UserId, DeviceInfo, err := Core.Login(Ip, Port, Username, Password)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (this *BallCamera) GetPTZ() (PTZ, error) {
|
||||
var data PTZ
|
||||
|
||||
ch := make(chan bool)
|
||||
SerialStartHandle, err := core.SerialStart(this.userId, func(lSerialHandle core.LONG, lChannel core.LONG, pRecvDataBuffer []byte, dwBufSize core.DWORD, pUser unsafe.Pointer) {
|
||||
SerialStartHandle, err := Core.SerialStart(this.userId, func(lSerialHandle Core.LONG, lChannel Core.LONG, pRecvDataBuffer []byte, dwBufSize Core.DWORD, pUser unsafe.Pointer) {
|
||||
if dwBufSize != 7 {
|
||||
ch <- false
|
||||
return
|
||||
@ -220,7 +220,7 @@ func (this *BallCamera) GetPTZ() (PTZ, error) {
|
||||
return data, err
|
||||
}
|
||||
defer func() {
|
||||
err = core.SerialStop(SerialStartHandle)
|
||||
err = Core.SerialStop(SerialStartHandle)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
@ -250,9 +250,9 @@ func (this *BallCamera) GetPTZ() (PTZ, error) {
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
var data core.CDVR_PTZPOS
|
||||
var data Core.CDVR_PTZPOS
|
||||
var dataPtr = unsafe.Pointer(&data)
|
||||
err := core.GetDVRConfig(this.userId, 293, 1, dataPtr, core.DWORD(unsafe.Sizeof(data)))
|
||||
err := Core.GetDVRConfig(this.userId, 293, 1, dataPtr, Core.DWORD(unsafe.Sizeof(data)))
|
||||
if err != nil {
|
||||
return PTZ{}, err
|
||||
}
|
||||
@ -274,13 +274,13 @@ func padding(n int) ([]byte, error) {
|
||||
|
||||
func (this *BallCamera) PtzGotoPut(Action int, P, T, Z float64) error {
|
||||
if this._type == BuKongQiu {
|
||||
SerialStartHandle, err := core.SerialStart(this.userId, func(lSerialHandle core.LONG, lChannel core.LONG, pRecvDataBuffer []byte, dwBufSize core.DWORD, pUser unsafe.Pointer) {
|
||||
SerialStartHandle, err := Core.SerialStart(this.userId, func(lSerialHandle Core.LONG, lChannel Core.LONG, pRecvDataBuffer []byte, dwBufSize Core.DWORD, pUser unsafe.Pointer) {
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
err = core.SerialStop(SerialStartHandle)
|
||||
err = Core.SerialStop(SerialStartHandle)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
}
|
||||
@ -321,43 +321,43 @@ func (this *BallCamera) PtzGotoPut(Action int, P, T, Z float64) error {
|
||||
zBuf = append(zBuf, zBufv)
|
||||
switch Action {
|
||||
case 1:
|
||||
err = core.SerialSend(SerialStartHandle, pBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, pBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = core.SerialSend(SerialStartHandle, tBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, tBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = core.SerialSend(SerialStartHandle, zBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, zBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
case 2:
|
||||
err = core.SerialSend(SerialStartHandle, pBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, pBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
case 3:
|
||||
err = core.SerialSend(SerialStartHandle, tBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, tBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
case 4:
|
||||
err = core.SerialSend(SerialStartHandle, zBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, zBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
break
|
||||
case 5:
|
||||
err = core.SerialSend(SerialStartHandle, pBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, pBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = core.SerialSend(SerialStartHandle, tBuf)
|
||||
err = Core.SerialSend(SerialStartHandle, tBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -367,19 +367,19 @@ func (this *BallCamera) PtzGotoPut(Action int, P, T, Z float64) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
var data core.CDVR_PTZPOS
|
||||
var data Core.CDVR_PTZPOS
|
||||
data.Set(float64(Action), P, T, Z)
|
||||
var dataPtr = unsafe.Pointer(&data)
|
||||
err := core.SetDVRConfig(this.userId, 292, 1, dataPtr, core.DWORD(unsafe.Sizeof(data)))
|
||||
err := Core.SetDVRConfig(this.userId, 292, 1, dataPtr, Core.DWORD(unsafe.Sizeof(data)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *BallCamera) retrySend(handle core.LONG, cmd []byte, maxRetries int, ch <-chan bool) error {
|
||||
func (this *BallCamera) retrySend(handle Core.LONG, cmd []byte, maxRetries int, ch <-chan bool) error {
|
||||
for retry := 0; retry < maxRetries; retry++ {
|
||||
if err := core.SerialSend(handle, cmd); err != nil {
|
||||
if err := Core.SerialSend(handle, cmd); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -401,14 +401,14 @@ func (this *BallCamera) retrySend(handle core.LONG, cmd []byte, maxRetries int,
|
||||
}
|
||||
|
||||
func (receiver *BallCamera) StartBus(direction int, speed int) error {
|
||||
err := core.PTZControlWithSpeed_Other(receiver.userId, core.LONG(receiver.deviceInfo.ByStartChan), core.DWORD(direction), core.DWORD(0), core.DWORD(speed))
|
||||
err := Core.PTZControlWithSpeed_Other(receiver.userId, Core.LONG(receiver.deviceInfo.ByStartChan), Core.DWORD(direction), Core.DWORD(0), Core.DWORD(speed))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (receiver *BallCamera) StopBus(direction int, speed int) error {
|
||||
err := core.PTZControlWithSpeed_Other(receiver.userId, core.LONG(receiver.deviceInfo.ByStartChan), core.DWORD(direction), core.DWORD(1), core.DWORD(speed))
|
||||
err := Core.PTZControlWithSpeed_Other(receiver.userId, Core.LONG(receiver.deviceInfo.ByStartChan), Core.DWORD(direction), Core.DWORD(1), Core.DWORD(speed))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -436,7 +436,7 @@ func (receiver *BallCamera) Logout() error {
|
||||
// return err
|
||||
// }
|
||||
//}
|
||||
err := core.Logout(receiver.userId)
|
||||
err := Core.Logout(receiver.userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -2,12 +2,12 @@ package HikSDK
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.com/kunmeng/HikNetSDKPkg/core"
|
||||
"gitea.com/kunmeng/HikNetSDKPkg/Core"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCamera(t *testing.T) {
|
||||
err := core.Init()
|
||||
err := Core.Init()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package Core
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../include
|
||||
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package Core
|
||||
|
||||
type DWORD uint32
|
||||
type WORD uint16
|
||||
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package Core
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I../include
|
||||
@ -1,4 +1,4 @@
|
||||
package core
|
||||
package Core
|
||||
|
||||
import "C"
|
||||
import (
|
||||
Loading…
Reference in New Issue
Block a user