<开发过过程中的经验总结>
➤工具的使用

    (1)首先将文件soapClientLib.c 中"代码"的第二行和第三行注释掉,实际上该文件根本没有用,为了保险起见,仅仅是注释掉。
    (2)合理的使用onvif test tool 工具 和 wireshark抓包工具,在开发中难度之一就是不知道代码中结构体中的数据填充具体是多少,所以可以使用onvif test tool 控制设备,抓取该工具发送过去的包,分析如何填充数据。
    (3)在onvif test tool 工具中:debug——>request中几乎包含了onvif 中所有的函数接口,和该接口发送的SOAP结构源代码

 ➤段错误处理
    (1)因为不同厂家制造的摄像头,有些摄像头并没有将“所有的能力”实现,这将导致如果一下 获取所有的设备能力,在解析xml 文件的时候,如果解析到一个没有实现的能力,将导致段错误。为了避免出现该问题,解决办法是需要什么能力,就获取什么能力,没有必要一次性获取完。
req.Category = (enum tt__CapabilityCategory*)soap_malloc (soap, sizeof(int));
*(req.Category) = (enum tt__CapabilityCategory)5/*(tt__CapabilityCategory__Media)*/;
其中enum tt_CapabilityCategory定义如下:
enum tt__CapabilityCategory {
tt__CapabilityCategory__All = 0,
tt__CapabilityCategory__Analytics = 1,
tt__CapabilityCategory__Device = 2,
tt__CapabilityCategory__Events = 3,
tt__CapabilityCategory__Imaging = 4,
tt__CapabilityCategory__Media = 5,
tt__CapabilityCategory__PTZ = 6
};
 
 
    (2)因为版本原因,并不是所有的设备都支持extention功能,在tt:Extension中的tt:DHCPv6中,也就是在tt:Extension中,暂时用不到extension中的东西,就注释掉了几个调用的地方,就正常得到Capabilities,前提是extension中是没有数据的,这个原因会到导致解析xml文件出现段错误。所以屏蔽掉这部分的解析代码。
/* file: soapC.c */
SOAP_FMAC3 struct tt__Capabilities * SOAP_FMAC4 soap_in_tt__Capabilities(struct soap *soap, const char *tag, struct tt__Capabilities *a, const char *type)
{
size_t soap_flag_Analytics = ;
size_t soap_flag_Device = ;
size_t soap_flag_Events = ;
size_t soap_flag_Imaging = ;
size_t soap_flag_Media = ;
size_t soap_flag_PTZ = ;
size_t soap_flag_Extension = ;
if (soap_element_begin_in(soap, tag, , type))
return NULL;
a = (struct tt__Capabilities *)soap_id_enter(soap, soap->id, a, SOAP_TYPE_tt__Capabilities, sizeof(struct tt__Capabilities), , NULL, NULL, NULL);
if (!a)
return NULL;
soap_default_tt__Capabilities(soap, a);
if (soap_s2string(soap, soap_attr_value(soap, "-anyAttribute", ), &a->__anyAttribute, , -))
return NULL;
if (soap->body && !*soap->href)
{
for (;;)
{ soap->error = SOAP_TAG_MISMATCH;
if (soap_flag_Analytics && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__AnalyticsCapabilities(soap, "tt:Analytics", &a->Analytics, "tt:AnalyticsCapabilities"))
{ soap_flag_Analytics--;
continue;
}
if (soap_flag_Device && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__DeviceCapabilities(soap, "tt:Device", &a->Device, "tt:DeviceCapabilities"))
{ soap_flag_Device--;
continue;
}
if (soap_flag_Events && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__EventCapabilities(soap, "tt:Events", &a->Events, "tt:EventCapabilities"))
{ soap_flag_Events--;
continue;
}
if (soap_flag_Imaging && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__ImagingCapabilities(soap, "tt:Imaging", &a->Imaging, "tt:ImagingCapabilities"))
{ soap_flag_Imaging--;
continue;
}
if (soap_flag_Media && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__MediaCapabilities(soap, "tt:Media", &a->Media, "tt:MediaCapabilities"))
{ soap_flag_Media--;
continue;
}
if (soap_flag_PTZ && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__PTZCapabilities(soap, "tt:PTZ", &a->PTZ, "tt:PTZCapabilities"))
{ soap_flag_PTZ--;
continue;
}
/* wenxy comment */
/*
if (soap_flag_Extension && soap->error == SOAP_TAG_MISMATCH)
if (soap_in_PointerTott__CapabilitiesExtension(soap, "tt:Extension", &a->Extension, "tt:CapabilitiesExtension"))
{ soap_flag_Extension--;
continue;
}
*/
if (soap->error == SOAP_TAG_MISMATCH)
soap->error = soap_ignore_element(soap);
if (soap->error == SOAP_NO_TAG)
break;
if (soap->error)
return NULL;
}
if (soap_element_end_in(soap, tag))
return NULL;
}
else
{ a = (struct tt__Capabilities *)soap_id_forward(soap, soap->href, (void*)a, , SOAP_TYPE_tt__Capabilities, , sizeof(struct tt__Capabilities), , NULL);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
}
return a;
} SOAP_FMAC3 struct tt__NetworkCapabilitiesExtension * SOAP_FMAC4 soap_in_tt__NetworkCapabilitiesExtension(struct soap *soap, const char *tag, struct tt__NetworkCapabilitiesExtension *a, const char *type)
{
struct soap_blist *soap_blist___any = NULL;
size_t soap_flag_Dot11Configuration = ;
size_t soap_flag_Extension = ;
if (soap_element_begin_in(soap, tag, , type))
return NULL;
a = (struct tt__NetworkCapabilitiesExtension *)soap_id_enter(soap, soap->id, a, SOAP_TYPE_tt__NetworkCapabilitiesExtension, sizeof(struct tt__NetworkCapabilitiesExtension), NULL, NULL, NULL, NULL);
if (!a)
return NULL;
soap_default_tt__NetworkCapabilitiesExtension(soap, a);
if (soap->body && *soap->href != '#')
{
for (;;)
{ soap->error = SOAP_TAG_MISMATCH;
if (soap_flag_Dot11Configuration && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerToxsd__boolean(soap, "tt:Dot11Configuration", &a->Dot11Configuration, "xsd:boolean"))
{ soap_flag_Dot11Configuration--;
continue;
}
}
/*if (soap_flag_Extension && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__NetworkCapabilitiesExtension2(soap, "tt:Extension", &a->Extension, "tt:NetworkCapabilitiesExtension2"))
{ soap_flag_Extension--;
continue;
}
}*/
/*if (soap->error == SOAP_TAG_MISMATCH && !soap_peek_element(soap))
{ if (a->__any == NULL)
{ if (soap_blist___any == NULL)
soap_blist___any = soap_alloc_block(soap);
a->__any = (char *)soap_push_block_max(soap, soap_blist___any, sizeof(char));
if (a->__any == NULL)
return NULL;
soap_default_byte(soap, a->__any);
}
if (soap_in_byte(soap, "-any", a->__any, "xsd:byte"))
{ a->__size++;
a->__any = NULL;
continue;
}
}*/
if (soap->error == SOAP_TAG_MISMATCH)
soap->error = soap_ignore_element(soap);
if (soap->error == SOAP_NO_TAG)
break;
if (soap->error)
return NULL;
}
if (a->__any)
soap_pop_block(soap, soap_blist___any);
if (a->__size)
{ a->__any = (char *)soap_save_block(soap, soap_blist___any, NULL, );
}
else
{ a->__any = NULL;
if (soap_blist___any)
soap_end_block(soap, soap_blist___any);
}
if (soap_element_end_in(soap, tag))
return NULL;
}
else
{ a = (struct tt__NetworkCapabilitiesExtension *)soap_id_forward(soap, soap->href, (void*)a, , SOAP_TYPE_tt__NetworkCapabilitiesExtension, SOAP_TYPE_tt__NetworkCapabilitiesExtension, sizeof(struct tt__NetworkCapabilitiesExtension), , NULL, NULL);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
}
return a;
} SOAP_FMAC3 struct tt__Capabilities * SOAP_FMAC4 soap_in_tt__Capabilities(struct soap *soap, const char *tag, struct tt__Capabilities *a, const char *type)
{
size_t soap_flag_Analytics = ;
size_t soap_flag_Device = ;
size_t soap_flag_Events = ;
size_t soap_flag_Imaging = ;
size_t soap_flag_Media = ;
size_t soap_flag_PTZ = ;
size_t soap_flag_Extension = ;
if (soap_element_begin_in(soap, tag, , type))
return NULL;
a = (struct tt__Capabilities *)soap_id_enter(soap, soap->id, a, SOAP_TYPE_tt__Capabilities, sizeof(struct tt__Capabilities), NULL, NULL, NULL, NULL);
if (!a)
return NULL;
soap_default_tt__Capabilities(soap, a);
if (soap_s2char(soap, soap_attr_value(soap, "-anyAttribute", , ), &a->__anyAttribute, , , -, NULL))
return NULL;
if (soap->body && *soap->href != '#')
{
for (;;)
{ soap->error = SOAP_TAG_MISMATCH;
if (soap_flag_Analytics && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__AnalyticsCapabilities(soap, "tt:Analytics", &a->Analytics, "tt:AnalyticsCapabilities"))
{ soap_flag_Analytics--;
continue;
}
}
if (soap_flag_Device && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__DeviceCapabilities(soap, "tt:Device", &a->Device, "tt:DeviceCapabilities"))
{ soap_flag_Device--;
continue;
}
}
if (soap_flag_Events && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__EventCapabilities(soap, "tt:Events", &a->Events, "tt:EventCapabilities"))
{ soap_flag_Events--;
continue;
}
}
if (soap_flag_Imaging && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__ImagingCapabilities(soap, "tt:Imaging", &a->Imaging, "tt:ImagingCapabilities"))
{ soap_flag_Imaging--;
continue;
}
}
if (soap_flag_Media && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__MediaCapabilities(soap, "tt:Media", &a->Media, "tt:MediaCapabilities"))
{ soap_flag_Media--;
continue;
}
}
if (soap_flag_PTZ && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__PTZCapabilities(soap, "tt:PTZ", &a->PTZ, "tt:PTZCapabilities"))
{ soap_flag_PTZ--;
continue;
}
}
/*if (soap_flag_Extension && soap->error == SOAP_TAG_MISMATCH)
{ if (soap_in_PointerTott__CapabilitiesExtension(soap, "tt:Extension", &a->Extension, "tt:CapabilitiesExtension"))
{ soap_flag_Extension--;
continue;
}
}*/
if (soap->error == SOAP_TAG_MISMATCH)
soap->error = soap_ignore_element(soap);
if (soap->error == SOAP_NO_TAG)
break;
if (soap->error)
return NULL;
}
if (soap_element_end_in(soap, tag))
return NULL;
}
else
{ a = (struct tt__Capabilities *)soap_id_forward(soap, soap->href, (void*)a, , SOAP_TYPE_tt__Capabilities, SOAP_TYPE_tt__Capabilities, sizeof(struct tt__Capabilities), , NULL, NULL);
if (soap->body && soap_element_end_in(soap, tag))
return NULL;
}
return a;
}
 
    因为摄像头2D转动已经包含了1D转动功能,但是在将代码中的数据转换成xml文件的过程中,会出现段错误,经过索引发现是在将数据转换成1D对应的xml文件的过程中出现错误,所以将这部分代码屏蔽。
SOAP_FMAC3 int SOAP_FMAC4 soap_out_tt__PTZSpeed(struct soap *soap, const char *tag, int id, const struct tt__PTZSpeed *a, const char *type)
{
(void)soap; (void)tag; (void)id; (void)a; (void)type; /* appease -Wall -Werror */
if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_tt__PTZSpeed), type))
return soap->error;
if (soap_out_PointerTott__Vector2D(soap, "tt:PanTilt", -, &a->PanTilt, ""))
return soap->error;
/*
if (soap_out_PointerTott__Vector1D(soap, "tt:Zoom", -1, &a->Zoom, ""))
return soap->error;
*/
return soap_element_end_out(soap, tag);
}
 
 
    在摄像头设置网关的过程中,出现段错误,经过反复检查,发现是参数设置错误。
int ONVIF_SetNetworkDefaultGateway(char *device_ip)
{
char new_gateway[] = {};
char *ip_p = new_gateway;
#if 1
printf("please input new gateway:");
scanf("%s" , new_gateway);
if(strcmp(new_gateway , "q") == )
{
return ;
}
printf("the new gateway is :%s\n" , new_gateway);
#endif int result = -;
int size = ;
struct soap *soap = NULL;// point of soap
struct _tds__SetNetworkDefaultGateway req;//requst
struct _tds__SetNetworkDefaultGatewayResponse resp;// respone //size = strlen(ip_p);
req.IPv4Address = &ip_p;
req.__sizeIPv4Address = ; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); result = soap_call___tds__SetNetworkDefaultGateway(soap , device_ip , NULL , &req ,&resp);
printf("result is :%d\n" , result); ONVIF_soap_delete(soap);
}
 
 
“req.__sizeIPv4Address = 1“ ,该参数对应的不是IP地址的长度,是IP地址的个数。
➤调试技巧
 ➣打印信息
    在编写Makefile的时候,加上编译选项"-DDEBUG"这样在发送和接收过程中,在当前目录下就会生成RECV.log ,SENT.log,TEST.log这三个文件,分别对应发送,接收的xml文件,和日志打印信息。
 ➣段错误索引
    在编写Makefile的时候,加上编译选项"-g",执行make 命令之前,先执行命令"ulimit -c unlimited",如果出现段错误,在当前路径下就会生成一个叫“core.*”的文件。
    然后执行命令:gdb 程序名称 core.* 
    接着执行命令:where 
这样就可以索引段错误发生在哪里了。
onvif:main.o soapClientLib.o wsaapi.o stdsoap2.o soapC.o duration.o soapClient.o wsseapi.o mecevp.o smdevp.o threads.o dom.o
gcc -g -DDEBUG main.o soapClientLib.o wsaapi.o stdsoap2.o soapC.o duration.o soapClient.o wsseapi.o mecevp.o smdevp.o threads.o dom.o -lssl -lcrypto -o onvif
main.o:main.c
gcc -c -g -DDEBUG main.c -o main.o
soapClientLib.o:soapClientLib.c
gcc -c -g -DDEBUG soapClientLib.c -o soapClientLib.o
wsaapi.o:wsaapi.c
gcc -c -g -DDEBUG wsaapi.c -o wsaapi.o
stdsoap2.o:stdsoap2.c
gcc -c -g -DDEBUG -DWITH_OPENSSL stdsoap2.c -o stdsoap2.o
soapC.o:soapC.c
gcc -c -g -DDEBUG soapC.c -o soapC.o
duration.o:duration.c
gcc -c -g -DDEBUG duration.c -o duration.o
soapClient.o:soapClient.c
gcc -c -g -DDEBUG soapClient.c -o soapClient.o
wsseapi.o:wsseapi.c
gcc -c -g -DDEBUG wsseapi.c -o wsseapi.o
mecevp.o:mecevp.c
gcc -c -g -DDEBUG mecevp.c -o mecevp.o
smdevp.o:smdevp.c
gcc -c -g -DDEBUG smdevp.c -o smdevp.o
threads.o:threads.c
gcc -c -g -DDEBUG threads.c -o threads.o
dom.o:dom.c
gcc -c -g -DDEBUG dom.c -o dom.o
.PHONY:clean
clean:
rm -rf *.o
 
 
 
<代码实例>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "soapH.h"
#include "wsaapi.h"
#include "soapStub.h"
#include "wsdd.nsmap"
#include "stdsoap2.h" #define USERNAME "admin"
#if 0
#define PASSWORD "goldsun123"
#endif
#define PASSWORD "admin123" #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 multicast address #define SOAP_ITEM ""// scope of device
#define SOAP_TYPES "dn:NetworkVideoTransmitter"// type of device #define SOAP_SOCK_TIMEOUT (1)// socket timeout
#define ONVIF_TOKEN_SIZE 65 // 唯一标识该视频编码器的令牌字符串 #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 () /*configuration of video encode */
struct tagVideoEncoderConfiguration
{
char token[ONVIF_TOKEN_SIZE];// video token
int Width;// resolution ratio
int Height;
}; /* configuration of device */
struct tagProfile {
char token[ONVIF_TOKEN_SIZE];// device token struct tagVideoEncoderConfiguration venc;// video encoding configuration information
}; //enum tt__CapabilityCategory my_category; void soap_perror(struct soap *soap, const char *str)
{
if (NULL == str) {
SOAP_DBGERR("[soap] error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
} else {
SOAP_DBGERR("[soap] %s error: %d, %s, %s\n", str, soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
}
return;
} void* ONVIF_soap_malloc(struct soap *soap, unsigned int n)
{
void *p = NULL; if (n > ) {
p = soap_malloc(soap, n);
SOAP_ASSERT(NULL != p);
memset(p, 0x00 ,n);
}
return p;
} struct soap *ONVIF_soap_new(int timeout)
{
struct soap *soap = NULL;// onvif soap SOAP_ASSERT(NULL != (soap = soap_new())); soap_set_namespaces(soap, namespaces);// set soap namespaces
soap->recv_timeout = timeout;// timeout
soap->send_timeout = timeout;
soap->connect_timeout = timeout; #if defined(__linux__) || defined(__linux) // 参考https://www.genivia.com/dev.html#client-c的修改:
soap->socket_flags = MSG_NOSIGNAL; // To prevent connection reset errors
#endif soap_set_mode(soap, SOAP_C_UTFSTRING);// set encoding of character return soap;
} void ONVIF_soap_delete(struct soap *soap)
{
soap_destroy(soap); // remove deserialized class instances (C++ only)
soap_end(soap); // Clean up deserialized data (except class instances) and temporary data
soap_done(soap);// Reset, close communications, and remove callbacks
soap_free(soap);// Reset and deallocate the context created with soap_new or soap_copy
} void ONVIF_init_header(struct soap *soap)
{
struct SOAP_ENV__Header *header = NULL; SOAP_ASSERT(NULL != soap); header = (struct SOAP_ENV__Header *)ONVIF_soap_malloc(soap, sizeof(struct SOAP_ENV__Header));//in heap
soap_default_SOAP_ENV__Header(soap, header);
header->wsa__MessageID = (char*)soap_wsa_rand_uuid(soap);//get uuid
header->wsa__To = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_TO) + );
header->wsa__Action = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_ACTION) + );
strcpy(header->wsa__To, SOAP_TO);
strcpy(header->wsa__Action, SOAP_ACTION);
soap->header = header; return;
} void ONVIF_init_ProbeType(struct soap *soap, struct wsdd__ProbeType *probe)
{
struct wsdd__ScopesType *scope = NULL;// 用于描述查找哪类的Web服务 SOAP_ASSERT(NULL != soap);
SOAP_ASSERT(NULL != probe); scope = (struct wsdd__ScopesType *)ONVIF_soap_malloc(soap, sizeof(struct wsdd__ScopesType));
soap_default_wsdd__ScopesType(soap, scope);// 设置寻找设备的范围
scope->__item = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_ITEM) + );
strcpy(scope->__item, SOAP_ITEM); memset(probe, 0x00, sizeof(struct wsdd__ProbeType));
soap_default_wsdd__ProbeType(soap, probe);
probe->Scopes = scope;
probe->Types = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_TYPES) + );// 设置寻找设备的类型
strcpy(probe->Types, SOAP_TYPES); return;
} static int ONVIF_SetAuthInfo(struct soap *soap, const char *username, const char *password)
{
int result = ; SOAP_ASSERT(NULL != username);
SOAP_ASSERT(NULL != password); result = soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);
SOAP_CHECK_ERROR(result, soap, "add_UsernameTokenDigest"); EXIT: return result;
} void ONVIF_DetectDevice(void (*cb)(char *DeviceXAddr) , char *ip)
{
int i;
int result = ;
unsigned int count = ;// count of device
struct soap *soap = NULL;// soap
struct wsdd__ProbeType req;// request
struct __wsdd__ProbeMatches resp;// respone
struct wsdd__ProbeMatchType *probeMatch; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); ONVIF_init_header(soap);// init header
ONVIF_init_ProbeType(soap, &req);//set scope and type
result = soap_send___wsdd__Probe(soap, SOAP_MCAST_ADDR, NULL, &req);// send request
while (SOAP_OK == result)// receive respone
{
memset(&resp, 0x00, sizeof(resp));
result = soap_recv___wsdd__ProbeMatches(soap, &resp);
if (SOAP_OK == result) {
if (soap->error) {
soap_perror(soap, "ProbeMatches");
}
else
{
for(i = ; i < resp.wsdd__ProbeMatches->__sizeProbeMatch; i++)//display information
{
printf("__sizeProbeMatch : %d\n", resp.wsdd__ProbeMatches->__sizeProbeMatch);
printf("wsa__EndpointReference : %p\n", resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference);
printf("Target EP Address : %s\n", resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address);
printf("Target Type : %s\n", resp.wsdd__ProbeMatches->ProbeMatch->Types);
printf("Target Service Address : %s\n", resp.wsdd__ProbeMatches->ProbeMatch->XAddrs);
memcpy(ip , resp.wsdd__ProbeMatches->ProbeMatch->XAddrs , strlen(resp.wsdd__ProbeMatches->ProbeMatch->XAddrs));
printf("Target Metadata Version : %d\n", resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion);
if(resp.wsdd__ProbeMatches->ProbeMatch->Scopes)
{
printf("Target Scopes Address : %s\n\n", resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item);
}
}
if (NULL != resp.wsdd__ProbeMatches)
{
count += resp.wsdd__ProbeMatches->__sizeProbeMatch;
for(i = ; i < resp.wsdd__ProbeMatches->__sizeProbeMatch; i++)
{
probeMatch = resp.wsdd__ProbeMatches->ProbeMatch + i;
if (NULL != cb)
{
cb(probeMatch->XAddrs); // run callback function
}
}
}
}
}
else if (soap->error)
{
break;
}
} //SOAP_DBGLOG("\ndetect end! It has detected %d devices!\n", count);
if (NULL != soap)
{
ONVIF_soap_delete(soap);
}
return ;
} //set ip address
int ONVIF_SetNetworkInterfaces(char *old_addr ,char *new_ip , char *device_token)
{
//char new_addr[128] = {"192.168.1.200"};
int result = SOAP_ERR;
if( old_addr != NULL && != strlen(old_addr) )
{
struct soap soap;
soap_init(&soap);
struct _tds__SetNetworkInterfaces req = {};
struct _tds__SetNetworkInterfacesResponse rsp; //rsp.RebootNeeded = 1;//设置后重启 //char interface[32] = "eth0";
req.InterfaceToken = device_token;//要设置的设备网络接口
//xsd__boolean dhcp = xsd__boolean__true_;
//network.Enabled = 1;
enum xsd__boolean netEnable = xsd__boolean__true_;
enum xsd__boolean ipv4Enable = xsd__boolean__true_;
enum xsd__boolean DHCP = xsd__boolean__false_;
enum xsd__boolean autoneg = xsd__boolean__true_;
enum xsd__boolean duplex = tt__Duplex__Full;
struct tt__NetworkInterfaceConnectionSetting net_set;
net_set.AutoNegotiation = autoneg;
net_set.Speed = ;
net_set.Duplex = duplex; struct tt__NetworkInterfaceSetConfiguration network;
soap_default_tt__NetworkInterfaceSetConfiguration(&soap, &network);
network.Enabled = &netEnable;
network.Link = &net_set; struct tt__IPv4NetworkInterfaceSetConfiguration tt_ipv4;
soap_default_tt__IPv4NetworkInterfaceSetConfiguration(&soap, &tt_ipv4); struct tt__PrefixedIPv4Address tt_prefAddr;
soap_default_tt__PrefixedIPv4Address(&soap, &tt_prefAddr);
tt_prefAddr.Address = new_ip;//the new ip address
tt_prefAddr.PrefixLength = ; tt_ipv4.Manual = &tt_prefAddr;
tt_ipv4.__sizeManual = ;//important
tt_ipv4.DHCP = &DHCP;
tt_ipv4.Enabled = &ipv4Enable; network.IPv4 = &tt_ipv4; int mtuLen = ;
network.MTU = &mtuLen; //printf("%d\n", network.IPv4->Manual->PrefixLength);
//printf("%s\n", network.IPv4->Manual->Address);
req.NetworkInterface = &network; ONVIF_SetAuthInfo(&soap, USERNAME, PASSWORD);
result = soap_call___tds__SetNetworkInterfaces(&soap,old_addr, NULL, &req, &rsp);
if(result == SOAP_OK)
{
printf("SetNetworkInterfaces successful\n");
}
soap_destroy(&soap);
soap_end(&soap);
soap_done(&soap);
}
return result; } int ONVIF_GetDeviceInformation(const char *DeviceXAddr)
{
int result = ;
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))); ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); 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");
printf("\n\n");
printf("SerialNumber number is :%d\n" , devinfo_resp.SerialNumber ); EXIT: if (NULL != soap) {
ONVIF_soap_delete(soap);
}
return result;
} int ONVIF_GetCapabilities(const char *device_server , char *media_ip , char *ptz_ip)
{
int result = ;
struct soap *soap = NULL;
struct _tds__GetCapabilities req;
struct _tds__GetCapabilitiesResponse resp; SOAP_ASSERT(NULL != device_server);
SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
memset(&req, 0x00, sizeof(req)); memset(&resp, 0x00, sizeof(resp));
req.__sizeCategory = ;
req.Category = (enum tt__CapabilityCategory*)soap_malloc (soap, sizeof(int));
*(req.Category) = (enum tt__CapabilityCategory)/*(tt__CapabilityCategory__Media)*/; ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); result = soap_call___tds__GetCapabilities(soap, device_server, NULL, &req, &resp);
printf("\n\n");
//printf("result is :%d\n", result);
SOAP_CHECK_ERROR(result, soap, "GetCapabilities");
if(strlen(resp.Capabilities->Media->XAddr) > )
{
return -;
}
else
{
memcpy(media_ip , resp.Capabilities->Media->XAddr , strlen(resp.Capabilities->Media->XAddr));
}
printf("media addr is :%s\n" , resp.Capabilities->Media->XAddr);
/*get PTZ address*/
req.__sizeCategory = ;
req.Category = (enum tt__CapabilityCategory*)soap_malloc (soap, sizeof(int));
*(req.Category) = (enum tt__CapabilityCategory)/*(tt__CapabilityCategory__Media)*/;
result = soap_call___tds__GetCapabilities(soap, device_server, NULL, &req, &resp);
printf("\n\n");
SOAP_CHECK_ERROR(result, soap, "GetCapabilities");
#if 1
if(resp.Capabilities->PTZ == NULL)
{
printf("unsurpport PTZ\n");
return -;
}
if(strlen(resp.Capabilities->PTZ->XAddr) > )
{
return -;
}
else
{
memcpy(ptz_ip , resp.Capabilities->PTZ->XAddr , strlen(resp.Capabilities->PTZ->XAddr));
}
//printf("PTZ addr is :%s\n" , resp.Capabilities->PTZ->XAddr);
#endif
EXIT: if (NULL != soap) {
ONVIF_soap_delete(soap);
}
return result;
} int ONVIF_GetZeroConfiguration(char *addr , char *device_token)
{
int result = ;
struct soap *soap = NULL;
struct _tds__GetZeroConfiguration req;
struct _tds__GetZeroConfigurationResponse resp; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); result = soap_call___tds__GetZeroConfiguration(soap , addr , NULL , &req , &resp);
if(strlen(resp.ZeroConfiguration->InterfaceToken) > )
{
return -;
}
else
{
memcpy(device_token , resp.ZeroConfiguration->InterfaceToken , strlen(resp.ZeroConfiguration->InterfaceToken));
}
printf("\ntoken is :%s\n" , resp.ZeroConfiguration->InterfaceToken);
ONVIF_soap_delete(soap);
return result; } int ONVIF_GetStreamUri(const char *MediaXAddr, char *ProfileToken)
{
int result = ;
char uri[] = {};
struct soap *soap = NULL;
struct tt__StreamSetup ttStreamSetup;
struct tt__Transport ttTransport;
struct _trt__GetStreamUri req;
struct _trt__GetStreamUriResponse resp; SOAP_ASSERT(NULL != MediaXAddr); SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); memset(&req, 0x00, sizeof(req));
memset(&resp, 0x00, sizeof(resp));
memset(&ttStreamSetup, 0x00, sizeof(ttStreamSetup));
memset(&ttTransport, 0x00, sizeof(ttTransport));
ttStreamSetup.Stream = tt__StreamType__RTP_Unicast;
ttStreamSetup.Transport = &ttTransport;
ttStreamSetup.Transport->Protocol = tt__TransportProtocol__RTSP;
ttStreamSetup.Transport->Tunnel = NULL;
req.StreamSetup = &ttStreamSetup;
req.ProfileToken = ProfileToken; ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
result = soap_call___trt__GetStreamUri(soap, MediaXAddr, NULL, &req, &resp);
SOAP_CHECK_ERROR(result, soap, "GetServices");
printf("uri is :%s\n", resp.MediaUri->Uri); EXIT: if (NULL != soap) {
ONVIF_soap_delete(soap);
}
return result;
}
/*get media profile*/
int ONVIF_Media_GetProfiles(const char *Media_ip)
{
int i = ;
int result = ;
int stmno = ;
struct soap *soap = NULL;
struct tagProfile *profiles = NULL;
struct _trt__GetProfiles req;
struct _trt__GetProfilesResponse resp; SOAP_ASSERT(NULL != Media_ip);
SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); memset(&req, 0x00, sizeof(req));
memset(&resp, 0x00, sizeof(resp));
result = soap_call___trt__GetProfiles(soap, Media_ip, NULL, &req, &resp);
printf(">>>result is :%d\n" , result);
SOAP_CHECK_ERROR(result, soap, "GetProfiles");
//printf information of profiles
printf("\n\n");
printf("__sizeprofiles is :%d\n" , resp.__sizeProfiles);
printf("name is :%s\n" , resp.Profiles->Name);
printf("token is :%s\n" , resp.Profiles->VideoSourceConfiguration->token);
printf("sourcetoken is :%s\n" , resp.Profiles->VideoSourceConfiguration->SourceToken);
printf("usecoutn is :%d\n" , resp.Profiles->VideoEncoderConfiguration->UseCount);
printf("__size is :%d\n" , resp.Profiles->VideoEncoderConfiguration->__size);
printf("__any is :%d\n" , resp.Profiles->VideoEncoderConfiguration->__any );
printf("profile token is :%s\n" , resp.Profiles->token);
printf("\n\n");
if (resp.__sizeProfiles > )
{
profiles = (struct tagProfile *)malloc(resp.__sizeProfiles * sizeof(struct tagProfile));//malloc cache
SOAP_ASSERT(NULL != profiles);
memset(profiles, 0x00, resp.__sizeProfiles * sizeof(struct tagProfile));
}
/*resolve respone*/
for(i = ; i < resp.__sizeProfiles; i++) {
struct tt__Profile *RespProfile = &resp.Profiles[i];
struct tagProfile *StoreProfile = &profiles[i]; if (NULL != RespProfile->token)// store Token
{
strncpy(StoreProfile->token, RespProfile->token, sizeof(StoreProfile->token) - );
} if (NULL != RespProfile->VideoEncoderConfiguration) //video encode configuration
{
if (NULL != RespProfile->VideoEncoderConfiguration->token) // store video Token
{
strncpy(StoreProfile->venc.token, RespProfile->VideoEncoderConfiguration->token, sizeof(StoreProfile->venc.token) - );
}
if (NULL != RespProfile->VideoEncoderConfiguration->Resolution) // video resolutio
{
StoreProfile->venc.Width = RespProfile->VideoEncoderConfiguration->Resolution->Width;
StoreProfile->venc.Height = RespProfile->VideoEncoderConfiguration->Resolution->Height;
}
}
ONVIF_GetStreamUri(Media_ip , profiles[i].token);
printf("profile token is :%s\n" , StoreProfile->token);
printf("video token is :%s\n" , StoreProfile->venc.token);
printf("video width is :%d\n" , StoreProfile->venc.Width);
printf("video height is :%d\n" , StoreProfile->venc.Height);
if(RespProfile->VideoEncoderConfiguration->Encoding == )
{
printf("video encode is :JPEG\n");
}
if(RespProfile->VideoEncoderConfiguration->Encoding == )
{
printf("video encode is :MPEG4\n");
}
if(RespProfile->VideoEncoderConfiguration->Encoding == )
{
printf("video encode is :H264\n");
}
printf("\n");
} return resp.__sizeProfiles;
EXIT: if (NULL != soap) {
ONVIF_soap_delete(soap);
} return resp.__sizeProfiles;
}
/*get PTZ profiles*/
int ONVIF_PTZ_GetProfiles(const char *media_ip , char *absolute_ip , char *zoom_ip)
{
int i = ;
int result = ;
struct soap *soap = NULL;
struct tagProfile *profiles = NULL;
struct _trt__GetProfiles req;
struct _trt__GetProfilesResponse resp; SOAP_ASSERT(NULL != media_ip);
SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); memset(&req, 0x00, sizeof(req));
memset(&resp, 0x00, sizeof(resp));
result = soap_call___trt__GetProfiles(soap, media_ip, NULL, &req, &resp);
printf("result is :%d\n" ,result);
SOAP_CHECK_ERROR(result, soap, "GetProfiles");
//printf information of profiles
printf("\n\n");
printf("__sizeprofiles is :%d\n" , resp.__sizeProfiles);
printf("name is :%s\n" , resp.Profiles->Name);
printf("token is :%s\n" , resp.Profiles->PTZConfiguration->token);
printf("NodeToken is :%s\n" , resp.Profiles->PTZConfiguration->NodeToken);
printf("UseCount is :%d\n" , resp.Profiles->PTZConfiguration->UseCount);
printf("DefaultAbsolutePantTiltPositionSpace is :%d\n" , resp.Profiles->PTZConfiguration->DefaultAbsolutePantTiltPositionSpace);
printf("DefaultAbsoluteZoomPositionSpace is :%d\n" , resp.Profiles->PTZConfiguration->DefaultAbsoluteZoomPositionSpace);
printf("DefaultRelativePanTiltTranslationSpace is :%d\n" , resp.Profiles->PTZConfiguration->DefaultRelativePanTiltTranslationSpace );
printf("DefaultRelativeZoomTranslationSpace is :%s\n" , resp.Profiles->PTZConfiguration->DefaultRelativeZoomTranslationSpace);
printf("DefaultRelativeZoomTranslationSpace is :%s\n" , resp.Profiles->PTZConfiguration->DefaultRelativeZoomTranslationSpace);
printf("DefaultContinuousPanTiltVelocitySpace is :%s\n" , resp.Profiles->PTZConfiguration->DefaultContinuousPanTiltVelocitySpace);
printf("DefaultContinuousZoomVelocitySpace is :%s\n" , resp.Profiles->PTZConfiguration->DefaultContinuousZoomVelocitySpace);
printf("DefualtPTZTimeout is :%d\n" , *(resp.Profiles->PTZConfiguration->DefaultPTZTimeout));
printf("DefaultPTZSpeed Vector2D PanTilt x is :%f\n" , resp.Profiles->PTZConfiguration->DefaultPTZSpeed->PanTilt->x);
printf("DefaultPTZSpeed dVector2D PanTilt y is :%f\n" , resp.Profiles->PTZConfiguration->DefaultPTZSpeed->PanTilt->y);
printf("DefaultPTZSpeed dVector2D PanTilt space is :%s\n" , resp.Profiles->PTZConfiguration->DefaultPTZSpeed->PanTilt->space);
memcpy(absolute_ip ,resp.Profiles->PTZConfiguration->DefaultPTZSpeed->PanTilt->space , strlen(resp.Profiles->PTZConfiguration->DefaultPTZSpeed->PanTilt->space));
printf("DefaultPTZSpeed Vector1D Zoom x is :%f\n" , resp.Profiles->PTZConfiguration->DefaultPTZSpeed->Zoom->x);
printf("DefaultPTZSpeed Vector2D Zoom space is :%s\n" , resp.Profiles->PTZConfiguration->DefaultPTZSpeed->Zoom->space);
printf("PanTiltLimits Range URI is :%s\n" ,resp.Profiles->PTZConfiguration->PanTiltLimits->Range->URI);
printf("PanTiltLimits Range XRange Min is :%f\n" ,resp.Profiles->PTZConfiguration->PanTiltLimits->Range->XRange->Min);
printf("PanTiltLimits Range XRange Max is :%f\n" ,resp.Profiles->PTZConfiguration->PanTiltLimits->Range->XRange->Max);
printf("PanTiltLimits Range YRange Min is :%f\n" ,resp.Profiles->PTZConfiguration->PanTiltLimits->Range->YRange->Min);
printf("PanTiltLimits Range YRange Max is :%f\n" ,resp.Profiles->PTZConfiguration->PanTiltLimits->Range->YRange->Max);
printf("ZoomLimits Range URI is :%s\n" ,resp.Profiles->PTZConfiguration->ZoomLimits->Range->URI);
memcpy(zoom_ip , resp.Profiles->PTZConfiguration->ZoomLimits->Range->URI , strlen(resp.Profiles->PTZConfiguration->ZoomLimits->Range->URI));
printf("ZoomLimits Range XRange Min is :%f\n" ,resp.Profiles->PTZConfiguration->ZoomLimits->Range->XRange->Min);
printf("ZoomLimits Range XRange Max is :%f\n" ,resp.Profiles->PTZConfiguration->ZoomLimits->Range->XRange->Max); printf("\n\n");
#if 0
if (resp.__sizeProfiles > )
{ // 分配缓存
profiles = (struct tagProfile *)malloc(resp.__sizeProfiles * sizeof(struct tagProfile));
SOAP_ASSERT(NULL != profiles);
memset(profiles, 0x00, resp.__sizeProfiles * sizeof(struct tagProfile));
} for(i = ; i < resp.__sizeProfiles; i++) { // 提取所有配置文件信息
struct tt__Profile *RespProfile = &resp.Profiles[i];
struct tagProfile *StoreProfile = &profiles[i]; if (NULL != RespProfile->token)// store Token
{
strncpy(StoreProfile->token, RespProfile->token, sizeof(StoreProfile->token) - );
} if (NULL != RespProfile->VideoEncoderConfiguration) //video encode configuration
{
if (NULL != RespProfile->VideoEncoderConfiguration->token) // store video Token
{
strncpy(StoreProfile->venc.token, RespProfile->VideoEncoderConfiguration->token, sizeof(StoreProfile->venc.token) - );
}
if (NULL != RespProfile->VideoEncoderConfiguration->Resolution) // video resolutio
{
StoreProfile->venc.Width = RespProfile->VideoEncoderConfiguration->Resolution->Width;
StoreProfile->venc.Height = RespProfile->VideoEncoderConfiguration->Resolution->Height;
}
}
ONVIF_GetStreamUri(MediaXAddr , profiles[i].token);
printf("profile token is :%s\n" , StoreProfile->token);
printf("video token is :%s\n" , StoreProfile->venc.token);
printf("video width is :%d\n" , StoreProfile->venc.Width);
printf("video height is :%d\n" , StoreProfile->venc.Height);
if(RespProfile->VideoEncoderConfiguration->Encoding == )
{
printf("video encode is :JPEG\n");
}
if(RespProfile->VideoEncoderConfiguration->Encoding == )
{
printf("video encode is :MPEG4\n");
}
if(RespProfile->VideoEncoderConfiguration->Encoding == )
{
printf("video encode is :H264\n");
}
printf("\n");
}
#endif
return resp.__sizeProfiles;
EXIT: if (NULL != soap) {
ONVIF_soap_delete(soap);
} return resp.__sizeProfiles;
} int ONVIF_Get_Gateway(char *device_ip)
{
int result = -;
struct soap *soap = NULL;// point of soap
struct _tds__GetNetworkDefaultGateway req;//requst
struct _tds__GetNetworkDefaultGatewayResponse resp;// respone SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
result = soap_call___tds__GetNetworkDefaultGateway(soap , device_ip , NULL , &req , &resp); printf("result is :%d\n" , result);
#if 1
if(*(resp.NetworkGateway->IPv4Address) == NULL)
{
printf("can't get gateway address \n");
return -;
}
else
{
printf("the gateway address is :%s\n" , *(resp.NetworkGateway->IPv4Address));
}
#endif
ONVIF_soap_delete(soap);
return ;
} int ONVIF_SetNetworkDefaultGateway(char *device_ip)
{
char new_gateway[] = {};
char *ip_p = new_gateway;
#if 1
printf("please input new gateway:");
scanf("%s" , new_gateway);
if(strcmp(new_gateway , "q") == )
{
return ;
}
printf("the new gateway is :%s\n" , new_gateway);
#endif int result = -;
int size = ;
struct soap *soap = NULL;// point of soap
struct _tds__SetNetworkDefaultGateway req;//requst
struct _tds__SetNetworkDefaultGatewayResponse resp;// respone //size = strlen(ip_p);
req.IPv4Address = &ip_p;
req.__sizeIPv4Address = ; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); result = soap_call___tds__SetNetworkDefaultGateway(soap , device_ip , NULL , &req ,&resp);
printf("result is :%d\n" , result); ONVIF_soap_delete(soap);
} #if 1
int ONVIF_AbsoluteMove(char *ptz_ip , char *absolute_move_ip , char *absolute_zoom_ip)
{ int result = -;
struct soap *soap = NULL;// pointer of soap
struct _tptz__AbsoluteMove req;
struct _tptz__AbsoluteMoveResponse resp; struct tt__Vector2D vector2d;
vector2d.x = -;//absolute x angle
vector2d.y = -;//absolute y angle
vector2d.space = absolute_move_ip;
#if 1
struct tt__Vector1D vector1d;
vector1d.x = ;//absolute foci
vector1d.space = absolute_zoom_ip;
#endif struct tt__PTZVector ptzvector;
ptzvector.PanTilt = &vector2d;
ptzvector.Zoom = &vector1d; req.Position = &ptzvector;
req.ProfileToken = "Profile_1";
req.Speed = NULL; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); result = ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); printf("ONvif_SetAuthInfo is :%d\n" , result); result =soap_call___tptz__AbsoluteMove(soap , ptz_ip , NULL , &req , &resp);
sleep();
ONVIF_soap_delete(soap);
printf("result is :%d\n" , result);
return result;
}
#endif #if 0
#endifSOAP_FMAC5 int SOAP_FMAC6 soap_call___tptz__RelativeMove(struct soap *soap, const char *soap_endpoint, const char *soap_action, struct _tptz__RelativeMove *tptz__RelativeMove, struct _tptz__RelativeMoveResponse *tptz__RelativeMoveResponse)
#endif int ONVIf_RelativeMove(char *tpz_ip , char *relative_move_ip , char *relative_zoom_ip )
{
int result = -;
struct soap *soap = NULL;// pointer of soap
struct _tptz__RelativeMove req;
struct _tptz__RelativeMoveResponse resp; struct tt__Vector2D vector2d;
vector2d.x = 0.3;
vector2d.y = 0.4;
vector2d.space = relative_move_ip; struct tt__Vector1D vector1d;
vector1d.x = 0.5;
vector1d.space = relative_zoom_ip; struct tt__PTZVector ptzvector;
ptzvector.PanTilt = &vector2d;
ptzvector.Zoom = &vector1d; req.ProfileToken = "Profile_1";
req.Translation = &ptzvector;
req.Speed = NULL; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); result = ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
printf("ONvif_SetAuthInfo is :%d\n" , result); result = soap_call___tptz__RelativeMove(soap , tpz_ip , NULL , &req ,&resp); ONVIF_soap_delete(soap); printf("result is :%d\n" , result);
return result;
} int ONVIF_Stop()
{ char *ptz_ip = "http://192.168.235.201/onvif/PTZ";
int result = -;
struct soap *soap = NULL;// pointer of soap
struct _tptz__Stop req;
struct _tptz__StopResponse resp; enum xsd__boolean stop_rote = xsd__boolean__true_;
enum xsd__boolean stop_foci = xsd__boolean__false_; req.PanTilt = &stop_rote;
req.Zoom = &stop_foci;
req.ProfileToken = "Profile_1"; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));
result = ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD); printf("ONvif_SetAuthInfo is :%d\n" , result);
result = soap_call___tptz__Stop(soap , ptz_ip , NULL , &req , &resp); ONVIF_soap_delete(soap);
} int ONVIF_ContinuousMove(char *ptz_ip , char *continuous_move_ip , char *continuous_zoom_ip)
{
int result = -;
struct soap *soap = NULL;// pointer of soap
struct _tptz__ContinuousMove req;
struct _tptz__ContinuousMoveResponse resp; struct tt__Vector2D vector2d;
vector2d.x = ;
vector2d.y = ;
vector2d.space = continuous_move_ip; struct tt__Vector1D vector1d;
vector1d.x = ;
vector1d.space = continuous_zoom_ip; struct tt__PTZSpeed ptzspeed;
ptzspeed.PanTilt = &vector2d;
ptzspeed.Zoom = &vector1d; req.ProfileToken = "Profile_1";
req.Velocity = &ptzspeed; SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT))); result = ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
printf("ONvif_SetAuthInfo is :%d\n" , result);
result = soap_call___tptz__ContinuousMove(soap , ptz_ip , NULL , &req , &resp);
printf("result is :%d\n" , result); ONVIF_soap_delete(soap);
return result; } void sig_fun(int signum)
{
printf("stop roting \n");
ONVIF_Stop();
exit();
} int main(int argc, char **argv)
{
#if 0
signal(SIGINT , sig_fun);
#endif //char device_ip[128] = {0};
char *device_ip = "http://192.168.235.201/onvif/device_service";
char media_ip[] = {};
char new_ip[] = {};
//char ptz_ip[128] = {0};
char *ptz_ip = "http://192.168.235.201/onvif/PTZ";
char device_token[] = {};
//char absolute_ip[128] = {0};
char *absolute_move_ip = "http://www.onvif.org/ver10/tptz/PanTiltSpaces/PositionGenericSpace";
//char zoom_ip[128] = {0};
char *absolute_zoom_ip = "http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace";
//char *addr = NULL;
//struct tagProfile *profiles = NULL;
char *relative_move_ip = "http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace";
char *relative_zoom_ip = "http://www.onvif.org/ver10/tptz/ZoomSpaces/TranslationGenericSpace"; char *continuous_move_ip = "http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace";
char *continuous_zoom_ip = "http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace";
int result = ; //ONVIF_Get_Gateway(device_ip); ONVIF_SetNetworkDefaultGateway(device_ip); #if 1
#if 0
char device_service_ip[] = {"http://192.168.235.200/onvif/device_service"};
#endif
/*get device ip*/
ONVIF_DetectDevice(NULL , device_ip);
printf("device ip is :%s\n" , device_ip);
/*get device token*/
//ONVIF_GetZeroConfiguration(device_ip , device_token); #if 1
//printf("\n\n");
printf("please input new ip :");
scanf("%s" , new_ip);
printf("new_ip is :%s\n" , new_ip);
if(strcmp(new_ip , "q") != )
{
result = ONVIF_SetNetworkInterfaces(device_ip , new_ip , device_token);
printf("result of set ip is :%d\n" , result);
sleep();
ONVIF_DetectDevice(NULL , device_ip);
printf("\n\n");
}
#endif
//get device info
ONVIF_GetDeviceInformation(device_ip);
//get capabilities
ONVIF_GetCapabilities(device_ip , media_ip , ptz_ip);
printf("ptz_ip is :%s\n" , ptz_ip);
//get profiles
result = ONVIF_Media_GetProfiles(media_ip);
result = ONVIF_PTZ_GetProfiles(media_ip , absolute_ip , zoom_ip);
printf("abusolute ip is :%s\n" , absolute_ip);
printf("zoom_ip ip is :%s\n" , zoom_ip);
#endif
#if 1
ONVIF_AbsoluteMove(ptz_ip , absolute_move_ip , absolute_zoom_ip);
//printf("result is :%d\n" , result);
#endif #if 1
ONVIf_RelativeMove(ptz_ip , relative_move_ip , relative_zoom_ip);
#endif #if 1
ONVIF_ContinuousMove(ptz_ip , continuous_move_ip , continuous_zoom_ip);
while();
return ;
#endif
}
 
 
 

<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">

 
 
 
 
  • Add to Phrasebook

     
    • No wordlists for English -> Simplified Chinese...

       
    • Create a new wordlist...
  • Copy

ONVIF开发实例的更多相关文章

  1. ecshop二次开发 给商品添加自定义字段【包含我自己进一步的开发实例详解】

    本文包含商品自定义添加教程及进一步的开发实例: 教程: 说起自定义字段,我想很多的朋友像我一样会想起一些开源的CMS(比如Dedecms.Phpcms.帝国)等,他们是可以在后台直接添加自定义字段的. ...

  2. RDIFramework.NET -.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(WebForm版)

    RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(WebForm版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之 ...

  3. RDIFramework.NET-.NET快速信息化系统开发整合框架 【开发实例 EasyUI】之产品管理(MVC版)

    RDIFramework.NET—.NET快速开发整合框架 [开发实例]之产品管理(MVC版) 接上篇:RDIFramework.NET (.NET快速信息化系统开发整合框架) [开发实例]之产品管理 ...

  4. Cocos2d-x 3.X手游开发实例详解

    Cocos2d-x 3.X手游开发实例详解(最新最简Cocos2d-x手机游戏开发学习方法,以热门游戏2048.卡牌为例,完整再现手游的开发过程,实例丰富,代码完备,Cocos2d-x作者之一林顺和泰 ...

  5. 免费的HTML5连载来了《HTML5网页开发实例详解》连载(二)

    最近新浪.百度.腾讯.京东.大众点评.淘宝等流行的网站都加大了招聘HTML5的力度,HTML5开发人员成了抢手货,本次连载的是由大众点评前端工程师和一淘网前端工程师基情奉献的<HTML5网页开发 ...

  6. RDIFramework.NET开发实例━表约束条件权限的使用-Web

    RDIFramework.NET开发实例━表约束条件权限的使用-Web 在上一篇文章“RDIFramework.NET开发实例━表约束条件权限的使用-WinForm”我们讲解了在WinForm下表约束 ...

  7. RDIFramework.NET开发实例━表约束条件权限的使用-WinForm

    RDIFramework.NET开发实例━表约束条件权限的使用-WinForm 在实际的应用中,客户常有这样的需求,指定用户或角色可以看指定条件下的数据,这里的“指定条件”在RDIFramework. ...

  8. RDIFramework.NET V2.8版本 ━ 开发实例之产品管理(WinForm)

    RDIFramework.NET V2.8版本 ━ 开发实例之产品管理(WinForm) 现在,我们使用.NET快速开发整合框架(RDIFramework.NET)来开发一个应用,此应用皆在说明如何使 ...

  9. Android音乐播放器的开发实例

    本文将引导大家做一个音乐播放器,在做这个Android开发实例的过程中,能够帮助大家进一步熟悉和掌握学过的ListView和其他一些组件.为了有更好的学习效果,其中很多功能我们手动实现,例如音乐播放的 ...

随机推荐

  1. hdu 1495 非常可乐 (广搜)

    题目链接 Problem Description 大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为.因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶 ...

  2. mysql关于“异步复制”“同步复制”“半同步复制”“无损复制”的概念与区别

    异步复制:主把事务写到binlog日志并不管从是否接收或者什么时候接收,commit之后,不会与从发生ack之类的交互. 同步复制:当主提交一个事务,在主向前端返回一个commit成功的指令前,必须保 ...

  3. vue项目的配置

    1.第一首先我们先安装:visual studio code开发环境,可以换成中文版的. 2.安装note.js   下载链接:https://nodejs.org/en/ 3.安装npm使用淘宝镜像 ...

  4. JQuery获取被选中的checkbox的value值

    文章源头:http://www.cnblogs.com/td960505/p/6123510.html 以下为使用JQuery获取input checkbox被选中的值代码: <html> ...

  5. 调整扩大VMDK格式VirtualBox磁盘空间

    如果虚拟机的格式是VDI格式的, 那么可以通过这篇文章来调整磁盘大小: 调整Virtual Box硬盘大小 不过楼主当初在创建虚拟机的时候,是用的VMDK格式, 以求与VMWare的兼容性.这时候要扩 ...

  6. python3学习笔记.5.打包发布

    为了给别人使用将 .py 文件打包成 .exe 文件 安装 PyInstaller  ,完成 打开 Cmd 调用 path:\pyinstaller.exe -F path:\name.py 发布文件 ...

  7. ctime 时间

    1. 类型clock_t: 是个long型,用来记录一段时间内的时钟计时单元数,即CPU的运行单元时间.size_t: 标准C库中定义的,应为unsigned int,在64位系统中为long uns ...

  8. C/S模式和B/S模式

    C/S模式和B/S模式 1.C/S模式(Client/Server,客户机/服务器模式) 如QQ 暴风影音,PPlive等应用软件都是C/S模式 是一种软件系统结构的一种,C/S模式是基于企业内部网络 ...

  9. margin-bottom无效问题以及div里内容动态居中样式!

    最近调前端样式时候,遇到一个需求,在中间文字不对等的情况下想让下面的操作文字距离底部对齐,如图: , 刚开始觉得使用margin-bottom就可以,后来发现只有margin-top是管用的,查了资料 ...

  10. 用jquery的ajax方法获取不到return返回值

    如果jquery中,获取不到ajax返回值. 两个错误写法会导致这种情况:1.ajax未用同步 2.在ajax方法中直接return返回值. 下面列举了三种写法,如果想成功获取到返回值,参考第三种写法 ...