您的位置:首页 > 理论基础 > 计算机网络

ONVIF协议网络摄像机(IPC)客户端程序开发(8):获取设备基本信息

2017-11-29 10:57 399 查看


1 专栏导读

本专栏第一篇文章「专栏开篇」列出了专栏的完整目录,按目录顺序阅读,有助于你的理解,专栏前面文章讲过的知识点(或代码段),后面文章不会赘述。为了节省篇幅,突出重点,在文章中展示的示例代码仅仅是关键代码,你可以在「专栏开篇」中获取完整代码。

如有错误,欢迎你的留言纠正!让我们共同成长!你的「点赞」或「打赏」是对我最大的支持和鼓励!


2 原理简介

上一篇文章介绍了如何搜索IPC摄像头,搜索出IPC后,就有了该IPC的Web Services地址,接下来就能通过一系列的ONVIF接口访问IPC。本文将介绍如何获取IPC摄像头的基本信息,即调用GetDeviceInformation接口。

有关GetDeviceInformation接口的描述,可以参阅devicemgmt.wsdl文档(https://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl),如下图所示:


 


3 示例代码

使用GetDeviceInformation接口获取设备基本信息的示例代码很简单,直接调用soap_call___tds__GetDeviceInformation接口即可,附上关键源码:
/* socket超时时间(单秒秒) */
#define SOAP_SOCK_TIMEOUT    (10)

#define SOAP_CHECK_ERROR(result, soap, str) \
do { \
if (SOAP_OK != (result) || SOAP_OK != (soap)->error) { \
soap_perror((soap), (str)); \
if (SOAP_OK == (result)) { \
(result) = (soap)->error; \
} \
goto EXIT; \
} \
} while (0)

/************************************************************************
**函数:ONVIF_GetDeviceInformation
**功能:获取设备基本信息
**参数:
[in] DeviceXAddr - 设备服务地址
**返回:
0表明成功,非0表明失败
**备注:
************************************************************************/
int ONVIF_GetDeviceInformation(const char *DeviceXAddr)
{
int result = 0;
struct soap *soap = NULL;
struct _tds__GetDeviceInformation           devinfo_req;
struct _tds__GetDeviceInformationResponse   devinfo_resp;

SOAP_ASSERT(NULL != DeviceXAddr);
SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

memset(&devinfo_req, 0x00, sizeof(devinfo_req));
memset(&devinfo_resp, 0x00, sizeof(devinfo_resp));
result = soap_call___tds__GetDeviceInformation(soap, DeviceXAddr, NULL, &devinfo_req, &devinfo_resp);
SOAP_CHECK_ERROR(result, soap, "GetDeviceInformation");

dump_tds__GetDeviceInformationResponse(&devinfo_resp);

EXIT:

if (NULL != soap) {
ONVIF_soap_delete(soap);
}
return result;
}

void cb_discovery(char *DeviceXAddr)
{
ONVIF_GetDeviceInformation(DeviceXAddr);
}

int main(int argc, char **argv)
{
ONVIF_DetectDevice(cb_discovery);
return 0;
}
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

如果顺利,执行结果类似:
================= + dump_tds__GetDeviceInformationResponse + >>>
Manufacturer:       Network Digital Video
Model:              HDIPC-S25
Serial Number:      1129464245
Hardware Id:        IPCamera
Firmware Version:   3.3.1.16
================= - dump_tds__GetDeviceInformationResponse - <<<
1
2
3
4
5
6
7


4 鉴权失败

对于需要鉴权的IPC(如大华IPC),会执行失败,错误信息类似:
[soap] GetDeviceInformation error: 401, is internal, HTTP Error
1

使用Wireshark抓包工具对IPC应答的HTTP信息进行抓包,发现错误信息包含「401 Unauthorized」,即鉴权(认证)失败的意思。调用ONVIF接口,市面上有些IPC要求必须携带用户名、密码认证信息(如大华IPC),而有些IPC则不需要携带认证信息。所以才会有如上两种执行结果。

有关ONVIF鉴权(认证),下一篇文章将单独介绍。为了让测试顺利通过,可以先通过WEB浏览器登录后台,关闭鉴权,如下图所示。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐