Ejemplo n.º 1
0
        private void btnConnectar_Click(object sender, EventArgs e)
        {
            try
            {
                // Attempt to open a connection to FSUIPC (running on any version of Flight Sim)
                FSUIPCConnection.Open();
                // Opened OK so disable the Connect button
                this.btnConnectar.Enabled     = false;
                this.chkEnableAIRadar.Enabled = true;
                // Start the timer ticking to drive the rest of the application
                this.timer1.Interval = 200;
                this.timer1.Enabled  = true;
                // Set the AI object
                AI = FSUIPCConnection.AITrafficServices;
            }
            catch (Exception ex)
            {
                // Badness occurred - show the error message
                MessageBox.Show(ex.Message, AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                FSUIPCConnection.Close();
                Debug.WriteLine(ex.Message);
            }

            if (simconnect == null)
            {
                try
                {
                    // the constructor is similar to SimConnect_Open in the native API
                    // the ConfigIndex enables you to choose which Simconnect profile to use (in a SimConnect.cfg) if you are
                    // connecting over a network. Leaving it to zero for a local connection here.
                    simconnect = new SimConnect("C# Monitoring AI Objects", this.Handle, WM_USER_SIMCONNECT, null, 0);

                    // setButtons(false, true, true);

                    initDataRequest();
                }
                catch
                {
                    MessageBox.Show("Make sure Microsoft ESP is running and that you have the SimConnect client installed.", "Unable to connect to ESP");
                }
            }

            // Store the current object type being monitored
            monitoredObjectType = SIMCONNECT_SIMOBJECT_TYPE.AIRCRAFT;

            // Refresh the list of monitored objects for this specific request
            // first, Clear any current objects and stop all data requests for those objects
            ResetDataAndShutDownRequests();

            // Now, Initiate a request for the list of objects we are interested in monitoring in the given radius
            simconnect.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_AI_OBJECT_ID_BYTYPE,
                                                  DEFINITIONS.AI_Entity_Definition, MONITOR_RADIUS, monitoredObjectType);
        }
Ejemplo n.º 2
0
        public static async Task <T> RequestDataOnSimObjectType(
            uint radius = 0,
            SIMCONNECT_SIMOBJECT_TYPE type = SIMCONNECT_SIMOBJECT_TYPE.USER)
        {
            TaskCompletionSource <T> task = new TaskCompletionSource <T>();

            tasks.Add(task.Task.Id, task);
            FSX.Sim.
            RequestDataOnSimObjectType(
                (REQUESTS)task.Task.Id,
                (DEFINITIONS)FSX.typeMap[typeof(T)],
                radius,
                type);

            T result = await task.Task;

            tasks.Remove(task.Task.Id);
            return(result);
        }
Ejemplo n.º 3
0
        public void OnTick(SIMCONNECT_SIMOBJECT_TYPE simObjectType)
        {
            if (_simConnect == null)
            {
                return;
            }

            _simConnect.ReceiveMessage();

            foreach (SimVarRequest simVarRequest in _simVarRequests)
            {
                if (!simVarRequest.Pending)
                {
                    _simConnect.RequestDataOnSimObjectType((eDummy)simVarRequest.Request, (eDummy)simVarRequest.Def, 0, simObjectType);
                    simVarRequest.Pending = true;
                }
                else
                {
                    simVarRequest.StillPending = true;
                }
            }
        }
Ejemplo n.º 4
0
        public void RequestDataOnSimObjectType(uint request, uint definition, uint radiusMeters, SIMCONNECT_SIMOBJECT_TYPE type)
        {
            if (simConnect == null)
            {
                return;
            }

            radiusMeters = Math.Min(200_000, radiusMeters);

            simConnect.RequestDataOnSimObjectType((REQUEST)request, (DEFINITION)definition, radiusMeters, type);
        }