近期由于项目原因接触到了Onvif协议,使用Onvif协议进行PTZ控制。
具体的Onvif协议是什么,PTZ是什么我就不介绍了,主要实现功能的步骤简单的介绍下(主要介绍ContinuousMove功能):
1、通过设备服务地址(形如http://xx/onvif/device_service),调用GetCapabilities函数接口,获取到Media的URL;
2、通过Media的URL,调用GetProfiles函数接口,获取到ProfileToken;
3、对_tptz__ContinuousMove结构体进行填充,具体填充内容在以下代码中可见;
4、调用soap_call___tptz__ContinuousMove函数接口实现摄像头转动功能;
由于涉及到公司的通信协议,我所给的代码是测试版的,数值是定的,不过功能可以实现(有不足之处希望各位可以指出,一起学习一起进步):
int main(int argc, char** argv)
{
struct soap soap;
soap_init(&soap);
char * ip;
int retval = 0;
int result;
char Mediaddr[256]="";
char profile[256]="";
int speed_x=100;
int speed_y=0;
int speed_z=0;
struct _tds__GetCapabilities req;
struct _tds__GetCapabilitiesResponse rep;
struct _trt__GetProfiles getProfiles;
struct _trt__GetProfilesResponse response;
struct _tptz__ContinuousMove continuousMove;
struct _tptz__ContinuousMoveResponse continuousMoveresponse;
struct _tptz__Stop stop;
struct _tptz__StopResponse stopresponse;
req.Category = (enum tt__CapabilityCategory *)soap_malloc(&soap, sizeof(int));
req.__sizeCategory = 1;
*(req.Category) = (enum tt__CapabilityCategory)0;
char endpoint[255];
memset(endpoint, '\0', 255);
if (argc > 1)
{
ip = argv[1];
}
else
{
ip = "10.27.13.6:80";
}
sprintf(endpoint, "http://%s/onvif/device_service", ip);
soap_call___tds__GetCapabilities(&soap, endpoint, NULL, &req, &rep);
if (soap.error)
{
printf("[%s][%d]--->>> soap error: %d, %s, %s\n", __func__, __LINE__, soap.error, *soap_faultcode(&soap), *soap_faultstring(&soap));
retval = soap.error;
}
else
{
printf("XAddr====%s\n",rep.Capabilities->Device->XAddr);
printf("XAddr====%s\n",rep.Capabilities->Media->XAddr);
strcpy(Mediaddr,rep.Capabilities->Media->XAddr);
printf("\n");
}
result = soap_call___trt__GetProfiles(&soap, Mediaddr, NULL, &getProfiles, &response);
if(result == SOAP_OK)
{
strcpy(profile,response.Profiles[0].token);
printf("profile====%s\n",profile);
}
continuousMove.ProfileToken =profile;
struct tt__PTZSpeed* velocity = soap_new_tt__PTZSpeed(&soap, -1);
continuousMove.Velocity = velocity;
struct tt__Vector2D* panTilt = soap_new_tt__Vector2D(&soap, -1);
continuousMove.Velocity->PanTilt = panTilt;
continuousMove.Velocity->PanTilt->space = "http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace";
struct tt__Vector1D* zoom = soap_new_tt__Vector1D(&soap, -1);
continuousMove.Velocity->Zoom = zoom;
continuousMove.Velocity->PanTilt->x = (float)speed_x/ 100;
continuousMove.Velocity->PanTilt->y = (float) speed_y/ 100;
continuousMove.Velocity->Zoom->x = (float)speed_z / 100;
if(soap_call___tptz__ContinuousMove(&soap,endpoint,NULL,&continuousMove,&continuousMoveresponse) == SOAP_OK)
{
printf("======SetPTZcontinuous_move is success!!!=======\n");
}
soap_destroy(&soap); // clean up class instances
soap_end(&soap); // clean up everything and close socket, // userid and passwd were deallocated
soap_done(&soap); // close master socket and detach context
return 0;
}
标签:__,continuousMove,struct,int,tt,PTZ,小结,soap,Onvif
From: https://blog.51cto.com/u_16264248/7479168