예제 #1
0
        public static PETSingleEventsPacket[] PackEventsToList(PETSingleEvent[] events, int EventsPerPacket)
        {
            var res = new List <PETSingleEventsPacket>();

            int num = events.Length;
            int i   = 0;

            while (i < num)
            {
                // сколько совпадений в этом пакете (не более EventsPerPacket, но в конце меньше)
                int cnt = Math.Min(num - i, EventsPerPacket);

                // начинаем новый пакет
                var p = new PETSingleEventsPacket();
                p.ItemCount = (byte)cnt;
                p.Flags     = 0;

                p.Events = new PETSingleEvent[cnt];

                for (int j = 0; j < cnt; j++)
                {
                    p.Events[j] = events[i + j];
                }

                i += EventsPerPacket;

                res.Add(p);
            }

            return(res.ToArray());
        }
예제 #2
0
        public static PETSingleEventsPacket[] CreateRandomPackets(int NumPackets)
        {
            var res = new PETSingleEventsPacket[NumPackets];

            var rnd = new System.Random();

            // Generate random single events and pack the to packets
            for (int i = 0; i < NumPackets; i++)
            {
                res[i] = PETSingleEventsPacket.RandomPacket(rnd);
            }

            return(res);
        }
예제 #3
0
        public bool CompareTo(PETSingleEventsPacket p)
        {
            if ((p.ItemCount != ItemCount) || (p.Flags != Flags))
            {
                return(false);
            }

            for (int i = 0; i < ItemCount; i++)
            {
                if (!this.Events[i].CompareTo(p.Events[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #4
0
        //		static int ItemSize = PETSingleEvent.Size; // Marshal.SizeOf(typeof(PETSingleEvent));

        public static PETSingleEventsPacket RandomPacket(System.Random rnd = null)
        {
            var res = new PETSingleEventsPacket();

            var r = (rnd == null) ? new System.Random() : rnd;

            res.Flags     = (byte)r.Next();
            res.ItemCount = (byte)r.Next(1, 10);

            res.Events = new PETSingleEvent[res.ItemCount];

            for (int i = 0; i < res.ItemCount; i++)
            {
                res.Events[i] = PETSingleEvent.RandomEvent(rnd);
            }

            return(res);
        }
예제 #5
0
        // один пакет с одним ивентом на детекторе 1
        public static PETSingleEventsPacket[] CreateUnitEventPacket()
        {
            var evt = new PETSingleEvent();

            evt.Flags     = 1;
            evt.Position  = 2;
            evt.XMinus    = 3;
            evt.XPlus     = 4;
            evt.YMinus    = 5;
            evt.YPlus     = 6;
            evt.Timestamp = 255;

            var packet = new PETSingleEventsPacket();

            packet.Flags     = 63;
            packet.ItemCount = 1;
            packet.Events    = new PETSingleEvent[1];
            packet.Events[0] = evt;

            return(new PETSingleEventsPacket[] { packet });
        }
예제 #6
0
        /// <summary>
        /// Decode byte[] array to a list of SingleEvent[]
        /// </summary>
        public static PETSingleEventsPacket[] DecodeArray(int NumPackets, int Offset, byte[] Src, bool UseSizeInfo = false)
        {
            int Ofs = 0;

            var res = new PETSingleEventsPacket[NumPackets];

            for (int i = 0; i < NumPackets; i++)
            {
                if (UseSizeInfo)
                {
                    // skip two bytes
                    Ofs += 2;
                }

                var pack = new PETSingleEventsPacket();
                pack.FromBytes(Offset + Ofs, Src);

                res[i] = pack;

                Ofs += pack.GetSize();
            }

            return(res);
        }