Browse Source

[feat] 更新震动服务命令

master
fajiao 2 years ago
parent
commit
c82e97ee9a
  1. 6
      EC.Util/CameraSDK/HiK/HiKSDK.cs
  2. 21
      EC.Util/CameraSDK/YuShi/YuShiSDK.cs
  3. 3
      EC.Util/Common/LogUnit.cs
  4. 10
      JiLinApp.Docking/FenceAlarm/Entity/UdpAlarmHost.cs
  5. 28
      JiLinApp.Docking/FenceAlarm/Service/UdpManager.cs
  6. 2
      JiLinApp.Docking/Military/Config.cs
  7. 13
      JiLinApp.Docking/Military/MilitaryService.cs
  8. 8
      JiLinApp.Docking/VibrateAlarm/Entity/ClientMessage.cs
  9. 117
      JiLinApp.Docking/VibrateAlarm/Service/TcpManager.cs
  10. 4
      JiLinApp/Components/CameraRealPlay.xaml
  11. 42
      JiLinApp/Pages/PtzManage/Main.xaml.cs
  12. 18
      JiLinApp/Pages/VibrateServerManage/Main.xaml.cs

6
EC.Util/CameraSDK/HiK/HiKSDK.cs

@ -126,7 +126,7 @@ public class HiKSDK : ICameraSDK
if (!ConnectSuccess()) return false; if (!ConnectSuccess()) return false;
int lChannel = 1; int lChannel = 1;
bool flag = HiKOriSDK.NET_DVR_PTZControlWithSpeed_Other(LoginId, lChannel, (uint)cmd, (uint)stop, (uint)speed); bool flag = HiKOriSDK.NET_DVR_PTZControlWithSpeed_Other(LoginId, lChannel, (uint)cmd, (uint)stop, (uint)speed);
//if (flag) BuildException(); if (flag) BuildException();
return flag; return flag;
} }
@ -134,7 +134,9 @@ public class HiKSDK : ICameraSDK
{ {
if (!ConnectSuccess()) return false; if (!ConnectSuccess()) return false;
int lChannel = 1; int lChannel = 1;
return HiKOriSDK.NET_DVR_PTZPreset_Other(LoginId, lChannel, (uint)cmd, (uint)presetId); bool flag = HiKOriSDK.NET_DVR_PTZPreset_Other(LoginId, lChannel, (uint)cmd, (uint)presetId);
if (flag) BuildException();
return flag;
} }
#endregion Ptz Method #endregion Ptz Method

21
EC.Util/CameraSDK/YuShi/YuShiSDK.cs

@ -64,11 +64,9 @@ public class YuShiSDK : ICameraSDK
{ {
bool ret = ConnectSuccess(); bool ret = ConnectSuccess();
if (!ret) return PtzInfo.Default; if (!ret) return PtzInfo.Default;
YuShiOriSDK.NETDEV_PTZ_STATUS_S entity = new(); YuShiOriSDK.NETDEV_PTZ_STATUS_S entity = new();
ret = YuShiOriSDK.NETDEV_PTZGetStatus(LoginId, 1, ref entity); ret = YuShiOriSDK.NETDEV_PTZGetStatus(LoginId, 1, ref entity);
if (!ret) { BuildException(); return PtzInfo.Default; } if (!ret) { BuildException(); return PtzInfo.Default; }
return PtzInfo.New(entity.fPanTiltX, entity.fPanTiltY, entity.fZoomX); return PtzInfo.New(entity.fPanTiltX, entity.fPanTiltY, entity.fZoomX);
} }
@ -76,11 +74,9 @@ public class YuShiSDK : ICameraSDK
{ {
bool ret = ConnectSuccess(); bool ret = ConnectSuccess();
if (!ret) { ptzInfo = PtzInfo.Default; return false; } if (!ret) { ptzInfo = PtzInfo.Default; return false; }
YuShiOriSDK.NETDEV_PTZ_STATUS_S entity = new(); YuShiOriSDK.NETDEV_PTZ_STATUS_S entity = new();
ret = YuShiOriSDK.NETDEV_PTZGetStatus(LoginId, 1, ref entity); ret = YuShiOriSDK.NETDEV_PTZGetStatus(LoginId, 1, ref entity);
if (!ret) { BuildException(); ptzInfo = PtzInfo.Default; return false; } if (!ret) { BuildException(); ptzInfo = PtzInfo.Default; return false; }
ptzInfo = PtzInfo.New(entity.fPanTiltX, entity.fPanTiltY, entity.fZoomX); ptzInfo = PtzInfo.New(entity.fPanTiltX, entity.fPanTiltY, entity.fZoomX);
return true; return true;
} }
@ -89,18 +85,21 @@ public class YuShiSDK : ICameraSDK
{ {
if (!ConnectSuccess()) return false; if (!ConnectSuccess()) return false;
if (stop == 1) cmd = YuShiOriSDK.ALLSTOP; if (stop == 1) cmd = YuShiOriSDK.ALLSTOP;
int channel = 1; int channel = 0;
int flag = YuShiOriSDK.NETDEV_PTZControl_Other(LoginId, channel, cmd, speed); int ret = YuShiOriSDK.NETDEV_PTZControl_Other(LoginId, channel, cmd, speed);
//if (flag) BuildException(); bool flag = ret == YuShiOriSDK.TRUE;
return flag == YuShiOriSDK.TRUE; if (!flag) BuildException();
return flag;
} }
public override bool PtzPreset(int cmd, int presetId) public override bool PtzPreset(int cmd, int presetId)
{ {
if (!ConnectSuccess()) return false; if (!ConnectSuccess()) return false;
int channel = 1; int channel = 0;
int flag = YuShiOriSDK.NETDEV_PTZPreset_Other(LoginId, channel, cmd, Array.Empty<byte>(), presetId); int ret = YuShiOriSDK.NETDEV_PTZPreset_Other(LoginId, channel, cmd, Array.Empty<byte>(), presetId);
return flag == YuShiOriSDK.TRUE; bool flag = ret == YuShiOriSDK.TRUE;
if (!flag) BuildException();
return flag;
} }
#endregion Ptz Method #endregion Ptz Method

3
EC.Util/Common/LogUnit.cs

@ -9,7 +9,8 @@ public static class LogUnit
static LogUnit() static LogUnit()
{ {
string fileName = Path.Combine("config", "log4net.Config"); string fileName = Path.Combine("config", "log4net.config");
if (!File.Exists(fileName)) throw new FileNotFoundException(fileName);
XmlConfigurator.Configure(new FileInfo(fileName)); XmlConfigurator.Configure(new FileInfo(fileName));
logger = LogManager.GetLogger(typeof(LogUnit)); logger = LogManager.GetLogger(typeof(LogUnit));
} }

10
JiLinApp.Docking/FenceAlarm/Entity/UdpAlarmHost.cs

@ -112,6 +112,16 @@ public class UdpAlarmHost
public ConcurrentDictionary<int, SectorState> SectorDict { get; } public ConcurrentDictionary<int, SectorState> SectorDict { get; }
public bool SectorsEmpty
{
get
{
return SectorDict == null || SectorDict.IsEmpty;
}
}
public ReaderWriterLockSlim SectorsLock { get; } = new();
public int OnlineState { get; set; }//设备在线状态 public int OnlineState { get; set; }//设备在线状态
public int KeepLive { get; set; }//设备在线状态 public int KeepLive { get; set; }//设备在线状态

28
JiLinApp.Docking/FenceAlarm/Service/UdpManager.cs

@ -103,8 +103,8 @@ public class UdpManager
//解码 //解码
byte[] msg = AlarmEncode.DecodeMessage(e.Datagram); byte[] msg = AlarmEncode.DecodeMessage(e.Datagram);
bool vaild = msg.Length >= 8 && msg[2] == AlarmEncode.Head[0] && msg[3] == AlarmEncode.Head[1]; bool vaild = msg.Length >= 8 && msg[2] == AlarmEncode.Head[0] && msg[3] == AlarmEncode.Head[1];
Console.WriteLine("Receive from {0}:{1} => {2}, {3}", ipep.Address.ToString(), ipep.Port, DataMessage.ToHexString(msg), vaild);
if (!vaild) return; if (!vaild) return;
Console.WriteLine("Receive from {0}:{1} => {2}", ipep.Address.ToString(), ipep.Port, DataMessage.ToHexString(msg));
//解析 //解析
DeviceCmd deviceCmd = (DeviceCmd)msg[4]; DeviceCmd deviceCmd = (DeviceCmd)msg[4];
switch (deviceCmd) switch (deviceCmd)
@ -158,7 +158,7 @@ public class UdpManager
OnlineState = 1, OnlineState = 1,
KeepLive = Config.DeviceHeartKeep KeepLive = Config.DeviceHeartKeep
}; };
AddDevice(deviceId, device); AddDevice(deviceId, ref device);
} }
byte defenceState = msg[17]; byte defenceState = msg[17];
ProcessDeviceStateEvent(ref device, 1, defenceState); ProcessDeviceStateEvent(ref device, 1, defenceState);
@ -205,7 +205,7 @@ public class UdpManager
OnlineState = 1, OnlineState = 1,
KeepLive = Config.DeviceHeartKeep KeepLive = Config.DeviceHeartKeep
}; };
AddDevice(deviceId, device); AddDevice(deviceId, ref device);
} }
string alarmTime = $"20{GetBCD(msg[17])}-{GetBCD(msg[18])}-{GetBCD(msg[19])} " + string alarmTime = $"20{GetBCD(msg[17])}-{GetBCD(msg[18])}-{GetBCD(msg[19])} " +
$"{GetBCD(msg[20])}:{GetBCD(msg[21])}:{GetBCD(msg[22])}"; $"{GetBCD(msg[20])}:{GetBCD(msg[21])}:{GetBCD(msg[22])}";
@ -244,7 +244,7 @@ public class UdpManager
OnlineState = 1, OnlineState = 1,
KeepLive = Config.DeviceHeartKeep KeepLive = Config.DeviceHeartKeep
}; };
AddDevice(deviceId, device); AddDevice(deviceId, ref device);
} }
device.SectorTotal = msg[17] * 256 + msg[18]; device.SectorTotal = msg[17] * 256 + msg[18];
int sectorNum = msg[19], startIndex = msg[20]; int sectorNum = msg[19], startIndex = msg[20];
@ -283,7 +283,7 @@ public class UdpManager
OnlineState = 1, OnlineState = 1,
KeepLive = Config.DeviceHeartKeep KeepLive = Config.DeviceHeartKeep
}; };
AddDevice(deviceId, device); AddDevice(deviceId, ref device);
} }
} }
@ -303,7 +303,7 @@ public class UdpManager
OnlineState = 1, OnlineState = 1,
KeepLive = Config.DeviceHeartKeep KeepLive = Config.DeviceHeartKeep
}; };
AddDevice(deviceId, device); AddDevice(deviceId, ref device);
} }
device.SectorTotal = msg[17] * 256 + msg[18]; device.SectorTotal = msg[17] * 256 + msg[18];
} }
@ -616,10 +616,24 @@ public class UdpManager
return DeviceDict.TryGetValue(deviceId, out device); return DeviceDict.TryGetValue(deviceId, out device);
} }
private bool AddDevice(int deviceId, UdpAlarmHost device) private bool AddDevice(int deviceId, ref UdpAlarmHost device)
{ {
if (ContainsDevice(deviceId)) return false; if (ContainsDevice(deviceId)) return false;
DeviceDict[deviceId] = device; DeviceDict[deviceId] = device;
UdpAlarmHost innerDevice = DeviceDict[deviceId];
if (innerDevice.SectorsEmpty && innerDevice.SectorsLock.TryEnterWriteLock(1000))
{
Task.Run(() =>
{
innerDevice = DeviceDict[deviceId];
while (innerDevice.SectorsEmpty)
{
SearchAllSectorState(innerDevice.DeviceId);
Thread.Sleep(1000);
}
innerDevice.SectorsLock.ExitWriteLock();
});
}
return true; return true;
} }

2
JiLinApp.Docking/Military/Config.cs

@ -2,6 +2,8 @@
public class MilitaryConfig public class MilitaryConfig
{ {
//public bool Enable { get; set; }
public string Url { get; set; } public string Url { get; set; }
public string UserName { get; set; } public string UserName { get; set; }

13
JiLinApp.Docking/Military/MilitaryService.cs

@ -28,6 +28,11 @@ public class MilitaryService
return Config.Url; return Config.Url;
} }
private IFlurlRequest WithToken(string url)
{
return url.WithHeader("X-Access-Token", Token);
}
#endregion Base #endregion Base
#region Cmd #region Cmd
@ -43,7 +48,7 @@ public class MilitaryService
JObject response = new(); JObject response = new();
for (int i = 0; i < Config.RequestRetryTime; i++) for (int i = 0; i < Config.RequestRetryTime; i++)
{ {
response = url.PostJsonAsync(data).ReceiveJson<JObject>().Result; response = WithToken(url).PostJsonAsync(data).ReceiveJson<JObject>().Result;
bool success = response["success"].ToBoolean(); bool success = response["success"].ToBoolean();
if (!success) if (!success)
{ {
@ -63,7 +68,7 @@ public class MilitaryService
JObject response = new(); JObject response = new();
for (int i = 0; i < Config.RequestRetryTime; i++) for (int i = 0; i < Config.RequestRetryTime; i++)
{ {
response = url.GetAsync().ReceiveJson<JObject>().Result; response = WithToken(url).GetAsync().ReceiveJson<JObject>().Result;
bool success = response["success"].ToBoolean(); bool success = response["success"].ToBoolean();
if (!success) if (!success)
{ {
@ -101,7 +106,7 @@ public class MilitaryService
JObject response = new(); JObject response = new();
for (int i = 0; i < Config.RequestRetryTime; i++) for (int i = 0; i < Config.RequestRetryTime; i++)
{ {
response = url.WithHeader("X-Access-Token", Token).GetAsync().ReceiveJson<JObject>().Result; response = WithToken(url).GetAsync().ReceiveJson<JObject>().Result;
bool success = response["success"].ToBoolean(); bool success = response["success"].ToBoolean();
if (!success) if (!success)
{ {
@ -120,7 +125,7 @@ public class MilitaryService
JObject response = new(); JObject response = new();
for (int i = 0; i < Config.RequestRetryTime; i++) for (int i = 0; i < Config.RequestRetryTime; i++)
{ {
response = url.GetAsync().ReceiveJson<JObject>().Result; response = WithToken(url).GetAsync().ReceiveJson<JObject>().Result;
bool success = response["success"].ToBoolean(); bool success = response["success"].ToBoolean();
if (!success) if (!success)
{ {

8
JiLinApp.Docking/VibrateAlarm/Entity/ClientMessage.cs

@ -33,6 +33,14 @@ public class ClientMessage
public int OnlineState { get; set; }//设备在线状态 public int OnlineState { get; set; }//设备在线状态
public bool IsOnline
{
get
{
return Host != null && Host.Id >= 0 && OnlineState == 1;
}
}
public int SensorTotal public int SensorTotal
{ {
get get

117
JiLinApp.Docking/VibrateAlarm/Service/TcpManager.cs

@ -91,6 +91,7 @@ public class TcpManager
{ {
foreach (var clientMsg in DeviceDict.Values) foreach (var clientMsg in DeviceDict.Values)
{ {
if (!clientMsg.IsOnline) continue;
SendHostHeart_01(clientMsg); SendHostHeart_01(clientMsg);
} }
} }
@ -144,22 +145,20 @@ public class TcpManager
#endregion Events #endregion Events
#region Analysisbo #region Analysis
private void AnalysisClientMessage(ref ClientMessage clientMsg) private void AnalysisClientMessage(ref ClientMessage clientMsg)
{ {
//AA AA 01 C0 A8 01 05 28 23 C0 A8 01 64 88 13 7C 04 02 04 00 2B
//AA AA 01 C0 A8 01 64 88 13 C0 A8 01 05 28 23 24 14 04 0A 00 02 00 03
List<byte[]> msglist = clientMsg.GetMessageList(); List<byte[]> msglist = clientMsg.GetMessageList();
if (msglist == null || msglist.Count == 0) return; if (msglist == null || msglist.Count == 0) return;
for (int i = 0; i < msglist.Count; i++) for (int i = 0; i < msglist.Count; i++)
{ {
byte[] msg = msglist[i]; byte[] msg = msglist[i];
bool vaild = msg.Length >= 19 && msg[0] == 0xAA && msg[1] == 0xAA; bool vaild = msg.Length >= 19 && msg[0] == 0xAA && msg[1] == 0xAA;
Console.WriteLine("Receive from {0}:{1} => {2}, {3}", clientMsg.Ip, clientMsg.Port, DataMessage.ToHexString(msg), vaild);
if (!vaild) continue; if (!vaild) continue;
DataMessage mm = new(); DataMessage mm = new();
mm.Decode(msglist[i]); mm.Decode(msglist[i]);
Console.WriteLine("Receive from {0}:{1} => {2}, {3}", clientMsg.Ip, clientMsg.Port, DataMessage.ToHexString(msglist[i]), JsonUtil.ToJson(mm));
switch (mm.FunctionNum) switch (mm.FunctionNum)
{ {
case 0x00: case 0x00:
@ -168,26 +167,31 @@ public class TcpManager
{ {
clientMsg.Host = new() { Id = mm.DeviceId, Ip = mm.SendIp, Port = mm.SendPort.ToString() }; clientMsg.Host = new() { Id = mm.DeviceId, Ip = mm.SendIp, Port = mm.SendPort.ToString() };
UpdateDevice(clientMsg.Ip, clientMsg.Host); UpdateDevice(clientMsg.Ip, clientMsg.Host);
ProcessDeviceStateEvent(ref clientMsg, 1);
} }
ProcessDeviceStateEvent(ref clientMsg, 1);
ResponseHostLogin_10(clientMsg, mm); ResponseHostLogin_10(clientMsg, mm);
ClientMessage clientMsg2 = clientMsg; ClientMessage taskClientMsg = clientMsg;
if (clientMsg2.SensorsEmpty && clientMsg2.SensorsLock.TryEnterWriteLock(1000)) if (taskClientMsg.SensorsEmpty && taskClientMsg.SensorsLock.TryEnterWriteLock(1000))
{ {
Task.Run(() => Task.Run(() =>
{ {
while (clientMsg2.SensorsEmpty) while (taskClientMsg.SensorsEmpty)
{ {
RequestSensorList_07(clientMsg2); RequestSensorList_07(taskClientMsg);
Thread.Sleep(1000); Thread.Sleep(1000);
} }
clientMsg2.SensorsLock.ExitWriteLock(); taskClientMsg.SensorsLock.ExitWriteLock();
}); });
} }
break; break;
case 0x01: case 0x01:
Console.WriteLine("心跳:{0}", clientMsg.Ip); Console.WriteLine("心跳:{0}", clientMsg.Ip);
if (clientMsg.Host == null || clientMsg.Host.Id != mm.DeviceId)
{
clientMsg.Host = new() { Id = mm.DeviceId, Ip = mm.SendIp, Port = mm.SendPort.ToString() };
UpdateDevice(clientMsg.Ip, clientMsg.Host);
}
ProcessDeviceStateEvent(ref clientMsg, 1); ProcessDeviceStateEvent(ref clientMsg, 1);
break; break;
@ -202,16 +206,11 @@ public class TcpManager
break; break;
case 0x14: case 0x14:
Console.WriteLine("传感器状态响应:{0}", clientMsg.Ip); Console.WriteLine("传感器轮询状态响应:{0}", clientMsg.Ip);
int sensorAddr = mm.Data[0] + mm.Data[1] * 256; int sensorAddr = mm.Data[0] + mm.Data[1] * 256;
int state = mm.Data[2] + mm.Data[3] * 256; int state = mm.Data[2] + mm.Data[3] * 256;
int online = state % 2; int online = state % 2;
int alarm = state / 2 % 2; int alarm = state / 2 % 2;
if (clientMsg.Host == null || clientMsg.Host.Id != mm.DeviceId)
{
clientMsg.Host = new() { Id = mm.DeviceId, Ip = mm.SendIp, Port = mm.SendPort.ToString() };
UpdateDevice(clientMsg.Ip, clientMsg.Host);
}
ProcessSensorStateEvent(ref clientMsg, mm, sensorAddr, online, alarm); ProcessSensorStateEvent(ref clientMsg, mm, sensorAddr, online, alarm);
SetDataRequest(mm, 0x04); SetDataRequest(mm, 0x04);
break; break;
@ -223,11 +222,6 @@ public class TcpManager
case 0x17: case 0x17:
Console.WriteLine("返回传感器列表:{0}", clientMsg.Ip); Console.WriteLine("返回传感器列表:{0}", clientMsg.Ip);
if (clientMsg.Host == null || clientMsg.Host.Id != mm.DeviceId)
{
clientMsg.Host = new() { Id = mm.DeviceId, Ip = mm.SendIp, Port = mm.SendPort.ToString() };
UpdateDevice(clientMsg.Ip, clientMsg.Host);
}
if (clientMsg.SensorsEmpty) if (clientMsg.SensorsEmpty)
{ {
for (int j = 2; j < mm.Data.Length; j++) for (int j = 2; j < mm.Data.Length; j++)
@ -236,10 +230,16 @@ public class TcpManager
SensorState sensor = new(mm.DeviceId, sensorAddr, 0, 0); SensorState sensor = new(mm.DeviceId, sensorAddr, 0, 0);
clientMsg.SensorDict[sensorAddr] = sensor; clientMsg.SensorDict[sensorAddr] = sensor;
} }
RequestSensorState_04(clientMsg); RequestSensorsStateActively_08(clientMsg);
} }
SetDataRequest(mm, 0x07); SetDataRequest(mm, 0x07);
break; break;
case 0x18:
Console.WriteLine("传感器主动状态响应:{0}", clientMsg.Ip);
SetDataRequest(mm, 0x08);
break;
} }
} }
} }
@ -296,7 +296,7 @@ public class TcpManager
OnVibrateTcpAlarm?.Invoke(alarmMsg); OnVibrateTcpAlarm?.Invoke(alarmMsg);
} }
#endregion Analysisbo #endregion Analysis
#region Send #region Send
@ -337,29 +337,40 @@ public class TcpManager
public bool SendHostHeart_01(ClientMessage client) public bool SendHostHeart_01(ClientMessage client)
{ {
if (client.Host == null) return false; if (!client.IsOnline) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x01, 1); DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x01, 1);
msg.Data = new byte[] { 0xFF }; msg.Data = new byte[] { 0xFF };
return SendNoRequest(msg); return SendNoRequest(msg);
} }
public bool RequestSensorChange_02(ClientMessage client) public bool RequestSensorChange_02(ClientMessage client, int newSensorAddr)
{ {
if (client.Host == null || client.Host.Id < 0) return false; if (!client.IsOnline) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x02, 4); DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x02, 4);
int channel = 10; msg.Data = new byte[] { (byte)(newSensorAddr % 256), (byte)(newSensorAddr / 256), (100 % 256), (100 / 256) };
msg.Data = new byte[] { (byte)(channel % 256), (byte)(channel / 256), (100 % 256), (100 / 256) };
DataRequest request = new() DataRequest request = new()
{ {
Request = msg Request = msg
}; };
SendRequest(ref request); return SendRequest(ref request);
return true; }
public bool RequestSensorState_04(ClientMessage client, int sensorAddr)
{
if (!client.IsOnline) return false;
if (!client.SensorDict.TryGetValue(sensorAddr, out _)) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x04, 2);
msg.Data = new byte[] { (byte)(sensorAddr % 256), (byte)(sensorAddr / 256) };
DataRequest request = new()
{
Request = msg
};
return SendRequest(ref request);
} }
public bool RequestSensorState_04(ClientMessage client) public bool RequestSensorsState_04(ClientMessage client)
{ {
if (client.Host == null || client.Host.Id < 0) return false; if (!client.IsOnline) return false;
if (client.SensorsEmpty) return false; if (client.SensorsEmpty) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x04, 2); DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x04, 2);
foreach (var item in client.SensorDict.Values) foreach (var item in client.SensorDict.Values)
@ -377,21 +388,20 @@ public class TcpManager
public bool RequestSensorReset_05(ClientMessage client, int sensorAddr) public bool RequestSensorReset_05(ClientMessage client, int sensorAddr)
{ {
if (client.Host == null || client.Host.Id < 0) return false; if (!client.IsOnline) return false;
if (client.SensorsEmpty) return false; if (!client.SensorDict.TryGetValue(sensorAddr, out _)) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x05, 2); DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x05, 2);
msg.Data = new byte[] { (byte)(sensorAddr % 256), (byte)(sensorAddr / 256) }; msg.Data = new byte[] { (byte)(sensorAddr % 256), (byte)(sensorAddr / 256) };
DataRequest request = new() DataRequest request = new()
{ {
Request = msg Request = msg
}; };
SendRequest(ref request); return SendRequest(ref request);
return true;
} }
public bool RequestSensorList_07(ClientMessage client) public bool RequestSensorList_07(ClientMessage client)
{ {
if (client.Host == null || client.Host.Id < 0) return false; if (!client.IsOnline) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x07, 0); DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x07, 0);
DataRequest request = new() DataRequest request = new()
{ {
@ -400,9 +410,40 @@ public class TcpManager
return SendRequest(ref request); return SendRequest(ref request);
} }
public bool RequestSensorStateActively_08(ClientMessage client, int sensorAddr)
{
if (!client.IsOnline) return false;
if (!client.SensorDict.TryGetValue(sensorAddr, out _)) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x08, 2);
msg.Data = new byte[] { (byte)(sensorAddr % 256), (byte)(sensorAddr / 256) };
DataRequest request = new()
{
Request = msg
};
return SendRequest(ref request);
}
public bool RequestSensorsStateActively_08(ClientMessage client)
{
if (!client.IsOnline) return false;
if (client.SensorsEmpty) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x08, 2);
foreach (var item in client.SensorDict.Values)
{
int sensorAddr = item.Addr;
msg.Data = new byte[] { (byte)(sensorAddr % 256), (byte)(sensorAddr / 256) };
DataRequest request = new()
{
Request = msg
};
SendRequest(ref request);
}
return true;
}
public bool ResponseHostLogin_10(ClientMessage client, DataMessage mm) public bool ResponseHostLogin_10(ClientMessage client, DataMessage mm)
{ {
if (client.Host == null) return false; if (!client.IsOnline) return false;
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x10, 0); DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x10, 0);
msg.FrameNum = mm.FrameNum; msg.FrameNum = mm.FrameNum;
return SendResponse(msg); return SendResponse(msg);

4
JiLinApp/Components/CameraRealPlay.xaml

@ -125,7 +125,7 @@
</StackPanel> </StackPanel>
<StackPanel Grid.Row="6" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel Grid.Row="6" Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Name="IrisCloseBtn" Width="25" Height="25" Padding="0" Style="{StaticResource MaterialDesignOutlinedLightButton}"> <Button Name="IrisCloseBtn" Width="25" Height="25" Padding="0" Style="{StaticResource MaterialDesignOutlinedLightButton}">
<materialDesign:PackIcon Kind="MinusThick"/> <materialDesign:PackIcon Kind="MinusThick" />
</Button> </Button>
</StackPanel> </StackPanel>
@ -136,7 +136,7 @@
</StackPanel> </StackPanel>
<StackPanel Grid.Row="9" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center"> <StackPanel Grid.Row="9" Grid.ColumnSpan="3" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Name="GotoBtn" Content="前往预置点" Width="90" Height="30" Click="GotoBtn_Click" Style="{StaticResource MaterialDesignOutlinedLightButton}" <Button Name="GotoBtn" Content="前往预置点" Width="90" Height="30" Click="GotoBtn_Click" Style="{StaticResource MaterialDesignOutlinedLightButton}"
Padding="0" FontSize="11" Foreground="#000000" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> Padding="0" FontSize="11" Foreground="#000000" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</StackPanel> </StackPanel>

42
JiLinApp/Pages/PtzManage/Main.xaml.cs

@ -320,20 +320,24 @@ public partial class Main : UserControl
bool realPlay = AppConfig.AlarmPlatform.RealPlay; bool realPlay = AppConfig.AlarmPlatform.RealPlay;
string deviceId = alarm.LabelCode; string deviceId = alarm.LabelCode;
string sensorId = alarm.ChannelId; string sensorId = alarm.ChannelId;
CameraLinkageInfo cameraLinkage = GetCameraLinkage(sensorId); //CameraLinkageInfo cameraLinkage = GetCameraLinkage(sensorId);
if (cameraLinkage == null) { LogUnit.Error(this, $"CameraLinkageInfo(sensorId:{sensorId}) not found."); return; } List<CameraLinkageInfo> cameraLinkages = GetCameraLinkageList(sensorId);
string cameraId = cameraLinkage.CameraId; foreach (var item in cameraLinkages)
ICameraSDK cameraSdk = GetCameraSdk(cameraId);
if (cameraSdk == null) { LogUnit.Error(this, $"CameraSdk(cameraId:{cameraId}) not found."); return; }
if (realPlay) Dispatcher.Invoke(() => ShowLiveVideo(cameraSdk));
// TODO: 设计 PriorityQueue
int len = cameraLinkage.PresetIds.Length;
for (int i = 0; i < len; i++)
{ {
int presetId = cameraLinkage.PresetIds[i]; if (item == null) { LogUnit.Error(this, $"CameraLinkageInfo(sensorId:{sensorId}) not found."); return; }
PtzCameraCmd.PtzMove(cameraSdk, PtzCmdType.PresetGoto, new int[] { presetId }); string cameraId = item.CameraId;
if (i != len) Thread.Sleep(5000); ICameraSDK cameraSdk = GetCameraSdk(cameraId);
if (cameraSdk == null) { LogUnit.Error(this, $"CameraSdk(cameraId:{cameraId}) not found."); return; }
if (realPlay) Dispatcher.Invoke(() => ShowLiveVideo(cameraSdk));
// TODO: 设计 PriorityQueue
int len = item.PresetIds.Length;
for (int i = 0; i < len; i++)
{
int presetId = item.PresetIds[i];
PtzCameraCmd.PtzMove(cameraSdk, PtzCmdType.PresetGoto, new int[] { presetId });
if (i != len) Thread.Sleep(5000);
}
} }
} }
@ -377,6 +381,8 @@ public partial class Main : UserControl
{ {
List<CameraInfo> cameraList = MilitaryService.GetCameraList(); List<CameraInfo> cameraList = MilitaryService.GetCameraList();
CameraLinkageList = MilitaryService.GetCameraLinkageList(); CameraLinkageList = MilitaryService.GetCameraLinkageList();
//List<CameraInfo> cameraList = new();
//CameraLinkageList = new();
TaskUtil.RunCatch(() => Dispatcher.Invoke(() => LoadCameraSdkDict(cameraList))); TaskUtil.RunCatch(() => Dispatcher.Invoke(() => LoadCameraSdkDict(cameraList)));
} }
@ -409,6 +415,16 @@ public partial class Main : UserControl
return null; return null;
} }
private List<CameraLinkageInfo> GetCameraLinkageList(string sensorId)
{
List<CameraLinkageInfo> list = new();
foreach (var item in CameraLinkageList)
{
if (sensorId.Equals(item.SensorId)) list.Add(item);
}
return list;
}
private ICameraSDK GetCameraSdk(string cameraId) private ICameraSDK GetCameraSdk(string cameraId)
{ {
foreach (var item in CameraSdkDict.Values) foreach (var item in CameraSdkDict.Values)

18
JiLinApp/Pages/VibrateServerManage/Main.xaml.cs

@ -122,14 +122,6 @@ public partial class Main : UserControl
onlineState = item.OnlineState onlineState = item.OnlineState
}); });
} }
//for (int i = 1; i <= 5; i++)
//{
// respDeviceList.Add(new
// {
// id = i,
// onlineState = i % 2
// });
//}
AlarmService.SendDevices(DeviceType.Vibrate, respDeviceList); AlarmService.SendDevices(DeviceType.Vibrate, respDeviceList);
} }
@ -148,16 +140,6 @@ public partial class Main : UserControl
alarmState = item.AlarmState, alarmState = item.AlarmState,
}); });
} }
//for (int i = 1; i <= 7; i++)
//{
// respSensorList.Add(new
// {
// id = i,
// deviceId = deviceId,
// onlineState = i % 2,
// alarmState = i % 2,
// });
//}
AlarmService.SendSensors(DeviceType.Vibrate, deviceId, respSensorList); AlarmService.SendSensors(DeviceType.Vibrate, deviceId, respSensorList);
} }

Loading…
Cancel
Save