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