예제 #1
0
        private void DealWithLastMPDU()
        {
            UpdateDataGrid UpdateDG = new UpdateDataGrid(UpdataDataGrid1);

            if (TempMPDU.MPDU1_Used)
            {
                TempMPDU.MPDU1_Used = false;
                int    len           = 1002 - TempMPDU.Pointer1Value;
                byte[] Deal_LastMPDU = new byte[len];
                Array.Copy(TempMPDU.MPDU_Body1, TempMPDU.Pointer1Value, Deal_LastMPDU, 0, len);

                while (len > 6)
                {
                    EPDU_Struct myEPDU = new EPDU_Struct();

                    Array.Copy(Deal_LastMPDU, 0, myEPDU.EPDU_Head, 0, 6);
                    Array.Copy(Deal_LastMPDU, 6, Deal_LastMPDU, 0, len - 6);
                    len -= 6;
                    myEPDU.DealEPDUHead();
                    if (myEPDU.Count > 249)
                    {
                        WrongEPDU += 1;
                        Trace.WriteLine(myEPDU.EPDU_Head[0]);
                        Trace.WriteLine(myEPDU.EPDU_Head[1]);
                        Trace.WriteLine(myEPDU.EPDU_Head[2]);
                        Trace.WriteLine(myEPDU.EPDU_Head[3]);
                        Trace.WriteLine(myEPDU.EPDU_Head[4]);
                        Trace.WriteLine(myEPDU.EPDU_Head[5]);
                        Trace.WriteLine("EPDU包长大于249,出错跳出");
                        break;
                    }

                    if (len > myEPDU.Count + 1)
                    {
                        Array.Copy(Deal_LastMPDU, 0, myEPDU.EPDU_Body, 0, myEPDU.Count + 1);
                        Array.Copy(Deal_LastMPDU, myEPDU.Count + 1, Deal_LastMPDU, 0, len - myEPDU.Count - 1);
                        len -= (myEPDU.Count + 1);

                        //将一个EPDU显示出来
                        //   dataGridView1.Invoke(UpdateDG, myEPDU);
                        switch (channel)
                        {
                        case 1:
                            dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList, Data.Apid_EPDU_Dictionary, Data.myDictionary1);
                            break;

                        case 2:
                            dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList2, Data.Apid_EPDU_Dictionary2, Data.myDictionary2);
                            break;

                        case 0:
                            dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList3, Data.Apid_EPDU_Dictionary3, Data.myDictionary3);
                            break;

                        default:
                            dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList, Data.Apid_EPDU_Dictionary, Data.myDictionary1);
                            break;
                        }
                    }
                    else
                    {
                        Trace.WriteLine("有帧头,但长度不足myEpdu.Count+1");
                    }
                }
            }
        }
예제 #2
0
        private void DealWith_Temp_MPDUS(byte[] Deal_TwoMPDU)
        {
            UpdateDataGrid UpdateDG = new UpdateDataGrid(UpdataDataGrid1);
            int            len      = Deal_TwoMPDU.Length;

            while (len > 6)
            {
                //       Trace.WriteLine("Deal_TwoMPUD中的数据长度是:" + len.ToString());

                EPDU_Struct myEPDU = new EPDU_Struct();

                Array.Copy(Deal_TwoMPDU, 0, myEPDU.EPDU_Head, 0, 6);
                Array.Copy(Deal_TwoMPDU, 6, Deal_TwoMPDU, 0, len - 6);
                len -= 6;
                myEPDU.DealEPDUHead();
                if (myEPDU.Count > 249)
                {
                    //           Trace.WriteLine(myEPDU.APID);
                    if (myEPDU.APID == "11111111111")
                    {
                        //               Trace.WriteLine("收到超过249的空闲EPDU包!");
                    }
                    else
                    {
                        WrongEPDU += 1;
                        //                Trace.WriteLine("EPDU包长大于249,出错跳出");
                        break;
                    }
                }

                if (len >= myEPDU.Count + 1)
                {
                    Array.Copy(Deal_TwoMPDU, 0, myEPDU.EPDU_Body, 0, myEPDU.Count + 1);
                    Array.Copy(Deal_TwoMPDU, myEPDU.Count + 1, Deal_TwoMPDU, 0, len - myEPDU.Count - 1);
                    len -= (myEPDU.Count + 1);

                    //将一个EPDU显示出来
                    switch (channel)
                    {
                    case 1:
                        dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList, Data.Apid_EPDU_Dictionary, Data.myDictionary1);
                        break;

                    case 2:
                        dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList2, Data.Apid_EPDU_Dictionary2, Data.myDictionary2);
                        break;

                    case 0:
                        dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList3, Data.Apid_EPDU_Dictionary3, Data.myDictionary3);
                        break;

                    default:
                        dataGridView1.Invoke(UpdateDG, myEPDU, Data.APIDList, Data.Apid_EPDU_Dictionary, Data.myDictionary1);
                        break;
                    }
                }
                else
                {
                    //         Trace.WriteLine("有帧头,但长度不足myEpdu.Count+1");
                }
            }
            //   Trace.WriteLine("剩余长度不足6Byte");
        }
예제 #3
0
        private void DealWithEpduQueue(string apid, int chan)
        {
            Trace.WriteLine("DealWithEpudQueue +" + apid + "-" + chan.ToString());
            List <string> APIDList;
            List <string> AlreadyOnApid;
            Dictionary <string, Queue <byte[]> > Apid_EPDU_Dictionary;

            switch (chan)
            {
            case 1:
                APIDList             = Data.APIDList;
                AlreadyOnApid        = Data.AlreadyOnApid;
                Apid_EPDU_Dictionary = Data.Apid_EPDU_Dictionary;
                break;

            case 2:
                APIDList             = Data.APIDList2;
                AlreadyOnApid        = Data.AlreadyOnApid2;
                Apid_EPDU_Dictionary = Data.Apid_EPDU_Dictionary2;
                break;

            case 0:
                APIDList             = Data.APIDList3;
                AlreadyOnApid        = Data.AlreadyOnApid3;
                Apid_EPDU_Dictionary = Data.Apid_EPDU_Dictionary3;
                break;

            default:
                APIDList             = Data.APIDList;
                AlreadyOnApid        = Data.AlreadyOnApid;
                Apid_EPDU_Dictionary = Data.Apid_EPDU_Dictionary;
                break;
            }

            while (ThreadOn)
            {
                if (APIDList.IndexOf(apid) >= 0)
                {
                    if (Apid_EPDU_Dictionary[apid].Count() > 0)
                    {
                        EPDU_Struct myEPDU = new EPDU_Struct();

                        byte[] tempEPDU = Apid_EPDU_Dictionary[apid].Dequeue();

                        Trace.WriteLine(tempEPDU.Count());
                        Array.Copy(tempEPDU, 0, myEPDU.EPDU_Head, 0, 6);
                        myEPDU.DealEPDUHead();
                        Array.Copy(tempEPDU, 6, myEPDU.EPDU_Body, 0, tempEPDU.Count() - 6);

                        dataGridView1.Rows[0].Cells[0].Value = myEPDU.Version;
                        dataGridView1.Rows[0].Cells[1].Value = myEPDU.Type;
                        dataGridView1.Rows[0].Cells[2].Value = myEPDU.FuDT;
                        dataGridView1.Rows[0].Cells[3].Value = myEPDU.APID;
                        dataGridView1.Rows[0].Cells[4].Value = myEPDU.DivdTag;
                        dataGridView1.Rows[0].Cells[5].Value = Convert.ToInt32(myEPDU.BagCount, 2);
                        dataGridView1.Rows[0].Cells[6].Value = myEPDU.CountStr;

                        string str = "";
                        for (int i = 0; i < myEPDU.Count; i++)
                        {
                            str += myEPDU.EPDU_Body[i].ToString("x2");
                        }
                        textBox1.AppendText(str + "\n");
                        if (textBox1.Lines.Count() > 20)
                        {
                            textBox1.Clear();
                        }
                    }
                }
                else
                {
                    Thread.Sleep(500);
                    Trace.WriteLine("111");
                }
            }
        }