Example #1
0
        private void buttonSetUserLocation_Click(object sender, EventArgs e)
        {
            // Update the user location to the same lat/lon at the ai object we create
            PositionData initPositionData;

            initPositionData.latitude  = 47.4315501972979;
            initPositionData.longitude = -122.308007293086;
            initPositionData.altitude  = 0;
            initPositionData.heading   = 360.0;
            initPositionData.pitch     = 0;
            initPositionData.bank      = 0;

            // Set the user aircraft location.
            simconnect.SetDataOnSimObject(DEFINITIONS.PositionData, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, initPositionData);
        }
Example #2
0
        private void simconnect_OnRecvSimObjectData(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA data)
        {
            switch ((DATA_REQUESTS)data.dwRequestID)
            {
            case DATA_REQUESTS.REQUEST_PLAYER_UPDATE_AND_ATTACH:
                AirplaneData dt = (AirplaneData)data.dwData[0];
                dt.desired = 0;
                simconnect.SetDataOnSimObject(DEFINITIONS.AirplaneData, towplaneid, 0, dt);
                break;

            default:
                MessageBox.Show("Unknown Request ID " + data.dwRequestID);
                break;
            }
        }
Example #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            deadman++;
            // Deadman timer is reset when when new input is received; if no input is received then stop sending old data and pass control back to joystock
            if (deadman > 15)
            {
                return;
            }

            // Set the aileron, elevator, throttle, and rudder positions
            simconnect.SetDataOnSimObject(DEFINITIONS.StructAil, SimConnect.SIMCONNECT_OBJECT_ID_USER, 0, sa);
            simconnect.SetDataOnSimObject(DEFINITIONS.StructEle, SimConnect.SIMCONNECT_OBJECT_ID_USER, 0, se);
            simconnect.SetDataOnSimObject(DEFINITIONS.StructThrottle, SimConnect.SIMCONNECT_OBJECT_ID_USER, 0, st);
            simconnect.SetDataOnSimObject(DEFINITIONS.StructRudder, SimConnect.SIMCONNECT_OBJECT_ID_USER, 0, sr);
        }
Example #4
0
 public void Teleport(double latitude, double longitude, double altitude)
 {
     simconnect.SetDataOnSimObject(DEFINITIONS.AircraftPosition, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT,
                                   new AircraftPositionStruct {
         Latitude = latitude, Longitude = longitude, Altitude = altitude
     });
 }
Example #5
0
 public void Init(AircraftPositionStruct position)
 {
     logger.LogDebug("Set initial position");
     simconnect.SetDataOnSimObject(DEFINITIONS.AircraftPositionInitial, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT,
                                   new SIMCONNECT_DATA_INITPOSITION
     {
         Latitude  = position.Latitude,
         Longitude = position.Longitude,
         Altitude  = position.Altitude,
         Pitch     = position.Pitch,
         Bank      = position.Bank,
         Heading   = position.TrueHeading,
         OnGround  = position.IsOnGround,
         Airspeed  = 0
     });
 }
        public void stop(SimConnect connection)
        {
            startStruct start = new startStruct(registration, 1);

            connection.SetDataOnSimObject(DATA_DEF.AIRCRAFT_START, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, start);
            connection.RequestDataOnSimObject(DATA_REQUESTID.FLIGHT_DATA, DATA_DEF.FLIGHT_DATA, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.NEVER, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 0, 0);
        }
        public void start(SimConnect connection)
        {
            connection.SetDataOnSimObject(DATA_DEF.AIRCRAFT_FUEL, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, fuelState);

            int payloadPerStation = (int)(payloadWeight / aircraft.specifications.numPayloadStations);

            for (int c = 0; c < aircraft.specifications.numPayloadStations; c++)
            {
                setPayloadStation(connection, c + 1, payloadPerStation);
            }

            startStruct start = new startStruct(registration, 0);

            connection.SetDataOnSimObject(DATA_DEF.AIRCRAFT_START, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, start);
            connection.RequestDataOnSimObject(DATA_REQUESTID.FLIGHT_DATA, DATA_DEF.FLIGHT_DATA, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 0, 0);
        }
Example #8
0
        public void setFail(SimConnect sc)
        {
            Console.WriteLine(sName + failureValue);
            switch (possibleType)
            {
            case POSSIBLE_FAIL_TYPE.STUCK:
            {
                if (!failStart)
                {
                    failureValue = dValue;
                    Console.WriteLine("start" + failureValue);
                    failStart = true;
                }
                dValue = failureValue;
                break;
            }

            case POSSIBLE_FAIL_TYPE.LEAK:
            {
                dValue -= failureValue;
                break;
            }

            case POSSIBLE_FAIL_TYPE.CONTINOUS:
            {
                if (isEvent)
                {
                    if (rnd.Next(11) >= 5)
                    {
                        sc.MapClientEventToSimEvent(eEvent, sName);
                        sc.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, eEvent, 0, GROUP.ID_PRIORITY_STANDARD, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
                    }
                }
                else
                {
                    dValue = failureValue;
                }
                break;
            }

            case POSSIBLE_FAIL_TYPE.COMPLETE:
            {
                if (isEvent)
                {
                    sc.MapClientEventToSimEvent(eEvent, sName);
                    sc.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, eEvent, 0, GROUP.ID_PRIORITY_STANDARD, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
                }
                else
                {
                    dValue = failureValue;
                }

                done = true;
                break;
            }
            }

            sc.SetDataOnSimObject(eDef, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dValue);
        }
Example #9
0
        private void PollThread()
        {
            double[] prevs  = { 0, 0, 0 };
            bool[]   hasNew = { false, false, false };

            while (continuePolling)
            {
                double[] joyStickAmounts = NXTcontroller.getAxisPositions();
                Console.WriteLine("Throttle is at: " + joyStickAmounts[0] + ", Pitch: " + joyStickAmounts[1] + ", Yaw: " + joyStickAmounts[2]);

                for (int i = 0; i < 2; i++)
                {
                    if (joyStickAmounts[i] != -1 && prevs[i] != joyStickAmounts[i])
                    {
                        hasNew[i] = true;
                    }
                }
                if (hasNew[0])
                {
                    StructPlaneThrottle planeThrottle = new StructPlaneThrottle()
                    {
                        ENG1 = joyStickAmounts[0],
                        ENG2 = joyStickAmounts[0]
                    };
                    if (connectedToSim)
                    {
                        simConnect.SetDataOnSimObject(DEFINITIONS.PlaneThrottle, 1, SIMCONNECT_DATA_SET_FLAG.DEFAULT, planeThrottle);
                        prevs[0] = joyStickAmounts[0];
                    }
                }
                if (hasNew[1] || hasNew[2])
                {
                    StructPlanePitchYaw planePY = new StructPlanePitchYaw {
                        ELEVATOR = joyStickAmounts[1],
                        AILERON  = joyStickAmounts[2]
                    };
                    if (connectedToSim)
                    {
                        simConnect.SetDataOnSimObject(DEFINITIONS.PlanePitchYaw, 1, SIMCONNECT_DATA_SET_FLAG.DEFAULT, planePY);
                        prevs[1] = joyStickAmounts[1];
                        prevs[2] = joyStickAmounts[2];
                    }
                }
                Thread.Sleep(2);
            }
        }
Example #10
0
 public void SetData(DefinitionsEnum definition, object data)
 {
     if (!Connected)
     {
         return;
     }
     simClient.SetDataOnSimObject(definition, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, data);
 }
        void setPayloadStation(SimConnect connection, int station, int weight)
        {
            payloadStruct payload = new payloadStruct(weight);

            connection.ClearDataDefinition(DATA_DEF.AIRCRAFT_PAYLOAD);
            connection.AddToDataDefinition(DATA_DEF.AIRCRAFT_PAYLOAD, String.Format("Payload station weight:{0}", station), "kg", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            connection.SetDataOnSimObject(DATA_DEF.AIRCRAFT_PAYLOAD, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, payload);
        }
        private void TrySetValue()
        {
            Console.WriteLine("TrySetValue");

            if (m_oSelectedSimvarRequest != null && m_sSetValue != null)
            {
                double dValue = 0.0;
                if (double.TryParse(m_sSetValue, NumberStyles.Any, null, out dValue))
                {
                    m_oSimConnect.SetDataOnSimObject(m_oSelectedSimvarRequest.eDef, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, dValue);
                }
            }
        }
Example #13
0
        public void SetValue(string simvar, string unit, double value)
        {
            var request = _simVarRequests.Find(x => (x.Name == simvar));

            if (request == null)
            {
                request = AddRequest(simvar, unit);
            }

            Console.WriteLine("Setting " + simvar + " to value: " + value);

            _simConnect.SetDataOnSimObject(request.Def, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, value);
        }
Example #14
0
        private void buttonLights_Click(object sender, EventArgs e)
        {
            if (MauleID != 0)
            {
                // Toggle the lights
                mauleLights.lightStates = (mauleLights.lightStates == 0) ? uint.MaxValue : 0;

                simconnect.SetDataOnSimObject(DEFINITIONS.MauleLights, MauleID, 0, mauleLights.lightStates);

                if (mauleLights.lightStates != 0)
                {
                    displayText("Lights on requested...");
                }
                else
                {
                    displayText("Lights off requesteed...");
                }
            }
            else
            {
                displayText("Maule M7 ID not set!");
            }
        }
Example #15
0
        private void SendToFSX(double aileron, double rudder, double elevator, double throttle, int gear, int flaps)
        {
            FsDataObjects.ControlDataStructure controls;
            controls.elevator  = elevator;
            controls.aileron   = aileron;
            controls.rudder    = rudder;
            controls.throttle1 = throttle * 100;
            controls.throttle2 = throttle * 100;
            controls.throttle3 = throttle * 100;
            controls.throttle4 = throttle * 100;

            simconnect.SetDataOnSimObject(FsDataObjects.DEFINITIONS.ControlDataStruct, SimConnect.SIMCONNECT_OBJECT_ID_USER, 0, controls);

            ControlsLatest = controls;

            if (gear != gear_last)
            {
                gear_last = gear;

                FsDataObjects.EVENTS g_state = (gear == 1) ? FsDataObjects.EVENTS.GEAR_UP : FsDataObjects.EVENTS.GEAR_DOWN;

                simconnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, g_state, 0, FsDataObjects.NOTIFICATION_GROUPS.GROUP0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }

            if (flaps != flaps_last)
            {
                flaps_last = flaps;

                FsDataObjects.EVENTS f_state = FsDataObjects.EVENTS.FLAPS0;

                if (flaps == 0)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS0;
                }
                else if (flaps == 1)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS1;
                }
                else if (flaps == 2)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS2;
                }

                play_flap = true;

                simconnect.TransmitClientEvent(SimConnect.SIMCONNECT_OBJECT_ID_USER, f_state, 0, FsDataObjects.NOTIFICATION_GROUPS.GROUP0, SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }
        }
        /// <summary>
        /// Set the value associated with a SimVar
        /// </summary>
        /// <param name="simVarValue">SimVar and associated value</param>
        public static int SetSimVar(SimConnectVariableValue simVarValue)
        {
            WriteLog("Start SetSimVar(SimConnectVariableValue)");
            // As for requests, setting values is a 2-step process, reserve the data area,then modify the data it holds
            GetSimVar(simVarValue.Request);

            var reqId = GetRequestId(simVarValue.Request);

            if (reqId > -1)
            {
                // Data area reserved, now set the value
                simConnect.SetDataOnSimObject((SIMVARDEFINITION)reqId, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, simVarValue.Value);
                //simConnect.SetDataOnSimObject((SIMVARDEFINITION)reqId, (uint)reqId, (SIMCONNECT_DATA_SET_FLAG)SimConnect.SIMCONNECT_OBJECT_ID_USER, simVarValue.Value);
            }
            WriteLog("End SetSimVar(SimConnectVariableValue)");
            return(reqId);
        }
 void send()
 {
     Console.WriteLine(log.Count);
     if (log.Count > 0)
     {
         var state   = log.First();
         var control = new Control1();
         control.aileron             = state.aileron;
         control.elevator            = state.elevator;
         control.flaps_handle_ind    = state.flaps_handle_ind;
         control.spoilers_handle_ind = state.spoilers_handle_ind;
         control.rudder = state.rudder;
         control.General_Eng_Throttle_Lever_Position_1 = state.General_Eng_Throttle_Lever_Position_1;
         control.General_Eng_Throttle_Lever_Position_2 = state.General_Eng_Throttle_Lever_Position_1;
         simconnect.SetDataOnSimObject(DEFINITIONS.Control1, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, control);
         log.RemoveAt(0);
     }
 }
        /// <summary>
        /// Set the value associated with a SimVar
        /// </summary>
        /// <param name="simVarValue">SimVar and associated value</param>
        public static int SetSimVar(SimConnectVariableValue simVarValue, bool disableAI = false)
        {
            WriteLog("Start SetSimVar(SimConnectVariableValue)");
            // As for requests, setting values is a 2-step process, reserve the data area,then modify the data it holds
            GetSimVar(simVarValue.Request);

            var reqId = GetRequestId(simVarValue.Request);

            if (reqId > -1)
            {
                if (disableAI)
                {
                    // We shall assume all SimVar updates will be in relation to the user's aircraft
                    DisableAI(reqId);
                }
                // Data area reserved, now set the value
                simConnect.SetDataOnSimObject((SIMVARDEFINITION)reqId, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, simVarValue.Value);
                //simConnect.SetDataOnSimObject((SIMVARDEFINITION)reqId, (uint)reqId, (SIMCONNECT_DATA_SET_FLAG)SimConnect.SIMCONNECT_OBJECT_ID_USER, simVarValue.Value);
            }
            WriteLog("End SetSimVar(SimConnectVariableValue)");
            return(reqId);
        }
Example #19
0
 /// <summary>
 /// See interface docs.
 /// </summary>
 /// <param name="defineID"></param>
 /// <param name="objectID"></param>
 /// <param name="flags"></param>
 /// <param name="data"></param>
 public void SetDataOnSimObject(Enum defineID, uint objectID, int flags, object data)
 {
     _SimConnect.SetDataOnSimObject(defineID, objectID, (SIMCONNECT_DATA_SET_FLAG)flags, data);
 }
Example #20
0
 public void Set(AircraftPositionSetStruct position)
 {
     simconnect.SetDataOnSimObject(DEFINITIONS.AircraftPositionSet, 0, SIMCONNECT_DATA_SET_FLAG.DEFAULT, position);
 }
Example #21
0
        /// <summary>
        /// Sends the input parameters to FSX
        /// </summary>
        /// <param name="aileron">An aileron input in percent, between -1 and 1</param>
        /// <param name="rudder">An rudder input in percent, between -1 and 1</param>
        /// <param name="elevator">An elevator input in percent, between -1 and 1</param>
        /// <param name="throttle">An throttle input in percent, between 0 and 1</param>
        /// <param name="gear">The landing gear status, 0 being down and 1 being up</param>
        /// <param name="flaps">The flap status, with 0 being up, 1 being halfway, and 2 being down</param>
        private void SendToFSX(
            double aileron,
            double rudder,
            double elevator,
            double throttle,
            int gear,
            int flaps)
        {
            // Skip if not connected
            if (simconnect == null)
            {
                return;
            }

            // Set the data in the control data structure
            FsDataObjects.ControlDataStructure controls;
            controls.elevator  = elevator;
            controls.aileron   = aileron;
            controls.rudder    = rudder;
            controls.throttle1 = throttle * 100;
            controls.throttle2 = throttle * 100;
            controls.throttle3 = throttle * 100;
            controls.throttle4 = throttle * 100;

            // Set the data in the simconnect object
            simconnect.SetDataOnSimObject(
                FsDataObjects.DEFINITIONS.ControlDataStruct,
                SimConnect.SIMCONNECT_OBJECT_ID_USER,
                0,
                controls);

            // Save the latest controls parameters
            ControlsLatest = controls;

            // Transmit the gear state if it is different from the last gear state
            if (gear != gear_last)
            {
                gear_last = gear;

                FsDataObjects.EVENTS g_state = (gear == 1) ? FsDataObjects.EVENTS.GEAR_UP : FsDataObjects.EVENTS.GEAR_DOWN;

                simconnect.TransmitClientEvent(
                    SimConnect.SIMCONNECT_OBJECT_ID_USER,
                    g_state,
                    0,
                    FsDataObjects.NOTIFICATION_GROUPS.GROUP0,
                    SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }

            // Transmit the flaps state if it is different from the last flaps state
            if (flaps != flaps_last)
            {
                flaps_last = flaps;

                FsDataObjects.EVENTS f_state = FsDataObjects.EVENTS.FLAPS0;

                if (flaps == 0)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS0;
                }
                else if (flaps == 1)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS1;
                }
                else if (flaps == 2)
                {
                    f_state = FsDataObjects.EVENTS.FLAPS2;
                }

                simconnect.TransmitClientEvent(
                    SimConnect.SIMCONNECT_OBJECT_ID_USER,
                    f_state,
                    0,
                    FsDataObjects.NOTIFICATION_GROUPS.GROUP0,
                    SIMCONNECT_EVENT_FLAG.GROUPID_IS_PRIORITY);
            }
        }