Beispiel #1
0
        public void HandleMessage(AMessage message, VSPCContext context)
        {
            var textMessage = (ATextMessage)message;
            bool messageShown = false;

            mainWindow.DoInUIThread(() =>
                {
                    foreach (var ccTab in mainWindow.CommChannelTabs.Where(t => !t.IsAllTab))
                    {
                        if (ccTab.MessageBelongsToMe(textMessage, context.Callsign))
                        {
                            messageShown |= (!ccTab.IsAllTab || textMessage.SenderIsServer); // Only mark message as shown if the message is shown in a tab other than "All" with server messages as exception
                            ccTab.ShowMessage(textMessage);
                        }
                    }
                    if (!messageShown && NewTabShouldBeOpened(textMessage, context))
                    {
                        CommChannelTab newCommTab = mainWindow.AddNewCommTab(textMessage.Sender);
                        newCommTab.ShowMessage(textMessage);
                        messageShown = true;
                    }

                    var allTab = mainWindow.CommChannelTabs.Single(t => t.IsAllTab);
                    if (messageShown || textMessage.SenderIsServer)
                        allTab.ShowMessage(textMessage);
                });
        }
Beispiel #2
0
 public void HandleMessage(AMessage message, VSPCContext context)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new InvokeDelegate(() => HandleMessage(message, context)));
     }
     else
     {
         textBoxMessages.Text += message.ToString() + Environment.NewLine;
     }
 }
Beispiel #3
0
 private void Connect(UserClickedLoginMessage msg, VSPCContext context)
 {
     this.context = context;
     fsdSession = new FSDSession(new ClientProperties("Claus Joergensen Client", new Version(1, 0), 0x5820, "163f6a324730ed0aa1ba30b29148687c"), msg);
     fsdSession.ServerIdentificationReceived += fsdSession_ServerIdentificationReceived;
     fsdSession.ClientQueryReceived += fsdSession_ClientQueryReceived;
     fsdSession.TextMessageReceived += fsdSession_TextMessageReceived;
     fsdSession.ATCPositionReceived += fsdSession_ATCPositionReceived;
     fsdSession.PilotPositionReceived += fsdSession_PilotPositionReceived;
     fsdSession.NetworkError += fsdSession_NetworkError;
     fsdSession.ProtocolErrorReceived += fsdSession_ProtocolErrorReceived;
     fsdSession.KillRequestReceived += fsdSession_KillRequestReceived;
     fsdSession.IgnoreUnknownPackets = true;
     fsdSession.Connect(msg.Server, 6809);
 }
Beispiel #4
0
        public void HandleMessage(Core.Messages.AMessage message, VSPCContext context)
        {
            if (message is TrafficPositionReportMessage && isSavingPosRepMessages)
            {
                var tp = (TrafficPositionReportMessage)message;
                saveFile.WriteLine(string.Format("{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}",
                    tp.Latitude,
                    tp.Longitude,
                    tp.TrueAltitude,
                    tp.PressureAltitude,
                    tp.Groundspeed,
                    tp.Heading,
                    tp.BankAngle,
                    tp.Pitch));

            }
            DoInUIThread(() => FSDMessages.Add((AFSDMessage)message));
        }
Beispiel #5
0
 public override void HandleMessage(AMessage message, VSPCContext context)
 {
     if (message is UserClickedLoginMessage)
         Connect((UserClickedLoginMessage)message, context);
     else if (message is UserClickedLogoffMessage)
         Disconnect((UserClickedLogoffMessage)message, context);
     else if (message is PositionReportMessage)
         SendPositionReportToFSDServer((PositionReportMessage)message, context);
     else if (message is ErrorMessage)
         Logger.Error("FSD Error received: {0} {1} {2}", ((ErrorMessage)message).ErrorCode, ((ErrorMessage)message).ErrorInfo, ((ErrorMessage)message).ErrorText);
     else if (message is VSPC.Core.Messages.FLSIM.FlightsimConnectedMessage)
         context.FlightsimIsConnected = true;
     else if (message is VSPC.Core.Messages.FLSIM.FlightsimDisconnectedMessage)
         context.FlightsimIsConnected = false;
     else if (message is TextMessageSend)
         SendTextMessage((TextMessageSend)message);
     else
         Logger.Error("Unexpected message type received in FSDMessageHandler: " + message.GetType().Name);
 }
Beispiel #6
0
        // Set up all the SimConnect related event handlers
        private void InitSimConnect(VSPCContext context)
        {
            try
            {
                if (simconnect == null)
                {
                    try
                    {
                        Logger.Trace("Connecting to FSX...");
                        simconnect = new SimConnect("Managed Client Events", hWnd, WM_USER_SIMCONNECT, null, 0);
                        Logger.Trace("Connection established");
                    }
                    catch (COMException ex)
                    {
                        Logger.Error("Unable to connect to FSX: " + ex);
                        throw;
                    }
                }

                // listen to connect and quit msgs
                simconnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
                simconnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);

                // listen to exceptions
                simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);

                // define a data structure for position reports for own plane
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "Pressure Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "Ground Velocity", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "PLANE PITCH DEGREES", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "PLANE BANK DEGREES", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "PLANE HEADING DEGREES TRUE", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                // simconnect.AddToDataDefinition(DEFINITIONS.PositionReportStruct, "TRANSPONDER CODE:1", "", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.RegisterDataDefineStruct<PositionReportStruct>(DEFINITIONS.PositionReportStruct);

                // define a data structure for updating position of AI planes
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "Ground Velocity", "knots", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "Plane Pitch Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "PLANE BANK DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "PLANE HEADING DEGREES TRUE", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "SIM ON GROUND", "", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIPositionUpdateStruct, "PLANE ALT ABOVE GROUND", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                //simconnect.AddToDataDefinition(DEFINITIONS.PositionUpdateStruct, "TRANSPONDER CODE:1", "", SIMCONNECT_DATATYPE.INT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);

                simconnect.RegisterDataDefineStruct<AIPositionReportStruct>(DEFINITIONS.AIPositionUpdateStruct);

                // define a data structure for moving AI
                simconnect.AddToDataDefinition(DEFINITIONS.AIMoveStruct, "Plane Latitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIMoveStruct, "Plane Longitude", "degrees", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIMoveStruct, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIMoveStruct, "Plane Pitch Degrees", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIMoveStruct, "PLANE BANK DEGREES", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.AddToDataDefinition(DEFINITIONS.AIMoveStruct, "PLANE HEADING DEGREES TRUE", "radians", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.RegisterDataDefineStruct<AIMoveStruct>(DEFINITIONS.AIMoveStruct);

                simconnect.AddToDataDefinition(DEFINITIONS.AISetAltAboveGroundStruct, "Plane alt above ground", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
                simconnect.RegisterDataDefineStruct<AIAltAboveGroundStruct>(DEFINITIONS.AISetAltAboveGroundStruct);

                // catch a simobject data request
                simconnect.OnRecvSimobjectData += new SimConnect.RecvSimobjectDataEventHandler(simconnect_OnRecvSimobjectData);
                simconnect.RequestDataOnSimObject(SIMCONNECT_EVENTS.EVENTID_POSITIONREPORT, DEFINITIONS.PositionReportStruct, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.DEFAULT, 0, 5, 0);

                // catch the assigned object IDs
                simconnect.OnRecvAssignedObjectId += new SimConnect.RecvAssignedObjectIdEventHandler(simconnect_OnRecvAssignedObjectId);

                // client event id's
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_SLEW_ON, "SLEW_ON");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_AXIS_SLEW_HEADING_SET, "AXIS_SLEW_HEADING_SET");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_AXIS_SLEW_ALT_SET, "AXIS_SLEW_ALT_SET");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_AXIS_SLEW_BANK_SET, "AXIS_SLEW_BANK_SET");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_AXIS_SLEW_PITCH_SET, "AXIS_SLEW_PITCH_SET");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_AXIS_SLEW_AHEAD_SET, "AXIS_SLEW_AHEAD_SET");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_SLEW_RESET, "SLEW_RESET");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_STROBES_ON, "STROBES_ON");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_TOGGLE_BEACON_LIGHTS, "TOGGLE_BEACON_LIGHTS");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_TOGGLE_TAXI_LIGHTS, "TOGGLE_TAXI_LIGHTS");
                simconnect.MapClientEventToSimEvent(SIMCONNECT_EVENTS.EVENTID_TOGGLE_WING_LIGHTS, "TOGGLE_WING_LIGHTS");
            }
            catch (COMException ex)
            {
                Logger.Error(ex.Message);
                broker.Publish(new SimCommErrorMessage());
            }
        }
Beispiel #7
0
 public override void HandleMessage(Core.Messages.AMessage message, VSPCContext context)
 {
     if (message is UserClickedLoginMessage)
         InitSimConnect(context);
     else if (message is UserClickedLogoffMessage)
         CloseConnection();
     else if (message is TrafficPositionReportMessage)
         HandleTrafficPositionReport((TrafficPositionReportMessage)message);
     else
         Logger.Error("Unexpected message type received in SimConnectInterface: " + message.GetType().Name);
 }
Beispiel #8
0
 public void HandleMessage(Core.Messages.AMessage message, VSPCContext context)
 {
     if (message is FlightsimConnectedMessage)
     {
         FlightsimState = ConnectionState.Online;
         if (FSDState == ConnectionState.Online) SwitchToOnlineMode();
     }
     else if (message is FSDConnectedMessage)
     {
         FSDState = ConnectionState.Online;
         if (FlightsimState == ConnectionState.Online) SwitchToOnlineMode();
     }
     else if (message is FlightsimDisconnectedMessage)
     {
         FlightsimState = ConnectionState.Offline;
         if (FSDState == ConnectionState.Offline) SwitchToOfflineMode();
     }
     else if (message is FSDDisconnectedMessage)
     {
         FSDState = ConnectionState.Offline;
         if (FlightsimState == ConnectionState.Offline) SwitchToOfflineMode();
     }
     else if (message is CommErrorMessage)
         HandleCommErrorMessage((CommErrorMessage)message);
     else if (message is SimCommErrorMessage)
         HandleCommErrorMessage((SimCommErrorMessage)message);
     else if (message is TextMessageReceive)
         HandleTextMessageReceive((TextMessageReceive)message);
 }
Beispiel #9
0
 private bool NewTabShouldBeOpened(ATextMessage textMessage, VSPCContext context)
 {
     return !textMessage.SenderIsServer && textMessage.Receiver == context.Callsign;
 }
Beispiel #10
0
 private void Disconnect(UserClickedLogoffMessage msg, VSPCContext context)
 {
     context.FSDIsConnected = false;
     fsdSession.SendPDU(new PDUDeletePilot(msg.Callsign, context.CID));
     fsdSession.Disconnect();
     broker.Publish(new FSDDisconnectedMessage());
 }
Beispiel #11
0
 private void SendPositionReportToFSDServer(PositionReportMessage positionReportMessage, VSPCContext context)
 {
     if (context.FSDIsConnected && fsdSession.Connected)
         // TODO: TrueAlt + PressureAlt
         fsdSession.SendPDU(new PDUPilotPosition(context.Callsign, positionReportMessage.Transponder, positionReportMessage.SquawkingCharlie, positionReportMessage.Identing, NetworkRating.OBS, positionReportMessage.Latitude, positionReportMessage.Longitude, (int)Math.Round(positionReportMessage.TrueAltitude), (int)Math.Round(positionReportMessage.PressureAltitude), (int)Math.Round(positionReportMessage.Groundspeed), (int)Math.Round(positionReportMessage.Pitch), (int)Math.Round(positionReportMessage.Bank), (int)Math.Round(positionReportMessage.Heading)));
 }