|
@ -1,5 +1,4 @@ |
|
|
using EC.Util.Common; |
|
|
using System.Collections.Concurrent; |
|
|
using System.Collections.Concurrent; |
|
|
|
|
|
using System.Net; |
|
|
using System.Net; |
|
|
using System.Timers; |
|
|
using System.Timers; |
|
|
using Timer = System.Timers.Timer; |
|
|
using Timer = System.Timers.Timer; |
|
@ -155,7 +154,7 @@ public class TcpManager |
|
|
{ |
|
|
{ |
|
|
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); |
|
|
Console.WriteLine("Recv 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]); |
|
@ -209,9 +208,9 @@ public class TcpManager |
|
|
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 offline = state % 2; |
|
|
int alarm = state / 2 % 2; |
|
|
int alarm = state / 2 % 2; |
|
|
ProcessSensorStateEvent(ref clientMsg, mm, sensorAddr, online, alarm); |
|
|
ProcessSensorStateEvent(ref clientMsg, mm, sensorAddr, offline, alarm); |
|
|
SetDataRequest(mm, 0x04); |
|
|
SetDataRequest(mm, 0x04); |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
@ -307,9 +306,9 @@ public class TcpManager |
|
|
string cmd = DataMessage.ToHexString(bytes); |
|
|
string cmd = DataMessage.ToHexString(bytes); |
|
|
DataMessage mm = new(); |
|
|
DataMessage mm = new(); |
|
|
mm.Decode(bytes); |
|
|
mm.Decode(bytes); |
|
|
Console.WriteLine("Send to {0}:{1} => {2}, {3}", ip, clientMsg.Port, cmd, JsonUtil.ToJson(mm)); |
|
|
bool flag = Server.SendAsync(clientMsg.Client, bytes); |
|
|
Server.SendAsync(clientMsg.Client, bytes); |
|
|
Console.WriteLine("Send to {0}:{1} => {2}, {3}", ip, clientMsg.Port, cmd, flag); |
|
|
return true; |
|
|
return flag; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public bool SendRequest(ref DataRequest request) |
|
|
public bool SendRequest(ref DataRequest request) |
|
@ -449,6 +448,85 @@ public class TcpManager |
|
|
return SendResponse(msg); |
|
|
return SendResponse(msg); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool RequestSensorTurnOff_09(ClientMessage client, int sensorAddr) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!client.IsOnline) return false; |
|
|
|
|
|
if (client.SensorsEmpty) return false; |
|
|
|
|
|
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x19, 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 RequestSensorsTurnOff_09(ClientMessage client) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!client.IsOnline) return false; |
|
|
|
|
|
if (client.SensorsEmpty) return false; |
|
|
|
|
|
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x19, 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 RequestSensorTurnOn_20(ClientMessage client, int sensorAddr) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!client.IsOnline) return false; |
|
|
|
|
|
if (client.SensorsEmpty) return false; |
|
|
|
|
|
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x20, 2); |
|
|
|
|
|
msg.Data = new byte[] { (byte)(sensorAddr % 256), (byte)(sensorAddr / 256) }; |
|
|
|
|
|
DataRequest request = new() |
|
|
|
|
|
{ |
|
|
|
|
|
Request = msg |
|
|
|
|
|
}; |
|
|
|
|
|
return SendRequest(ref request); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool RequestSensorsTurnOn_20(ClientMessage client) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!client.IsOnline) return false; |
|
|
|
|
|
if (client.SensorsEmpty) return false; |
|
|
|
|
|
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x20, 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 RequestSensorsTurnOn_21(ClientMessage client) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!client.IsOnline) return false; |
|
|
|
|
|
if (client.SensorsEmpty) return false; |
|
|
|
|
|
DataMessage msg = GetSendMessageHead(client.Host.Id, client, 0x21, 0); |
|
|
|
|
|
DataRequest request = new() |
|
|
|
|
|
{ |
|
|
|
|
|
Request = msg |
|
|
|
|
|
}; |
|
|
|
|
|
return SendRequest(ref request); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#endregion Send
|
|
|
#endregion Send
|
|
|
|
|
|
|
|
|
#region ClientMessage
|
|
|
#region ClientMessage
|
|
|