文章目录
一、运行流程
二、头文件
#ifndef _CLIENT_H_
#define _CLIENT_H_
#include <assert.h>
#include "soapH.h"
#include "soapStub.h"
#include "wsseapi.h"
#include "wsaapi.h"
#include <map>
#include <string>
#define SOAP_ASSERT assert
#define SOAP_DBGLOG printf
#define SOAP_DBGERR printf
#define SOAP_TO "urn:schemas-xmlsoap-org:ws:2005:04:discovery"
#define SOAP_ACTION "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe"
#define SOAP_MCAST_ADDR "soap.udp://239.255.255.250:3702" // onvif规定的组播地址
#define SOAP_ITEM "" // 寻找的设备范围
#define SOAP_TYPES "dn:NetworkVideoTransmitter" // 寻找的设备类型
#define SOAP_SOCK_TIMEOUT (3) // socket超时时间(单位秒)
struct OnvifAvailableDevice
{
int availableNum;
std::string AvailableDeviceXAddr[256];
};
struct OnvifDeviceInfo
{
std::string manufacturer;
std::string model;
std::string firmwareVersion;
std::string serialNumber;
std::string hardwareId;
};
struct OnvifDeviceCapabilities
{
std::string device;
std::string media;
std::string analytics;
std::string events;
std::string imaging;
std::string ptz;
std::string extension_deviceio;
std::string extension_display;
std::string extension_recording;
std::string extension_search;
std::string extension_replay;
std::string extension_receiver;
std::string extension_analyticsdevice;
};
struct OnvifPTZInfo
{
int status;
float p;
float t;
float z;
};
struct ONVIFPTZAbsoluteMoveInfo
{
float absoluteP;
float absoluteT;
float absoluteZ;
float vp;
float vt;
float vz;
};
struct ONVIFPTZRelativeMoveInfo
{
float relativeP;
float relativeT;
float relativeZ;
float vp;
float vt;
float vz;
};
enum TYPE
{
DEVICE,
MEDIA,
ANALYTICS,
EVENTS,
IMAGING,
PTZ,
EXTENSION_DEVICEIO,
EXTENSION_DISPLAY,
EXTENSION_RECORDING,
EXTENSION_SEARCH,
EXTENSION_REPLAY,
EXTENSION_RECEIVER,
EXTENSION_ANALYTICSDEVICE,
};
enum PTZCMD
{
PTZ_CMD_LEFT,
PTZ_CMD_RIGHT,
PTZ_CMD_UP,
PTZ_CMD_DOWN,
PTZ_CMD_LEFTUP,
PTZ_CMD_LEFTDOWN,
PTZ_CMD_RIGHTUP,
PTZ_CMD_RIGHTDOWN,
PTZ_CMD_ZOOM_IN,
PTZ_CMD_ZOOM_OUT,
};
void ONVIF_DeviceDiscovery(struct OnvifAvailableDevice *availableDevice);
void setUSERNAME(const char *username);
void setPASSWORD(const char *password);
int ONVIF_GetDeviceInformation(const std::string& deviceXAddr, struct OnvifDeviceInfo* DeviceInfo);
int ONVIF_GetTypeCapabilities(const std::string& deviceXAddr,enum TYPE type, std::string * typeXAddr);
int ONVIF_GetMediaCapabilities(const std::string& deviceXAddr, std::string *mediaXAddr);
int ONVIF_GetPTZCapabilities(const std::string& deviceXAddr, std::string *ptzXAddr);
void ONVIF_GetCapabilities(const std::string& deviceXAddr,struct OnvifDeviceCapabilities* deviceCapabilities);
bool ONVIF_GetMediaProfilesToken(const std::string& mediaXAddr, std::string *mediaprofilesToken);
bool ONVIF_GetPTZProfilesToken(const std::string& mediaXAddr, std::string *ptzprofilesToken);
int ONVIF_GetStreamUri(const std::string&MediaXAddr, const std::string&ProfileToken, std::string *streamUri);
int ONVIF_PTZ_GetStatus(const std::string& ptzXAddr, const std::string& ProfileToken, struct OnvifPTZInfo * ptzInfo);
int ONVIF_PTZStopMove(const std::string& ptzXAddr, const std::string& ProfileToken);
int ONVIF_PTZAbsoluteMove(const std::string& ptzXAddr, const std::string& ProfileToken, struct ONVIFPTZAbsoluteMoveInfo *ptzAbsoluteMoveInfo);
int ONVIF_PTZRelativeMove(const std::string& ptzXAddr, const std::string& ProfileToken, struct ONVIFPTZRelativeMoveInfo *ptzRelativeMoveInfo);
int ONVIF_PTZContinuousMove(const std::string& ptzXAddr, const std::string& ProfileToken, enum PTZCMD cmd, float speed);
#endif
三、主程序
#include "client.h"
int main(void)
{
struct OnvifAvailableDevice availableDevice; // 可用设备
struct OnvifDeviceInfo deviceInfo; // 设备信息
struct OnvifDeviceCapabilities deviceCapabilities; // 设备能力
struct OnvifPTZInfo ptzInfo; // ptz信息
struct ONVIFPTZAbsoluteMoveInfo ptzAbsoluteMoveInfo; // 绝对移动的参数
struct ONVIFPTZRelativeMoveInfo ptzRelativeMoveInfo; // 相对移动的参数
//绝对移动的参数初始化
ptzAbsoluteMoveInfo.absoluteP = 0;
ptzAbsoluteMoveInfo.absoluteT = 0;
ptzAbsoluteMoveInfo.absoluteZ = 0;
ptzAbsoluteMoveInfo.vp = 0.5;
ptzAbsoluteMoveInfo.vt = 0.5;
ptzAbsoluteMoveInfo.vz = 0.5;
//相对移动的参数初始化
ptzRelativeMoveInfo.relativeP = 0.5;
ptzRelativeMoveInfo.relativeT = 0.5;
ptzRelativeMoveInfo.relativeZ = 0.5;
ptzRelativeMoveInfo.vp = 0.5;
ptzRelativeMoveInfo.vt = 0.5;
ptzRelativeMoveInfo.vz = 0.5;
// 连接设备的service
std::string deviceXAddr = "http://192.168.1.137:81/onvif/device_service";
// 获取设备相关信息
std::string mediaXAddr;
std::string ptzXAddr;
std::string mediaprofilesToken;
std::string ptzprofilesToken;
std::string streamUri;
const char *username = "admin";
const char *password = "admin";
//1.设备发现
ONVIF_DeviceDiscovery(&availableDevice);
//2.鉴权
setUSERNAME(username);
setPASSWORD(password);
//3.获取设备信息
ONVIF_GetDeviceInformation(deviceXAddr, &deviceInfo);
//4.获取设备能力
ONVIF_GetCapabilities(deviceXAddr, &deviceCapabilities);
ONVIF_GetMediaCapabilities(deviceXAddr, &mediaXAddr);
ONVIF_GetPTZCapabilities(deviceXAddr, &ptzXAddr);
//5.获取Token
ONVIF_GetMediaProfilesToken(mediaXAddr, &mediaprofilesToken);
ONVIF_GetPTZProfilesToken(ptzXAddr, &ptzprofilesToken);
//6.获取RTSP地址
ONVIF_GetStreamUri(mediaXAddr, mediaprofilesToken, &streamUri);
//7.ptz控制
//所有移动命令应以非阻塞方式执行,表示不应等到请求的移动操作完成。新的移动请求可以覆盖最后的移动操作。
ONVIF_PTZ_GetStatus(ptzXAddr, ptzprofilesToken, &ptzInfo);
ONVIF_PTZAbsoluteMove(ptzXAddr, ptzprofilesToken, &ptzAbsoluteMoveInfo);
sleep(5);
ONVIF_PTZRelativeMove(ptzXAddr, ptzprofilesToken, &ptzRelativeMoveInfo);
sleep(5);
ONVIF_PTZContinuousMove(ptzXAddr, ptzprofilesToken, PTZ_CMD_UP, float(0.5));
sleep(5);
/*
sleep(1); //如果当前soap被删除(或者发送stop指令),就会停止移动
ONVIF_PTZStopMove(ptzXAddr, ProfileToken);
*/
ONVIF_PTZContinuousMove(ptzXAddr, ptzprofilesToken, PTZ_CMD_DOWN, float(0.5));
sleep(5);
ONVIF_PTZ_GetStatus(ptzXAddr, ptzprofilesToken, &ptzInfo);
return 0;
}
四、运行结果
--------------------ONVIF_DeviceDiscovery--------------------
1 http://192.168.1.132:2000/onvif/device_service
2 http://192.168.1.67:1936/onvif/device_service
3 http://192.168.1.102:2000/onvif/device_service
4 http://192.168.5.168:2000/onvif/device_service
5 http://192.168.1.71:2000/onvif/device_service
6 http://192.168.5.168:2000/onvif/device_service
7 http://192.168.1.60:2000/onvif/device_service
8 http://192.168.1.128:2000/onvif/device_service
9 http://192.168.1.107:2000/onvif/device_service
10 http://192.168.1.110:5000/onvif/device_service
11 http://192.168.1.98:5000/onvif/device_service
12 http://192.168.1.117:2000/onvif/device_service
13 http://192.168.1.30:2000/onvif/device_service
14 http://192.168.1.65:5000/onvif/device_service
15 http://192.168.5.168:2000/onvif/device_service
16 http://192.168.1.137:81/onvif/device_service
17 http://192.168.1.75:2000/onvif/device_service
18 http://192.168.1.85:2000/onvif/device_service
19 http://192.168.1.68:2000/onvif/device_service
20 http://192.168.1.40:2000/onvif/device_service
21 http://192.168.1.206:2000/onvif/device_service
22 http://192.168.1.126:81/onvif/device_service
Detect end! It has detected 22 devices!
-------------------------------------------------------------
-------------------------setUSERNAME-------------------------
USERNAME = admin
-------------------------------------------------------------
-------------------------setPASSWORD-------------------------
PASSWORD = admin
-------------------------------------------------------------
-------------------ONVIF_GetDeviceInformation----------------
Manufacturer:N
Model:HD_Camera
FirmwareVersion:X8.02.91
SerialNumber:vf392b11e84
HardwareId:002
-------------------------------------------------------------
--------------------ONVIF_GetTypeCapabilities----------------
Device:http://192.168.1.137:81/onvif/device_service
Media:http://192.168.1.137:81/onvif/media
Analytics:null
Events:null
Imaging:http://192.168.1.137:81/onvif/imaging
PTZ:http://192.168.1.137:81/onvif/ptz
Extension.DeviceIO:null
Extension.Display:null
Extension.Recording:null
Extension.Search:null
Extension.Replay:null
Extension.Receiver:null
Extension.AnalyticsDevice:null
-------------------------------------------------------------
---------------------ONVIF_GetPTZCapabilities----------------
Media:http://192.168.1.137:81/onvif/media
-------------------------------------------------------------
---------------------ONVIF_GetPTZCapabilities----------------
PTZ:http://192.168.1.137:81/onvif/ptz
-------------------------------------------------------------
-----------------ONVIF_GetMediaProfilesToken-----------------
MainProfileToken
-------------------------------------------------------------
-----------------ONVIF_GetPTZProfilesToken-------------------
MainProfileToken
-------------------------------------------------------------
----------------------ONVIF_GetStreamUri---------------------
RTSP URI: rtsp://192.168.1.137:554/stream1
-------------------------------------------------------------
----------------------ONVIF_PTZ_GetStatus--------------------
MoveStatus:IDLE
当前p: 0
当前t: 0
当前z: 0
-------------------------------------------------------------
----------------------ONVIF_PTZ_GetStatus--------------------
MoveStatus:IDLE
当前p: 0
当前t: 0
当前z: 0
-------------------------------------------------------------
----------------------ONVIF_PTZ_GetStatus--------------------
MoveStatus:IDLE
当前p: 0.499641
当前t: -0.4416
当前z: 0.5
-------------------------------------------------------------
标签:std,10,onvif,函数,192.168,http,Onvif,string,ONVIF
From: https://blog.csdn.net/weixin_56438859/article/details/139506782