Beispiel #1
0
        private void WxUpdate_Elapsed(object sender, ElapsedEventArgs e)
        {
            //Called every time the timer interval elapses.
            //Update weather info
            if (_TcpConnected)
            {
                //If we are connected to the player location server, go ahead and get the first wx request
                string[] response = WxManager.GetMetar(PlayerData.playerLat, PlayerData.playerLng, 20); //Get the closest metar within a 20 nm radius
                                                                                                        //Convert from inHg to QNH
                                                                                                        //Update player location display


                if (label2.InvokeRequired)
                {
                    label2.Invoke(new Action(() => label2.Text = PlayerData.playerLat.ToString()));
                }
                else
                {
                    label2.Text = PlayerData.playerLat.ToString();
                }

                if (label3.InvokeRequired)
                {
                    label3.Invoke(new Action(() => label3.Text = PlayerData.playerLng.ToString()));
                }
                else
                {
                    label3.Text = PlayerData.playerLng.ToString();
                }

                if (response[0] != null)
                {
                    double pressure = Convert.ToDouble(response[5]) * 33.864;


                    //Update the screen
                    //Combine the wind speed
                    string winddir = response[3];
                    string windspd = response[4];
                    if (label28.InvokeRequired)
                    {
                        label28.Invoke(new Action(() => label28.Text = winddir + "/" + windspd));
                    }
                    else
                    {
                        label28.Text = winddir + "/" + windspd;
                    }

                    if (label26.InvokeRequired)
                    {
                        label26.Invoke(new Action(() => label26.Text = pressure.ToString()));
                    }
                    else
                    {
                        label26.Text = pressure.ToString();
                    }

                    if (label24.InvokeRequired)
                    {
                        label24.Invoke(new Action(() => label24.Text = response[0]));
                    }
                    else
                    {
                        label24.Text = response[0];
                    }

                    //Now that we have updated the screen, we need to send the pressure over UDP
                    //First, convert double to whole int- then to string.
                    int QNH = Convert.ToInt32(pressure);

                    string almost = QNH.ToString();

                    string final = "Q" + almost; //So it will come out as 'Q1013' instead of just '1013'- this is required by the server software.


                    //Then, make it a byte[] that can be sent via UDP

                    byte[] toSend = Encoding.ASCII.GetBytes(final);

                    UdpClient udpSender = new UdpClient();

                    //Connect to the server
                    udpSender.Connect(IPAddress.Loopback, 49004);

                    //Send it!
                    //Per the spec, the QNH only needs to be sent every 8 or 9 seconds, but I don't want to DDOS the
                    //federal government's weather servers, so there isn't really much I can do here.
                    //Okay... they don't explicitly say not to do that, so I don't see much harm in requesting 1 station.
                    //I'll change the per minute section to be per second.
                    udpSender.Send(toSend, toSend.Length);

                    if (_ADSBConnected)
                    {
                        //I'm piggybacking off the wx timer because I'm too lazy to make another one.
                        //TODO: make a timer exclusively for ADS-B Data.
                        UpdateAircraft(AirTraffic.Get(PlayerData.playerLat, PlayerData.playerLng, _trackRad));
                    }
                }
            }
            //Otherwise do nothing
        } //Called every time the timer elapses
Beispiel #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     _planeList = AirTraffic.Get(PlayerData.playerLat, PlayerData.playerLng, _trackRad);
     UpdateAircraft(_planeList);
 }