|
|
|
@ -154,11 +154,6 @@ namespace Ems.CollectService.Analysis
|
|
|
|
|
if(SendMessageAsync(client, SendMessagePackInfo))
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"向客户端:{client.ID};地址:{client.GetIPPort()};回复心跳指令成功");
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
SendMessagePackInfo.m_MessageType = (byte)CallbackSendData._SetTime;
|
|
|
|
|
SendMessagePackInfo.m_PackLen = new byte[] {0x00, 0x0D};
|
|
|
|
|
bool isRes = SendTimeSyncToClient(client, SendMessagePackInfo);
|
|
|
|
|
logger.Info($"向客户端:{client.ID};地址:{client.GetIPPort()};发送校时指令{(isRes ? "成功":"失败")}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -173,6 +168,58 @@ namespace Ems.CollectService.Analysis
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 校时指令处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="buffer"></param>
|
|
|
|
|
/// <param name="count"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool CheckTimeHandlingAsync(SocketClient client, byte[] buffer, int count)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var flag = "";
|
|
|
|
|
byte[] SendMessage = new byte[12];
|
|
|
|
|
string DeviceType = "";
|
|
|
|
|
byte[] bDeviceType = new byte[1];
|
|
|
|
|
byte[] bDeviceID = new byte[2];
|
|
|
|
|
Array.Copy(buffer, 1, bDeviceType, 0, 1);
|
|
|
|
|
Array.Copy(buffer, 2, bDeviceID, 0, 2);
|
|
|
|
|
|
|
|
|
|
DeviceType = Encoding.ASCII.GetString(buffer, 1, 1);
|
|
|
|
|
DeviceType += msgUtil.ConverToString(bDeviceID);
|
|
|
|
|
|
|
|
|
|
flag = msgUtil.ConverToString(bDeviceType);
|
|
|
|
|
flag += msgUtil.ConverToString(bDeviceID);
|
|
|
|
|
|
|
|
|
|
logger.Debug($"收到客户端:{client.ID};地址:{client.GetIPPort()}请求校时指令");
|
|
|
|
|
MessagePack SendMessagePackInfo = new MessagePack();
|
|
|
|
|
SendMessagePackInfo.m_EnergyType = buffer[1];
|
|
|
|
|
Array.Copy(buffer, 2, SendMessagePackInfo.m_Meteraddr, 0, 2);
|
|
|
|
|
Array.Copy(buffer, 4, SendMessagePackInfo.m_Msta, 0, 2);
|
|
|
|
|
SendMessagePackInfo.m_StartFlag = buffer[6];
|
|
|
|
|
SendMessagePackInfo.m_MessageType = (byte)CallbackSendData._SetTime;
|
|
|
|
|
SendMessagePackInfo.m_PackLen = new byte[] {0x00, 0x06};
|
|
|
|
|
bool isRes = SendTimeSyncToClient(client, SendMessagePackInfo);
|
|
|
|
|
if(isRes)
|
|
|
|
|
{
|
|
|
|
|
logger.Info($"向客户端:{client.ID};地址:{client.GetIPPort()};发送校时指令{(isRes ? "成功":"失败")}");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Debug($"向客户端:{client.ID};地址:{client.GetIPPort()};回复校时指令失败");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"CheckTimeHandlingAsync校时指令解析异常:{ex.Message}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 电力仪表
|
|
|
|
@ -917,7 +964,7 @@ namespace Ems.CollectService.Analysis
|
|
|
|
|
ushort num = 0;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
byte[] SendBuffer = new byte[25];
|
|
|
|
|
byte[] SendBuffer = new byte[18];
|
|
|
|
|
SendBuffer[num] = pMessagePack.m_BeginChar;
|
|
|
|
|
num = (ushort)(num + 1);
|
|
|
|
|
SendBuffer[num] = pMessagePack.m_EnergyType;
|
|
|
|
@ -936,13 +983,6 @@ namespace Ems.CollectService.Analysis
|
|
|
|
|
DateTime currentTime = DateTime.Now;
|
|
|
|
|
byte[] timeBuffer = new byte[]
|
|
|
|
|
{
|
|
|
|
|
0x00,
|
|
|
|
|
0x00,
|
|
|
|
|
0x00,
|
|
|
|
|
0x00,
|
|
|
|
|
0x00,
|
|
|
|
|
0x00,
|
|
|
|
|
0x00,
|
|
|
|
|
HexStrTorbytes(currentTime.ToString("ss"))[0],
|
|
|
|
|
HexStrTorbytes(currentTime.ToString("mm"))[0],
|
|
|
|
|
HexStrTorbytes(currentTime.ToString("HH"))[0],
|
|
|
|
@ -952,7 +992,7 @@ namespace Ems.CollectService.Analysis
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Array.Copy(timeBuffer, 0, SendBuffer, num, timeBuffer.Length);
|
|
|
|
|
num = (ushort)(num + 13);
|
|
|
|
|
num = (ushort)(num + 6);
|
|
|
|
|
|
|
|
|
|
pMessagePack.m_Verify = MsgUtil.CalculateVerify(SendBuffer, SendBuffer.Length - 1)[0];
|
|
|
|
|
SendBuffer[num] = pMessagePack.m_Verify;
|
|
|
|
|