You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
7.4 KiB

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,
"HikSdk" => PtzControlType.HikSdk,
_ => PtzControlType.None
};
}
public static PtzCmdType GetCmdType(string cmdStr)
{
return cmdStr switch
{
"Top" => PtzCmdType.Top,
"Down" => PtzCmdType.Down,
"Left" => PtzCmdType.Left,
"Right" => PtzCmdType.Right,
"TopLeft" => PtzCmdType.LeftTop,
"TopRight" => PtzCmdType.RightTop,
"DownLeft" => PtzCmdType.LeftDown,
"DownRight" => PtzCmdType.RightDown,
"Stop" => PtzCmdType.Stop,
"AutoStart" => PtzCmdType.AutoStart,
"AutoStop" => PtzCmdType.AutoStop,
"PresetSet" => PtzCmdType.PresetSet,
"PresetClear" => PtzCmdType.PresetClear,
"PresetGoto" => PtzCmdType.PresetGoto,
_ => PtzCmdType.None
};
}
/// <summary>
/// GetPelcoDCmd
/// GetPelcoPCmd
/// DCamearCmd
/// </summary>
/// <param name="ctrlType"></param>
/// <param name="cmdType"></param>
/// <param name="args"></param>
/// <returns></returns>
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<byte>(),
};
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.AutoStart => 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<byte>(),
};
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.AutoStart => 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<byte>(),
};
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(),
//PtzCmdType.PresetGoto => DCamera.Up(speed),
_ => Array.Empty<byte>(),
};
return cmd;
}
public static void HikPtzMove(ref HiKSDK sdk, PtzCmdType cmdType, uint[] args)
{
if (sdk == null || args == null) return;
uint[] arr = new uint[args.Length + 1];
args.CopyTo(arr, 1);
switch (cmdType)
{
case PtzCmdType.Left:
arr[0] = HiKOriSDK.PAN_LEFT;
sdk.PtzMove(arr);
break;
case PtzCmdType.Right:
arr[0] = HiKOriSDK.PAN_RIGHT;
sdk.PtzMove(arr);
break;
case PtzCmdType.Top:
arr[0] = HiKOriSDK.TILT_UP;
sdk.PtzMove(arr);
break;
case PtzCmdType.Down:
arr[0] = HiKOriSDK.TILT_DOWN;
sdk.PtzMove(arr);
break;
case PtzCmdType.LeftTop:
arr[0] = HiKOriSDK.UP_LEFT;
sdk.PtzMove(arr);
break;
case PtzCmdType.LeftDown:
arr[0] = HiKOriSDK.DOWN_LEFT;
sdk.PtzMove(arr);
break;
case PtzCmdType.RightTop:
arr[0] = HiKOriSDK.UP_RIGHT;
sdk.PtzMove(arr);
break;
case PtzCmdType.RightDown:
arr[0] = HiKOriSDK.DOWN_RIGHT;
sdk.PtzMove(arr);
break;
case PtzCmdType.AutoStart:
arr[0] = HiKOriSDK.PAN_AUTO;
sdk.PtzMove(arr);
break;
case PtzCmdType.PresetGoto:
arr[0] = HiKOriSDK.GOTO_PRESET;
sdk.PtzPreset(arr);
break;
default:
break;
}
}
}
public enum PtzControlType
{
PelcoD,
PelcoP,
DCamera,
HikSdk,
None,
}
public enum PtzCmdType
{
Top,
Down,
Left,
Right,
LeftTop,
LeftDown,
RightTop,
RightDown,
Stop,
AutoStart,
AutoStop,
PresetSet,
PresetClear,
PresetGoto,
None
}