Linux onvif协议实现二(C语言客户端)

本文详细介绍了如何在Linux环境下使用C语言实现ONVIF协议的云台控制,包括绝对移动、相对移动、持续移动、停止移动等关键步骤,提供源码实例,适合开发者参考学习。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创作人QQ:851301776,邮箱:lfr890207@163.com,欢迎大家一起技术交流,本博客主要是自己学习的心得体会,只为每天进步一点点!

个人座右铭:
1.没有横空出世,只要厚积一定发。
2.你可以学历不高,你可以不上学,但你不能不学习

一、介绍

        这里主要是以测试实现功能为准则,并没有进一步的整理和优化,测试完成功能后,后期项目进行整理。

        ONVIF网上介绍的很多,还有很多对实现进行介绍的,这里不做介绍,网上很多的获取设备能力、获取音视频数据等都有,这里主要贴云台控制。

二、绝对移动

1.或者云台地址

ONVIF_GetCapabilities(DeviceXAddr, ptzXAddr);

2.获取配置文件token

ONVIF_GetProfiles(ptzXAddr, profilesToken); 

3.绝对移动(切记使用动态分配)

int ONVIF_PTZAbsoluteMove(const char *ptzXAddr, const char *ProfileToken)

{

    int result = 0;
    struct soap *soap = NULL;
    struct _tptz__AbsoluteMove           absoluteMove;
    struct _tptz__AbsoluteMoveResponse   absoluteMoveResponse;

    SOAP_ASSERT(ptzXAddr != NULL);
    SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));


    ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
    absoluteMove.ProfileToken = (char *)soap_malloc(soap, 128);
    memcpy(absoluteMove.ProfileToken, "MediaProfile00000", strlen("MediaProfile00000"));    
    printf("absoluteMove.ProfileToken = %s\n", absoluteMove.ProfileToken);

    absoluteMove.Position = soap_new_tt__PTZVector(soap,sizeof(struct tt__PTZVector));
    absoluteMove.Position->PanTilt = soap_new_tt__Vector2D(soap, sizeof(struct tt__Vector2D));
    absoluteMove.Position->Zoom = soap_new_tt__Vector1D(soap, sizeof(struct tt__Vector1D));
    absoluteMove.Speed = soap_new_tt__PTZSpeed(soap, sizeof(struct tt__PTZSpeed));
    absoluteMove.Speed->PanTilt = soap_new_tt__Vector2D(soap, sizeof(struct tt__Vector2D));
    absoluteMove.Speed->Zoom = soap_new_tt__Vector1D(soap, sizeof(struct tt__Vector1D));


    absoluteMove.Position->PanTilt->x = 0;  // p
    absoluteMove.Position->PanTilt->y = 0;   // t
    absoluteMove.Position->Zoom->x = -1;   // z

     // x 和y的绝对值越接近1,表示云台的速度越快
    absoluteMove.Speed->PanTilt->x = 0;
    absoluteMove.Speed->PanTilt->y = 0;
    absoluteMove.Speed->Zoom->x = 1;
    result = soap_call___tptz__AbsoluteMove(soap,ptzXAddr, NULL,&absoluteMove,&absoluteMoveResponse);
    SOAP_CHECK_ERROR(result, soap, "ONVIF_PTZAbsoluteMove");
    
    printf("%s result = %d \n", __func__);

EXIT:
    if (NULL != soap) {
        ONVIF_soap_delete(soap);
    }
    return 0;

}

4.相对移动

void ONVIF_PTZMoveStep(const char *ptzXAddr, char *ProfileToken, enum ptz_common cmd, float move_step)
{
    SOAP_ASSERT(NULL != ptzXAddr);
    SOAP_ASSERT(NULL != ProfileToken);

    float MoveStep = 0;
    if(move_step >= 1)
        MoveStep = 0.9;
    else{
        MoveStep = move_step;
    }

    struct soap *soap = NULL;
    SOAP_ASSERT(NULL != (soap = ONVIF_soap_new(SOAP_SOCK_TIMEOUT)));

    ONVIF_SetAuthInfo(soap, USERNAME, PASSWORD);
    
    
    struct _tptz__RelativeMove RelativeMove;
    struct _tptz__RelativeMoveResponse RelativeMoveResponse;

    RelativeMove.ProfileToken = ProfileToken;
    printf("tptz__RelativeMove.ProfileToken:%s\n", RelativeMove.ProfileToken);
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QQ851301776

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值