要求
- 源设备向目标设备发送控制命令,控制命令类型包括:
- 摄像机云台控制
- 远程启动
- 录像控制
- 报警布防/撤防
- 报警复位
- 强制关键帧
- 拉框放大/缩小
- 看守位控制
- PTZ精准控制
- 存储卡格式化
- 目标跟踪
- 软件升级
- 设备配置
- 设备配置的内容包括:
- 基本参数
- 视频参数范围
- SVAC编码
- SVAC解码
- 视频参数属性
- 录像计划
- 报警录像
- 视频画面遮挡
- 画面翻转
- 报警上报开关
- 前端OSD
- 图像抓拍配置
- 控制采用MESSAGE方法实现;
- 源设备向目标设备发送控制命令后,目标设备不需要发送应答命令的控制命令包括:
- 摄像机云台控制
- 远程启动
- 强制关键帧
- 拉框放大/缩小
- PTZ精准控制
- 存储卡格式化
- 目标跟踪
- 源设备向目标设备发送控制命令后,目标设备需要发送应答命令的控制命令包括:
- 录像控制
- 报警布防/撤防
- 报警复位
- 看守位控制
- 软件升级
- 设备配置
- 源设备包括:
- SIP客户端
- 网关
- 联网系统
- 目标设备包括:
- SIP设备
- 网关
- 联网系统
流程
- 无应答设备控制流程
- 有应答设备控制流程
协议接口
请求命令
- MESSAGE消息头Content-type头域为Content-type:Application/MANSCDP+xml;
- 设备控制命令消息体采用XML封装;
- 设备控制命令应包括:
- 命令类型(CmdType);
- 命令序列号(SN);
- 设备编码(DeviceID);
- 子命令;
- 设备收到MESSAGE消息后,应立即返回应答,应答命令中无消息体;
应答命令
- MESSAGE消息头Content-type头域为Content-type:Application/MANSCDP+xml;
- 设备控制命令消息体采用XML封装;
- 设备控制命令应包括:
- 命令类型(CmdType);
- 命令序列号(SN);
- 设备编码(DeviceID);
- 执行结果(Result);
- 设备收到MESSAGE消息后,应立即返回应答,应答命令中无消息体;
控制定义
指令格式
PTZ控制、镜头变大/缩小s
定义
示例
FI指令
定义
示例
代码
命令宏定义:
enum PTZControlType
{PTZ_CTRL_HALT = 0, // 停止PTZ_CTRL_RIGHT, // 右转PTZ_CTRL_RIGHTUP, // 右上PTZ_CTRL_UP, // 上转PTZ_CTRL_LEFTUP, // 左上PTZ_CTRL_LEFT, // 左转PTZ_CTRL_LEFTDOWN, // 左下PTZ_CTRL_DOWN, // 下转PTZ_CTRL_RIGHTDOWN, // 右下PTZ_CTRL_ZOOM, // 镜头放大/缩小PTZ_CTRL_IRIS, // 光圈放大/缩小PTZ_CTRL_FOCUS, // 镜头聚焦/放焦
};
PTZ转换流程:
std::string CMySipContext::ParsePTZCmd(CMyGBDevice* device, const std::string& gbid, PTZControlType ptzType, int paramValue)
{unsigned char ptzCmdStr[8] = { 0xA5, 0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 };PTZControlType type = ptzType;if (0 == paramValue)type = PTZ_CTRL_HALT;switch (type){case PTZ_CTRL_HALT:break;case PTZ_CTRL_RIGHT: // 右ptzCmdStr[3] = 0x01;ptzCmdStr[4] = paramValue & 0xFF;break;case PTZ_CTRL_RIGHTUP: // 右上ptzCmdStr[3] = 0x09;ptzCmdStr[4] = paramValue & 0xFF;ptzCmdStr[5] = paramValue & 0xFF;break;case PTZ_CTRL_UP: // 上ptzCmdStr[3] = 0x08;ptzCmdStr[5] = paramValue & 0xFF;break;case PTZ_CTRL_LEFTUP: // 左上ptzCmdStr[3] = 0x0A;ptzCmdStr[4] = paramValue & 0xFF;ptzCmdStr[5] = paramValue & 0xFF;break;case PTZ_CTRL_LEFT: // 左ptzCmdStr[3] = 0x02;ptzCmdStr[4] = paramValue & 0xFF;break;case PTZ_CTRL_LEFTDOWN: // 左下ptzCmdStr[3] = 0x06;ptzCmdStr[4] = paramValue & 0xFF;ptzCmdStr[5] = paramValue & 0xFF;break;case PTZ_CTRL_DOWN: // 下ptzCmdStr[3] = 0x04;ptzCmdStr[5] = paramValue & 0xFF;break;case PTZ_CTRL_RIGHTDOWN: // 右下ptzCmdStr[3] = 0x05;ptzCmdStr[4] = paramValue & 0xFF;ptzCmdStr[5] = paramValue & 0xFF;break;case PTZ_CTRL_ZOOM:if (paramValue > 0){ptzCmdStr[3] = 0x10;ptzCmdStr[6] = (paramValue & 0x0F) << 4;}else if (paramValue < 0){ptzCmdStr[3] = 0x20;ptzCmdStr[6] = ((-paramValue) & 0x0F) << 4;}break;case PTZ_CTRL_IRIS:if (paramValue > 0){ptzCmdStr[3] = 0x44;ptzCmdStr[5] = paramValue & 0xFF;}else if (paramValue < 0){ptzCmdStr[3] = 0x48;ptzCmdStr[5] = (-paramValue) & 0xFF;}break;case PTZ_CTRL_FOCUS:if (paramValue > 0){ptzCmdStr[3] = 0x41;ptzCmdStr[4] = paramValue & 0xFF;}else if (paramValue < 0){ptzCmdStr[3] = 0x42;ptzCmdStr[4] = (-paramValue) & 0xFF;}break;default:break;}std::string cmdstr;char tmp[8] = { 0, };for (int i = 0; i < 7; i++){ptzCmdStr[7] += ptzCmdStr[i];sprintf(tmp, "%02X", ptzCmdStr[i]);cmdstr += tmp;}sprintf(tmp, "%02X", ptzCmdStr[7]);cmdstr += tmp;char szPTZInfo[200] = { 0 };pj_ansi_snprintf(szPTZInfo, 200,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n""<Control>\n""<CmdType>DeviceControl</CmdType>\n""<SN>130</SN>\n""<DeviceID>%s</DeviceID>\n""<PTZCmd>%s</PTZCmd>\n""</Control>\n", gbid.c_str(), cmdstr.c_str());return szPTZInfo;
}
抓包
PTZ控制
- 上(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F010800FA00B7</PTZCmd>
</Control>
- 下(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F010400FA00B3</PTZCmd>
</Control>
- 左(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0102FA0000B1</PTZCmd>
</Control>
- 右(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0101FA0000B0</PTZCmd>
</Control>
- 左上(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F010AFAFA00B3</PTZCmd>
</Control>
- 左下(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0106FAFA00AF</PTZCmd>
</Control>
- 右上(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0109FAFA00B2</PTZCmd>
</Control>
- 右下(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0105FAFA00AE</PTZCmd>
</Control>
- 停止(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0100000000B5</PTZCmd>
</Control>
镜头放大/缩小
- 放大(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F01100000A065</PTZCmd>
</Control>
- 缩小(值:-250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F01200000A075</PTZCmd>
</Control>
光圈放大/缩小
- 光圈放大(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F014400FA00F3</PTZCmd>
</Control>
- 光圈缩小(值:-250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F014800FA00F7</PTZCmd>
</Control>
镜头聚焦/放焦
- 镜头聚焦(值:250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType>v<SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0141FA0000F0</PTZCmd>
</Control>
- 镜头放焦(值:-250 请求)
<?xml version="1.0" encoding="UTF-8"?>
<Control><CmdType>DeviceControl</CmdType><SN>130</SN><DeviceID>xxx</DeviceID><PTZCmd>A50F0142FA0000F1</PTZCmd>
</Control>