Ejemplo n.º 1
0
        public void ParseData(byte[] Arr, int ArrLength, ref DLT698Message.FrameInfo gFrame)
        {
            bool   flag  = false;
            string text  = string.Empty;
            string empty = string.Empty;
            int    i     = 0;

            checked
            {
                while (i < ArrLength)
                {
                    if (!flag)
                    {
                        if (Arr[i] == 104)
                        {
                            flag = true;
                            text = "68";
                        }
                    }
                    else
                    {
                        text += Arr[i].ToString("X2");
                    }

                    i++;
                }
                this.FillStruct(text, ref gFrame);
            }
        }
Ejemplo n.º 2
0
 public void FillStruct(string strValue, ref DLT698Message.FrameInfo gFrame)
 {
     checked
     {
         try
         {
             gFrame.ReSet();
             gFrame.L1 = GetDataLen(strValue.Substring(2, 4)).ToString();
             GetControlField(strValue.Substring(12, 2), ref gFrame.DIR, ref gFrame.PRM, ref gFrame.FCB, ref gFrame.FCV, ref gFrame.CID);
             GetAddressField(strValue.Substring(14, 10), ref gFrame.A1, ref gFrame.A2, ref gFrame.MSA, ref gFrame.ArrFlag);
             gFrame.AFN = strValue.Substring(24, 2);
             this.GetSEQ(strValue.Substring(26, 2), ref gFrame.TpV, ref gFrame.FIR, ref gFrame.FIN, ref gFrame.CON, ref gFrame.PSEQ);
             if (gFrame.PRM == "0" & gFrame.CID == "9")
             {
                 gFrame.Data = "否认:无所召唤的数据";
             }
             else
             {
                 this.GetDataCellMark(strValue.Substring(28, 8), ref gFrame.FN, ref gFrame.PN);
                 string text = strValue.Substring(36, strValue.Length - 40);
                 if (gFrame.DIR == "0")
                 {
                     if (gFrame.TpV == "1")
                     {
                         GetTimeFlag(text.Substring(text.Length - 12, 12), ref gFrame.PFC, ref gFrame.Time, ref gFrame.Delay);
                         text = text.Substring(0, text.Length - 12);
                     }
                     if (gFrame.AFN == "01" || gFrame.AFN == "04" || gFrame.AFN == "05" || gFrame.AFN == "06" || gFrame.AFN == "0F" || gFrame.AFN == "10")
                     {
                         gFrame.PW = text.Substring(text.Length - 32, 32);
                         text      = text.Substring(0, text.Length - 32);
                     }
                     gFrame.Data = text;
                 }
                 else
                 {
                     if (gFrame.TpV == "1")
                     {
                         GetTimeFlag(text.Substring(text.Length - 12, 12), ref gFrame.PFC, ref gFrame.Time, ref gFrame.Delay);
                         text = text.Substring(0, text.Length - 12);
                     }
                     if (gFrame.FCB == "1")
                     {
                         gFrame.EC1 = text.Substring(text.Length - 2, 2);
                         gFrame.EC2 = text.Substring(text.Length - 4, 2);
                         text       = text.Substring(0, text.Length - 4);
                     }
                     gFrame.Data = text;
                 }
             }
             gFrame.CS        = strValue.Substring(strValue.Length - 4, 2);
             gFrame.FrameByte = strValue;
         }
         catch
         {
         }
     }
 }
Ejemplo n.º 3
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
            {
            }
        }
Ejemplo n.º 4
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
     {
     }
 }
Ejemplo n.º 5
0
 public void AddFrame(bool isend, DLT698Message.FrameInfo gFrame)
 {
     gFrame.IsSend = isend;
     this._framelists.Add(gFrame);
 }
Ejemplo n.º 6
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;
 }