首页 > 其他分享 >10-Onvif协议:主函数分析

10-Onvif协议:主函数分析

时间:2024-06-06 18:02:58浏览次数:20  
标签:std 10 onvif 函数 192.168 http Onvif string ONVIF

文章目录

一、运行流程

在这里插入图片描述

二、头文件

#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

相关文章

  • 【Python Cookbook】S01E22 替换文本 re.sub(),re.subn() 以及 回调函数
    目录问题解决方案讨论问题如果我们想要对字符串中的文本做替换,该如何办?解决方案针对简单的文本模式,我们直接使用字符串内置方法str.replace()函数即可。text="Ileaveamessageforyou."print(text.replace('leave','left'))结果:Ileftamessagefor......
  • C语言杂谈:函数栈帧,函数调用时到底发生了什么
            我们都知道在调用函数时,要为函数在栈上开辟空间,函数后续内容都会在栈帧空间中保存,如非静态局部变量,返回值等。这段空间就叫栈帧。    当函数调用,就会开辟栈帧空间,函数返回时,栈帧空间就会被释放。这里的释放并非清空,而是让其无效化,可以后续的使用。1,......
  • osgearth2.10 demo功能介绍 转载文章
    osgearth-2.10demo:说明:1、运行环境win7x64旗舰版,CPUi5-64008核,8G内存;2、括号内是对应demo的测试参数(.earth);3、配置OSG_FILE_PATH;4、参数命令行可以查看各个demo需要的输入参数;5、前缀说明:gui界面程序、cmd控制台程序、non功能未知;6、程序后括号里的non表示不需要通过命令......
  • §1. 隐函数
    掌握隐函数的概念和隐函数存在唯一性定理,会求隐函数的(高阶)导数、(高阶)偏导数和极值。难点:1.求高阶导数或高阶偏导数。2.求隐函数极值。重点习题:例1、例2、例4   勒内·笛卡尔(ReneDescartes,公元1596年3月31日—公元1650年2月11日),出生于法国安德尔-卢瓦尔省的图赖讷拉......
  • §2. 隐函数组
    掌握隐函数组的概念和隐函数组定理,会求隐函数组的偏导数。掌握反函数组定理,会求反函数组的偏导数。难点:求解隐函数组的偏导数(公式法或直接求偏导数然后解方程组)。重点习题:例1、例2、例3   卡尔·雅可比(CarlGustavJacobJacobi,1804~1851),德国数学家。1804年12月10日生......
  • §1. 平面点集与多元函数
    掌握平面点集中的相关概念(邻域、内点、外点、界点、聚点、孤立点、开集、闭集、区域、有界点集),能够判断开集,闭集、有界集、区域、及它们的聚点、界点等,以及上的完备性定理(柯西准则、闭域套定理及推论、聚点原理、有界覆盖原理)。掌握二元(多元)函数的概念。难点:1.内点、外点、界点......
  • §2. 二元函数的极限
    掌握二元函数重极限和累次极限的定义及它们的关系,能够求出给定的二元函数重(累次)极限。特别注意例3中判断极限不存在的方法。难点:1.重极限定义中要注意(1)必须为聚点(2)空心邻域(3)与定义域有关。2.用定义证明重极限时选取方邻域还是圆邻域,如例1为方邻域,例2为圆邻域。3.利用定理......
  • 输出有10个元素的整型数组各元素的值
    (1)下标法编写程序:(2)指针法:将上面程序第7行和第10行的a[i]改为"*(a+i)"。(3)用指针变量指向数组元素编写程序:运行结果:对3种方法的比较:        方法(1)和(2)的执行效率是相同的。C++编译系统是将a[i]转换为*(a+1)处理的,对每个a[i]都分别计算地址a+ixd,然后访问该元素。第......
  • GLM-4-9B领先!伯克利函数调用榜单BFCL的Function Calling评测方法解析与梳理
    智谱公布的GLM-4-9B基于BFCL榜单的工具调用能力测试结果©作者|格林来源|神州问学在智谱最新开源的GLM-4-9B-Chat中,其工具调用能力在BFCL(伯克利函数调用排行榜)榜上获得了超高的总BFCL分,和gpt-4-turbo-2024-04-09几乎不相上下。在榜单中,还提到了AST总分以及Exec总分两个......
  • 函数
    用def定义一个函数不定长函数defhello(*args):#返回是一个集合print(args)#print(min(args))#print(max(args))hello(5,2,1,6,3)defhello(**kwargs):#返回是一个字典print(kwargs)hello(nihao='你好',byebye="再见")defhello(username,age=14):print(username,......