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&v=2&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(); //} }
/// <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); } }
/// <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; }
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(); }
/// <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; } }