Exemplo n.º 1
0
        public SoccerBotViewModel(ISoccerBot soccerBot, ISoccerBotLogger logger, Server server)
        {
            _server = server;

            _logger = logger;

            _soccerBot = soccerBot;
        }
Exemplo n.º 2
0
        private async Task InitSoccerBot()
        {
            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.Write("========================================");
            Debug.Write("NOTE: NOTE: NOTE: Your PIN is: " + pin);
            Debug.Write("========================================");

            _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 SerialChannel(ports.First().Id, _logger);
                await serialPortChannel.ConnectAsync();

                _soccerBot     = new mBlockSoccerBot(serialPortChannel, _logger, pin);
                _sensorManager = new SensorManager();
                await _sensorManager.InitAsync();

                _sensorManager.Start();

                Managers.ConnectionManager.Instance.MakeDiscoverable(computerName);
                break;

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

                break;
            }

            Managers.ConnectionManager.Instance.Init(_soccerBot, _logger);
            Managers.ConnectionManager.Instance.StartWebServer(80, computerName);
            Managers.ConnectionManager.Instance.StartTCPServer(9000, _soccerBot, _sensorManager);
        }
Exemplo n.º 3
0
        public Server(ISoccerBotLogger logger, int port, ISoccerBot soccerBot, SensorManager sensorManager)
        {
            _port      = port;
            _logger    = logger;
            _soccerBot = soccerBot;

            _sensorManager = sensorManager;

            _listener = new TCPListener(_logger, this, _port);
            _clients  = new List <Client>();

            _watchDog          = new System.Threading.Timer(_watchDog_Tick, null, 0, 2500);
            _sensorUpdateTimer = new System.Threading.Timer(_sensorUpdateTimer_Tick, null, 0, 1000);
        }
Exemplo n.º 4
0
 public void Init(ISoccerBot soccerBot, ISoccerBotLogger logger)
 {
     _soccerBot = soccerBot;
     _logger    = logger;
 }
Exemplo n.º 5
0
 public void StartTCPServer(int port, ISoccerBot soccerBot, SensorManager sensorManager)
 {
     _tcpServer = new Channels.Server(_logger, port, soccerBot, sensorManager);
     _tcpServer.Start();
 }