Пример #1
0
 /// <summary>
 /// Costruttore
 /// </summary>
 public FSWrapper()
 {
     LastPosition                        = new AircraftPosition();
     LastPosition.Altitude               = double.NaN;
     LastPosition.RadioAltitude          = double.NaN;
     LastPosition.AvailableFuel          = double.NaN;
     LastPosition.Heading                = double.NaN;
     LastPosition.IsAirborne             = false;
     LastPosition.IsEngineStarted        = false;
     LastPosition.Latitude               = double.NaN;
     LastPosition.Longitude              = double.NaN;
     LastPosition.TrueAirspeedSpeed      = double.NaN;
     LastPosition.IndicatedAirspeedSpeed = double.NaN;
     LastPosition.GroundSpeed            = double.NaN;
     LastPosition.QNH                    = double.NaN;
     LastPosition.Timestamp              = DateTime.Now;
     LastPosition.Nav1                   = double.NaN;
     LastPosition.Nav1Localizer          = 0;
     LastPosition.Nav1Glide              = 0;
     LastPosition.Nav1OBS                = 0;
     LastPosition.Nav1Radial             = 0;
     LastPosition.Nav1DME                = double.NaN;
     LastPosition.AutopilotHeading       = 0;
     LastPosition.ThrottlePercentage     = 0;
 }
Пример #2
0
        public byte[] GetByte(AircraftPosition aircraft)
        {
            _coordinateHelper.LocalCordToLatLon(_aerodromePoint.AerodromeInfo.Runway.Threshold.Latitude, _aerodromePoint.AerodromeInfo.Runway.Threshold.Longitude, aircraft.GeoCoordinate.X, aircraft.GeoCoordinate.Z,
                                                out var lat, out var lon
                                                );

            _aircraft.Kren  = aircraft.Kren;
            _aircraft.Risk  = aircraft.Risk;
            _aircraft.Tang  = aircraft.Tang;
            _aircraft.HLand = _coordinateHelper.GetElevation(lat, lon, _aerodromePoint.NavigationPoint.GeoCoordinate.H);
            _aircraft.GeoCoordinate.Latitude  = lat;
            _aircraft.GeoCoordinate.Longitude = lon;
            _aircraft.GeoCoordinate.X         = aircraft.GeoCoordinate.X;
            _aircraft.GeoCoordinate.Z         = aircraft.GeoCoordinate.Z;
            _aircraft.GeoCoordinate.H         = aircraft.GeoCoordinate.H;
            _aircraft.V = aircraft.V;


            DebugParameters.LatLA  = lat;
            DebugParameters.LonLA  = lon;
            DebugParameters.HLA    = _aircraft.HLand;
            DebugParameters.PsiLA  = _aircraft.Risk;
            DebugParameters.HbarLA = _aircraft.GeoCoordinate.H - _aircraft.HLand;

            EventsHelper.OnChangeAircraftCoordinateEvent(_aircraft);

            return(ConvertHelper.ObjectToByte(_aircraft));
        }
Пример #3
0
        public static void writeFile(String path, List <Aircraft> aircrafts, Main main)
        {
            for (int id = 0; id < aircrafts.Count; id++)
            {
                var csv = new StringBuilder();

                Aircraft aircraft = aircrafts[id];

                csv.AppendLine("Time,Longitude,Latitude,Altitude,Roll (deg),Pitch (deg),Yaw (deg)");

                for (int i = 0; i < aircraft.positions.Count; i++)
                {
                    AircraftPosition position = aircraft.positions[i];

                    var newLine = string.Format("{0},{1},{2},{3},{4},{5},{6}",
                                                position.time.ToString(),
                                                position.longitude.ToString(),
                                                position.latitude.ToString(),
                                                position.altitude.ToString(),
                                                position.roll.ToString(),
                                                position.pitch.ToString(),
                                                position.yaw.ToString(),
                                                position.fuel.ToString()
                                                );
                    csv.AppendLine(newLine);
                }

                //after your loop
                File.WriteAllText(path + "/A-29 (" + aircraft.pilot + ") [" + aircraft.color + "].csv", csv.ToString());
            }
            Process.Start(path);
        }
Пример #4
0
        private async void ButtonExport_Click(object sender, RoutedEventArgs e)
        {
            if (!recorderLogic.CanSave)
            {
                MessageBox.Show("Nothing to export!");
                return;
            }

            var dialog = new SaveFileDialog
            {
                FileName = $"Export {DateTime.Now:yyyy-MM-dd-HH-mm}.csv",
                Filter   = "CSV (for Excel)|*.csv"
            };

            if (dialog.ShowDialog() == true)
            {
                await exportLogic.ExportAsync(dialog.FileName, recorderLogic.Records.Select(o =>
                {
                    var result          = AircraftPosition.FromStruct(o.position);
                    result.Milliseconds = o.milliseconds;
                    return(result);
                }));

                logger.LogDebug("Save file into {fileName}", dialog.FileName);
            }
        }
        private async void ButtonExport_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog
            {
                FileName = $"Export {DateTime.Now:yyyy-MM-dd-HH-mm}.csv",
                Filter   = "CSV (for Excel)|*.csv"
            };

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    await exportLogic.ExportAsync(dialog.FileName, replayLogic.Records.Select(o =>
                    {
                        var result          = AircraftPosition.FromStruct(o.position);
                        result.Milliseconds = o.milliseconds;
                        return(result);
                    }));

                    logger.LogDebug("Save file into {fileName}", dialog.FileName);
                }
                catch (IOException)
                {
                    MessageBox.Show("Flight Recorder cannot write the file to disk.\nPlease make sure the folder is accessible by Flight Recorder, and you are not overwriting a locked file.", "Flight Recorder", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Пример #6
0
        public void ReadPosition(AircraftPosition pos)
        {
            backgroundSpeaker = new SpeakingThread(Controller);

            if (pos != null)
            {
                StringBuilder toBeSpeeked = new StringBuilder();
                string        tmp         = Convert.ToInt32(pos.Heading).ToString("000");
                string        tmp2        = tmp[0] + ", " + tmp[1] + ", " + tmp[2] + ", ";
                toBeSpeeked.Append(string.Format(TEMPLATE_HEADING, tmp2));
                toBeSpeeked.Append(SSML_PAUSE_SHORT);
                int RoundedAltitude = Convert.ToInt32(pos.Altitude) / 100 * 100;                                           // /100*100 inserito per arrotondare ai 100 piedi;
                toBeSpeeked.Append(string.Format(TEMPLATE_ALTITUDE, RoundedAltitude.ToString("0,000").Replace('.', ','))); //RoundedAltitude.ToString("0,000").Replace('.',',') per issue 75
                toBeSpeeked.Append(SSML_PAUSE_SHORT);
                toBeSpeeked.Append(string.Format(TEMPLATE_SPEED, Convert.ToInt32(pos.TrueAirspeedSpeed)));
                toBeSpeeked.Append(SSML_PAUSE_SHORT);

                backgroundThread = new Thread(new ThreadStart(backgroundSpeaker.Run));
            }
            else
            {
                backgroundSpeaker.AddInSpeakingBuffer("Position unknown", "Position unknown");
                backgroundThread = new Thread(new ThreadStart(backgroundSpeaker.Run));
            }
            backgroundThread.IsBackground = true;//issue 107
            backgroundThread.Start();
        }
Пример #7
0
 public SendAircraftStruct()
 {
     _aerodromePoint   = new AerodromePoint();
     _coordinateHelper = new CoordinateHelper();
     _aircraft         = new AircraftPosition();
     _aircraft.Head    = _aircraft.GetHead("Aircraft_Position");
     EventsHelper.ChangeAerodromeEvent += ChangeAerodrome;
 }
Пример #8
0
 /// <summary>
 /// Gestore dei soli eventi di posizionamento per poter forzare il repaint
 /// </summary>
 /// <param name="e"></param>
 public void HandleEvent(AircraftPosition pos)
 {
     if (lastMapUpdate.AddSeconds(MAP_AUTOUPDATE_DELAY_IN_SECONDS).CompareTo(DateTime.Now) < 0)
     {
         GoToPosition(pos);
         lastMapUpdate = DateTime.Now;
     }
 }
Пример #9
0
        private void Connector_AircraftPositionUpdated(object sender, AircraftPositionUpdatedEventArgs e)
        {
            recorderLogic.NotifyPosition(e.Position);

            Dispatcher.Invoke(() =>
            {
                viewModel.AircraftPosition = AircraftPosition.FromStruct(e.Position);
            });
        }
Пример #10
0
 private void ChangeAircraftCoordinate(AircraftPosition aircraft)
 {
     _coordinateHelper.LatLonToPixel(aircraft.GeoCoordinate.Latitude, aircraft.GeoCoordinate.Longitude, out var px, out var py);
     Dispatcher.Invoke(() => Canvas.SetLeft(this, px));
     Dispatcher.Invoke(() => Canvas.SetTop(this, py));
     Dispatcher.Invoke(() => zzz.Angle  = 360 - aircraft.Risk);
     Dispatcher.Invoke(() => l1.Content = px);
     Dispatcher.Invoke(() => l2.Content = py);
 }
Пример #11
0
 public SendLandingStruct()
 {
     _landingHelper    = new LandingHelper();
     _aircraft         = new AircraftPosition();
     _aerodromePoint   = new AerodromePoint();
     _landing          = new Landing();
     _coordinateHelper = new CoordinateHelper();
     _landing.Head     = _landing.GetHead("TacticalEditor_Landing");
     EventsHelper.ChangeAircraftCoordinateEvent += ChangeAircraftCoordinate;
     EventsHelper.ChangeAerodromeEvent          += ChangeAerodrome;
 }
Пример #12
0
 public override byte[] GetPosition(AircraftPosition aircraftPosition)
 {
     aircraftPosition.IsDegree = 1;
     aircraftPosition.Tang     = KinematicsState.Angs.Fi;
     aircraftPosition.Kren     = KinematicsState.Angs.Gam;
     aircraftPosition.Risk     = KinematicsState.Angs.Psi;
     aircraftPosition.GeoCoordinate.Latitude  = KinematicsState.Pos.Latitude;
     aircraftPosition.GeoCoordinate.Longitude = KinematicsState.Pos.Longitude;
     aircraftPosition.GeoCoordinate.H         = KinematicsState.Pos.Elevation;
     aircraftPosition.GeoCoordinate.X         = 0;
     aircraftPosition.GeoCoordinate.Z         = 0;
     return(ConvertHelper.ObjectToByte(aircraftPosition));
 }
Пример #13
0
 public override byte[] GetPosition(AircraftPosition aircraftPosition)
 {
     aircraftPosition.IsDegree = 0;
     aircraftPosition.Tang     = out_Tang;
     aircraftPosition.Kren     = out_Kren;
     aircraftPosition.Risk     = out_Kurs;
     aircraftPosition.GeoCoordinate.Latitude  = 0;
     aircraftPosition.GeoCoordinate.Longitude = 0;
     aircraftPosition.GeoCoordinate.H         = in_Hgeom;
     aircraftPosition.GeoCoordinate.X         = out_Xg;
     aircraftPosition.GeoCoordinate.Z         = out_Zg;
     return(ConvertHelper.ObjectToByte(aircraftPosition));
 }
Пример #14
0
        private void InitObject()
        {
            _config               = Config.Instance();
            _udpHelper            = new UdpHelper();
            _deviceControlElement = DeviceControlElement.GetInstance();
            _deviceControlElement.AddJoystick(_config.Default.DefaultControlElement.Rus.Guid);
            _deviceControlElement.AddJoystick(_config.Default.DefaultControlElement.Rud.Guid);
            _dynamicModelToBmpi     = new DynamicModelToBmpi();
            _aircraftPosition       = new AircraftPosition();
            _dynamicModelToVaps     = new DynamicModelToVaps();
            _modelState             = new ModelState();
            _channelRadar           = new ChannelRadar();
            _channelThermalEffect   = new ChannelThermalEffect();
            _channelTvHeadEffect    = new ChannelTvHeadEffect();
            _ethernetControlElement = new EthernetControlElement();
            _cLSEControl            = new CLSEControl();
            _cLSEState           = new CLSEState();
            _parametersOfControl = new ParametersOfControl();
            _lptp       = new Lptp();
            _commandPue = new CommandPue();

            if (_typeModel == 0)
            {
                _controlElement = new ControlElementKa52();
                _dynamicModel   = new ModelKa52();
            }
            _startPosition = new StartPosition();
            _landing       = new Landing();
            _route         = new Route();

            uint   version       = 0;
            uint   release       = 0;
            uint   releaseDay    = 0;
            uint   releaseMonth  = 0;
            uint   releaseYear   = 0;
            IntPtr pversion      = GetIntPtr(version);
            IntPtr prelease      = GetIntPtr(release);
            IntPtr preleaseDay   = GetIntPtr(releaseDay);
            IntPtr preleaseMonth = GetIntPtr(releaseMonth);
            IntPtr preleaseYear  = GetIntPtr(releaseYear);

            GetDllVersion(pversion, prelease, preleaseDay, preleaseMonth, preleaseYear);
            version      = (uint)Marshal.ReadInt32(pversion);
            release      = (uint)Marshal.ReadInt32(prelease);
            releaseDay   = (uint)Marshal.ReadInt32(preleaseDay);
            releaseMonth = (uint)Marshal.ReadInt32(preleaseMonth);
            releaseYear  = (uint)Marshal.ReadInt32(preleaseYear);
            Init("ConfigBrunner.xml");
        }
Пример #15
0
        private void Connector_AircraftPositionUpdated_Video(object sender, AircraftPositionUpdatedEventArgs e)
        {
            if (obs_connect.Content == "Disconnect")
            {
                var response = _obs.SendRequest("GetRecordingStatus");

                recorderLogic.NotifyPositionVideo((string)response["recordTimecode"]);



                Dispatcher.Invoke(() =>
                {
                    viewModel.AircraftPosition = AircraftPosition.FromStruct(e.Position);
                });
            }
        }
Пример #16
0
        private void AircraftCoordinateChange(AircraftPosition aircraft)
        {
            for (int i = 0; i < _aerodromePoints?.Length; i++)
            {
                if (_aerodromePoints[i] == null)
                {
                    continue;
                }

                var abp  = _aerodromePoints[i].NavigationPoint;
                var abpR = _aerodromePoints[i].AerodromeInfo.Runway;
                var acG  = aircraft.GeoCoordinate;

                abp.Measure.Distance =
                    _measureHelper.GetDistanceInKmLatLon(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, acG.Latitude, acG.Longitude);

                abp.Measure.Psi =
                    _measureHelper.GetDegreesAzimuthLatLon(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, acG.Latitude, acG.Longitude);

                _coordinateHelper.LocalCordToXZ(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, abpR.Threshold.Latitude, abpR.Threshold.Longitude,
                                                out var x, out var z);
                _aerodromePoints[i].AerodromeInfo.Runway.Threshold.X = x - acG.X;
                _aerodromePoints[i].AerodromeInfo.Runway.Threshold.Z = z - acG.Z;

                _coordinateHelper.LocalCordToXZ(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, abpR.GlideSlope.Latitude, abpR.GlideSlope.Longitude,
                                                out x, out z);
                _aerodromePoints[i].AerodromeInfo.Runway.GlideSlope.X = x - acG.X;
                _aerodromePoints[i].AerodromeInfo.Runway.GlideSlope.Z = z - acG.Z;

                _coordinateHelper.LocalCordToXZ(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, abpR.Localizer.Latitude, abpR.Localizer.Longitude,
                                                out x, out z);
                _aerodromePoints[i].AerodromeInfo.Runway.Localizer.X = x - acG.X;
                _aerodromePoints[i].AerodromeInfo.Runway.Localizer.Z = z - acG.Z;

                _coordinateHelper.LocalCordToXZ(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, abpR.LocatorMiddle.Latitude, abpR.LocatorMiddle.Longitude,
                                                out x, out z);
                _aerodromePoints[i].AerodromeInfo.Runway.LocatorMiddle.X = x - acG.X;
                _aerodromePoints[i].AerodromeInfo.Runway.LocatorMiddle.Z = z - acG.Z;

                _coordinateHelper.LocalCordToXZ(abp.GeoCoordinate.Latitude, abp.GeoCoordinate.Longitude, abpR.LocatorOuter.Latitude, abpR.LocatorOuter.Longitude,
                                                out x, out z);
                _aerodromePoints[i].AerodromeInfo.Runway.LocatorOuter.X = x - acG.X;
                _aerodromePoints[i].AerodromeInfo.Runway.LocatorOuter.Z = z - acG.Z;
            }
        }
Пример #17
0
        public void GoToPosition(AircraftPosition pos)
        {
            lastPos = pos;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<html> ");
            sb.AppendLine("  <head> ");
            sb.AppendLine("    <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/> ");
            sb.AppendLine("    <title>Google Maps JavaScript API Example: Map Markers</title> ");
            sb.AppendLine("    <script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA\"");
            sb.AppendLine("            type=\"text/javascript\"></script> ");
            sb.AppendLine("    <script type=\"text/javascript\"> ");
            sb.AppendLine("    ");
            sb.AppendLine("    function initialize() {");
            sb.AppendLine("      if (GBrowserIsCompatible()) {");
            sb.AppendLine("        var map = new GMap2(document.getElementById(\"map_canvas\"));");
            sb.AppendLine("        var latitude = " + pos.Latitude.ToString("0.00000").Replace(',', '.') + ";");
            sb.AppendLine("        var longitude = " + pos.Longitude.ToString("0.00000").Replace(',', '.') + ";");
            sb.AppendLine("        map.setCenter(new GLatLng(latitude, longitude), 13);");
            sb.AppendLine("        map.addControl(new GSmallMapControl());");
            sb.AppendLine("        map.addControl(new GMapTypeControl());");
            sb.AppendLine("        map.setMapType(G_SATELLITE_MAP);");
            sb.AppendLine("          var point = new GLatLng(latitude,longitude);");
            sb.AppendLine("          var marker = new GMarker(point);");
            sb.AppendLine("          map.addOverlay(marker);");
            sb.AppendLine("      }");
            sb.AppendLine("    }");
            sb.AppendLine(" ");
            sb.AppendLine("    </script> ");
            sb.AppendLine("  </head> ");
            sb.AppendLine("  <body onload=\"initialize()\" onunload=\"GUnload()\"> ");
            sb.AppendLine("    <div id=\"map_canvas\" style=\"width: " + webBrowser1.Width + "px; height: " + webBrowser1.Height + "px\"></div> ");
            sb.AppendLine("  </body> ");
            sb.AppendLine("</html> ");

            webBrowser1.DocumentText = sb.ToString();

            //using (System.IO.StreamWriter sw = System.IO.File.CreateText(@"C:\provadoppia.html"))
            //{
            //    sw.Write(sb.ToString());
            //    sw.Close();
            //}
        }
Пример #18
0
        public ProcessingLoop()
        {
            IsLooping = true;

            _udpHelper        = new UdpHelper();
            _aircraftPosition = new AircraftPosition();

            _listOfNavigationPoint = new ListOfNavigationPoint();
            _listOfAerodromes      = new ListOfAerodromes();
            _sendLandingStruct     = new SendLandingStruct();
            _sendAircraftStruct    = new SendAircraftStruct();
            _sendRouteToIup        = new SendRouteToIup();
            _calculatePpmPoints    = new CalculatePpmPoints();
            _calculateAerodromes   = new CalculateAerodromes();
            _sendToSvvo            = new SendToSvvo();
            _changeNp   = new ChangeNp();
            _threadSend = new Thread(SendingLoop);
            _threadSend.Start();
            _threadReceive = new Thread(ReceivingLoop);
            _threadReceive.Start();
        }
Пример #19
0
 private void ChangeAircraftCoordinate(AircraftPosition aircraft)
 {
     _aircraft = aircraft;
 }
Пример #20
0
        private void AircraftCoordinateChange(AircraftPosition aircraft)
        {
            for (int i = 0; i < _ppmPoints?.Length; i++)
            {
                if (_ppmPoints[i] == null)
                {
                    continue;
                }

                var ppmM = _ppmPoints[i].NavigationPoint;
                var ppmG = _ppmPoints[i].NavigationPoint;
                var acG  = aircraft.GeoCoordinate;
                var abpG = _aerodromePoint.NavigationPoint;

                ppmM.Measure.Distance =
                    _measureHelper.GetDistanceInKmLatLon(acG.Latitude, acG.Longitude, ppmG.GeoCoordinate.Latitude,
                                                         ppmG.GeoCoordinate.Longitude);

                ppmM.Measure.Psi =
                    _measureHelper.GetDegreesAzimuthLatLon(acG.Latitude, acG.Longitude, ppmG.GeoCoordinate.Latitude,
                                                           ppmG.GeoCoordinate.Longitude);

                _coordinateHelper.LocalCordToXZ(abpG.GeoCoordinate.Latitude, abpG.GeoCoordinate.Longitude,
                                                ppmG.GeoCoordinate.Latitude, ppmG.GeoCoordinate.Longitude,
                                                out var x, out var z);

                ppmG.GeoCoordinate.X = x - acG.X;
                ppmG.GeoCoordinate.Z = z - acG.Z;

                ppmM.Measure.Distance =
                    Math.Sqrt(Math.Pow(ppmG.GeoCoordinate.X, 2) + Math.Pow(ppmG.GeoCoordinate.Z, 2)) / 1000;

                var time = (ppmM.Measure.Distance * 1000) / aircraft.V;
                if (double.IsInfinity(time))
                {
                    ppmM.Measure.RemainingTime = 0;
                }
                else
                {
                    ppmM.Measure.RemainingTime = time;
                }

                if (2000 > Math.Sqrt(ppmG.GeoCoordinate.X * ppmG.GeoCoordinate.X +
                                     ppmG.GeoCoordinate.Z * ppmG.GeoCoordinate.Z))
                {
                    if (ppmG.Executable == 1)
                    {
                        EventsHelper.OnChangeNpDEvent(new ChangeNp()
                        {
                            Action = 1, TypeOfNp = 2, IdNp = i + 2
                        });
                    }
                }

                if (i == 0)
                {
                    DebugParameters.XPPM = ppmG.GeoCoordinate.X;
                    DebugParameters.ZPPM = ppmG.GeoCoordinate.Z;
                }
            }
        }
Пример #21
0
 public virtual byte[] GetPosition(AircraftPosition aircraftPosition)
 {
     return(new byte[1]);
 }
Пример #22
0
 public static void OnChangeAircraftCoordinateEvent(AircraftPosition aircraft) =>
 ChangeAircraftCoordinateEvent?.Invoke(aircraft);
Пример #23
0
        /// <summary>
        /// Gestore interno del watch dog sulle FSUIPC. In caso di errore sorreva un ErrorOccurredEvent
        /// </summary>
        private void TickHandle(object sender, ElapsedEventArgs e)
        {
            try
            {
                PositioningEvent toBeRaised      = new PositioningEvent();
                AircraftPosition currentPosition = new AircraftPosition();

#if FEDE_DEBUG
                currentPosition.IndicatedAirspeedSpeed = (new Random()).NextDouble() * 100;
                currentPosition.Altitude         = 0;
                currentPosition.AutopilotHeading = 100;
                currentPosition.AvailableFuel    = 100;
                currentPosition.GroundSpeed      = currentPosition.IndicatedAirspeedSpeed;
                currentPosition.Heading          = 196;
                currentPosition.IsAirborne       = false;
                currentPosition.IsEngineStarted  = false;
                currentPosition.Latitude         = 44;
                currentPosition.Longitude        = 11;
                currentPosition.Nav1             = 112.2;
                currentPosition.Nav1DME          = 0.7;
                currentPosition.Nav1Glide        = 0;
                currentPosition.Nav1OBS          = 270;
                currentPosition.Nav1Radial       = 291;
                currentPosition.Nav1Localizer    = 50;
                currentPosition.QNH                = 1013;
                currentPosition.RadioAltitude      = 0;
                currentPosition.Timestamp          = DateTime.Now;
                currentPosition.TrueAirspeedSpeed  = currentPosition.IndicatedAirspeedSpeed;
                currentPosition.ThrottlePercentage = 75;

                toBeRaised.Position = currentPosition;
                FlightSimEvent(toBeRaised);
                return;
#endif

                FSUIPCConnection.Process();

                //issue 63
                #region gestione di ivap
                IvapStatus.Instance.IsRunning = ((byte)ivapDetected.Value == 1);
                if (IvapStatus.Instance.IsRunning)
                {
                    IvapStatus.Instance.IvapTrasponderIsInStandby = ((byte)ivapTrasponder.Value == 1);
                }
                else
                {
                    IvapStatus.Instance.IvapTrasponderIsInStandby = true;
                }
                #endregion

                //issue 11
                #region versione FS
                switch ((short)ivapTrasponder.Value)
                {
                case 7:
                    IvapStatus.Instance.FSVersion = FlightSimulatorVersion.FS2004;
                    break;

                case 9:
                    IvapStatus.Instance.FSVersion = FlightSimulatorVersion.FSX;
                    break;

                default:
                    IvapStatus.Instance.FSVersion = FlightSimulatorVersion.Altro;
                    break;
                }
                #endregion

                //ground speed
                currentPosition.GroundSpeed = ((double)groundspeed.Value / 65536d) * 1.943844492; //Knots
                //airspeed
                currentPosition.TrueAirspeedSpeed      = ((double)airspeed.Value / 128);          //issue 38
                currentPosition.IndicatedAirspeedSpeed = ((double)indicatedAirspeed.Value / 128);
                //latitude
                currentPosition.Latitude = (double)latitude.Value * 90d / (10001750d * 65536d * 65536d);
                //longitude
                currentPosition.Longitude = (double)longitude.Value * 360d / (65536d * 65536d * 65536d * 65536d);
                //altitude
                currentPosition.Altitude = (int)altitude.Value * 3.28d;
                //radio altitude
                currentPosition.RadioAltitude = (double)radioAlt.Value / 65536;
                //heading
                currentPosition.Heading = heading.Value * 360d / (65536d * 65536d);
                if (currentPosition.Heading < 0)
                {
                    currentPosition.Heading = 360 + currentPosition.Heading;
                }
                //QNH letto sull'altimetro
                currentPosition.QNH = (int)qnh.Value / 16;
                //NAV 1
                currentPosition.Nav1          = 100 + ReadBCD((short)nav1.Value);
                currentPosition.Nav1Localizer = (short)(byte)nav1_loc.Value;
                if (currentPosition.Nav1Localizer > 128)
                {
                    currentPosition.Nav1Localizer = (short)(-256 + currentPosition.Nav1Localizer);
                }
                currentPosition.Nav1Glide = (byte)nav1_glide.Value;
                currentPosition.Nav1OBS   = (short)nav1_obs.Value;
                if (currentPosition.Nav1OBS < 0)
                {
                    currentPosition.Nav1OBS = (180 - currentPosition.Nav1OBS);
                }
                currentPosition.Nav1Radial = ((short)nav1_radial.Value) * 360 / 65536;
                if (currentPosition.Nav1Radial < 0)
                {
                    currentPosition.Nav1Radial = (180 - currentPosition.Nav1Radial);
                }

                currentPosition.Nav1DME = ReadDME((byte[])nav1_dme.Value);

                //Throttle
                if ((short)throttle1.Value <= 0)
                {
                    currentPosition.ThrottlePercentage = 0;                             //inversori di spinta inseriti
                }
                else
                {
                    currentPosition.ThrottlePercentage = (int)((short)throttle1.Value / 16384d * 100);
                }



                //Autopilot
                currentPosition.AutopilotHeading = ((short)autopilot_hdg.Value) * 360 / 65536;
                if (currentPosition.AutopilotHeading < 0)
                {
                    currentPosition.AutopilotHeading = (180 - currentPosition.AutopilotHeading);
                }

                //fuel
                currentPosition.AvailableFuel  = 0;
                currentPosition.AvailableFuel += fuelCap1.Value * ((double)(fuelQty1.Value) / (128 * 65536));
                currentPosition.AvailableFuel += fuelCap2.Value * ((double)(fuelQty2.Value) / (128 * 65536));
                currentPosition.AvailableFuel += fuelCap3.Value * ((double)(fuelQty3.Value) / (128 * 65536));
                currentPosition.AvailableFuel += fuelCap4.Value * ((double)(fuelQty4.Value) / (128 * 65536));
                currentPosition.AvailableFuel += fuelCap5.Value * ((double)(fuelQty5.Value) / (128 * 65536));
                currentPosition.AvailableFuel += fuelCap6.Value * ((double)(fuelQty6.Value) / (128 * 65536));
                currentPosition.AvailableFuel += fuelCap7.Value * ((double)(fuelQty7.Value) / (128 * 65536));

                toBeRaised.Position = currentPosition;
                //sollevo l'evento
                FlightSimEvent(toBeRaised);

                //gestione stato airborne
                currentPosition.IsAirborne = (airborne.Value == 0) || /*issue 36*/ (currentPosition.RadioAltitude > 10);
                if (!LastPosition.IsAirborne && currentPosition.IsAirborne)
                {
                    //decollato
                    FSEvent to = new TakeOffEvent();
                    FlightSimEvent(to);
                }
                else if (LastPosition.IsAirborne && !currentPosition.IsAirborne)
                {
                    //atterrato
                    FSEvent ldg = new LandingEvent();
                    FlightSimEvent(ldg);
                }

                //gestione dello stato del motore (ed invio eventi associati) issue 29
                currentPosition.IsEngineStarted = currentPosition.AvailableFuel < LastPosition.AvailableFuel;

                if (!LastPosition.IsEngineStarted && currentPosition.IsEngineStarted)
                {
                    //il motore si è acceso
                    FSEvent evt = new EngineStartUpEvent();
                    FlightSimEvent(evt);
                }
                else if (LastPosition.IsEngineStarted && !currentPosition.IsEngineStarted)
                {
                    if (isFirsPosWithNoFuelFlow)
                    {
                        //visto che è la prima volta che questo accade, lascio una tolleranza di un giro
                        //issue 44
                        isFirsPosWithNoFuelFlow         = false;
                        currentPosition.IsEngineStarted = true;
                    }
                    else
                    {
                        //il motore si è spento davvero
                        FSEvent evt = new EngineShutDownEvent();
                        FlightSimEvent(evt);
                        isFirsPosWithNoFuelFlow = true;
                    }
                }

                //gestione del movimento (ed invio eventi associati) issue 29
                //l'1 invece dello 0 è dovuto a potenziali errori di arrotondamento nel calcolo della velocità
                if (LastPosition.GroundSpeed <= 1 && currentPosition.GroundSpeed > 1)
                {
                    //inizia a muoversi
                    FSEvent evt = new StartMovingEvent();
                    FlightSimEvent(evt);
                }
                else if (LastPosition.GroundSpeed >= 1 && currentPosition.GroundSpeed < 1)
                {
                    //si ferma
                    FSEvent evt = new EndMovingEvent();
                    FlightSimEvent(evt);
                }

                LastPosition = currentPosition;
            }
            catch (Exception ex)
            {
                ErrorOccurred(ex);
            }
        }
Пример #24
0
 private void Hub_OnTeleport(string connectionId, AircraftPosition position)
 {
     flightConnector.Teleport(position.Latitude, position.Longitude, position.Altitude);
 }