4-Onvif协议:IPC客户端之获取设备基本信息

参考文章

https://blog.csdn.net/zhizhengguan/article/details/109311628

一、简介

客户端要做的第一件事情就是获取IPC摄像头的基本信息,即调用GetDeviceInformation接口。

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

在这里插入图片描述

二、相关数据结构和函数

1.数据结构

# 数据结构定义在client\application\soapStub.h
_tds__GetDeviceInformation           devinfo_req;
_tds__GetDeviceInformationResponse   devinfo_resp;
/* ../onvif_head/onvif.h:438 */
#ifndef SOAP_TYPE__tds__GetDeviceInformation
#define SOAP_TYPE__tds__GetDeviceInformation (455)
/* complex XML schema type 'tds:GetDeviceInformation': */
class SOAP_CMAC _tds__GetDeviceInformation {
      public:
        /// Context that manages this object
        struct soap *soap;
      public:
        /// Return unique type id SOAP_TYPE__tds__GetDeviceInformation
        virtual long soap_type(void) const { return SOAP_TYPE__tds__GetDeviceInformation; }
        /// (Re)set members to default values
        virtual void soap_default(struct soap*);
        /// Serialize object to prepare for SOAP 1.1/1.2 encoded output (or with SOAP_XML_GRAPH) by analyzing its (cyclic) structures
        virtual void soap_serialize(struct soap*) const;
        /// Output object in XML, compliant with SOAP 1.1 encoding style, return error code or SOAP_OK
        virtual int soap_put(struct soap*, const char *tag, const char *type) const;
        /// Output object in XML, with tag and optional id attribute and xsi:type, return error code or SOAP_OK
        virtual int soap_out(struct soap*, const char *tag, int id, const char *type) const;
        /// Get object from XML, compliant with SOAP 1.1 encoding style, return pointer to object or NULL on error
        virtual void *soap_get(struct soap*, const char *tag, const char *type);
        /// Get object from XML, with matching tag and type (NULL matches any tag and type), return pointer to object or NULL on error
        virtual void *soap_in(struct soap*, const char *tag, const char *type);
        /// Return a new object of type _tds__GetDeviceInformation, default initialized and not managed by a soap context
        virtual _tds__GetDeviceInformation *soap_alloc(void) const { return SOAP_NEW_UNMANAGED(_tds__GetDeviceInformation); }
      public:
        /// Constructor with default initializations
        _tds__GetDeviceInformation() : soap() { }
        /// Destructor
        virtual ~_tds__GetDeviceInformation() { }
        /// Friend allocator used by soap_new__tds__GetDeviceInformation(struct soap*, int)
        friend SOAP_FMAC1 _tds__GetDeviceInformation * SOAP_FMAC2 soap_instantiate__tds__GetDeviceInformation(struct soap*, int, const char*, const char*, size_t*);
};
#endif

/* ../onvif_head/onvif.h:440 */
#ifndef SOAP_TYPE__tds__GetDeviceInformationResponse
#define SOAP_TYPE__tds__GetDeviceInformationResponse (456)
/* complex XML schema type 'tds:GetDeviceInformationResponse': */
class SOAP_CMAC _tds__GetDeviceInformationResponse {
      public:
        /// Required element 'tds:Manufacturer' of XML schema type 'xsd:string'
        char *Manufacturer;
        /// Required element 'tds:Model' of XML schema type 'xsd:string'
        char *Model;
        /// Required element 'tds:FirmwareVersion' of XML schema type 'xsd:string'
        char *FirmwareVersion;
        /// Required element 'tds:SerialNumber' of XML schema type 'xsd:string'
        char *SerialNumber;
        /// Required element 'tds:HardwareId' of XML schema type 'xsd:string'
        char *HardwareId;
        /// Context that manages this object
        struct soap *soap;
      public:
        /// Return unique type id SOAP_TYPE__tds__GetDeviceInformationResponse
        virtual long soap_type(void) const { return SOAP_TYPE__tds__GetDeviceInformationResponse; }
        /// (Re)set members to default values
        virtual void soap_default(struct soap*);
        /// Serialize object to prepare for SOAP 1.1/1.2 encoded output (or with SOAP_XML_GRAPH) by analyzing its (cyclic) structures
        virtual void soap_serialize(struct soap*) const;
        /// Output object in XML, compliant with SOAP 1.1 encoding style, return error code or SOAP_OK
        virtual int soap_put(struct soap*, const char *tag, const char *type) const;
        /// Output object in XML, with tag and optional id attribute and xsi:type, return error code or SOAP_OK
        virtual int soap_out(struct soap*, const char *tag, int id, const char *type) const;
        /// Get object from XML, compliant with SOAP 1.1 encoding style, return pointer to object or NULL on error
        virtual void *soap_get(struct soap*, const char *tag, const char *type);
        /// Get object from XML, with matching tag and type (NULL matches any tag and type), return pointer to object or NULL on error
        virtual void *soap_in(struct soap*, const char *tag, const char *type);
        /// Return a new object of type _tds__GetDeviceInformationResponse, default initialized and not managed by a soap context
        virtual _tds__GetDeviceInformationResponse *soap_alloc(void) const { return SOAP_NEW_UNMANAGED(_tds__GetDeviceInformationResponse); }
      public:
        /// Constructor with default initializations
        _tds__GetDeviceInformationResponse() : Manufacturer(), Model(), FirmwareVersion(), SerialNumber(), HardwareId(), soap() { }
        /// Destructor
        virtual ~_tds__GetDeviceInformationResponse() { }
        /// Friend allocator used by soap_new__tds__GetDeviceInformationResponse(struct soap*, int)
        friend SOAP_FMAC1 _tds__GetDeviceInformationResponse * SOAP_FMAC2 soap_instantiate__tds__GetDeviceInformationResponse(struct soap*, int, const char*, const char*, size_t*);
};
#endif

2.函数

函数声明在client\application\soapClient.h

/** Web service synchronous operation 'soap_call___tds__GetDeviceInformation' to the specified endpoint and SOAP Action header, returns SOAP_OK or error code */
    SOAP_FMAC5 int SOAP_FMAC6 soap_call___tds__GetDeviceInformation(struct soap *soap, const char *soap_endpoint, const char *soap_action, _tds__GetDeviceInformation *tds__GetDeviceInformation, _tds__GetDeviceInformationResponse &tds__GetDeviceInformationResponse);

函数定义在client\application\soapClient.cpp

SOAP_FMAC5 int SOAP_FMAC6 soap_call___tds__GetDeviceInformation(struct soap *soap, const char *soap_endpoint, const char *soap_action, _tds__GetDeviceInformation *tds__GetDeviceInformation, _tds__GetDeviceInformationResponse &tds__GetDeviceInformationResponse)
{	if (soap_send___tds__GetDeviceInformation(soap, soap_endpoint, soap_action, tds__GetDeviceInformation) || soap_recv___tds__GetDeviceInformation(soap, tds__GetDeviceInformationResponse))
		return soap->error;
	return SOAP_OK;
}

三、获取设备基本信息实现

struct OnvifDeviceInfo
{
    std::string manufacturer;
    std::string model;
    std::string firmwareVersion;
    std::string serialNumber;
    std::string hardwareId;
};

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

            SOAP_ASSERT(!deviceXAddr.empty());
            SOAP_ASSERT(nullptr != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));


	// 获取设备信息需要鉴权
    ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);

    result = soap_call___tds__GetDeviceInformation(soap, deviceXAddr.c_str(), nullptr, &devinfo_req, devinfo_resp);
    SOAP_CHECK_ERROR(result, soap, "GetDeviceInformation");
    DeviceInfo->manufacturer = devinfo_resp.Manufacturer;
    DeviceInfo->model = devinfo_resp.Model;
    DeviceInfo->firmwareVersion = devinfo_resp.FirmwareVersion;
    DeviceInfo->serialNumber = devinfo_resp.SerialNumber;
    DeviceInfo->hardwareId = devinfo_resp.HardwareId;

#if DEBUG
    std::cout << "-------------------ONVIF_GetDeviceInformation----------------" << "\n";
    std::cout << "Manufacturer:" << DeviceInfo->manufacturer << "\n";
    std::cout << "Model:" << DeviceInfo->model << "\n";
    std::cout << "FirmwareVersion:" << DeviceInfo->firmwareVersion;
    std::cout << "SerialNumber:" << DeviceInfo->serialNumber << "\n";
    std::cout << "HardwareId:" << DeviceInfo->hardwareId << "\n";
    std::cout << "-------------------------------------------------------------" << "\n";
#endif


    EXIT:

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

四、实现效果

-------------------ONVIF_GetDeviceInformation----------------
Manufacturer:N
Model:HD_Camera
FirmwareVersion:X8.02.91
SerialNumber:vf392b11e84
HardwareId:002
-------------------------------------------------------------
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ONVIF是开放网络视频接口论坛(Open Network Video Interface Forum)的简称,是由一群网络视频设备制造商共同组成的一个开放性标准组织,旨在为网络视频设备制造商提供共同的标准和协议,使设备之间更加互通、兼容和易于部署。而在ONVIF生态圈中,IPC设备服务则是指IPC设备提供的HTTP API接口,以便于设备接入ONVIF网络系统。 IPC设备服务主要包括基本设备管理、视频独享、音频数据、运动检测、智能分析、元数据、事件、存储与再生、信令流管理、设备信息、网络配置等方面。通过ONVIF协议,用户可以通过设备服务进行设备管理、视频监控、事件告警等操作,并可以与其他ONVIF兼容的厂商的设备集成。 ONVIF-IPC设备服务的实现可以依据ONVIF协议和API文档,基于设备提供商提供的SDK或者API完成开发,或通过第三方开发人员提供的开发包进行实现。同时IPC设备也要支持ONVIF协议的规范和相关标准,才能保证其ONVIF-IPC设备服务的正常运行。 总之,通过ONVIF-IPC设备服务的实现,可以使得设备厂商提供的设备可以与其他ONVIF兼容的设备集成,为用户提供更为灵活、高效、可扩展的视频监控解决方案。 ### 回答2: ONVIF是一种标准化协议,用于IP视频监控设备之间的互通性。IPC设备是指网络摄像机,包括网络球机、固定枪机和卡口摄像机等。ONVIF-IPC设备服务是指网络摄像机作为服务(即提供服务)使用ONVIF协议与其他设备通信。 ONVIF协议是由IP视频监控行业的领导厂商共同制定的,旨在解决设备之间的互联互通问题。使用ONVIF协议IPC设备可以与其他厂商的设备和软件进行互联,不受品牌限制,实现方便的互联互通。 ONVIF-IPC设备服务需要实现ONVIF协议的各项功能,包括设备管理、媒体管理、事件管理等。同时,服务需要支持视频编码格式、视频分辨率和码率等参数配置,以适应不同场景的需求。此外,服务还需要支持网络设置、用户管理和安全防范等功能,为用户提供完整的安全保障和智能化管理。 总之,ONVIF-IPC设备服务是一种遵循ONVIF协议的网络摄像机,可以作为服务与其他设备进行通信,实现设备互联互通和智能化管理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值