📄 pelco_p.cxx
字号:
#include"Pelco_p.hxx"
CPelco_p::CPelco_p():CPTZ(0x02,0x04,0x08,0x10,0x20,0x40,0x00,0x40,0X00,0X3F),
CCamera(0x01,0x02,0x04,0x08,0x10,0x20)
{
STX = 0xA0;
ETX = 0xAF;
CameraOn = 0x80;
}
CPelco_p::~CPelco_p()
{
if(NULL != com)
{
delete com;
com = NULL;
}
}
bool CPelco_p::Init()
{
com = new CCOM();
if(NULL == com)
{
return false;
}
return true;
}
//设置预置位,清除预置位,转到预置位
void CPelco_p::Preset(void *proto,unsigned int deviceAddress, byte preset, byte action)
{
byte m_action;
switch (action)
{
case PRESET:
m_action = 0x03;
break;
case PRECLEAR:
m_action = 0x05;
break;
case PREGOTO:
m_action = 0x07;
break;
default:
m_action = 0x03;
break;
}
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,m_action,0x00,preset);
}
void CPelco_p::Flip(void *proto,unsigned int deviceAddress)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x07,0x00,0x21);
}
void CPelco_p::ZeroPanPosition(void *proto,unsigned int deviceAddress)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x07,0x00,0x22);
}
void CPelco_p::SetAuxiliary(void *proto,unsigned int deviceAddress,byte auxiliaryID, byte action)
{
if(auxiliaryID<0x01)
{
auxiliaryID = 0x01;
}
if(auxiliaryID>0x08)
{
auxiliaryID = 0x08;
}
GetMessage((Pelco_p_Stru *)proto,deviceAddress,0x00,(byte)action,0x00,auxiliaryID);
}
void CPelco_p::RemoteReset(void *proto,unsigned int deviceAddress)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x0F,0x00,0x00);
}
void CPelco_p::Zone(void *proto,unsigned int deviceAddress,byte zone, byte action)
{
if(zone<0x01 & zone>0x08)
{
return;
}
byte m_action;
if(action == ACTSTART)
m_action = 0x11;
else
m_action = 0x13;
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,m_action,0x00,zone);
}
void CPelco_p::ClearScreen(void *proto,unsigned int deviceAddress)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x17,0x00,0x00);
}
void CPelco_p::AlarmAcknowledge(void *proto,unsigned int deviceAddress, unsigned int alarmID)
{
if(alarmID < 1 & alarmID>8)
{
return;
}
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x19,0x00,byte(alarmID));
}
void CPelco_p::ZoneScan(void *proto,unsigned int deviceAddress,byte action)
{
byte m_action;
if(action == ACTSTART)
m_action = 0x1B;
else
m_action = 0x1D;
GetMessage((Pelco_p_Stru*)proto, deviceAddress,0x00,m_action,0x00,0x00);
}
void CPelco_p::Pattern(void *proto,unsigned int deviceAddress,byte action)
{
byte m_action;
switch (action)
{
case PATTERNSTART:
m_action = 0x1F;
break;
case PATTERNSTOP:
m_action = 0x21;
break;
case PATTERNRUN:
m_action = 0x23;
break;
default:
m_action = 0x23;
break;
}
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,m_action,0x00,0x00);
}
void CPelco_p::SetZoomLensSpeed(void *proto,unsigned int deviceAddress, unsigned int speed)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x25,0x00,speed);
}
void CPelco_p::SetFocusLensSpeed(void *proto,unsigned int deviceAddress, byte speed)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x27,0x00,speed);
}
void CPelco_p::CameraSwitch(void *proto ,unsigned int deviceAddress,byte action)
{
byte m_action = CameraOnOff;
if(action == ON)
m_action += CameraOnOff; //Maybe wrong !!!
GetMessage((Pelco_p_Stru*)proto,deviceAddress,m_action,0x00,0x00,0x00);
}
void CPelco_p::CameraIrisSwitch(void *proto ,unsigned int deviceAddress,byte action)
{
return GetMessage((Pelco_p_Stru*)proto,deviceAddress,(byte)action,0x00,0x00,0x00);
}
void CPelco_p::CameraFocus(void *proto ,unsigned int deviceAddress,byte action)
{
return GetMessage((Pelco_p_Stru*)proto,deviceAddress,(byte)action,0x00,0x00,0x00);
}
void CPelco_p::CameraZoom(void *proto ,unsigned int deviceAddress,byte action)
{
return GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,(byte)action,0x00,0x00);
}
void CPelco_p::CameraTilt(void *proto ,unsigned int deviceAddress,byte action, unsigned int speed)
{
if(speed<PTILTSPEEDMIN)
speed = PTILTSPEEDMIN;
if(speed>PTILTSPEEDMAX)
speed = PTILTSPEEDMAX;
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,(byte)action,0x00,(byte)speed);
}
void CPelco_p::CameraPan(void *proto ,unsigned int deviceAddress,byte action, unsigned int speed)
{
if(speed < PTILTSPEEDMIN)
speed = PTILTSPEEDMIN;
if(speed > PTILTSPEEDMAX && speed < 0xFF)
speed = PTILTSPEEDMAX;
if(speed > 0xFF)
speed = 0xFF;
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,(byte)action,(byte)speed,0x00);
}
void CPelco_p::CameraPanTilt(void *proto ,unsigned int deviceAddress,byte panAction, unsigned int panSpeed, byte tiltAction, unsigned int tiltSpeed)
{
GetMessage((Pelco_p_Stru *)proto,deviceAddress,0x00,panAction + tiltAction,panSpeed,tiltSpeed);
}
void CPelco_p::CameraStop(void *proto ,unsigned int deviceAddress)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x00,0x00,0x00);
}
void CPelco_p::CameraScan(void *proto ,unsigned int deviceAddress,byte action)
{
byte m_action;
if(action == ACTSTART)
m_action = 0x09;
else
m_action = 0x0B;
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,m_action,0x00,0x00);
}
void CPelco_p::LightSwitch(void *proto ,unsigned int deviceAddress,byte action)
{
GetMessage((Pelco_p_Stru*)proto,deviceAddress,0x00,0x00,0x00,0x00);
}
void CPelco_p::OpenCOM()
{
com->OpenCOM();
}
void CPelco_p::set_speed(int speed)
{
com->set_speed(speed);
}
/**
*@brief 设置串口数据位,停止位和效验位
*@param databits 类型 int 数据位 取值 为 7 或者8
*@param stopbits 类型 int 停止位 取值为 1 或者2
*@param parity 类型 int 效验类型 取值为N,E,O,S
*/
bool CPelco_p::set_Parity(int databits,int stopbits,int parity)
{
if(false == com->set_Parity(databits,stopbits,parity))
{
return false;
}
return true;
}
int CPelco_p::SendData(void *buffer,int Len)
{
int wByte = com->SendData(buffer,Len);
return wByte;
}
int CPelco_p::ReadData(void *buffer,int Len)
{
int rByte = com->ReadData(buffer,sizeof(buffer));
return rByte;
}
void CPelco_p::CloseCOM()
{
com->CloseCOM();
}
void CPelco_p::GetMessage(Pelco_p_Stru *pp,unsigned int address, byte data1, byte data2, byte data3, byte data4)
{
if(NULL == pp)
{
return;
}
if (address<0 & address>32)
{
return;
}
byte checkSum = (byte)(STX ^ (byte)address ^ data1 ^ data2 ^ data3 ^ data4 ^ ETX);
pp->STX = STX;
pp->Address = address;
pp->Data1 = data1;
pp->Data2 = data2;
pp->Data3 = data3;
pp->Data4 = data4;
pp->ETX = ETX;
pp->CheckSum = checkSum;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -