// один пакет с одним совпадением на детекторах 1 и 2, всё остальное по нулям public static PETCoincidencePacket[] CreateUnitCoincidencePacket() { var coinc = new PETCoincidence(); coinc.Position1 = 1; coinc.Position2 = 2; coinc.Flags = 13; coinc.XPlus1 = 5; coinc.XMinus1 = 6; coinc.YPlus1 = 7; coinc.YMinus1 = 8; coinc.XPlus2 = 9; coinc.XMinus2 = 10; coinc.YPlus2 = 11; coinc.YMinus2 = 12; coinc.Timestamp = 255; var packet = new PETCoincidencePacket(); packet.Flags = 63; packet.ItemCount = 1; packet.Coincidences = new PETCoincidence[1]; packet.Coincidences[0] = coinc; return(new PETCoincidencePacket[] { packet }); }
public static PETCoincidencePacket[] PackCoincidencesToList(PETCoincidence[] coincidences, int CoincPerPacket) { var res = new List <PETCoincidencePacket>(); int num = coincidences.Length; int i = 0; while (i < num) { // сколько совпадений в этом пакете (не более CoincPerPacket, но в конце меньше) int cnt = Math.Min(num - i, CoincPerPacket); // начинаем новый пакет var p = new PETCoincidencePacket(); p.ItemCount = (byte)cnt; p.Flags = 0; p.Coincidences = new PETCoincidence[cnt]; for (int j = 0; j < cnt; j++) { p.Coincidences[j] = coincidences[i + j]; } i += CoincPerPacket; res.Add(p); } return(res.ToArray()); }
public static PETCoincidencePacket[] CreateRandomCoincidencePackets(int NumPackets) { var res = new PETCoincidencePacket[NumPackets]; var rnd = new System.Random(); // Generate random coincidences and pack the to packets for (int i = 0; i < NumPackets; i++) { res[i] = PETCoincidencePacket.RandomPacket(rnd); } return(res); }
public bool CompareTo(PETCoincidencePacket p) { if ((p.ItemCount != ItemCount) || (p.Flags != Flags)) { return(false); } for (int i = 0; i < ItemCount; i++) { if (!this.Coincidences[i].CompareTo(p.Coincidences[i])) { return(false); } } return(true); }
//static int ItemSize = PETCoincidence.Size; //Marshal.SizeOf(typeof(PETCoincidence)); public static PETCoincidencePacket RandomPacket(System.Random rnd = null) { var res = new PETCoincidencePacket(); var r = (rnd == null) ? new System.Random() : rnd; res.Flags = (byte)r.Next(); res.ItemCount = (byte)r.Next(1, 10); res.Coincidences = new PETCoincidence[res.ItemCount]; for (int i = 0; i < res.ItemCount; i++) { res.Coincidences[i] = PETCoincidence.RandomCoincidence(rnd); } return(res); }
/// <summary> /// Decode byte[] array to a list of Coincidence[] /// </summary> public static PETCoincidencePacket[] DecodeArray(int NumPackets, int Offset, byte[] Src, bool UseSizeInfo = false) { int Ofs = 0; var res = new PETCoincidencePacket[NumPackets]; for (int i = 0; i < NumPackets; i++) { if (UseSizeInfo) { // skip two bytes Ofs += 2; } var pack = new PETCoincidencePacket(); pack.FromBytes(Offset + Ofs, Src); res[i] = pack; Ofs += pack.GetSize(); } return(res); }