Esempio n. 1
0
        void fsdSession_PilotPositionReceived(object sender, DataReceivedEventArgs <PDUPilotPosition> e)
        {
            var msg = new TrafficPositionReportMessage()
            {
                ReceiveTime = DateTime.Now, Sender = e.PDU.From, TrueAltitude = e.PDU.TrueAltitude, PressureAltitude = e.PDU.PressureAltitude, BankAngle = e.PDU.Bank, Groundspeed = e.PDU.GroundSpeed, Heading = e.PDU.Heading, Latitude = e.PDU.Lat, Longitude = e.PDU.Lon, Pitch = e.PDU.Pitch
            };

            Logger.Info(string.Format("Pilot pos received: Lat, Long: {0},{1}, GS: {2}, hdg: {3} dgr ({8} rad), bank: {4}, pitch: {5}, press.alt: {6}, truealt: {7}", e.PDU.Lat.ToString("####0.00000000"), e.PDU.Lon.ToString("####0.00000000"), e.PDU.GroundSpeed, e.PDU.Heading, e.PDU.Bank, e.PDU.Pitch, e.PDU.PressureAltitude, e.PDU.TrueAltitude, e.PDU.Heading * (Math.PI / 180.0)));
            broker.Publish(msg);
        }
        public void TestReceiveSubscribedMultipleReceivers()
        {
            var msg = new TrafficPositionReportMessage()
            {
                TrueAltitude = 1234
            };

            var handler1 = new Mock <IVSPCMessageHandler>();
            var handler2 = new Mock <IVSPCMessageHandler>();

            broker.Subscribe(handler1.Object, typeof(TrafficPositionReportMessage));
            broker.Subscribe(handler2.Object, typeof(TrafficPositionReportMessage));
            broker.Publish(msg);
            handler1.Verify(h => h.HandleMessage(msg, context), Times.Once());
            handler2.Verify(h => h.HandleMessage(msg, context), Times.Once());
        }
Esempio n. 3
0
        private void UpdateExisitingAIData(TrafficPositionReportMessage msg)
        {
            var AIAircraft = CallsignToAIPlaneMap[msg.Sender];

            // Sync AI data for this airplane with receival of position reports, 1) Cancel it 2) Restart it
            // simconnect.RequestDataOnSimObject((SIMCONNECT_EVENTS)((uint)SIMCONNECT_EVENTS.EVENTID_POSITIONREPORT_FOR_AIUPDATE + AIAircraft.AICounter), DEFINITIONS.AIPositionUpdateStruct, AIAircraft.SimConnectObjectId, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, uint.MaxValue, uint.MaxValue, 0);
            AIAircraft.SetTargetWaypoint(CreateWaypointFromTrafficPositionReportMsg(msg));
            // simconnect.RequestDataOnSimObject((SIMCONNECT_EVENTS)((uint)SIMCONNECT_EVENTS.EVENTID_POSITIONREPORT_FOR_AIUPDATE + AIAircraft.AICounter), DEFINITIONS.AIPositionUpdateStruct, AIAircraft.SimConnectObjectId, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 1, 0);

            // Nothing more to do here, the next AI position update event from SimConnect will use the new waypoint
        }
Esempio n. 4
0
        private void HandleTrafficPositionReport(TrafficPositionReportMessage trafficPositionReportMessage)
        {
            var origCallsign = trafficPositionReportMessage.Sender;

            // for (int i = 1; i < 10; i++)
            {
                // trafficPositionReportMessage.Sender = origCallsign + ("-" + i);
                // trafficPositionReportMessage.Longitude += 0.0003;

                if (CallsignToAIPlaneMap.ContainsKey(trafficPositionReportMessage.Sender))
                {
                    UpdateExisitingAIData(trafficPositionReportMessage);
                }
                else
                {
                    CreateNewAIAircraft(trafficPositionReportMessage);

                }
            }
        }
Esempio n. 5
0
        private void CreateNewAIAircraft(TrafficPositionReportMessage trafficPositionReportMessage)
        {
            uint counter;

            lock (AICounterLock)
            {
                counter = AICounter++;
            }

            AICounterToCallsignMap.Add(counter, trafficPositionReportMessage.Sender);

            try
            {
                // TODO: OnGround + airspeed
                var initpos = new SIMCONNECT_DATA_INITPOSITION()
                {
                    Altitude = trafficPositionReportMessage.TrueAltitude,
                    Bank = -trafficPositionReportMessage.BankAngle,
                    Heading = trafficPositionReportMessage.Heading,
                    Latitude = trafficPositionReportMessage.Latitude,
                    Longitude = trafficPositionReportMessage.Longitude,
                    Pitch = -trafficPositionReportMessage.Pitch,
                    OnGround = 1,
                    Airspeed = 0
                };

                simconnect.AICreateNonATCAircraft(GetRepaintTitle(),  trafficPositionReportMessage.Sender, initpos, (SIMCONNECT_EVENTS)((uint)SIMCONNECT_EVENTS.EVENTID_SETAIAC + counter));
                // simconnect.AICreateSimulatedObject(GetRepaintTitle(), initpos, (SIMCONNECT_EVENTS)((uint)SIMCONNECT_EVENTS.EVENTID_SETAIAC + counter));

                var aiplane = new AIPlane(trafficPositionReportMessage.Sender);
                aiplane.SetTargetWaypoint(CreateWaypointFromTrafficPositionReportMsg(trafficPositionReportMessage));
                aiplane.AICounter = counter;
                CallsignToAIPlaneMap.Add(aiplane.Callsign, aiplane);
            }
            catch (COMException e)
            {
                Logger.Error("SimConnectInterface.CreateNewAIAircraft: " + e);
            }
        }
Esempio n. 6
0
 public static Waypoint CreateWaypointFromTrafficPositionReportMsg(TrafficPositionReportMessage msg)
 {
     var currentWp = new Waypoint()
     {
         Altitude = msg.TrueAltitude,
         Bank = SimMath.deg2rad(-msg.BankAngle),
         Heading = SimMath.deg2rad(msg.Heading),
         Latitude = msg.Latitude,
         Longitude = msg.Longitude,
         Pitch = SimMath.deg2rad(-msg.Pitch),
         GroundSpeed = SimMath.knotsToMetersPerSecond(msg.Groundspeed),
         Timestamp = msg.ReceiveTime
     };
     return currentWp;
 }
Esempio n. 7
0
 void fsdSession_PilotPositionReceived(object sender, DataReceivedEventArgs<PDUPilotPosition> e)
 {
     var msg = new TrafficPositionReportMessage() { ReceiveTime = DateTime.Now, Sender = e.PDU.From, TrueAltitude = e.PDU.TrueAltitude, PressureAltitude = e.PDU.PressureAltitude, BankAngle = e.PDU.Bank, Groundspeed = e.PDU.GroundSpeed, Heading = e.PDU.Heading, Latitude = e.PDU.Lat, Longitude = e.PDU.Lon, Pitch = e.PDU.Pitch };
     Logger.Info(string.Format("Pilot pos received: Lat, Long: {0},{1}, GS: {2}, hdg: {3} dgr ({8} rad), bank: {4}, pitch: {5}, press.alt: {6}, truealt: {7}", e.PDU.Lat.ToString("####0.00000000"), e.PDU.Lon.ToString("####0.00000000"), e.PDU.GroundSpeed, e.PDU.Heading, e.PDU.Bank, e.PDU.Pitch, e.PDU.PressureAltitude, e.PDU.TrueAltitude, e.PDU.Heading * (Math.PI / 180.0)));
     broker.Publish(msg);
 }