Camera Information System
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.
 
 
 
 

164 lines
3.5 KiB

namespace EC.Helper.CameraSDK;
/// <summary>
/// 相机信息
/// </summary>
public class CameraInfo
{
#region Attr
/// <summary>
/// 相机类型
/// </summary>
public int Type { get; set; }
/// <summary>
/// ip 地址
/// </summary>
public string Ip { get; set; } = string.Empty;
/// <summary>
/// 端口
/// </summary>
public int Port { get; set; }
/// <summary>
/// 账号
/// </summary>
public string UserName { get; set; } = string.Empty;
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; } = string.Empty;
#endregion Attr
public static CameraInfo New(int type, string ip, int port, string userName, string password)
{
CameraInfo info = new() { Type = type, Ip = ip, Port = port, UserName = userName, Password = password };
if (port <= 0)
throw new Exception("Camera type not support.");
return info;
}
public static CameraInfo New(int type, string ip, string userName, string password)
{
CameraInfo info = new() { Type = type, Ip = ip, UserName = userName, Password = password };
int port = (CameraType)type switch
{
CameraType.HiK => CameraPort.HiK,
CameraType.DaHua => CameraPort.DaHua,
CameraType.YuShi => CameraPort.YuShi,
_ => -1,
};
info.Port = port;
if (port <= 0)
throw new Exception("Camera type not support.");
return info;
}
}
/// <summary>
/// 相机类型
/// </summary>
public enum CameraType
{
HiK = 0,
DaHua = 1,
YuShi = 2,
}
/// <summary>
/// 相机默认连接端口
/// </summary>
public class CameraPort
{
public const int HiK = 8000;
public const int DaHua = 37777;
public const int YuShi = 8800;
}
/// <summary>
/// Ptz 信息
/// </summary>
public class PtzInfo
{
#region Attr
public double Pan { get; set; }
public double Tilt { get; set; }
public double Zoom { get; set; }
#endregion Attr
public PtzInfo(double pan, double tilt, double zoom)
{
Pan = pan;
Tilt = tilt;
Zoom = zoom;
}
public static PtzInfo Default
{
get { return new(0, 0, 0); }
}
public static PtzInfo New(double pan, double tilt, double zoom)
{
return new PtzInfo(pan, tilt, zoom);
}
}
/// <summary>
/// 相机异常
/// </summary>
public class CameraException : Exception
{
public CameraException() : base()
{
}
public CameraException(string? message) : base(message)
{
}
public CameraException(string? message, Exception? innerException) : base(message, innerException)
{
}
protected class CameraExceptionObj
{
public CameraType Type { get; set; }
public int ErrCode { get; set; }
public string? ErrMsg { get; set; }
public override string? ToString()
{
return $"Type:{Type}, ErrCode:{ErrCode}, ErrMsg:{ErrMsg}";
}
}
public static CameraException New(CameraType type, int errCode)
{
CameraExceptionObj obj = new()
{
Type = type,
ErrCode = errCode
};
return new CameraException(obj.ToString());
}
public static CameraException New(CameraType type, int errCode, string errMsg)
{
CameraExceptionObj obj = new()
{
Type = type,
ErrCode = errCode,
ErrMsg = errMsg
};
return new CameraException(obj.ToString());
}
}