change - 添加设备请求校时指令处理

master
wenjy 9 months ago
parent 7935d4086a
commit 750686c7c5

@ -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;

@ -58,7 +58,7 @@ namespace Ems.CollectService.TouchSocket
byteBlock.Pos = 0;
byteBlock.Read(out m_sync, 10);
Array.Copy(header, 8, m_length, 0, 2);
if (header[7] == 0X01 || header[7] == 0X24)
if (header[7] == 0X01 || header[7] == 0X24 || header[7] == 0x08)
{
this.m_bodyLength = 2;//先把crc校验和end都获取。
return true;

@ -128,6 +128,11 @@ namespace Ems.CollectService.TouchSocket
logger.Info($"{client.ID}心跳指令Header{header}Body{body}");
bufferAnalysis.HeartMessageHandlingAsync(client, buffer, requestInfo.Header.Length + requestInfo.Body.Length);
break;
case 0X08:
//请求校时指令
logger.Info($"{client.ID}请求校时指令Header{header}Body{body}");
bufferAnalysis.CheckTimeHandlingAsync(client, buffer, requestInfo.Header.Length + requestInfo.Body.Length);
break;
case 131:
//电表数据
//db.StringSet("DnbMessage:" + clientId, body, TimeSpan.FromMinutes(10));

Loading…
Cancel
Save