namespace EC.Helper.CameraSDK; /// /// 相机信息 /// public class CameraInfo { #region Attr /// /// 相机类型 /// public int Type { get; set; } /// /// ip 地址 /// public string Ip { get; set; } = string.Empty; /// /// 端口 /// public int Port { get; set; } /// /// 账号 /// public string UserName { get; set; } = string.Empty; /// /// 密码 /// 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; } } /// /// 相机类型 /// public enum CameraType { HiK = 0, DaHua = 1, YuShi = 2, } /// /// 相机默认连接端口 /// public class CameraPort { public const int HiK = 8000; public const int DaHua = 37777; public const int YuShi = 8800; } /// /// Ptz 信息 /// 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); } } /// /// 相机异常 /// 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()); } }