Exemple #1
0
        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);
        }