コード例 #1
0
ファイル: App.xaml.cs プロジェクト: drewmoseley/TankBot
        private async void InitSockerBot()
        {
            var hostNames    = NetworkInformation.GetHostNames();
            var computerName = hostNames.FirstOrDefault(name => name.Type == HostNameType.DomainName)?.DisplayName ?? "???";



            var pin = await LagoVista.Core.PlatformSupport.Services.Storage.GetKVPAsync <string>("PIN");

            if (String.IsNullOrEmpty(pin))
            {
                var rnd = new Random();
                pin = rnd.Next(1000, 9999).ToString();
                await LagoVista.Core.PlatformSupport.Services.Storage.StoreKVP("PIN", pin);
            }

            Debug.WriteLine("========================================");
            Debug.WriteLine("NOTE: NOTE: NOTE: Your PIN is: " + pin);
            Debug.WriteLine("========================================");

            _logger = new Loggers.DebugLogger();

            switch (AnalyticsInfo.VersionInfo.DeviceFamily)
            {
            case "Windows.IoT":
                var ports = (await LagoVista.Core.PlatformSupport.Services.DeviceManager.GetSerialPortsAsync());
                if (ports.Count == 0)
                {
                    throw new Exception("Could not find any serial ports, a serial port is required.");
                }
                else if (ports.Count > 1)
                {
                    throw new Exception("Found more than one serial port, please add additional logic to select the serial port the mBot is connected to.");
                }

                var serialPortChannel = new SerialPortChannel(ports.First().Id, _logger);
                await serialPortChannel.ConnectAsync();

                _tankBot       = new mBlockTankBot(serialPortChannel, _logger, pin);
                _sensorManager = new SensorManager();
                await _sensorManager.InitAsync();

                _sensorManager.Start();

                break;

            case "Windows.Desktop":
                _tankBot = new SimulatedSoccerBot();

                break;
            }

            ConnectionManager.Start(computerName, _tankBot, _logger, _sensorManager, Constants.WebListenerPort, Constants.TCPListenPort, Constants.UPNPListenPort);
        }
コード例 #2
0
 private void StartTCPServer(int port, ITankBot soccerBot, ISensorManager sensorManager)
 {
     try
     {
         Server = new Server(_logger, port, soccerBot, sensorManager);
         Server.Start();
     }
     catch (Exception ex)
     {
         _logger.NotifyUserError("ConnectionManager_StartTCPServer", ex.Message);
     }
 }
コード例 #3
0
ファイル: Server.cs プロジェクト: drewmoseley/TankBot
        public Server(ITankBotLogger logger, int port, ITankBot soccerBot, ISensorManager sensorManager)
        {
            _port    = port;
            _logger  = logger;
            _tankBot = soccerBot;

            _sensorManager = sensorManager;

            _clients = new ConcurrentDictionary <string, IClient>();

            _watchDog          = new System.Threading.Timer(_watchDog_Tick, null, 0, 2500);
            _sensorUpdateTimer = new System.Threading.Timer(_sensorUpdateTimer_Tick, null, 0, 100);
        }
コード例 #4
0
        public void Start(String tankBotName, ITankBot tankBot, ITankBotLogger logger, ISensorManager sensorManager, int webServerPort, int tcpListenerPort, int uPnPListenerPort)
        {
            _logger           = logger;
            _tankBotName      = tankBotName;
            _tankBot          = tankBot;
            _sensorManager    = sensorManager;
            _webServerPort    = webServerPort;
            _tcpListenerPort  = tcpListenerPort;
            _uPnPListenerPort = uPnPListenerPort;

            var networkInfo = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();

            App.TheApp.HasInternetConnection = networkInfo.GetNetworkConnectivityLevel() == Windows.Networking.Connectivity.NetworkConnectivityLevel.InternetAccess;

            if (App.TheApp.HasInternetConnection)
            {
                MakeDiscoverable(tankBotName);
                StartWebServer(_webServerPort, _tankBotName);
                StartTCPServer(_tcpListenerPort, _tankBot, _sensorManager);
            }
        }
コード例 #5
0
 public LocalClientTankBotViewModel(IChannel channel, ITankBotLogger logger, IJoyStick joyStick) : base(joyStick)
 {
     _channel       = channel;
     _mblockTankBot = new mBlockTankBot(channel, logger);
     _logger        = logger;
 }
コード例 #6
0
ファイル: MotionRestAPI.cs プロジェクト: drewmoseley/TankBot
 public MotionRestAPI(ITankBot tankBot, ITankBotLogger logger)
 {
     _tankBot = tankBot;
     _logger  = logger;
 }