📄 d.h
字号:
/// <summary>
/// dot.NET Implementation of Pelco D Protocol
/// </summary>
#pragma once
#include "stdafx.h"
#include <string>
const BYTE STX = 0xFF;
const BYTE FocusNear = 0x01;
const BYTE IrisOpen = 0x02;
const BYTE IrisClose = 0x04;
const BYTE CameraOnOff = 0x08;
const BYTE AutoManualScan = 0x10;
const BYTE Sense = 0x80;
const BYTE PanRight = 0x02;
const BYTE PanLeft = 0x04;
const BYTE TiltUp = 0x08;
const BYTE TiltDown = 0x10;
const BYTE ZoomTele = 0x20;
const BYTE ZoomWide = 0x40;
const BYTE FocusFar = 0x80;
const BYTE PanSpeedMin = 0x00;
const BYTE PanSpeedMax = 0xFF;
const BYTE TiltSpeedMin = 0x00;
const BYTE TiltSpeedMax = 0x3F;
enum Action {Start,Stop};
enum LensSpeed {Low=0x00,Medium=0x01,High=0x02,Turbo=0x03};
enum Switch {On=0x01,Off=0x02};
enum Focus {Near = FocusNear,Far = FocusFar};
enum Zoom {Wide = ZoomWide,Tele = ZoomTele};
enum Tilt {Up = TiltUp,Down = TiltDown};
enum Pan {Left = PanLeft,Right = PanRight};
enum Scan {ScanAuto, ScanManual};
enum Iris {Open = IrisOpen,Close = IrisClose};
enum AuxAction {AuxSet=0x09,AuxClear=0x0B};
enum PatternAction {PatternStart,PatternStop,PatternRun};
enum SwitchAction {SwitchAuto=0x00,SwitchOn=0x01,SwitchOff=0x02};
enum PresetAction {PresetSet,PresetClear,PresetGoto};
// typedef struct {BYTE Set; BYTE Clear;}AuxAction;// ={0x09,0x0B} ;
//typedef struct {BYTE Start; BYTE Stop; BYTE Run;}PatternAction;// ={0x00,0x01,0x02} ;
//typedef struct {BYTE Auto; BYTE On; BYTE Off;}SwitchAction;// ={0x00,0x01,0x02} ;
class D_Pelco
{
private:
BYTE Address;
BYTE CheckSum;
BYTE Command1,Command2,Data1,Data2;
BYTE m_transmit_pelco_message[7];
LPBYTE GetMessage(BYTE address, BYTE command1, BYTE command2, BYTE data1, BYTE data2)
{
// if (address<1 || address>256)
// throw new Exception("Protocol Pelco D support 256 devices only");
Address = address;
Data1 = data1;
Data2 = data2;
Command1 = command1;
Command2 = command2;
// CheckSum = (BYTE)(STX ^ Address ^ Command1 ^ Command2 ^ Data1 ^ Data2);
CheckSum = (BYTE)((Address % 256)+ (Command1 % 256) + (Command2 % 256)+ (Data1 % 256) + (Data2 % 256));
m_transmit_pelco_message[0] = STX; m_transmit_pelco_message[1] = Address; m_transmit_pelco_message[2] = Command1;
m_transmit_pelco_message[3] = Command2; m_transmit_pelco_message[4] = Data1; m_transmit_pelco_message[5] = Data2;
m_transmit_pelco_message[6] = CheckSum;
return m_transmit_pelco_message;
}
public:
D_Pelco(){;}
~D_Pelco(){;}
LPBYTE Preset(UINT deviceAddress, BYTE preset, PresetAction action)
{
BYTE m_action;
switch (action)
{
case PresetSet:
m_action = 0x03;
break;
case PresetClear:
m_action = 0x05;
break;
case PresetGoto:
m_action = 0x07;
break;
default:
m_action = 0x03;
break;
}
return GetMessage(deviceAddress,0x00,m_action,0x00,preset);
}
LPBYTE Flip(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x07,0x00,0x21);
}
LPBYTE ZeroPanPosition(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x07,0x00,0x22);
}
LPBYTE SetAuxiliary(UINT deviceAddress,BYTE auxiliaryID, AuxAction action)
{
if(auxiliaryID<0x00)
auxiliaryID = 0x00;
else if(auxiliaryID>0x08)
auxiliaryID = 0x08;
return GetMessage(deviceAddress,0x00,(BYTE)action,0x00,auxiliaryID);
}
LPBYTE RemoteReset(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x0F,0x00,0x00);
}
LPBYTE Zone(UINT deviceAddress,BYTE zone, Action action)
{
// if(zone<0x01 & zone>0x08)
// throw new Exception("Zone value should be between 0x01 and 0x08 include");
BYTE m_action;
if(action == Start)
m_action = 0x11;
else
m_action = 0x13;
return GetMessage(deviceAddress,0x00,m_action,0x00,zone);
}
LPBYTE WriteToScreen(UINT deviceAddress, char ch, BYTE pos)
{
return GetMessage(deviceAddress,0x00,0x15,pos,ch);
}
//LPBYTE WriteToScreen(UINT deviceAddress,string text)
//{
// if(text.Length > 40)
// text = text.Remove(40,text.Length-40);
// System.Text.Encoding encoding = System.Text.Encoding.ASCII;
// BYTE[] m_BYTEs = new BYTE[(text.length())*7];
// int i = 0;
// BYTE m_scrPosition;
// BYTE m_ASCIIchr;
// foreach(char ch in text)
// {
// m_scrPosition = (BYTE)(i/7);
// m_ASCIIchr = (BYTE)ch;
// Array.Copy(GetMessage(deviceAddress,0x00,0x15,m_scrPosition,m_ASCIIchr),0,m_BYTEs,i,7);
// i = i + 7;
// }
// return m_BYTEs;
//}
LPBYTE ClearScreen(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x17,0x00,0x00);
}
LPBYTE AlarmAcknowledge(UINT deviceAddress, UINT alarmID)
{
// if(alarmID < 1 & alarmID>8)
// throw new Exception("Only 8 alarms allowed for Pelco P implementation");
return GetMessage(deviceAddress,0x00,0x19,0x00,(BYTE)alarmID);
}
LPBYTE ZoneScan(UINT deviceAddress,Action action)
{
BYTE m_action;
if(action == Start)
m_action = 0x1B;
else
m_action = 0x1D;
return GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}
LPBYTE Pattern(UINT deviceAddress,PatternAction 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;
}
return GetMessage(deviceAddress,0x00,m_action,0x00,0x00);
}
LPBYTE SetZoomLensSpeed(UINT deviceAddress, LensSpeed speed)
{
return GetMessage(deviceAddress,0x00,0x25,0x00,(BYTE)speed);
}
LPBYTE SetFocusLensSpeed(UINT deviceAddress, LensSpeed speed)
{
return GetMessage(deviceAddress,0x00,0x27,0x00,(BYTE)speed);
}
LPBYTE ResetCamera(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x29,0x00,0x00);
}
LPBYTE AutoFocus(UINT deviceAddress, SwitchAction action)
{
return GetMessage(deviceAddress,0x00,0x2B,0x00,(BYTE)action);
}
LPBYTE AutoIris(UINT deviceAddress, SwitchAction action)
{
return GetMessage(deviceAddress,0x00,0x2D,0x00,(BYTE)action);
}
LPBYTE AGC(UINT deviceAddress, SwitchAction action)
{
return GetMessage(deviceAddress,0x00,0x2F,0x00,(BYTE)action);
}
LPBYTE BackLightCompensation(UINT deviceAddress, Switch action)
{
return GetMessage(deviceAddress,0x00,0x31,0x00,(BYTE)action);
}
LPBYTE AutoWhiteBalance(UINT deviceAddress, Switch action)
{
return GetMessage(deviceAddress,0x00,0x33,0x00,(BYTE)action);
}
LPBYTE EnableDevicePhaseDelayMode(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x35,0x00,0x00);
}
LPBYTE SetShutterSpeed(UINT deviceAddress,BYTE speed)
{
return GetMessage(deviceAddress,0x00,0x37,speed,speed);//Not sure about
}
LPBYTE AdjustLineLockPhaseDelay(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x39,0x00,0x00);
}
LPBYTE AdjustWhiteBalanceRB(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x3B,0x00,0x00);
}
LPBYTE AdjustWhiteBalanceMG(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x3D,0x00,0x00);
}
LPBYTE AdjustGain(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x3F,0x00,0x00);
}
LPBYTE AdjustAutoIrisLevel(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x41,0x00,0x00);
}
LPBYTE AdjustAutoIrisPeakValue(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x43,0x00,0x00);
}
LPBYTE Query(UINT deviceAddress)
{
// throw new Exception("Did not implemented");
return GetMessage(deviceAddress,0x00,0x45,0x00,0x00);
}
LPBYTE CameraSwitch(UINT deviceAddress,Switch action)
{
BYTE m_action = CameraOnOff;
if(action == SwitchOn)
m_action = CameraOnOff + Sense;
return GetMessage(deviceAddress,m_action,0x00,0x00,0x00);
}
LPBYTE CameraIrisSwitch(UINT deviceAddress,Iris action)
{
return GetMessage(deviceAddress,(BYTE)action,0x00,0x00,0x00);
}
LPBYTE CameraFocus(UINT deviceAddress,Focus action)
{
if(action == Near)
return GetMessage(deviceAddress,(BYTE)action,0x00,0x00,0x00);
else
return GetMessage(deviceAddress,0x00,(BYTE)action,0x00,0x00);
}
LPBYTE CameraZoom(UINT deviceAddress,Zoom action)
{
return GetMessage(deviceAddress,0x00,(BYTE)action,0x00,0x20);
}
LPBYTE CameraTilt(UINT deviceAddress,Tilt action, UINT speed)
{
if(speed<TiltSpeedMin)
speed = TiltSpeedMin;
if(speed<TiltSpeedMax)
speed = TiltSpeedMax;
return GetMessage(deviceAddress,0x00,(BYTE)action,0x00,(BYTE)speed);
}
LPBYTE CameraPan(UINT deviceAddress,Pan action, UINT speed)
{
if(speed < PanSpeedMin)
speed = PanSpeedMin;
if(speed > PanSpeedMax)
speed = PanSpeedMax;
return GetMessage(deviceAddress,0x00,(BYTE)action,(BYTE)speed,0x00);
}
LPBYTE CameraPanTilt(UINT deviceAddress,Pan panAction, UINT panSpeed, Tilt tiltAction, UINT tiltSpeed)
{
BYTE m_BYTEs[7];
LPBYTE lpb_tmp;
LPBYTE m_tiltMessage = CameraTilt(deviceAddress,tiltAction,tiltSpeed);
LPBYTE m_panMessage = CameraPan(deviceAddress,panAction,panSpeed);
/*m_BYTEs[0] = m_tiltMessage[0];
m_BYTEs[1] = m_tiltMessage[1];
m_BYTEs[2] = m_tiltMessage[2];
m_BYTEs[3] = (BYTE)(m_tiltMessage[3]+m_panMessage[3]);
m_BYTEs[4] = (BYTE)(m_tiltMessage[4]+m_panMessage[4]);
m_BYTEs[5] = (BYTE)(m_tiltMessage[5]+m_panMessage[5]);
m_BYTEs[6] = m_tiltMessage[6];
m_BYTEs[7] = m_tiltMessage[7];*/
lpb_tmp = GetMessage(deviceAddress,0x00,(BYTE)(m_tiltMessage[3] + m_panMessage[3]),
m_panMessage[4],m_tiltMessage[5]);
memcpy(m_BYTEs, lpb_tmp, 7);
return m_BYTEs;
}
LPBYTE CameraStop(UINT deviceAddress)
{
return GetMessage(deviceAddress,0x00,0x00,0x00,0x00);
}
LPBYTE CameraScan(UINT deviceAddress,Scan scan)
{
BYTE m_BYTE = AutoManualScan;
if(scan == ScanAuto)
m_BYTE = AutoManualScan+Sense;
return GetMessage(deviceAddress,m_BYTE,0x00,0x00,0x00);
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -