命令宏定义:
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,
"\n"
"\n"
"DeviceControl \n"
"130 \n"
"%s \n"
"%s \n"
" \n", gbid.c_str(), cmdstr.c_str()
);
return szPTZInfo;
}
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F010800FA00B7PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F010400FA00B3PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0102FA0000B1PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0101FA0000B0PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F010AFAFA00B3PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0106FAFA00AFPTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0109FAFA00B2PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0105FAFA00AEPTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0100000000B5PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F01100000A065PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F01200000A075PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F014400FA00F3PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F014800FA00F7PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>v
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0141FA0000F0PTZCmd>
Control>
<Control>
<CmdType>DeviceControlCmdType>
<SN>130SN>
<DeviceID>xxxDeviceID>
<PTZCmd>A50F0142FA0000F1PTZCmd>
Control>