Пример #1
0
        private DroneResponse SendCommandWaitResponse(string DroneCommand)
        {
            lock (commandQueue)
            {
                if (commandQueue.Count > 0)
                {
                    return(null);
                }
                commandQueue.Enqueue(DroneCommand);
                commanderSender.Send(DroneCommand);
                eventHandler.CommandSent(DroneCommand, false);
            }

            lock (responseQueue)
            {
                Monitor.Wait(responseQueue, RESPONSE_TIMEOUT_MS);
            }

            DroneResponse response = null;

            lock (responseQueue)
            {
                if (responseQueue.Count != 0)
                {
                    response = responseQueue.Dequeue();
                    if (eventHandler != null)
                    {
                        eventHandler.ReceiveTelloResponse(response.Host, response.Port, DroneCommand, response.Response);
                    }
                    return(response);
                }
            }
            return(null);
        }
Пример #2
0
        private string GetString(string QueryCommand, string DefaultValue = "")
        {
            DroneResponse response = SendCommandWaitResponse(QueryCommand);

            if (response != null)
            {
                return(response.Response);
            }
            return(DefaultValue);
        }
Пример #3
0
        private int GetInt(string QueryCommand, int DefaultValue)
        {
            DroneResponse response = SendCommandWaitResponse(QueryCommand);
            int           value    = DefaultValue;

            if (response != null)
            {
                int.TryParse(response.Response, out value);
            }
            return(value);
        }
Пример #4
0
        public bool StreamOff()
        {
            DroneResponse resp = SendCommandWaitResponse(TelloCommand.StreamOff.GetCommand());

            if (resp.Response == DroneResponseValue.OK)
            {
                stream_on = false;
                return(true);
            }
            return(false);
        }
Пример #5
0
        public bool IncreaseSpeed(int By = 5)
        {
            int newSpeed = CurrentSpeed + By;

            try
            {
                string        command = TelloCommand.SetSpeed.GetCommand(newSpeed);
                DroneResponse resp    = SendCommandWaitResponse(command);
                if (resp.Response == DroneResponseValue.OK)
                {
                    speed = newSpeed;
                    return(true);
                }
            }
            catch (CommandIntegerParamException e)
            {}
            return(false);
        }