Tomcat7的装置和部署

Tomcat的装和部署我已经采用过tomcat,并贯彻了一个简约的servlet程序。没悟出再安装tomcat的早晚用浪费了我大半天的日子。我想有必要举行个小结,否则下次不知而比方费我聊时间。

<开发了过程遭到的经验总结>

 1、 Tomcat下载

➤工具的动

    Tomcat是Apache开源工程的一个列,因此我们得以错过http://tomcat.apache.org/
tomcat官网去下时版本的tomcat。目前行的是Tomcat7.02,但是由tomcat与jdk版本要配合(一般景象是jdk1.5对准承诺tomcat5,jdk1.6对许tomcat6),保险起见还是选用用Tomcat6
。网址:http://tomcat.apache.org/download-60.cgi
问题来了,网站上提供了又版的tomcat,到底哪一样暂缓符合自己吗?在网站提供的README文件中叫闹了各个版本的牵线如下:

    (1)首先以文件soapClientLib.c
中”代码”的老二推行与老三推行注释掉,实际上该文件根本没就此,为了保证起见,仅仅是注释掉。

apache-tomcat-[version].zip or .tar.gz

    (2)合理之动onvif test tool 工具 和
wireshark抓包工具,在开中难度之一就是是不知情代码中结构体中之数填充具体是有点,所以可以动用onvif
test tool 控制装备,抓取该工具发送过去的承保,分析哪些填写数据。

Base distribution. These distributions do not include the Windows
service wrapper nor the compiled APR/native library for Windows.

    (3)在onvif test tool 工具被:debug——>request中几涵盖了onvif
中具有的函数接口,和拖欠接口发送的SOAP结构源代码

apache-tomcat-[version].exe

图片 1

32-bit/64-bit Windows installer for Tomcat. Please note that while this
distribution includes the vast majority of the base distribution, some
of the command-line scripts for launching Tomcat are not included. This
distribution is intended for those users planning to launch Tomcat
through the Windows shortcuts or services.

 ➤段错误处理

apache-tomcat-[version]-windows-x86.zip

 
  (1)因为不同厂家制造的摄像头,有些摄像头并无用“所有的力量”实现,这将造成如果转 获取具有的设备能力,在解析xml
文件之时节,如果条分缕析及一个未曾落实的力,将促成段错误。为了避免出现该问题,解决办法是要什么力量,就收获什么力量,没有必要一次性取得了。

32-bit Windows specific distribution that includes the Windows service
wrapper and the compiled APR/native library for use with 32-bit JVMs on
both 32 and 64 bit Windows platforms.

req.Category = (enum tt__CapabilityCategory*)soap_malloc (soap, sizeof(int));
*(req.Category) = (enum tt__CapabilityCategory)5/*(tt__CapabilityCategory__Media)*/;

apache-tomcat-[version]-windows-x64.zip

 

64-bit Windows specific distribution that includes the Windows service
wrapper and the compiled APR/native library for use with 64-bit JVMs on
x64 Windows platforms.

其中enum
tt_CapabilityCategory定义如下:

apache-tomcat-[version]-windows-i64.zip

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
};

64-bit Windows specific distribution that includes the Windows service
wrapper and the compiled APR/native library for use with 64-bit JVMs on
Itanium 64-bit Windows platforms.

 

apache-tomcat-[version]-deployer.zip or .tar.gz

 
  (2)因为本原因,并无是有的装备都支持extention功能,在tt:Extension中的tt:DHCPv6丁,也就算是以tt:Extension中,暂时用不到extension中的物,就注释掉了几只调用的地方,就正常得到Capabilities,前提是extension中凡绝非数据的,这个由会到招解析xml文件出现段错误。所以屏蔽掉就片之剖析代码。

The standalone Tomcat Web Application Deployer.
apache-tomcat-[version]-fulldocs.tar.gz The Tomcat documentation
bundle, including complete javadocs.

/* 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 = 1;
    size_t soap_flag_Device = 1;
    size_t soap_flag_Events = 1;
    size_t soap_flag_Imaging = 1;
    size_t soap_flag_Media = 1;
    size_t soap_flag_PTZ = 1;
    size_t soap_flag_Extension = 1;
    if (soap_element_begin_in(soap, tag, 0, type))
        return NULL;
    a = (struct tt__Capabilities *)soap_id_enter(soap, soap->id, a, SOAP_TYPE_tt__Capabilities, sizeof(struct tt__Capabilities), 0, NULL, NULL, NULL);
    if (!a)
        return NULL;
    soap_default_tt__Capabilities(soap, a);
    if (soap_s2string(soap, soap_attr_value(soap, "-anyAttribute", 0), &a->__anyAttribute, 0, -1))
        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, 0, SOAP_TYPE_tt__Capabilities, 0, sizeof(struct tt__Capabilities), 0, NULL);
        if (soap->body && soap_element_end_in(soap, tag))
            return NULL;
    }
    return a;
}

诚如景象咱挑选apache-tomcat-[version]-windows-x86.zip
下载后直解压至指定目录即可(我选择了C:\tomcat) 。当然我们唯有关心binary
distributions就可以了,至于code版就看君个人学习激情了。

 

 2、 tomcat 环境布置

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 = 1;
    size_t soap_flag_Extension = 1;
    if (soap_element_begin_in(soap, tag, 0, 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, 1);
        }
        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, 0, SOAP_TYPE_tt__NetworkCapabilitiesExtension, SOAP_TYPE_tt__NetworkCapabilitiesExtension, sizeof(struct tt__NetworkCapabilitiesExtension), 0, NULL, NULL);
        if (soap->body && soap_element_end_in(soap, tag))
            return NULL;
    }
    return a;
}

    配置Tomcat的环境变量:在“我之电脑”上触右键—>“属性”—>“高级”—>
“环境变量(N)”。

 

1、新建系统变量CATALINA_HOME:C:\Tomcat(注意此后毫无加分号)

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 = 1;
    size_t soap_flag_Device = 1;
    size_t soap_flag_Events = 1;
    size_t soap_flag_Imaging = 1;
    size_t soap_flag_Media = 1;
    size_t soap_flag_PTZ = 1;
    size_t soap_flag_Extension = 1;
    if (soap_element_begin_in(soap, tag, 0, 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", 0, 0), &a->__anyAttribute, 0, 0, -1, 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, 0, SOAP_TYPE_tt__Capabilities, SOAP_TYPE_tt__Capabilities, sizeof(struct tt__Capabilities), 0, NULL, NULL);
        if (soap->body && soap_element_end_in(soap, tag))
            return NULL;
    }
    return a;
}

2、新建系统变量TOMCAT_HOME:C:\Tomcat(好像是为MyEclipse配置的)

 

3.以系变量CLASSPATH的值的后面加入:CATALINA_HOME%\lib;(这个只要加分号)

   
因为摄像头2D盘已经包含了1D筋斗功能,但是于拿代码中的多寡易成xml文件之进程被,会出现段错误,经过索引发现凡是于用数据易成1D对应的xml文件的长河被冒出谬误,所以将马上有些代码屏蔽。

4、在系统变量Path的价的后面加入以下内容:CATALINA_HOME%\bin;f\便利用户运行tomcat的各种本子:

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", -1, &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);
}

5、在系变量CLASSPATH的价的在:
CATALINA_HOME%\lib\servlet-api.jar;

 

3、 运行tomcat  直接运行startup.bat

   
在摄像头安装网关的长河遭到,出现段错误,经过三番五次检讨,发现凡是参数设置错误。

    个人建议用命令提示符程序(cmd.exe)运行C:\Tomcat\bin目录下的批判处理公事(.bat)。如:注意要以当前目录下运行否则寻不至
C:\Tomcat\bin> startup.bat install C:\Tomcat\bin> shutdown.bat
install C:\Tomcat\bin> service.bat install
开启tomcat后方可为此浏览器访问http://localhost:8080/
如果起tomcat的界面就证实你曾经成安装tomcat。

int ONVIF_SetNetworkDefaultGateway(char *device_ip)
{
    char new_gateway[128] = {0};
    char *ip_p = new_gateway;
#if 1
    printf("please input new gateway:");
    scanf("%s" , new_gateway);
    if(strcmp(new_gateway , "q") == 0)
    {
        return 0;
    }
    printf("the new gateway is :%s\n" , new_gateway);
#endif

    int result = -1;
    int size = 0;
    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 = 1;

    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);
}

4、 tomcat账户设置

 

    如果您拣的凡exe安装文件,在安装过程遭到他会见唤起而输入用户名密码。

“req.__sizeIPv4Address = 1“
,该参数对应的免是IP地址的长度,是IP地址之个数。

    如果你用的是解压包形式之,则需要在CATALINA_HOME/conf/tomcat-users.xml文件中。编辑这文件,可以修改用户名和密码,例如添加一个名“tomcat”的“manager”角色到该文件被:然后再次启航Tomcat。
登录时输入tomcat,密码tomcat即可。注意:rolename 只能是manager

➤调试技巧

5、 win7生tomcat6w.exe无法运行:

 ➣打印信息

    在windows7操作系统下,安装了tomcat6。双击tomcat6w.exe时,提示错误“Unable
to open the service ‘tomcat6’”。解决智一致:此题材也许是windows
7的安全控制限制所赋予。在tomcat6w.exe文件及点击右键–属性–兼容性,勾选“以管理员身份运行此程序”,点击确定。然后双击运行即可;如果还老见方法二。解决措施二:可能是不曾安装之起服务。具体装方式:打开命令行提示符窗口
=> 进入Tomcat安装目录==> 进入bin目录下==> 输入:service.bat
install
即可。如果还是蛮,目前便无知晓什么缓解,还期待知晓之大牛们于起实质的解决方案!(可能的因是因为网络端口独占不可知少独tomcat同时运行)

 
  在编制Makefile的时,加上编译选项”-DDEBUG”这样以殡葬和吸收过程遭到,在当前目录下虽见面生成RECV.log
,SENT.log,TEST.log这三独文本,分别指向承诺发送,接收的xml文件,和日志打印信息。

6、tomcat.ext 与tomcat6.ext主要区别:

 ➣段落错误索引

     tomcat6.exe与tomcat6w.exe这简单独都能启动tomcat,一个凡提供dos界面的开行方式,一个凡是可视化的界面启动方式。但是呢tomcat6w.exe并无是用来启动tomcat的,而是用来安排tomcat在windows下的系统服务之。两只非克同时启动。

    在编辑Makefile的时段,加上编译选项”-g”,执行make
命令之前,先执行命令”ulimit -c
unlimited”,如果起段错误,在眼前路下就会扭转一个给“core.*”的文件。

7.看俄服务器8080端口经常,在地点栏肯定要输入”http”的完好形式,否则浏览器可能不会见采取http协议去看该端口。

    然后执行命令: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 (0)

/*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 > 0) {
        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) + 1);
    header->wsa__Action    = (char*)ONVIF_soap_malloc(soap, strlen(SOAP_ACTION) + 1);
    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) + 1);
    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) + 1);// 设置寻找设备的类型
    strcpy(probe->Types, SOAP_TYPES);

    return;
}

static int ONVIF_SetAuthInfo(struct soap *soap, const char *username, const char *password)
{
    int result = 0;

    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 = 0;
    unsigned int count = 0;// 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 = 0; 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 = 0; 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 && 0 != strlen(old_addr) )
    {   
        struct soap soap;
        soap_init(&soap);
        struct _tds__SetNetworkInterfaces req = {0};
        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 = 100;
        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 = 24;

        tt_ipv4.Manual = &tt_prefAddr;
        tt_ipv4.__sizeManual = 1;//important
        tt_ipv4.DHCP = &DHCP;
        tt_ipv4.Enabled = &ipv4Enable;

        network.IPv4 = &tt_ipv4;

        int mtuLen = 1500;
        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 = 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)));

    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 = 0;
    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 = 1;
    req.Category = (enum tt__CapabilityCategory*)soap_malloc (soap, sizeof(int));
    *(req.Category) = (enum tt__CapabilityCategory)5/*(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) > 128)
    {
        return -1;
    }
    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 = 1;
    req.Category = (enum tt__CapabilityCategory*)soap_malloc (soap, sizeof(int));
    *(req.Category) = (enum tt__CapabilityCategory)6/*(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 -1;
    }
    if(strlen(resp.Capabilities->PTZ->XAddr) > 128)
    {
        return -1;
    }
    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 = 0;
    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)  > 16)
    {
        return -1;
    }
    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 = 0;
    char uri[128] = {0};
    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 = 0;
    int result = 0;
    int stmno = 0;
    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 > 0) 
    {                                               
        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 = 0; 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) - 1);
        }

        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) - 1);
            }
            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 == 0)
          {
                printf("video encode is      :JPEG\n");
          }
          if(RespProfile->VideoEncoderConfiguration->Encoding == 1)
          {
                printf("video encode is      :MPEG4\n");
          }
          if(RespProfile->VideoEncoderConfiguration->Encoding == 2)
          {
                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 = 0;
    int result = 0;
    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 > 0) 
    {                                               // 分配缓存
        profiles = (struct tagProfile *)malloc(resp.__sizeProfiles * sizeof(struct tagProfile));
        SOAP_ASSERT(NULL != profiles);
        memset(profiles, 0x00, resp.__sizeProfiles * sizeof(struct tagProfile));
    }

    for(i = 0; 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) - 1);
        }

        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) - 1);
            }
            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 == 0)
          {
                printf("video encode is      :JPEG\n");
          }
          if(RespProfile->VideoEncoderConfiguration->Encoding == 1)
          {
                printf("video encode is      :MPEG4\n");
          }
          if(RespProfile->VideoEncoderConfiguration->Encoding == 2)
          {
                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 = -1;
    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 -1;
    }
    else
    {
        printf("the gateway address is          :%s\n" , *(resp.NetworkGateway->IPv4Address));   
    }
#endif
    ONVIF_soap_delete(soap);
    return 0;
}

int ONVIF_SetNetworkDefaultGateway(char *device_ip)
{
    char new_gateway[128] = {0};
    char *ip_p = new_gateway;
#if 1
    printf("please input new gateway:");
    scanf("%s" , new_gateway);
    if(strcmp(new_gateway , "q") == 0)
    {
        return 0;
    }
    printf("the new gateway is :%s\n" , new_gateway);
#endif

    int result = -1;
    int size = 0;
    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 = 1;

    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 = -1;
    struct soap *soap = NULL;// pointer of soap
    struct _tptz__AbsoluteMove req;
    struct _tptz__AbsoluteMoveResponse resp;

    struct tt__Vector2D vector2d;
    vector2d.x = -1;//absolute x angle
    vector2d.y = -1;//absolute y angle
    vector2d.space = absolute_move_ip;
#if 1
    struct tt__Vector1D vector1d;
    vector1d.x = 0;//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(1);
    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 = -1;
    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 = -1;
    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 = -1;
    struct soap *soap = NULL;// pointer of soap
    struct _tptz__ContinuousMove req;
    struct _tptz__ContinuousMoveResponse resp;

    struct tt__Vector2D vector2d;
    vector2d.x = 1;
    vector2d.y = 0;
    vector2d.space = continuous_move_ip;

    struct tt__Vector1D vector1d; 
    vector1d.x = 0;
    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(1);
}


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[128] = {0};
    char new_ip[128] = {0};
    //char ptz_ip[128] = {0};
    char *ptz_ip = "http://192.168.235.201/onvif/PTZ";
    char device_token[16] = {0};
    //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 = 0;

    //ONVIF_Get_Gateway(device_ip);

    ONVIF_SetNetworkDefaultGateway(device_ip);

#if 1
#if 0
    char device_service_ip[128] = {"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") != 0)
    {
        result = ONVIF_SetNetworkInterfaces(device_ip , new_ip , device_token);
        printf("result of set ip is           :%d\n" , result);
        sleep(10);
        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(1);
    return 0;
#endif
}

 

 

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

 

 

 

 

来源为掌握笔记(Wiz)

  

 

  

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注