Пример #1
0
        private void SendControllerData()
        {
            while (!_serviceDone)
            {
                if (_controller.IsConnected)
                {
                    if (!_controllerIsConnected)
                    {
                        _controllerIsConnected = true;
                        EventLog.WriteEntry(this.GetType().Name, $"Controller connected");
                    }

                    _controller.Update();
                    byte[] buffer = _controller.GetBytes();
                    EnqueueData(buffer);
                }
                else
                {
                    if (_controllerIsConnected)
                    {
                        _controllerIsConnected = false;
                        EventLog.WriteEntry(this.GetType().Name, $"Controller disconnected");
                    }
                }

                Thread.Sleep(50);
            }
        }
Пример #2
0
        private void StreamDataToClient(WebSocket socket, CancellationToken cancellationToken)
        {
            Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    DroneController droneController = new DroneController();
                    droneController.Update();

                    if (droneController.IsConnected)
                    {
                        byte[] bytes = droneController.GetBytes();
                        await socket.SendAsync(new ArraySegment <byte>(bytes), WebSocketMessageType.Binary, true, CancellationToken.None);
                        Thread.Sleep(10);
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }
                }
            });
        }