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.

128 lines
3.8 KiB

namespace JiLinApp.Docking.Ptz;
public class DCamera
{
#region Fields
#region Data3
public static double SpeedMin = 1;
public static double SpeedMax = 60;
#endregion Data3
#endregion Fields
#region BaseMethod
private static byte[] CommandPara(byte com1, byte com2, int data1, int data2)
{
byte[] b = new byte[11];
b[0] = 0xA1;
int temp1 = data1;
int temp2 = data2;
b[1] = 0x00;
b[2] = 0x0B;
b[3] = com1;
b[4] = com2;
b[5] = (byte)(data1 >> 8 & 0xFF);
b[6] = (byte)(temp1 & 0xFF);
b[7] = (byte)(data2 >> 8 & 0xFF);
b[8] = (byte)(temp2 & 0xFF);
b[9] = (byte)(b[0] ^ b[1] ^ b[2] ^ b[3] ^ b[4] ^ b[5] ^ b[6] ^ b[7] ^ b[8]);
b[10] = 0xAF;
return b;
}
private static byte[] SendJoystick(double headSpeed, double pitchSpeed)
{
return CommandPara(0x4D, 0x58, (int)(headSpeed * 100), (int)(pitchSpeed * 100));
}
#endregion BaseMethod
#region PtzMethod
public static byte[] Left(double headSpeed)
{
double absHs = Math.Abs(headSpeed);
if (absHs < SpeedMin) headSpeed = -SpeedMin;
if (absHs > SpeedMax) headSpeed = -SpeedMax;
return SendJoystick(headSpeed, 0);
}
public static byte[] Right(double headSpeed)
{
double absHs = Math.Abs(headSpeed);
if (absHs < SpeedMin) headSpeed = SpeedMin;
if (absHs > SpeedMax) headSpeed = SpeedMax;
return SendJoystick(headSpeed, 0);
}
public static byte[] Up(double pitchSpeed)
{
double absPs = Math.Abs(pitchSpeed);
if (absPs < SpeedMin) pitchSpeed = SpeedMin;
if (absPs > SpeedMax) pitchSpeed = SpeedMax;
return SendJoystick(0, pitchSpeed);
}
public static byte[] Down(double pitchSpeed)
{
double absPs = Math.Abs(pitchSpeed);
if (absPs < SpeedMin) pitchSpeed = -SpeedMin;
if (absPs > SpeedMax) pitchSpeed = -SpeedMax;
return SendJoystick(0, pitchSpeed);
}
public static byte[] LeftUp(double headSpeed, double pitchSpeed)
{
double absHs = Math.Abs(headSpeed);
if (absHs < SpeedMin) headSpeed = -SpeedMin;
if (absHs > SpeedMax) headSpeed = -SpeedMax;
double absPs = Math.Abs(pitchSpeed);
if (absPs < SpeedMin) pitchSpeed = SpeedMin;
if (absPs > SpeedMax) pitchSpeed = SpeedMax;
return SendJoystick(headSpeed, pitchSpeed);
}
public static byte[] LeftDown(double headSpeed, double pitchSpeed)
{
double absHs = Math.Abs(headSpeed);
if (absHs < SpeedMin) headSpeed = -SpeedMin;
if (absHs > SpeedMax) headSpeed = -SpeedMax;
double absPs = Math.Abs(pitchSpeed);
if (absPs < SpeedMin) pitchSpeed = -SpeedMin;
if (absPs > SpeedMax) pitchSpeed = -SpeedMax;
return SendJoystick(headSpeed, pitchSpeed);
}
public static byte[] RightUp(double headSpeed, double pitchSpeed)
{
double absHs = Math.Abs(headSpeed);
if (absHs < SpeedMin) headSpeed = SpeedMin;
if (absHs > SpeedMax) headSpeed = SpeedMax;
double absPs = Math.Abs(pitchSpeed);
if (absPs < SpeedMin) pitchSpeed = SpeedMin;
if (absPs > SpeedMax) pitchSpeed = SpeedMax;
return SendJoystick(headSpeed, pitchSpeed);
}
public static byte[] RightDown(double headSpeed, double pitchSpeed)
{
double absHs = Math.Abs(headSpeed);
if (absHs < SpeedMin) headSpeed = SpeedMin;
if (absHs > SpeedMax) headSpeed = SpeedMax;
double absPs = Math.Abs(pitchSpeed);
if (absPs < SpeedMin) pitchSpeed = -SpeedMin;
if (absPs > SpeedMax) pitchSpeed = -SpeedMax;
return SendJoystick(headSpeed, pitchSpeed);
}
public static byte[] Stop()
{
return SendJoystick(0, 0);
}
#endregion PtzMethod
}