using EC.Util.CameraSDK;
namespace JiLinApp.Docking.Ptz;
public class PtzCmd
{
public static PtzControlType GetControlType(string ctrlType)
{
return ctrlType switch
{
"PelcoD" => PtzControlType.PelcoD,
"PelcoP" => PtzControlType.PelcoP,
"DCamera" => PtzControlType.DCamera,
"CameraSdk" => PtzControlType.CameraSdk,
_ => PtzControlType.None
};
}
public static PtzCmdType GetCmdType(string cmdStr)
{
return cmdStr switch
{
"Left" => PtzCmdType.Left,
"Right" => PtzCmdType.Right,
"Top" => PtzCmdType.Top,
"Down" => PtzCmdType.Down,
"LeftTop" => PtzCmdType.LeftTop,
"LeftDown" => PtzCmdType.LeftDown,
"RightTop" => PtzCmdType.RightTop,
"RightDown" => PtzCmdType.RightDown,
"Stop" => PtzCmdType.Stop,
"AutoMove" => PtzCmdType.AutoMove,
"ZoomIn" => PtzCmdType.ZoomIn,
"ZoomOut" => PtzCmdType.ZoomOut,
"FocusNear" => PtzCmdType.FocusNear,
"FocusFar" => PtzCmdType.FocusFar,
"IrisOpen" => PtzCmdType.IrisOpen,
"IrisClose" => PtzCmdType.IrisClose,
"PresetSet" => PtzCmdType.PresetSet,
"PresetClear" => PtzCmdType.PresetClear,
"PresetGoto" => PtzCmdType.PresetGoto,
_ => PtzCmdType.None
};
}
}
public class PtzComCmd
{
///
/// GetPelcoDCmd
/// GetPelcoPCmd
/// DCamearCmd
///
///
///
///
///
public static byte[] GetCmd(PtzControlType ctrlType, PtzCmdType cmdType, object[] args = null)
{
byte[] cmd = ctrlType switch
{
PtzControlType.PelcoD => GetPelcoDCmd(cmdType, args),
PtzControlType.PelcoP => GetPelcoPCmd(cmdType, args),
PtzControlType.DCamera => GetDCameraCmd(cmdType, args),
_ => Array.Empty(),
};
return cmd;
}
public static byte[] GetPelcoDCmd(PtzCmdType cmdType, object[] args)
{
uint addr = (byte)args[0];
uint panSpeed = 0x2f;
uint tiltSpeed = (uint)(PelcoD.TiltSpeedMax + PelcoD.TiltSpeedMin) / 2;
byte[] cmd = cmdType switch
{
PtzCmdType.Left => PelcoD.CameraPan(addr, PelcoD.Pan.Left, panSpeed),
PtzCmdType.Right => PelcoD.CameraPan(addr, PelcoD.Pan.Right, panSpeed),
PtzCmdType.Top => PelcoD.CameraTilt(addr, PelcoD.Tilt.Up, tiltSpeed),
PtzCmdType.Down => PelcoD.CameraTilt(addr, PelcoD.Tilt.Down, tiltSpeed),
PtzCmdType.LeftTop => PelcoD.CameraPan(addr, PelcoD.Pan.LeftUp, panSpeed),
PtzCmdType.LeftDown => PelcoD.CameraPan(addr, PelcoD.Pan.LeftDown, panSpeed),
PtzCmdType.RightTop => PelcoD.CameraPan(addr, PelcoD.Pan.RightUp, panSpeed),
PtzCmdType.RightDown => PelcoD.CameraPan(addr, PelcoD.Pan.RightDown, panSpeed),
PtzCmdType.Stop => PelcoD.CameraStop(addr),
PtzCmdType.AutoMove => PelcoD.CameraScan(addr, PelcoD.Scan.Auto),
//PtzCmdType.AutoStop => PelcoD.CameraScan(addr, PelcoD.Scan.Manual),
PtzCmdType.PresetGoto => PelcoD.Preset(addr, PelcoD.PresetAction.Goto, (byte)args[1]),
_ => Array.Empty(),
};
return cmd;
}
public static byte[] GetPelcoPCmd(PtzCmdType cmdType, object[] args)
{
uint addr = (byte)args[0];
uint panSpeed = (uint)(PelcoP.PanSpeedMax + PelcoP.PanSpeedMin) / 2;
uint tiltSpeed = (uint)(PelcoP.TiltSpeedMax + PelcoP.TiltSpeedMin) / 2;
byte[] cmd = cmdType switch
{
PtzCmdType.Left => PelcoP.CameraPan(addr, PelcoP.Pan.Left, panSpeed),
PtzCmdType.Right => PelcoP.CameraPan(addr, PelcoP.Pan.Right, panSpeed),
PtzCmdType.Top => PelcoP.CameraTilt(addr, PelcoP.Tilt.Up, tiltSpeed),
PtzCmdType.Down => PelcoP.CameraTilt(addr, PelcoP.Tilt.Down, tiltSpeed),
PtzCmdType.LeftTop => PelcoP.CameraPanTilt(addr, PelcoP.Pan.Left, panSpeed, PelcoP.Tilt.Up, tiltSpeed),
PtzCmdType.LeftDown => PelcoP.CameraPanTilt(addr, PelcoP.Pan.Left, panSpeed, PelcoP.Tilt.Down, tiltSpeed),
PtzCmdType.RightTop => PelcoP.CameraPanTilt(addr, PelcoP.Pan.Right, panSpeed, PelcoP.Tilt.Up, tiltSpeed),
PtzCmdType.RightDown => PelcoP.CameraPanTilt(addr, PelcoP.Pan.Right, panSpeed, PelcoP.Tilt.Down, tiltSpeed),
PtzCmdType.Stop => PelcoP.CameraStop(addr),
PtzCmdType.AutoMove => PelcoP.AutoScan(addr, PelcoP.Action.Start),
//PtzCmdType.AutoStop => PelcoP.AutoScan(addr, PelcoP.Action.Stop),
PtzCmdType.PresetGoto => PelcoP.Preset(addr, PelcoP.PresetAction.Goto, (byte)args[1]),
_ => Array.Empty(),
};
return cmd;
}
public static byte[] GetDCameraCmd(PtzCmdType cmdType, object[] args)
{
double speed = (DCamera.SpeedMax + DCamera.SpeedMin) / 2;
byte[] cmd = cmdType switch
{
PtzCmdType.Left => DCamera.Left(speed),
PtzCmdType.Right => DCamera.Right(speed),
PtzCmdType.Top => DCamera.Up(speed),
PtzCmdType.Down => DCamera.Down(speed),
PtzCmdType.LeftTop => DCamera.LeftUp(speed, speed),
PtzCmdType.LeftDown => DCamera.LeftDown(speed, speed),
PtzCmdType.RightTop => DCamera.RightUp(speed, speed),
PtzCmdType.RightDown => DCamera.RightDown(speed, speed),
PtzCmdType.Stop => DCamera.Stop(),
_ => Array.Empty(),
};
return cmd;
}
}
public class PtzCameraCmd
{
public static void PtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args)
{
if (sdk == null || !sdk.ConnectSuccess() || args == null) return;
switch (sdk.CameraInfo.Manufactor)
{
case CameraManufactor.HiK:
HikPtzMove(sdk, cmdType, args);
break;
case CameraManufactor.DaHua:
DaHuaPtzMove(sdk, cmdType, args);
break;
case CameraManufactor.YuShi:
YuShiPtzMove(sdk, cmdType, args);
break;
default:
break;
}
}
public static void HikPtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args)
{
int stop = args[0], presetId = args[0];
int speed = HiKOriSdk.PtzSpeedMax;
//int speed = (HiKOriSdk.PtzSpeedMin + HiKOriSdk.PtzSpeedMax) / 2;
switch (cmdType)
{
case PtzCmdType.Left:
sdk.PtzMove(HiKOriSdk.PAN_LEFT, stop, speed);
break;
case PtzCmdType.Right:
sdk.PtzMove(HiKOriSdk.PAN_RIGHT, stop, speed);
break;
case PtzCmdType.Top:
sdk.PtzMove(HiKOriSdk.TILT_UP, stop, speed);
break;
case PtzCmdType.Down:
sdk.PtzMove(HiKOriSdk.TILT_DOWN, stop, speed);
break;
case PtzCmdType.LeftTop:
sdk.PtzMove(HiKOriSdk.UP_LEFT, stop, speed);
break;
case PtzCmdType.LeftDown:
sdk.PtzMove(HiKOriSdk.DOWN_LEFT, stop, speed);
break;
case PtzCmdType.RightTop:
sdk.PtzMove(HiKOriSdk.UP_RIGHT, stop, speed);
break;
case PtzCmdType.RightDown:
sdk.PtzMove(HiKOriSdk.DOWN_RIGHT, stop, speed);
break;
case PtzCmdType.AutoMove:
sdk.PtzMove(HiKOriSdk.PAN_AUTO, stop, speed);
break;
case PtzCmdType.ZoomIn:
sdk.PtzMove(HiKOriSdk.ZOOM_IN, stop, speed);
break;
case PtzCmdType.ZoomOut:
sdk.PtzMove(HiKOriSdk.ZOOM_OUT, stop, speed);
break;
case PtzCmdType.FocusNear:
sdk.PtzMove(HiKOriSdk.FOCUS_NEAR, stop, speed);
break;
case PtzCmdType.FocusFar:
sdk.PtzMove(HiKOriSdk.FOCUS_FAR, stop, speed);
break;
case PtzCmdType.IrisOpen:
sdk.PtzMove(HiKOriSdk.IRIS_OPEN, stop, speed);
break;
case PtzCmdType.IrisClose:
sdk.PtzMove(HiKOriSdk.IRIS_CLOSE, stop, speed);
break;
case PtzCmdType.PresetGoto:
sdk.PtzPreset(HiKOriSdk.GOTO_PRESET, presetId);
break;
default:
break;
}
}
private static void DaHuaPtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args)
{
int stop = args[0], presetId = args[0];
int speed = DaHuaOriSdk.PtzSpeedMax;
//int speed = (DaHuaOriSdk.PtzSpeedMin + DaHuaOriSdk.PtzSpeedMax) / 2;
switch (cmdType)
{
case PtzCmdType.Left:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.LEFT, stop, speed);
break;
case PtzCmdType.Right:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.RIGHT, stop, speed);
break;
case PtzCmdType.Top:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.UP, stop, speed);
break;
case PtzCmdType.Down:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.DOWN, stop, speed);
break;
case PtzCmdType.LeftTop:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.LEFTTOP, stop, speed);
break;
case PtzCmdType.LeftDown:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.LEFTDOWN, stop, speed);
break;
case PtzCmdType.RightTop:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.RIGHTTOP, stop, speed);
break;
case PtzCmdType.RightDown:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.RIGHTDOWN, stop, speed);
break;
//case PtzCmdType.AutoMove:
// sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.STARTPANCRUISE, stop, speed);
// break;
case PtzCmdType.ZoomIn:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.ZOOM_ADD, stop, speed);
break;
case PtzCmdType.ZoomOut:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.ZOOM_DEC, stop, speed);
break;
case PtzCmdType.FocusNear:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.FOCUS_ADD, stop, speed);
break;
case PtzCmdType.FocusFar:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.FOCUS_DEC, stop, speed);
break;
case PtzCmdType.IrisOpen:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.APERTURE_ADD, stop, speed);
break;
case PtzCmdType.IrisClose:
sdk.PtzMove((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.APERTURE_DEC, stop, speed);
break;
case PtzCmdType.PresetGoto:
sdk.PtzPreset((int)DaHuaOriSdk.EM_EXTPTZ_ControlType.GOTOPRESET, presetId);
break;
default:
break;
}
}
public static void YuShiPtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args)
{
int stop = args[0], presetId = args[0];
int speed = YuShiOriSdk.PtzSpeedMax;
//int speed = (YuShiOriSdk.PtzSpeedMax + YuShiOriSdk.PtzSpeedMin) / 2;
switch (cmdType)
{
case PtzCmdType.Left:
sdk.PtzMove(YuShiOriSdk.PANLEFT, stop, speed);
break;
case PtzCmdType.Right:
sdk.PtzMove(YuShiOriSdk.PANRIGHT, stop, speed);
break;
case PtzCmdType.Top:
sdk.PtzMove(YuShiOriSdk.TILTUP, stop, speed);
break;
case PtzCmdType.Down:
sdk.PtzMove(YuShiOriSdk.TILTDOWN, stop, speed);
break;
case PtzCmdType.LeftTop:
sdk.PtzMove(YuShiOriSdk.LEFTUP, stop, speed);
break;
case PtzCmdType.LeftDown:
sdk.PtzMove(YuShiOriSdk.LEFTDOWN, stop, speed);
break;
case PtzCmdType.RightTop:
sdk.PtzMove(YuShiOriSdk.RIGHTUP, stop, speed);
break;
case PtzCmdType.RightDown:
sdk.PtzMove(YuShiOriSdk.RIGHTDOWN, stop, speed);
break;
case PtzCmdType.ZoomIn:
sdk.PtzMove(YuShiOriSdk.ZOOMTELE, stop, speed);
break;
case PtzCmdType.ZoomOut:
sdk.PtzMove(YuShiOriSdk.ZOOMWIDE, stop, speed);
break;
case PtzCmdType.FocusNear:
sdk.PtzMove(YuShiOriSdk.FOCUSNEAR, stop, speed);
break;
case PtzCmdType.FocusFar:
sdk.PtzMove(YuShiOriSdk.FOCUSFAR, stop, speed);
break;
case PtzCmdType.IrisOpen:
sdk.PtzMove(YuShiOriSdk.IRISOPEN, stop, speed);
break;
case PtzCmdType.IrisClose:
sdk.PtzMove(YuShiOriSdk.IRISCLOSE, stop, speed);
break;
case PtzCmdType.PresetGoto:
sdk.PtzPreset(YuShiOriSdk.PRESET_GOTO, presetId);
break;
default:
break;
}
}
}
public enum PtzControlType
{
PelcoD,
PelcoP,
DCamera,
CameraSdk,
None,
}
public enum PtzCmdType
{
Left,
Right,
Top,
Down,
LeftTop,
LeftDown,
RightTop,
RightDown,
Stop,
AutoMove,
ZoomIn,
ZoomOut,
FocusNear,
FocusFar,
IrisOpen,
IrisClose,
PresetSet,
PresetClear,
PresetGoto,
None
}