Beispiel #1
0
        public static List <EnvelopeData> UnpackInt(byte[] dat, int len, byte[] buffer, ref int remain)
        {
            List <EnvelopeData> list = new List <EnvelopeData>();
            int s = remain;

            for (int i = 0; i < len; i++)
            {
                buffer[s] = dat[i];
                s++;
            }
            len += remain;
            s    = 0;
            int e = 0;

            for (int i = 0; i < len; i++)
            {
                var b = buffer[i];
                if (b == 255)
                {
                    if (i + 3 < buffer.Length)
                    {
                        if (buffer[i + 1] == 255)
                        {
                            if (buffer[i + 2] == 255)
                            {
                                b = buffer[i + 3];
                                if (b == 255)
                                {
                                    s = i + 5;
                                }
                                else if (b == 254)
                                {
                                    e = i;
                                    EnvelopeData data = new EnvelopeData();
                                    data.data = UnpackInt(buffer, s, e);
                                    data.type = buffer[s - 1];
                                    list.Add(data);
                                }
                            }
                        }
                    }
                }
            }
            if (e != 0)
            {
                remain = len - e - 4;
                for (int i = 0; i < remain; i++)
                {
                    buffer[i] = buffer[e];
                    e++;
                }
            }
            return(list);
        }
 protected List <EnvelopeData> OrganizeSubVolume(List <EnvelopePart> list, int fs)
 {
     if (list != null)
     {
         List <EnvelopeData> datas = new List <EnvelopeData>();
         for (int j = 0; j < list.Count; j++)
         {
             var item = list[j];
             int ap   = item.head.AllPart;
             if (ap > 1)
             {
                 int s = -1;
                 for (int i = 0; i < 128; i++)
                 {
                     if (s < 0)
                     {
                         if (pool[i].head.MsgID == 0)
                         {
                             s = i;
                         }
                     }
                     if (item.head.MsgID == pool[i].head.MsgID)
                     {
                         if (Envelope.SetChecked(pool[i].checks, item.head.CurPart))
                         {
                             Envelope.CopyToBuff(pool[i].buff, item.data, 0, item.head, fs);
                             pool[i].part++;
                             pool[i].rcvLen += item.head.PartLen;
                             if (pool[i].rcvLen >= item.head.Lenth)
                             {
                                 EnvelopeData data = new EnvelopeData();
                                 data.data          = pool[i].buff;
                                 data.type          = (byte)(pool[i].head.Type);
                                 pool[i].head.MsgID = 0;
                                 datas.Add(data);
                             }
                         }
                         goto label;
                     }
                 }
                 pool[s].head   = item.head;
                 pool[s].part   = 1;
                 pool[s].rcvLen = item.head.PartLen;
                 pool[s].buff   = new byte[item.head.Lenth];
                 pool[s].time   = DateTime.Now.Ticks;
                 Envelope.CopyToBuff(pool[s].buff, item.data, 0, item.head, fs);
                 int c = ap / 32 + 1;
                 pool[s].checks = new Int32[c];
             }
             else
             {
                 EnvelopeData data = new EnvelopeData();
                 data.data = item.data;
                 data.type = (byte)(item.head.Type);
                 datas.Add(data);
             }
             label :;
         }
         return(datas);
     }
     return(null);
 }
 protected void OrganizeSubVolume(List <EnvelopePart> list, int fs)
 {
     if (list != null)
     {
         for (int j = 0; j < list.Count; j++)
         {
             var item = list[j];
             int ap   = item.head.AllPart;
             if (ap > 1)
             {
                 for (int i = 0; i < 128; i++)
                 {
                     if (item.head.MsgID == pool[i].head.MsgID)
                     {
                         if (pool[i].buff == null)
                         {
                             goto label;
                         }
                         if (Envelope.SetChecked(pool[i].checks, item.head.CurPart))
                         {
                             Envelope.CopyToBuff(pool[i].buff, item.data, 0, item.head, fs);
                             pool[i].part++;
                             pool[i].rcvLen += item.head.PartLen;
                             if (pool[i].rcvLen >= item.head.Lenth)
                             {
                                 EnvelopeData data = new EnvelopeData();
                                 data.data    = pool[i].buff;
                                 data.type    = (byte)(pool[i].head.Type);
                                 pool[i].buff = null;
                                 //pool[i].checks = null;
                                 QueueBuf.Enqueue(data);
                                 pool[i].done = true;
                             }
                         }
                         goto label;
                     }
                 }
                 int s = point;
                 for (int i = 0; i < 128; i++)
                 {
                     if (pool[s].head.MsgID == 0 | pool[s].done)
                     {
                         point = s; break;
                     }
                     s++;
                     if (s >= 128)
                     {
                         s = 0;
                     }
                 }
                 pool[s].head   = item.head;
                 pool[s].part   = 1;
                 pool[s].rcvLen = item.head.PartLen;
                 pool[s].buff   = new byte[item.head.Lenth];
                 pool[s].time   = DateTime.Now.Ticks;
                 Envelope.CopyToBuff(pool[s].buff, item.data, 0, item.head, fs);
                 int c = ap / 32 + 1;
                 pool[s].checks = new Int32[c];
                 Envelope.SetChecked(pool[s].checks, item.head.CurPart);
             }
             else
             {
                 EnvelopeData data = new EnvelopeData();
                 data.data = item.data;
                 data.type = (byte)(item.head.Type);
                 QueueBuf.Enqueue(data);
             }
             label :;
         }
     }
 }