public bool Start() { try { xPlaneConnector = new XPlaneConnector.XPlaneConnector( "127.0.0.1", 49000 ); xPlaneConnector.Start(); } catch { return(false); } try { if (configManager.GetConfig().mcdu1Enabled) { mcdu1Client = new TcpClient(); mcdu1Client.Connect( configManager.GetConfig().mcdu1Ip, configManager.GetConfig().mcdu1Port ); mcdu1Thread = new Thread(new McduConnector( ref xPlaneConnector, ref mcdu1Client, ref dataRefManager, 1 ).StartThread); mcdu1Thread.Start(); } if (configManager.GetConfig().mcdu2Enabled) { mcdu2Client = new TcpClient(); mcdu2Client.Connect( configManager.GetConfig().mcdu2Ip, configManager.GetConfig().mcdu2Port ); mcdu2Thread = new Thread(new McduConnector( ref xPlaneConnector, ref mcdu2Client, ref dataRefManager, 2 ).StartThread); mcdu2Thread.Start(); } } catch { return(false); } return(true); }
public McduConnector( ref XPlaneConnector.XPlaneConnector xPlaneConnector, ref TcpClient mcduClient, ref DataRefManager dataRefManager, int mcduNumber ) { this.xPlaneConnector = xPlaneConnector; this.mcduClient = mcduClient; this.dataRefManager = dataRefManager; this.mcduNumber = mcduNumber; }
public XplaneConnectionManager(IEventBroker broker, IAppConfig config, IFsdManger fsdManager) : base(broker) { DealerSocket visualDealerSocket = null; mVisualDealerSockets = null; mConfig = config; mFsdManager = fsdManager; if (mConfig.VisualClientIPs.Count > 0) { foreach (string mIP in mConfig.VisualClientIPs) { visualDealerSocket = new DealerSocket(); visualDealerSocket.Options.Identity = Encoding.UTF8.GetBytes("CLIENT"); visualDealerSocket.Options.TcpKeepalive = true; try { visualDealerSocket.Connect("tcp://" + mIP + ":" + mConfig.TcpPort); if (mVisualDealerSockets == null) { mVisualDealerSockets = new List <DealerSocket>(); } mVisualDealerSockets.Add(visualDealerSocket); } catch (AddressAlreadyInUseException) { NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Plugin port already in use. Please choose a different TCP port.")); } } } if (!string.IsNullOrEmpty(mConfig.SimClientIP)) { mSimulatorIP = mConfig.SimClientIP; } mMessageQueue = new NetMQQueue <string>(); mDealerSocket = new DealerSocket(); mDealerSocket.Options.TcpKeepalive = true; mDealerSocket.Options.Identity = Encoding.UTF8.GetBytes("CLIENT"); mDealerSocket.ReceiveReady += DealerSocket_ReceiveReady; try { mDealerSocket.Connect("tcp://" + mSimulatorIP + ":" + mConfig.TcpPort); } catch (AddressAlreadyInUseException) { NotificationPosted?.Invoke(this, new NotificationPostedEventArgs(NotificationType.Error, "Plugin port already in use. Please choose a different TCP port.")); } mPoller = new NetMQPoller { mDealerSocket, mMessageQueue }; if (!mPoller.IsRunning) { mPoller.RunAsync(); } mMessageQueue.ReceiveReady += (s, e) => { if (mMessageQueue.TryDequeue(out string msg, TimeSpan.FromMilliseconds(100))) { if (mDealerSocket != null) { mDealerSocket.SendFrame(msg); } if (mVisualDealerSockets != null && mVisualDealerSockets.Count > 0) { foreach (DealerSocket socket in mVisualDealerSockets) { socket.SendFrame(msg); } } } }; mXplaneConnector = new XPlaneConnector.XPlaneConnector(mSimulatorIP); mUserAircraftData = new UserAircraftData(); mRadioStackState = new UserAircraftRadioStack(); mGetXplaneDataTimer = new Timer { Interval = 10 }; mGetXplaneDataTimer.Tick += GetXplaneDataTimer_Tick; mGetXplaneDataTimer.Start(); mConnectionTimer = new Timer { Interval = 50 }; mConnectionTimer.Tick += ConnectionTimer_Tick; mConnectionTimer.Start(); mRetryConnectionTimer = new Timer { Interval = 1000 }; mRetryConnectionTimer.Tick += RetryConnectionTimer_Tick; mRetryConnectionTimer.Start(); mWhosOnlineListRefresh = new Timer { Interval = 5000 }; mWhosOnlineListRefresh.Tick += WhosOnlineListRefresh_Tick; SetupSubscribers(); if (!Directory.Exists(Path.Combine(mConfig.AppPath, "PluginLogs"))) { Directory.CreateDirectory(Path.Combine(mConfig.AppPath, "PluginLogs")); } var directory = new DirectoryInfo(Path.Combine(mConfig.AppPath, "PluginLogs")); var query = directory.GetFiles("*", SearchOption.AllDirectories); foreach (var file in query.OrderByDescending(file => file.CreationTime).Skip(10)) { file.Delete(); } mRawDataStream = new StreamWriter(Path.Combine(mConfig.AppPath, string.Format($"PluginLogs/PluginLog-{DateTime.UtcNow:yyyyMMddHHmmss}.log")), false); }