Example #1
0
        void ReadTelemetry()
        {
            UdpClient socket = new UdpClient();

            socket.ExclusiveAddressUse = false;
            socket.Client.Bind(new IPEndPoint(IPAddress.Any, readPort));

            Stopwatch sw = new Stopwatch();

            sw.Start();

            StartSending();

            while (!IsStopped)
            {
                try
                {
                    //wait for telemetry
                    if (socket.Available == 0)
                    {
                        if (sw.ElapsedMilliseconds > 500)
                        {
                            Thread.Sleep(1000);
                        }
                        continue;
                    }

                    Byte[] received = socket.Receive(ref senderIP);

                    var alloc = GCHandle.Alloc(received, GCHandleType.Pinned);
                    telemetryData = (IL2API)Marshal.PtrToStructure(alloc.AddrOfPinnedObject(), typeof(IL2API));
                    alloc.Free();

                    if (socket.Available != 0)
                    {
                        continue;
                    }

                    if (telemetryData.packetID == 0x494C0100)
                    {
                        dt = (float)sw.Elapsed.TotalSeconds;
                        sw.Restart();
                        ProcessIL2API(dt);
                    }
                }
                catch (Exception e)
                {
                    Thread.Sleep(1000);
                }
            }

            StopSending();
            socket.Close();

            Thread.CurrentThread.Join();
        }
Example #2
0
        public byte[] ToByteArray()
        {
            IL2API packet = this;
            int    num    = Marshal.SizeOf <IL2API>(packet);

            byte[] array  = new byte[num];
            IntPtr intPtr = Marshal.AllocHGlobal(num);

            Marshal.StructureToPtr <IL2API>(packet, intPtr, false);
            Marshal.Copy(intPtr, array, 0, num);
            Marshal.FreeHGlobal(intPtr);
            return(array);
        }
Example #3
0
 public void CopyFields(IL2API other)
 {
     packetID = other.packetID;
     tick     = other.tick;
     yaw      = other.yaw;
     pitch    = other.pitch;
     roll     = other.roll;
     spinX    = other.spinX;
     spinY    = other.spinY;
     spinZ    = other.spinZ;
     accX     = other.accX;
     accY     = other.accY;
     accZ     = other.accZ;
 }