From e66bd40e06b440c3090fda812dfd581cb3a9cb0f Mon Sep 17 00:00:00 2001 From: bbod Date: Wed, 4 Sep 2019 18:36:26 -0600 Subject: [PATCH] almost there --- .../.idea.Tello Drone/.idea/contentModel.xml | 2 + Tello Drone/ConsoleClient.cs | 3 +- Tello Drone/CoreModule.cs | 1 + Tello Drone/DroneComands.cs | 5 +- Tello Drone/DroneConstants.cs | 8 +++ Tello Drone/IDroneConstants.cs | 10 ++++ Tello Drone/Missions.cs | 3 +- Tello Drone/Program.cs | 4 +- Tello Drone/UdpClientWrapper.cs | 51 ++++++++++++------- 9 files changed, 65 insertions(+), 22 deletions(-) create mode 100644 Tello Drone/DroneConstants.cs create mode 100644 Tello Drone/IDroneConstants.cs diff --git a/.idea/.idea.Tello Drone/.idea/contentModel.xml b/.idea/.idea.Tello Drone/.idea/contentModel.xml index c1bd6f2..ccde461 100644 --- a/.idea/.idea.Tello Drone/.idea/contentModel.xml +++ b/.idea/.idea.Tello Drone/.idea/contentModel.xml @@ -19,10 +19,12 @@ + + diff --git a/Tello Drone/ConsoleClient.cs b/Tello Drone/ConsoleClient.cs index 9b56c16..d96c27b 100644 --- a/Tello Drone/ConsoleClient.cs +++ b/Tello Drone/ConsoleClient.cs @@ -5,6 +5,7 @@ namespace Tello_Drone { public class ConsoleClient { + private readonly IMissions _missions; private readonly IConsoleLogger _consoleLogger; @@ -16,7 +17,6 @@ namespace Tello_Drone public void Run() { - _consoleLogger.Log("Choose a mission to run."); _consoleLogger.Log("1: Mission 1"); _consoleLogger.Log("2: Mission 2"); @@ -37,5 +37,6 @@ namespace Tello_Drone } + } } diff --git a/Tello Drone/CoreModule.cs b/Tello Drone/CoreModule.cs index 2a46252..626980e 100644 --- a/Tello Drone/CoreModule.cs +++ b/Tello Drone/CoreModule.cs @@ -11,6 +11,7 @@ namespace Tello_Drone container.Register(Reuse.Singleton); container.Register(Reuse.Singleton); container.Register(Reuse.Singleton); + //container.Register(Reuse.Singleton); } public void Resolve(IContainer container) diff --git a/Tello Drone/DroneComands.cs b/Tello Drone/DroneComands.cs index 87240bc..89e4224 100644 --- a/Tello Drone/DroneComands.cs +++ b/Tello Drone/DroneComands.cs @@ -1,4 +1,5 @@ using System; +using System.Net; namespace Tello_Drone { @@ -6,9 +7,9 @@ namespace Tello_Drone { private readonly IUdpClientWrapper _udpClient; - public DroneComands() + public DroneComands(IConsoleLogger consoleLogger) { - var udpClient = new UdpClientWrapper(127001, 8000); + var udpClient = new UdpClientWrapper(consoleLogger); _udpClient = udpClient; } diff --git a/Tello Drone/DroneConstants.cs b/Tello Drone/DroneConstants.cs new file mode 100644 index 0000000..92ae8c6 --- /dev/null +++ b/Tello Drone/DroneConstants.cs @@ -0,0 +1,8 @@ +namespace Tello_Drone +{ + public class DroneConstants : IDroneConstants + { + public string DroneIPAddress { get; set; } + public int DronePortNumber { get; set; } + } +} \ No newline at end of file diff --git a/Tello Drone/IDroneConstants.cs b/Tello Drone/IDroneConstants.cs new file mode 100644 index 0000000..f528587 --- /dev/null +++ b/Tello Drone/IDroneConstants.cs @@ -0,0 +1,10 @@ +using DryIoc; + +namespace Tello_Drone +{ + public interface IDroneConstants + { + string DroneIPAddress { get; set; } + int DronePortNumber { get; set; } + } +} \ No newline at end of file diff --git a/Tello Drone/Missions.cs b/Tello Drone/Missions.cs index d285c68..2bd971d 100644 --- a/Tello Drone/Missions.cs +++ b/Tello Drone/Missions.cs @@ -15,7 +15,8 @@ namespace Tello_Drone public void RunMission1() { - + _drone.Down(); + _drone.Up(); } private void MissionSetup() diff --git a/Tello Drone/Program.cs b/Tello Drone/Program.cs index f4f6a45..b0c3c2c 100644 --- a/Tello Drone/Program.cs +++ b/Tello Drone/Program.cs @@ -9,8 +9,10 @@ namespace Tello_Drone var bootstrapper = BootStrapper.BootstrapSystem(new CoreModule()); var missions = bootstrapper.Resolve(); var consoleLogger = bootstrapper.Resolve(); + var droneConstants = new DroneConstants(); + droneConstants.DronePortNumber = 1; + droneConstants.DroneIPAddress = "d"; var consoleClient = new ConsoleClient(missions, consoleLogger); - consoleClient.Run(); } } diff --git a/Tello Drone/UdpClientWrapper.cs b/Tello Drone/UdpClientWrapper.cs index 2e77838..72b6206 100644 --- a/Tello Drone/UdpClientWrapper.cs +++ b/Tello Drone/UdpClientWrapper.cs @@ -1,41 +1,58 @@ using System; using System.Diagnostics; using System.Net; +using System.Net.Http; using System.Net.Sockets; using System.Text; +using System.Threading.Tasks; +using System.Transactions; +using System.Xml.Schema; namespace Tello_Drone { - internal class UdpClientWrapper : IUdpClientWrapper + internal class UdpClientWrapper : IUdpClientWrapper { private readonly UdpClient _client; - private const string LocalHost = "127.0.0.1"; - private readonly int _port = 8889; - private IPEndPoint _ipEndPoint; private int retryCount = 0; - + private IPEndPoint _ipEndPoint; + private IDroneConstants _droneConstants; + private IConsoleLogger _consoleLogger; - public UdpClientWrapper(long ipAddress, int port) + + public UdpClientWrapper(IConsoleLogger consoleLogger) { - _ipEndPoint = new IPEndPoint(ipAddress, port); - _client = new UdpClient(LocalHost, _port); - + _consoleLogger = consoleLogger; + _droneConstants = new DroneConstants(); + consoleLogger.Log("Enter Drone IPAddress:"); + _droneConstants.DroneIPAddress = Console.ReadLine(); + consoleLogger.Log("Enter Drone Port Number:"); + _droneConstants.DronePortNumber = Convert.ToInt32(Console.ReadLine()); + _client = new UdpClient(_droneConstants.DroneIPAddress, _droneConstants.DronePortNumber); + _ipEndPoint = new IPEndPoint(IPAddress.Parse(_droneConstants.DroneIPAddress), _droneConstants.DronePortNumber); } public bool TrySend(string message, int timeOut) - { - if(retryCount < 3 ) + { + bool successfullFlag = false; + while(retryCount < 3 && successfullFlag == false) { - _client.Send(Encoding.UTF8.GetBytes(message), 1, _ipEndPoint.Address.ToString(), _ipEndPoint.Port); - var timer = new Stopwatch(); - timer.Start(); - while (timer.ElapsedMilliseconds <= timeOut) + _client.Client.ReceiveTimeout = 1_500; + _client.Send(Encoding.UTF8.GetBytes(message), 1); + + try { var bytes = _client.Receive(ref _ipEndPoint); var returnMessage = Encoding.ASCII.GetString(bytes, 0, bytes.Length); - if (returnMessage == "Ok") return true; + if (returnMessage == "Ok") + successfullFlag = true; + } + catch + { + _consoleLogger.Log("SHIT BROKE"); + } + retryCount++; } - return false; + return successfullFlag; } public void Dispose()