예제 #1
0
 private bool BasicProcessMessage(byte[] data, SocketAsyncEventArgs socketAsync, EndPoint remoteEndPoint, DLT698Message.FrameInfo frameInfo, TCPClientInfo cl)
 {
     if (frameInfo.AFN == AFN.链路接口检测)
     {
         if (frameInfo.FN == "0001")
         {
             byte[] array = DLT698Message.CreateLogOKMessage(frameInfo.A1, frameInfo.A2, frameInfo.FN, frameInfo.PSEQ, this.Tpv);
             LogMSG.AddInfo(string.Concat(new string[] { DateTime.Now.ToString(), " ->终端 [", remoteEndPoint.ToString(), "] 登录:", PubFuncHelper.ByteToHexStr(data), "\r\n", DateTime.Now.ToString(), " ->回应 [", remoteEndPoint.ToString(), "] 登录确认:", PubFuncHelper.ByteToHexStr(array), "\r\n" }), 6);
             socketAsync.AcceptSocket.Send(array);
             socketAsync.UserToken = cl;
             lock (this.clients)
             {
                 if (!this.clients.Exists((TCPClientInfo gcl) => gcl.Host == cl.Host))
                 {
                     this.clients.Add(cl);
                 }
             }
         }
         else
         {
             if (frameInfo.FN == "0003")
             {
                 byte[] array = DLT698Message.CreateLogOKMessage(frameInfo.A1, frameInfo.A2, frameInfo.FN, frameInfo.PSEQ, this.Tpv);
                 LogMSG.AddInfo(string.Concat(new string[] { DateTime.Now.ToString(), " ->终端 [", remoteEndPoint.ToString(), "] 心跳:", PubFuncHelper.ByteToHexStr(data), "\r\n", DateTime.Now.ToString(), " ->回应 [", remoteEndPoint.ToString(), "] 心跳确认:", PubFuncHelper.ByteToHexStr(array), "\r\n" }), 7);
                 socketAsync.AcceptSocket.Send(array);
             }
         }
         return(true);
     }
     else
     {
         if (frameInfo.PRM == "0" & frameInfo.DIR == "1")
         {
             BufferManager.AddDataItem(frameInfo.A1, frameInfo.A2, data);
         }
         else
         {
             if (frameInfo.PRM == "1" & frameInfo.DIR == "1")
             {
                 ActiveReportMsg.AddInfo(data);
             }
         }
         return(false);
     }
     //return frameInfo;
 }
예제 #2
0
        //接收数据,开始解析,
        private void DataOn(byte[] data, SocketAsyncEventArgs socketAsync)
        {
            try
            {
                if (data.Length > 0)
                {
                    EndPoint remoteEndPoint = socketAsync.AcceptSocket.RemoteEndPoint;
                    RecieveLog.AddInfo(string.Concat(new string[]                                   { DateTime.Now.ToString(), " ->接收 [", remoteEndPoint.ToString(), "] :", PubFuncHelper.ByteToHexStr(data), "\r\n" }));
                    DLT698Message.FrameInfo frameInfo = new DLT698Message.FrameInfo();
                    DLT698Message           dLT       = new DLT698Message();

                    var x = new byte[data.Length - 36];
                    Array.Copy(data, 33, x, 0, data.Length - 36);
                    data = x;
                    if (dLT.Assert_Basic(data))                    //数据内容基本ok
                    {
                        dLT.ParseData(data, data.Length, ref frameInfo);
                        TCPClientInfo cl = new TCPClientInfo();
                        cl.Host = remoteEndPoint;
                        cl.Sock = socketAsync.AcceptSocket;
                        cl.A1   = frameInfo.A1;
                        cl.A2   = frameInfo.A2;



                        bool processed = BasicProcessMessage(data, socketAsync, remoteEndPoint, frameInfo, cl);
                        //
                        if (!processed && OnDLT698Message != null)
                        {
                            OnDLT698Message(this, new DLT698MessageEventArgs(dLT));
                        }
                    }
                }
            }
            catch
            {
            }
        }
예제 #3
0
 private void OnDataReceived(object sender, SocketAsyncEventArgs e)
 {
     try
     {
         if (e.BytesTransferred > 0)
         {
             EndPoint remoteEndPoint = e.RemoteEndPoint;
             byte[]   array          = new byte[e.BytesTransferred];
             Array.Copy(e.Buffer, 0, array, 0, e.BytesTransferred);
             RecieveLog.AddInfo(string.Concat(new string[]
             {
                 DateTime.Now.ToString(),
                 " ->接收(UDP) [",
                 remoteEndPoint.ToString(),
                 "] :",
                 this.ByteToHexStr(array),
                 "\r\n"
             }));
             DLT698Message.FrameInfo frameInfo = default(DLT698Message.FrameInfo);
             DLT698Message           dLT       = new DLT698Message();
             if (dLT.Assert_Basic(array))
             {
                 dLT.ParseData(array, e.BytesTransferred, ref frameInfo);
                 if (frameInfo.AFN == "02")
                 {
                     if (frameInfo.FN == "0003")
                     {
                         byte[] data = this.LogOK(frameInfo.A1, frameInfo.A2, frameInfo.FN, frameInfo.PSEQ);
                         LogMSG.AddInfo(string.Concat(new string[]
                         {
                             DateTime.Now.ToString(),
                             " ->终端(UDP) [",
                             remoteEndPoint.ToString(),
                             "] 心跳:",
                             this.ByteToHexStr(array),
                             "\r\n",
                             DateTime.Now.ToString(),
                             " ->回应(UDP) [",
                             remoteEndPoint.ToString(),
                             "] 心跳确认:",
                             this.ByteToHexStr(data),
                             "\r\n"
                         }), 7);
                         this.Send(data);
                     }
                 }
                 else
                 {
                     if (frameInfo.PRM == "0" & frameInfo.DIR == "1")
                     {
                         BufferManager.AddDataItem(frameInfo.A1, frameInfo.A2, array);
                     }
                     else
                     {
                         if (frameInfo.PRM == "1" & frameInfo.DIR == "1")
                         {
                             ActiveReportMsg.AddInfo(array);
                         }
                     }
                 }
             }
         }
     }
     catch
     {
     }
 }
예제 #4
0
 public DLT698MessageEventArgs(DLT698Message message)
 {
     _message = message;
 }