add ptz support
This commit is contained in:
parent
952e34bcb4
commit
3967a6c9ac
81
device.go
81
device.go
|
@ -11,8 +11,10 @@ import (
|
|||
"git.pyer.club/kingecg/goonvif/onvif"
|
||||
device "git.pyer.club/kingecg/goonvif/onvif/device"
|
||||
"git.pyer.club/kingecg/goonvif/onvif/media"
|
||||
ptz "git.pyer.club/kingecg/goonvif/onvif/ptz"
|
||||
sdk "git.pyer.club/kingecg/goonvif/onvif/sdk/device"
|
||||
media_sdk "git.pyer.club/kingecg/goonvif/onvif/sdk/media"
|
||||
ptz_sdk "git.pyer.club/kingecg/goonvif/onvif/sdk/ptz"
|
||||
wsdiscovery "git.pyer.club/kingecg/goonvif/onvif/ws-discovery"
|
||||
"git.pyer.club/kingecg/goonvif/onvif/xsd"
|
||||
onvifmodel "git.pyer.club/kingecg/goonvif/onvif/xsd/onvif"
|
||||
|
@ -30,6 +32,11 @@ type Device struct {
|
|||
mediaCapablities *media.Capabilities
|
||||
}
|
||||
|
||||
const (
|
||||
panTiltSpace string = "http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace"
|
||||
zoomSpace string = "http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace"
|
||||
)
|
||||
|
||||
var ErrAuthRequired = errors.New("auth required")
|
||||
|
||||
func NewDevice(params onvif.DeviceParams) *Device {
|
||||
|
@ -219,6 +226,80 @@ func (d *Device) GetProfiles() ([]onvifmodel.Profile, error) {
|
|||
}
|
||||
return resp.Profiles, nil
|
||||
}
|
||||
|
||||
func (d *Device) GetDeviceInformation() (interface{}, error) {
|
||||
err := d.check()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := sdk.Call_GetDeviceInformation(d.ctx, d.device, device.GetDeviceInformation{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (d *Device) PTZNodes() ([]onvifmodel.PTZNode, error) {
|
||||
err := d.check()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := ptz_sdk.Call_GetNodes(d.ctx, d.device, ptz.GetNodes{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.PTZNode, nil
|
||||
}
|
||||
|
||||
func (d *Device) continueMove(panTilt onvifmodel.Vector2D, zoom float64) error {
|
||||
err := d.check()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
v := onvifmodel.PTZSpeed{}
|
||||
panTilt.Space = xsd.AnyURI(panTiltSpace)
|
||||
v.PanTilt = panTilt
|
||||
v.Zoom = onvifmodel.Vector1D{
|
||||
Space: xsd.AnyURI(zoomSpace),
|
||||
X: zoom,
|
||||
}
|
||||
|
||||
_, perr := ptz_sdk.Call_ContinuousMove(d.ctx, d.device, ptz.ContinuousMove{
|
||||
ProfileToken: "Profile_1",
|
||||
Velocity: v,
|
||||
})
|
||||
return perr
|
||||
}
|
||||
|
||||
func (d *Device) StopMove() error {
|
||||
err := d.check()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, perr := ptz_sdk.Call_Stop(d.ctx, d.device, ptz.Stop{})
|
||||
return perr
|
||||
}
|
||||
|
||||
// Pan 执行设备的水平和垂直移动。
|
||||
// 此函数通过指定的x和y坐标来控制设备的移动方向和距离。
|
||||
// 参数:
|
||||
//
|
||||
// x - 水平移动的坐标值。range: -1 to 1
|
||||
// y - 垂直移动的坐标值。range: -1 to 1
|
||||
//
|
||||
// 返回值:
|
||||
//
|
||||
// 如果移动操作成功,返回nil;否则返回错误。
|
||||
func (d *Device) Pan(x, y float64) error {
|
||||
// 创建一个二维向量来表示移动的方向和距离。
|
||||
v := onvifmodel.Vector2D{X: x, Y: y}
|
||||
// 调用continueMove函数来执行实际的移动操作,移动速度设置为0。
|
||||
return d.continueMove(v, 0)
|
||||
}
|
||||
|
||||
func (d *Device) Zoom(zoom float64) error {
|
||||
return d.continueMove(onvifmodel.Vector2D{}, zoom)
|
||||
}
|
||||
func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) ([]Device, error) {
|
||||
// Call a ws-discovery Probe Message to Discover NVT type Devices
|
||||
devices, err := wsdiscovery.SendProbe(interfaceName, nil, []string{"dn:" + onvif.NVT.String()}, map[string]string{"dn": "http://www.onvif.org/ver10/network/wsdl"})
|
||||
|
|
|
@ -121,3 +121,28 @@ func TestGetStreamUri(t *testing.T) {
|
|||
}
|
||||
fmt.Println(uri)
|
||||
}
|
||||
|
||||
func TestGetPtzNodes(t *testing.T) {
|
||||
d := NewDevice(onvif.DeviceParams{
|
||||
Xaddr: "192.168.12.52",
|
||||
Username: "dctdev",
|
||||
Password: "dacenT2017",
|
||||
})
|
||||
nodes, err := d.PTZNodes()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(nodes)
|
||||
}
|
||||
|
||||
func TestZoom(t *testing.T) {
|
||||
d := NewDevice(onvif.DeviceParams{
|
||||
Xaddr: "192.168.12.52",
|
||||
Username: "dctdev",
|
||||
Password: "dacenT2017",
|
||||
})
|
||||
err := d.Zoom(-0.5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ type GetNodes struct {
|
|||
}
|
||||
|
||||
type GetNodesResponse struct {
|
||||
PTZNode onvif.PTZNode
|
||||
PTZNode []onvif.PTZNode
|
||||
}
|
||||
|
||||
type GetNode struct {
|
||||
|
|
|
@ -933,14 +933,14 @@ type PTZNode struct {
|
|||
}
|
||||
|
||||
type PTZSpaces struct {
|
||||
AbsolutePanTiltPositionSpace Space2DDescription
|
||||
AbsoluteZoomPositionSpace Space1DDescription
|
||||
RelativePanTiltTranslationSpace Space2DDescription
|
||||
RelativeZoomTranslationSpace Space1DDescription
|
||||
ContinuousPanTiltVelocitySpace Space2DDescription
|
||||
ContinuousZoomVelocitySpace Space1DDescription
|
||||
PanTiltSpeedSpace Space1DDescription
|
||||
ZoomSpeedSpace Space1DDescription
|
||||
AbsolutePanTiltPositionSpace []Space2DDescription
|
||||
AbsoluteZoomPositionSpace []Space1DDescription
|
||||
RelativePanTiltTranslationSpace []Space2DDescription
|
||||
RelativeZoomTranslationSpace []Space1DDescription
|
||||
ContinuousPanTiltVelocitySpace []Space2DDescription
|
||||
ContinuousZoomVelocitySpace []Space1DDescription
|
||||
PanTiltSpeedSpace []Space1DDescription
|
||||
ZoomSpeedSpace []Space1DDescription
|
||||
Extension PTZSpacesExtension
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue