-
Notifications
You must be signed in to change notification settings - Fork 12
/
PTZService.cs
200 lines (199 loc) · 8.48 KB
/
PTZService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Linq;
using XiaoFeng.Xml;
namespace XiaoFeng.Onvif
{
/// <summary>
/// 云台服务
/// </summary>
public class PTZService
{
public static readonly string URL = "onvif/ptz_service";
/// <summary>
/// 获取云台状态
/// </summary>
/// <param name="ip"></param>
/// <param name="user"></param>
/// <param name="pass"></param>
/// <param name="onvifUTCDateTime"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async Task<List<string>> GetStatus(IPEndPoint iPEndPoint, string user, string pass, DateTime onvifUTCDateTime,string token)
{
string reqMessageStr = $@"
<tptz:GetStatus xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
</tptz:GetStatus>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
var xnode = result.Html.ReplacePattern(@"(<|/)[a-z\-]+:", "$1");
if (result.StatusCode == HttpStatusCode.OK)
{
var status = XElement.Parse(xnode).Descendants("PTZStatus");
}
else
{
/*请求失败*/
}
return default;
}
public static async Task<List<string>> AbsoluteMove(IPEndPoint iPEndPoint, string user, string pass,
DateTime onvifUTCDateTime, string token,double x, double y)
{
string reqMessageStr = $@"
<tptz:AbsoluteMove xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
<tptz:Position>
<tt:PanTilt x=""{x}"" y=""{y}"" space=""http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace"" />
</tptz:Position>
</tptz:AbsoluteMove>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
if (result.StatusCode == HttpStatusCode.OK)
{
var xnode_list = result.Html.XmlToEntity<XmlValue>();
}
else
{
/*请求失败*/
}
return default;
}
/// <summary>
/// 停止移动
/// </summary>
/// <param name="ip"></param>
/// <param name="user"></param>
/// <param name="pass"></param>
/// <param name="onvifUTCDateTime"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async Task<List<string>> Stop(IPEndPoint iPEndPoint, string user, string pass,
DateTime onvifUTCDateTime, string token)
{
string reqMessageStr = $@"
<tptz:Stop xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
<tptz:PanTilt>true</tptz:PanTilt>
<tptz:Zoom>true</tptz:Zoom>
</tptz:Stop>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
if (result.StatusCode == HttpStatusCode.OK)
{
var xnode_list = result.Html.XmlToEntity<XmlValue>();
}
else
{
/*请求失败*/
}
return default;
}
/// <summary>
/// 继续移动
/// </summary>
/// <param name="ip"></param>
/// <param name="user"></param>
/// <param name="pass"></param>
/// <param name="onvifUTCDateTime"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async Task<List<string>> ContinuousMove(IPEndPoint iPEndPoint, string user, string pass,
DateTime onvifUTCDateTime, string token, double x, double y, double z)
{
string reqMessageStr = $@"
<tptz:ContinuousMove xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
<tptz:Velocity>
<tt:PanTilt x=""{x}"" y=""{y}"" />
<tt:Zoom x=""{z}"" />
</tptz:Velocity>
</tptz:ContinuousMove>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
if (result.StatusCode == HttpStatusCode.OK)
{
var xnode_list = result.Html.XmlToEntity<XmlValue>();
}
else
{
/*请求失败*/
}
return default;
}
/// <summary>
///
/// </summary>
/// <param name="ip"></param>
/// <param name="user"></param>
/// <param name="pass"></param>
/// <param name="onvifUTCDateTime"></param>
/// <param name="token"></param>
/// <returns></returns>
public static async Task<List<string>> SetHomePosition(IPEndPoint iPEndPoint, string user, string pass,
DateTime onvifUTCDateTime, string token)
{
string reqMessageStr = $@"
<tptz:SetHomePosition xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
</tptz:SetHomePosition>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
if (result.StatusCode == HttpStatusCode.OK)
{
var xnode_list = result.Html.XmlToEntity<XmlValue>();
}
else
{
/*请求失败*/
}
return default;
}
public static async Task<List<string>> GotoHomePosition(IPEndPoint iPEndPoint, string user, string pass,
DateTime onvifUTCDateTime, string token, double x, double y, double z)
{
string reqMessageStr = $@"
<tptz:GotoHomePosition xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
<tptz:Speed>
<tt:PanTilt x=""{x}"" y=""{y}"" space=""http://uri1"" />
<tt:Zoom x=""{z}"" space=""http://uri1"" />
</tptz:Speed>
</tptz:GotoHomePosition>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
if (result.StatusCode == HttpStatusCode.OK)
{
var xnode_list = result.Html.XmlToEntity<XmlValue>();
}
else
{
/*请求失败*/
}
return default;
}
public static async Task<List<string>> RelativeMove(IPEndPoint iPEndPoint, string user, string pass,
DateTime onvifUTCDateTime, string token, double x, double y, double z)
{
string reqMessageStr = $@"
<tptz:RelativeMove xmlns:tptz=""http://www.onvif.org/ver20/ptz/wsdl"">
<tptz:ProfileToken>{token}</tptz:ProfileToken>
<tptz:Translation>
<tt:PanTilt x=""{x}"" y=""{y}"" />
<tt:Zoom x=""{z}"" />
</tptz:Translation>
<tptz:Speed>
<tt:PanTilt x=""{x}"" y=""{y}"" />
<tt:Zoom x=""{z}"" />
</tptz:Speed>
</tptz:RelativeMove>";
var result = await OnvifAuth.RemoteClient(iPEndPoint, URL, reqMessageStr, user, pass, onvifUTCDateTime);
if (result.StatusCode == HttpStatusCode.OK)
{
var xnode_list = result.Html.XmlToEntity<XmlValue>();
}
else
{
/*请求失败*/
}
return default;
}
}
}