} // End of ReplyClient() //2017-11-07 Write by AlexWang 身份识别 public static void ParseIdentity(ref ClientInfo clientInfo, byte[] buffer, int nDataLen) { if (nDataLen < 11) { return; } bool bVerified = clientInfo.Verified; if (bVerified) { } else { clientInfo.Sim = GetSimCard(buffer, 3); clientInfo.Verified = true; clientInfo.NeedVerify = false; ClientInfoCommon.AddClientInfo(clientInfo); } Log.RecvLog(clientInfo.Sim, "recv", MyHelper.ByteArray2HexStr(buffer, nDataLen)); byte[] sendData = { 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; sendData[3] = buffer[3]; sendData[4] = buffer[4]; sendData[5] = buffer[5]; sendData[6] = buffer[6]; sendData[7] = buffer[7]; sendData[8] = buffer[8]; DateTime time = DateTime.Now; int nYear = time.Year; int nMon = time.Month; int nDay = time.Day; int nHour = time.Hour; int nMin = time.Minute; int nSec = time.Second; sendData[9] = (byte)(nYear & 0xFF); sendData[10] = (byte)((nYear >> 8) & 0xFF); sendData[11] = (byte)nMon; sendData[12] = (byte)nDay; sendData[13] = (byte)nHour; sendData[14] = (byte)nMin; sendData[15] = (byte)nSec; byte[] tx2 = MyHelper.CRC16_C(sendData, 16); sendData[16] = tx2[1]; sendData[17] = tx2[0]; int sndLen = clientInfo.Client.Send(sendData); string strSndMsg = MyHelper.ByteArray2HexStr(sendData, sndLen); Log.RecvLog(clientInfo.Sim, "ack identity ", strSndMsg.ToString()); // 写接收日志 }
// 2018-09-11 解析接收到的数据报文 public static int ParseRealDataProtocal(ref ClientInfo clientInfo, byte[] buffer, int nDataLen) { if (nDataLen <= 18) { return(0); } bool bVerified = clientInfo.Verified; if (bVerified) { } else { clientInfo.Sim = GetSimCard(buffer, 3); clientInfo.Verified = true; clientInfo.NeedVerify = false; ClientInfoCommon.AddClientInfo(clientInfo); } //Log.RecvLog(clientInfo.Sim, "recv", buffer, nDataLen); // 写接收日志 // 三相多功能表 MeterInfo1 mMeterInfo1 = new MeterInfo1(); mMeterInfo1.InsertTime = DateTime.Now.ToString(); mMeterInfo1.MsgTime = GetMsgTime(ref buffer, 9, 7); mMeterInfo1.GateId = GetSimCard(buffer, 3); mMeterInfo1.MeterAddr = GetMeterId(buffer); mMeterInfo1.RecvData = MyHelper.ByteArray2HexStr(buffer, nDataLen); // ClientInfoCommon.AddMsg(mMeterInfo1); Log.RecvLog(clientInfo.Sim, "recv MsgTime:" + mMeterInfo1.MsgTime + " meterId:" + mMeterInfo1.MeterAddr, MyHelper.ByteArray2HexStr(buffer, nDataLen)); ReplyClient(ref clientInfo, buffer, nDataLen); ClientInfoCommon.MsgUpdate(mMeterInfo1); // 更新数据到内存缓存 return(0); } // End of ParseRealDataProtocal()