Exemplo n.º 1
0
        protected bool RunSingleScript(string name, int flag)
        {
            try
            {
                Offset param = null;
                if (flag != -1)
                {
                    param = new Offset(0x0D6C, 4);
                    param.SetValue(flag);
                    FSUIPCConnection.Process();
                }

                Offset request = new Offset(0x0D70, 128);
                request.SetValue(name);

                FSUIPCConnection.Process();
                request.Disconnect();
                request = null;
                if (flag != -1)
                {
                    param.Disconnect();
                    param = null;
                }
            }
            catch
            {
                Log.Logger.Error($"IPCManager: Exception while Executing Script: {name}");
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
 private static void OnTimedEvent(Object source, ElapsedEventArgs e)
 {
     if (!isConnectedtoFSUIPC)
     {
         try
         {
             Console.Write(".");
             FSUIPCConnection.Open();
             isConnectedtoFSUIPC = true;
         } catch (Exception ex)
         {
             isConnectedtoFSUIPC = false;
         }
     }
     else
     {
         try
         {
             FSUIPCConnection.Process();
         } catch (Exception ex)
         {
             Errormessage.sendErrorMessage("FSUIPC Process", ex.Message);
             FSUIPCConnection.Close();
             isConnectedtoFSUIPC = false;
         }
     }
 }
Exemplo n.º 3
0
        public bool Process(string group)
        {
            try
            {
                foreach (var address in persistentValues)
                {
                    currentValues[address].Connect();
                }

                FSUIPCConnection.Process(group); //should update all offsets in currentOffsets (type OFFSETx and SCRIPT)
                if (!IsReady)
                {
                    return(false);
                }

                foreach (var value in currentValues.Values) //read Lvars
                {
                    value.Process();
                }

                return(true);
            }
            catch
            {
                Log.Logger.Error("IPCManager: Exception while process call to FSUIPC");
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fs"></param>
        public bool StartFlight()
        {
            try
            {
                PirepID = FlightDatabase.StartFlight(this);
                Telemetry.SetValue(FSUIPCOffsets.engine1, false);
                Telemetry.SetValue(FSUIPCOffsets.engine2, false);
                Telemetry.SetValue(FSUIPCOffsets.engine3, false);
                Telemetry.SetValue(FSUIPCOffsets.engine4, false);
                Telemetry.SetValue(FSUIPCOffsets.parkingBrake, true);

                Telemetry.SetValue(FSUIPCOffsets.environmentDateTimeHour, DateTime.UtcNow.Hour);
                Telemetry.SetValue(FSUIPCOffsets.environmentDateTimeMinute, DateTime.UtcNow.Minute);
                Telemetry.SetValue(FSUIPCOffsets.environmentDateTimeDayOfYear, DateTime.UtcNow.DayOfYear);
                Telemetry.SetValue(FSUIPCOffsets.environmentDateTimeYear, DateTime.UtcNow.Year);

                string Message = "Welcome to FlyAtlantic Acars";
                FSUIPCOffsets.messageWrite.Value    = Message;
                FSUIPCOffsets.messageDuration.Value = 10;
                FSUIPCConnection.Process();

                phase         = FlightPhases.PREFLIGHT;
                FlightRunning = true;
            }
            catch (Exception crap)
            {
                throw new Exception("Failed to start flight.", crap);
            }

            // TODO: do all stuff via telemetry to force desired values


            return(FlightRunning);
        }
        static void Main(string[] args)
        {
            FSUIPCConnection.Open();

            Offset <long> playerLatitude = new Offset <long>(0x0560);

            Offset <long> playerLongitude = new Offset <long>(0x0568);

            Offset <int> autoThrottle = new Offset <int>(0x0810);

            Offset <int> flightDirector = new Offset <int>(0x2EE0);

            while (true)
            {
                FSUIPCConnection.Process();
                FsLongitude lon = new FsLongitude(playerLongitude.Value);
                FsLatitude  lat = new FsLatitude(playerLatitude.Value);

                var atSwitch = autoThrottle.Value;

                var fdSwitch = flightDirector.Value;

                Thread.Sleep(5000);
            }
        }
Exemplo n.º 6
0
 private void UpdateFsuipc()
 {
     if (_fsuipcConnected)
     {
         FSUIPCConnection.Process();
     }
 }
Exemplo n.º 7
0
        public static FSUIPCGets GetCurrent()
        {
            FSUIPCGets result = new FSUIPCGets();

            // snapshot data
            try
            {
                FSUIPCConnection.Process();
            }
            catch (Exception crap)
            {
                // failed to connect to the sim?
                return(null);
            }

            // capture values
            result.Latitude         = FSUIPCOffsets.latitude.Value * (90.0 / (10001750.0 * 65536.0 * 65536.0));
            result.Longitude        = FSUIPCOffsets.longitude.Value * (360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0));
            result.Compass          = FSUIPCOffsets.compass.Value;
            result.GroundSpeed      = (FSUIPCOffsets.groundspeed.Value / 65536) * 1.94384449;
            result.Altitude         = (FSUIPCOffsets.altitude.Value * 3.2808399);
            result.AiTfraffic       = FSUIPCOffsets.AiTfraffic.Value;
            result.AiTfrafficInsert = FSUIPCOffsets.AiTfrafficInsert.Value;

            return(result);
        }
Exemplo n.º 8
0
        // This method runs 20 times per second (every 50ms). This is set in the form constructor above.
        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();

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

                Data data = parseData();

                this.txtAirspeed.Text    = data.parsedAirspeed.ToString();
                this.txtGroundspeed.Text = data.parsedGS.ToString("F0");
                this.txtVertspeed.Text   = data.parsedVertSpd.ToString("F0");
                this.txtHeading.Text     = data.parsedHDG.ToString("F0");
                this.txtSimNum.Text      = simStupidNumber.Value.ToString();
                this.txtOnGround.Text    = data.parsedGround.ToString();
            }
            catch (Exception ex)
            {
                // An error occured. Tell the user and stop this timer.
                this.timerMain.Stop();
                System.Windows.MessageBox.Show("Flight Simulator closed! Error:" + ex.Message, "FSUIPC", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                if (Properties.Settings.Default.CloseWithSim)
                {
                    System.Windows.Application.Current.Shutdown();
                }
                // Update the connection status
                configureForm();
            }
        }
Exemplo n.º 9
0
        // This method runs 10 times per second (every 100ms). 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();
                inst.ReadAircraftState();
                // Update the information on the form
                // (See the Examples Application for more information on using Offsets).

                // 1. Airspeed
                double airspeedKnots = (double)Aircraft.AirspeedTrue.Value / 128d;
                this.txtAirspeed.Text = airspeedKnots.ToString("F0");

                // 2. Master Avionics
                this.chkAvionicsMaster.Checked = Aircraft.AvionicsMaster.Value > 0;
            }
            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();
                // start the connection timer
                this.timerConnection.Start();
            }
        }
        // This method runs 10 times per second (every 100ms). 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();
                inst.MonitorN1Limit();
                if (Aircraft.AircraftName.Value.Contains("PMDG"))
                {
                    Aircraft.pmdg737.RefreshData();
                    Aircraft.pmdg747.RefreshData();
                }
                inst.ReadAircraftState();
                if (!inst.PostTakeOffChecklist())
                {
                    inst.PostTakeOffChecklist();
                }
            }


            catch (Exception ex)
            {
                // An error occured. Tell the user and stop this timer.
                this.timerMain.Stop();
                logger.Debug($"High priority instruments failed to read: {ex.Message}");
                // Update the connection status
                // start the connection timer
                this.timerConnection.Start();
            }
        }
Exemplo n.º 11
0
        private void RUNTIMERTick(Object myObject, EventArgs myEventArgs)
        {
            try
            {
                FSUIPCConnection.Process();

                double airpeedKnots     = (double)airspeed.Value / 128d;
                double groundspeedKnots = (double)groundspeed.Value / 128d;
                double vspeedFT         = (double)vspeed.Value * 60 * 3.28084 / 256;
                this.airspeedLabel.Text = "airspeed: " + airpeedKnots.ToString("f1");
                this.vspeedLabel.Text   = "vspeed: " + vspeedFT;
                this.onGroundLabel.Text = "onGround: " + ((onground.Value == 1) ? "YES" : "NO");
                this.parkingLabel.Text  = "parkingBrake: " + ((parkingBrake.Value == 32767) ? "ON" : "OFF");

                if (!trackingFinished && !tracking && !trackingAllowed && parkingBrake.Value == 0)
                {
                    sendMessage("Semik requires to apply parking brake before you start flight tracking.", 0);
                }
                if (!trackingFinished && !trackingAllowed && !tracking && parkingBrake.Value == 32767)
                {
                    if (onground.Value == 1)
                    {
                        trackingAllowed = true;
                        sendMessage("Semik is now connected and ready.", 10);
                    }
                    else
                    {
                        sendMessage("Semik also wants you to start the flight on ground.", 10);
                    }
                }
                if (!trackingFinished && !tracking && trackingAllowed && parkingBrake.Value == 0 && Math.Abs(groundspeedKnots) < 4)
                {
                    sendMessage("Semik started the flight tracking...", 10);
                    mainForm.setStatus("Tracking in progress...");
                    tracking = true;
                }
                if (!trackingFinished && tracking && !wasAirborne && onground.Value == 0)
                {
                    wasAirborne = true;
                }
                if (!trackingFinished && tracking && wasAirborne && parkingBrake.Value == 32767 && onground.Value == 1 && Math.Abs(groundspeedKnots) < 4)
                {
                    tracking         = false;
                    trackingFinished = true;
                    sendMessage("Semik finished tracking, thank you!", 5);
                    mainForm.setStatus("Tracking finished.");
                }

                this.trackingLabel.Text = "tracking : " + ((tracking) ? "ON" : "OFF");
                this.finishedLabel.Text = "tracking finished : " + ((trackingFinished) ? "YES" : "NO");
            }
            catch (FSUIPCException ex)
            {
                Logger.Log("Connection to FS was lost - " + ex);
                FSUIPCConnection.Close();
                mainForm.setStatus("Connection lost");
                RUNTIMER.Stop();
            }
        }
Exemplo n.º 12
0
        public static void ManualUnicom()
        {
            int unicom = 8832;

            _radio1standby.Value = _radio1.Value;
            _radio1.Value        = Convert.ToInt16(unicom);
            FSUIPCConnection.Process();
        }
        public static List <FSPOffset> Process(String groupName)
        {
            FSUIPCConnection.Process(groupName);
            var offsets = from offset in _offsets
                          where offset.Datagroup == groupName
                          select offset;

            return(offsets.ToList());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Returns an FSUIPCSnapshot instance with the current state of the sim
        ///
        ///
        /// </summary>
        /// <param name="connectCooldown">Time between reconnect tries to Simulator, in miliseconds.
        /// Defaults to 30000.</param>
        /// <returns></returns>
        public static FSUIPCSnapshot Pool(int connectCooldown = 30000)
        {
            // TODO: do not block the current thread on this
            //       application may receive a OS taskkill command.
            //       Maybe expose connected = true?
            while (!connected)
            {
                try
                {
                    FSUIPCConnection.Open();

                    connected = true;
                }
                catch (FSUIPCException crap)
                {
                    switch (crap.FSUIPCErrorCode)
                    {
                    case FSUIPCError.FSUIPC_ERR_OPEN:
                        connected = true;
                        break;

                    case FSUIPCError.FSUIPC_ERR_NOFS:
                        Thread.Sleep(connectCooldown);
                        break;

                    default:
                        throw new ApplicationException(
                                  "Unexpected exception trying FSUIPC.Open(). Check inner exception.",
                                  crap);
                    }
                }
            }

            try
            {
                FSUIPCConnection.Process();
            }
            catch (Exception crap)
            {
                // TODO: catch ONLY relevant execeptions
                //       connected = false;
                throw new ApplicationException("Provider.Pool() failed with:", crap);
            }

            if (connected)
            {
                FSUIPCSnapshot data = new FSUIPCSnapshot(true);

                // FSUIPC will return data even if the user is in scenario screen
                // or any other screen really.
                // TODO: actually filter invalid locations
                return(data.Position.SequenceEqual(new double[] { 0, 0 }) ? null : data);
            }

            return(null);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns a snapshot of the current simulator telemetry, or, if unable returns null
        ///
        /// </summary>
        /// <returns></returns>
        public static Telemetry GetCurrent()
        {
            Telemetry result = new Telemetry();

            // snapshot data
            try
            {
                FSUIPCConnection.Process();
            }
            catch (Exception crap)
            {
                // failed to connect to the sim?
                return(null);
            }

            result.Timestamp = DateTime.UtcNow;

            // capture values
            result.IndicatedAirSpeed = (FSUIPCOffsets.indicatedAirSpeed.Value / 128);
            result.Pitch             = ((((FSUIPCOffsets.pitch.Value) / 360) / 65536) * 2) / -1;
            result.Bank              = (((FSUIPCOffsets.bank.Value) / 360) / 65536) * 2;
            result.Engine1           = (FSUIPCOffsets.engine1.Value == 0) ? false : true;
            result.Engine2           = (FSUIPCOffsets.engine2.Value == 0) ? false : true;
            result.Engine3           = (FSUIPCOffsets.engine3.Value == 0) ? false : true;
            result.Engine4           = (FSUIPCOffsets.engine4.Value == 0) ? false : true;
            result.ParkingBrake      = (FSUIPCOffsets.parkingBrake.Value == 0) ? false : true;
            result.ParkingBrakeWrite = FSUIPCOffsets.parkingBrakeWrite.Value;
            result.OnGround          = (FSUIPCOffsets.onGround.Value == 0) ? false : true;
            result.VerticalSpeed     = (FSUIPCOffsets.verticalSpeed.Value * 3.28084) / -1;
            result.Throttle          = FSUIPCOffsets.throttle.Value;
            result.Altitude          = (FSUIPCOffsets.altitude.Value * 3.2808399);
            result.Gear              = FSUIPCOffsets.GetBool(FSUIPCOffsets.gear);
            result.Slew              = FSUIPCOffsets.slew.Value;
            result.Pause             = (FSUIPCOffsets.pause.Value == 0) ? false : true;
            result.OverSpeed         = (FSUIPCOffsets.overSpeed.Value == 0) ? false : true;
            result.Stall             = (FSUIPCOffsets.stall.Value == 0) ? false : true;
            result.Battery           = (FSUIPCOffsets.battery.Value == 0) ? false : true;
            result.LandingLights     = (FSUIPCOffsets.landingLights.Value == 0) ? false : true;
            result.GrossWeight       = FSUIPCOffsets.grossWeight.Value * 0.45359237;
            result.ZeroFuelWeight    = (FSUIPCOffsets.zeroFuelWeight.Value / 256) * 0.45359237;
            result.Squawk            = FSUIPCOffsets.squawk.Value;
            result.SimTime           = (new DateTime(BitConverter.ToInt16(FSUIPCOffsets.simTime.Value, 8), 1, 1, FSUIPCOffsets.simTime.Value[0], FSUIPCOffsets.simTime.Value[1], FSUIPCOffsets.simTime.Value[2])).Add(new TimeSpan(BitConverter.ToInt16(FSUIPCOffsets.simTime.Value, 6) - 1, 0, 0, 0));
            result.SimRate           = (FSUIPCOffsets.simRate.Value / 256);
            result.QNH           = FSUIPCOffsets.qnh.Value / 16;
            result.EngineCount   = FSUIPCOffsets.engineCount.Value;
            result.Compass       = FSUIPCOffsets.compass.Value;
            result.Latitude      = FSUIPCOffsets.latitude.Value * (90.0 / (10001750.0 * 65536.0 * 65536.0));
            result.Longitude     = FSUIPCOffsets.longitude.Value * (360.0 / (65536.0 * 65536.0 * 65536.0 * 65536.0));
            result.Location      = new GeoCoordinate(result.Latitude, result.Longitude);
            result.GroundSpeed   = (FSUIPCOffsets.groundspeed.Value / 65536) * 1.94384449;
            result.RadioAltitude = FSUIPCOffsets.RadioAltitude.Value / 65536;
            result.MachSpeed     = FSUIPCOffsets.machSpeed.Value / 20480;
            result.Flaps         = FSUIPCOffsets.flapsControl.Value;

            return(result);
        }
 private void SendControlToFS(uint controlNumber, uint parameterValue)
 {
     if (!_isArduinoConnected)
     {
         return;
     }
     sendControl.Value  = controlNumber;
     controlParam.Value = parameterValue;
     FSUIPCConnection.Process("sendControl");
 }
Exemplo n.º 17
0
 private void FSUIPCProcessTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         FSUIPCConnection.Process();
     }
     catch
     {
         this.DwcOpen();
     }
 }
Exemplo n.º 18
0
        /*public static void FailEngine(byte engine) {
         *  engineFail.Value = engine;
         *  try
         *  {
         *      FSUIPCConnection.Process();
         *  }
         *  catch (Exception)
         *  {
         *
         *  }
         * }*/

        public static void SetAPMasterSwitch(int ap)
        {
            APMasterSwitch.Value = ap;
            try
            {
                FSUIPCConnection.Process();
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 19
0
 private static void DrawAircraftType(Graphics g, int x, int y)
 {
     // Aircraft type is in the "AircraftInfo" data group so we only want to proccess that here.
     try
     {
         FSUIPCConnection.Process("AircraftInfo");
         g.DrawString(aircraftType.Value, F, B, x, y);
     }
     catch (Exception ex)
     {
     }
 }
Exemplo n.º 20
0
        private void startDiscord()
        {
            FSUIPCConnection.Process();
            if (simStupidNumber.Value > 0 && simStupidNumber.Value < 5)
            {
                version = simVersion.FSX;
            }
            else if (simStupidNumber.Value > 100 && simStupidNumber.Value < 110)
            {
                version = simVersion.FSXSE;
            }
            else if (simStupidNumber.Value > 9 && simStupidNumber.Value < 15)
            {
                version = simVersion.P3Dv1;
            }
            else if (simStupidNumber.Value > 19 && simStupidNumber.Value < 26)
            {
                version = simVersion.P3Dv2;
            }
            else if (simStupidNumber.Value > 29 && simStupidNumber.Value < 35)
            {
                version = simVersion.P3Dv3;
            }
            else if (simStupidNumber.Value == 0)
            {
                version = simVersion.XPlane;
            }
            else
            {
                version = simVersion.P3Dv4;
            }

            string cID = version == simVersion.FSX || version == simVersion.FSXSE ? "447447349594292226" : "466739324537405441";

            cID = version == simVersion.XPlane ? "480825144265277461" : cID;

            try
            {
                client = new DiscordRpcClient(cID, true, -1);
                client.Initialize();
                client.SetPresence(new RichPresence()
                {
                    Details = version.ToString(),
                    State   = "Booting up - Don't worry, we're getting things running!"
                });

                timerDiscord.Start();
            } catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Discord Start Error! Error:" + ex.Message, "FSUIPC", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Exemplo n.º 21
0
        private void threadTick()
        {
            if (!ValueBag.Connected)
            {
                return;
            }
            try
            {
                FSUIPCConnection.Process();
                ValueBag.Paused = ipcPaused.Value == 1;
                if (ValueBag.Paused)
                {
                    ValueBag.TrueAirSpeed  = 0;
                    ValueBag.Lat           = 0;
                    ValueBag.Lng           = 0;
                    ValueBag.XVelocity     = 0;
                    ValueBag.YVelocity     = 0;
                    ValueBag.ZVelocity     = 0;
                    ValueBag.XAcceleration = 0;
                    ValueBag.YAcceleration = 0;
                    ValueBag.ZAcceleration = 0;
                    ValueBag.PitchVelocity = 0;
                    ValueBag.RollVelocity  = 0;
                    ValueBag.YawVelocity   = 0;
                }
                else
                {
                    ValueBag.TrueAirSpeed  = (double)ipcTrueAirSpeed.Value / 128d;
                    ValueBag.Lat           = ipcLat.Value;
                    ValueBag.Lng           = ipcLng.Value;
                    ValueBag.XVelocity     = ipcXVelocity.Value;
                    ValueBag.YVelocity     = ipcYVelocity.Value;
                    ValueBag.ZVelocity     = ipcZVelocity.Value;
                    ValueBag.XAcceleration = ipcXAcceleration.Value;
                    ValueBag.YAcceleration = ipcYAcceleration.Value;
                    ValueBag.ZAcceleration = ipcZAcceleration.Value;
                    ValueBag.PitchVelocity = ipcPitchVelocity.Value * 180d / Math.PI;
                    ValueBag.RollVelocity  = ipcRollVelocity.Value * 180d / Math.PI;
                    ValueBag.YawVelocity   = ipcYawVelocity.Value * 180d / Math.PI;
                }

                FsxiValueBagUpdated?.Invoke(this, EventArgs.Empty);
            }
            catch (FSUIPCException ex) when(ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG)
            {
                Disconnect();
            }
            catch (Exception)
            {
                // In case of bad data conversion
            }
        }
Exemplo n.º 22
0
        private static void DrawScreen(Graphics g, int w, int h)
        {
            B   = new SolidBrush(planeStall ? Color.White : Color.Black);
            Pen = new Pen(B);

            DrawArtificialHorizon(g, w - h - 6, 0, h, h);
            DrawAltimeter(g, w - h - 6 - AltimeterWidth, h - 10);
            DrawSpeedometer(g, w - h - 6 - AltimeterWidth + 6, h - 21);
            DrawVerticalSpeed(g, w - 6, 0, h);


            FSUIPCConnection.Process();
        }
Exemplo n.º 23
0
 public static void sendMessage(string mes, int timeout)
 {
     message.Value        = mes;
     messageControl.Value = timeout;
     try
     {
         FSUIPCConnection.Process();
     }
     catch (Exception) {
         //Logger.Log("Connection to FS was lost");
         FSUIPCConnection.Close();
         mainForm.setStatus("Connection lost");
     }
 }
Exemplo n.º 24
0
 /// <summary>
 /// Handles
 /// </summary>
 /// <returns></returns>
 private void process()
 {
     // for now just pass all expections to the application and call Process();
     try
     {
         if (requiresProcessCall)
         {
             FSUIPCConnection.Process();
         }
         lastProcessCall = DateTime.UtcNow;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 25
0
 private static void CheckConnected(Object myObject, EventArgs myEventArgs)
 {
     try
     {
         FSUIPCConnection.Process();
     }
     catch (Exception)
     {
         //Logger.Log("Connection to FS was lost");
         FSUIPCConnection.Close();
         mainForm.setStatus("Connection lost");
         FLIGHTTIMER.Stop();
         TIMER.Stop();
         connected = false;
         Connect();
     }
 }
        // second 200 MS timer for lower priority instruments, or instruments that don't work well on 100 MS
        private void timerLowPriority_Tick(object sender, EventArgs e)
        {
            try
            {
                FSUIPCConnection.Process("LowPriority");
                inst.ReadLowPriorityInstruments();
            }
            catch (Exception ex)
            {
                // Stop the timer.
                this.timerLowPriority.Stop();

                // Make a log entry since notifying the user is pointless.
                logger.Debug("Low priority instruments failed to read. Probable causes include simulator shutdown, loss of network access, or a fsuipc problem.");
                this.timerConnection.Start();
            }
        }
Exemplo n.º 27
0
        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
            {
                FSUIData.DME_SWITCH.Value = (ushort)FSUIPCConnection.ReadLVar("DME_Switch");

                FSUIPCConnection.Process(); // 有这句就可以更新数据了

                chkAvionicsMaster.IsChecked = (FSUIData.AvionicsMaster.Value > 0);

                FieldInfo[] myField = typeof(FSUIData).GetFields(BindingFlags.Public | BindingFlags.Static);

                foreach(var fd in myField)
                {
                    var obj = fd.GetValue(null); // 获取静态 Field, 否则用 Instance 最为参数
                    UpdateDeltaObject(fd.Name, GetOffsetValue(obj));
                }

                if (chkShowValues.IsChecked == true)
                {
                    txtPrevious.Text = JsonConvert.SerializeObject(previousValues, Formatting.Indented);
                    txtJson.Text = JsonConvert.SerializeObject(deltaValues, Formatting.Indented);
                }
                else
                {
                    txtPrevious.Text = "";
                    txtJson.Text = "";
                }

                if (JsonConvert.SerializeObject(deltaValues, Formatting.None) != "{}") {
                    // 请求更新数据内容
                    if (chkSendFull.IsChecked == true)
                        wssv.WebSocketServices.Broadcast(JsonConvert.SerializeObject(previousValues, Formatting.None));
                    else
                        wssv.WebSocketServices.Broadcast(JsonConvert.SerializeObject(deltaValues, Formatting.None));
                }
            }
            catch(Exception ex)
            {
                timerMain.Stop();
                txtJson.Text = ex.Message;
            }
        }
Exemplo n.º 28
0
        public bool RunMacro(string name)
        {
            try
            {
                Offset request = new Offset(0x0D70, 128);
                request.SetValue(name);
                FSUIPCConnection.Process();
                request.Disconnect();
                request = null;
            }
            catch
            {
                Log.Logger.Error($"IPCManager: Exception while Executing Macro: {name}");
                return(false);
            }

            return(true);
        }
Exemplo n.º 29
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();
        }
Exemplo n.º 30
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();
            }
        }