示例#1
0
        // This method runs 20 times per second (every 50ms). This is set on the timerMain properties.
        private void timerMain_Tick(object sender, EventArgs e)
        {
            // Call process() to read/write data to/from FSUIPC
            // We do this in a Try/Catch block incase something goes wrong
            try
            {
                FSUIPCConnection.Process();
                FSUIPCConnection.Process("LatLonPoint");
                if (this.onGround.Value == 0)
                {
                    this.tookOf = true;
                }

                if (this.onGround.Value == 1 && this.tookOf == true)
                {
                    double verticalSpeedMPS = (double)this.verticalSpeed.Value / 256d;
                    double verticalSpeedFPM = verticalSpeedMPS * 60d * 3.28084d;
                    this.landingRate = verticalSpeedFPM;
                    this.tookOf      = false;
                }

                // Update the information on the form
                // (See the Examples Application for more information on using Offsets).



                FsLatLonPoint playerPos = new FsLatLonPoint(this.playerLat.Value, this.playerLon.Value);
                this.txtAircraft.Text = this.model.Value;

                PayloadServices ps = FSUIPCConnection.PayloadServices;
                ps.RefreshData();
                this.currentFuel = ps.FuelWeightKgs;

                // this.txtPlayerLocation.Text = this.playerLat.Value.DecimalDegrees.ToString();
            }
            catch (Exception ex)
            {
                // An error occured. Tell the user and stop this timer.
                this.timerMain.Stop();
                MessageBox.Show("Communication with FSUIPC Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // Update the connection status
                configureForm();
            }
        }
示例#2
0
        public void BroadcastPosition()
        {
            udp.Connect("192.168.1.103", 49002);
            string basePacket = "XGPSSimulator,";

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;

                while (true)
                {
                    playerPos = FSUIPCConnection.GetPositionSnapshot();
                    //Populate positional variables
                    alt = (Decimal)playerPos.Altitude.Feet;
                    FsLatLonPoint location = playerPos.Location;
                    lat = (Decimal)location.Latitude.DecimalDegrees;
                    lon = (Decimal)location.Longitude.DecimalDegrees;
                    hdg = (Decimal)playerPos.HeadingDegreesTrue;
                    FSUIPCConnection.Process();
                    groundSpeed.Reconnect();
                    spd = groundSpeed.GetValue <UInt32>();
                    spd = spd / 65536;
                    spd = spd * 3600;
                    spd = spd / 1852;


                    alt = Decimal.Round(alt, 1);
                    lat = Decimal.Round(lat, 3);
                    lon = Decimal.Round(lon, 3);
                    hdg = Decimal.Round(hdg, 2);

                    //Assemble a packet
                    string packetToSend = basePacket + lon.ToString() + "," + lat.ToString() + "," + alt.ToString() + "," + hdg.ToString() + "," + spd.ToString() + ".0";
                    byte[] sendMe       = Encoding.ASCII.GetBytes(packetToSend);

                    //Broadcast via UDP

                    udp.Send(sendMe, sendMe.Length);

                    //Pause the thread to allow for the one second gap required by foreflight.
                    Thread.Sleep(990); //Only 990 to allow for processing time.
                }
            }).Start();
        }