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.
113 lines
2.4 KiB
113 lines
2.4 KiB
using Cis.Application.Cb;
|
|
using Cis.Application.Cm;
|
|
using Cis.Application.Tb;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace Cis.Application.Core;
|
|
|
|
public class CameraDataCenter
|
|
{
|
|
#region Attr
|
|
|
|
private Thread _thread { get; set; }
|
|
private List<TbPtzCamera> _tbPtzCameraList { get; set; }
|
|
private ConcurrentDictionary<string, CameraCalcInfo> _cameraPtzInfoDict { get; set; }
|
|
|
|
private readonly SqlSugarRepository<CbCamera> _cbCameraRep;
|
|
private readonly SqlSugarRepository<CmMarkLabel> _cmMarkLableRep;
|
|
private readonly SqlSugarRepository<TbPtzCamera> _tbPtzCameraRep;
|
|
private readonly PtzServerApi _ptzServerApi;
|
|
|
|
#endregion Attr
|
|
|
|
public CameraDataCenter()
|
|
{
|
|
_cbCameraRep = App.GetService<SqlSugarRepository<CbCamera>>();
|
|
_cmMarkLableRep = App.GetService<SqlSugarRepository<CmMarkLabel>>();
|
|
_tbPtzCameraRep = App.GetService<SqlSugarRepository<TbPtzCamera>>();
|
|
_ptzServerApi = App.GetService<PtzServerApi>();
|
|
Init();
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
// 初始化 tbPtzCameraList
|
|
_tbPtzCameraList = _tbPtzCameraRep.GetList();
|
|
// 根据 Ip 去重
|
|
_tbPtzCameraList = _tbPtzCameraList.Where((a, i) => _tbPtzCameraList.FindIndex(b => b.Ip == a.Ip) == i).ToList();
|
|
|
|
// 初始化 ptzInfoDict
|
|
_cameraPtzInfoDict = new ConcurrentDictionary<string, CameraCalcInfo>();
|
|
|
|
// 初始化 thread
|
|
_thread = new Thread(WorkLoop)
|
|
{
|
|
IsBackground = true// 设置后台线程
|
|
};
|
|
_thread.Start();
|
|
}
|
|
|
|
private void LazyInit()
|
|
{
|
|
// 初始化 tbPtzCameraList
|
|
_tbPtzCameraList = new();
|
|
|
|
// 初始化 ptzInfoDict
|
|
_cameraPtzInfoDict = new ConcurrentDictionary<string, CameraCalcInfo>();
|
|
|
|
// 初始化 thread
|
|
_thread = new Thread(WorkLoop)
|
|
{
|
|
IsBackground = true// 设置后台线程
|
|
};
|
|
_thread.Start();
|
|
}
|
|
|
|
#region Loop
|
|
|
|
private void WorkLoop()
|
|
{
|
|
while (true)
|
|
{
|
|
GetPtzInfoByApi();
|
|
Thread.Sleep(10000);
|
|
}
|
|
}
|
|
|
|
private void GetPtzInfoByApi()
|
|
{
|
|
foreach (TbPtzCamera item in _tbPtzCameraList)
|
|
{
|
|
RequestRealControl rrc = _ptzServerApi.GetPtzInfo(item.CameraId);
|
|
CameraCalcInfo ptzInfo = new()
|
|
{
|
|
Pan = rrc.PTZPositionInfo.FP,
|
|
Tilt = rrc.PTZPositionInfo.FT,
|
|
Zoom = rrc.PTZPositionInfo.FZ
|
|
};
|
|
_cameraPtzInfoDict[item.Ip] = ptzInfo;
|
|
}
|
|
}
|
|
|
|
private void Calc()
|
|
{
|
|
}
|
|
|
|
#endregion Loop
|
|
|
|
#region external call
|
|
|
|
public bool GetCamera(string ip)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public bool ActiveCamera(string ip)
|
|
{
|
|
|
|
|
|
return false;
|
|
}
|
|
|
|
#endregion external call
|
|
}
|