commit 8c9bebb78318b0f925033a6f1e573bca558dbab2 Author: bbod Date: Mon Sep 2 23:13:05 2019 -0600 Need to work on Getting the Missions running, There is currently an issue with the UDP Client sending to a bad IP diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b230ab5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +obj/ +/packages/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..19593da --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ + +# Default ignored files +/.idea.Tello Drone/.idea/workspace.xml \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/.idea/contentModel.xml b/.idea/.idea.Tello Drone/.idea/contentModel.xml new file mode 100644 index 0000000..c1bd6f2 --- /dev/null +++ b/.idea/.idea.Tello Drone/.idea/contentModel.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/.idea/encodings.xml b/.idea/.idea.Tello Drone/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.Tello Drone/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/.idea/indexLayout.xml b/.idea/.idea.Tello Drone/.idea/indexLayout.xml new file mode 100644 index 0000000..27ba142 --- /dev/null +++ b/.idea/.idea.Tello Drone/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/.idea/modules.xml b/.idea/.idea.Tello Drone/.idea/modules.xml new file mode 100644 index 0000000..42f76bb --- /dev/null +++ b/.idea/.idea.Tello Drone/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/.idea/projectSettingsUpdater.xml b/.idea/.idea.Tello Drone/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..7515e76 --- /dev/null +++ b/.idea/.idea.Tello Drone/.idea/projectSettingsUpdater.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/.idea/vcs.xml b/.idea/.idea.Tello Drone/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.Tello Drone/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Tello Drone/riderModule.iml b/.idea/.idea.Tello Drone/riderModule.iml new file mode 100644 index 0000000..41bb8ae --- /dev/null +++ b/.idea/.idea.Tello Drone/riderModule.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Tello Drone.sln b/Tello Drone.sln new file mode 100644 index 0000000..5cd7d52 --- /dev/null +++ b/Tello Drone.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tello Drone", "Tello Drone\Tello Drone.csproj", "{06798083-360C-4FF0-B96F-7011835E489B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {06798083-360C-4FF0-B96F-7011835E489B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06798083-360C-4FF0-B96F-7011835E489B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06798083-360C-4FF0-B96F-7011835E489B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06798083-360C-4FF0-B96F-7011835E489B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Tello Drone/BootStrapper.cs b/Tello Drone/BootStrapper.cs new file mode 100644 index 0000000..3566863 --- /dev/null +++ b/Tello Drone/BootStrapper.cs @@ -0,0 +1,34 @@ +using System; +using DryIoc; + +namespace Tello_Drone +{ + public class BootStrapper + { + private static readonly string NoBootstrapperMessage = $"Called {nameof(BootStrapper)} before it existed"; + + private static BootStrapper _bootStrapper; + private static IContainer _container; + + public static BootStrapper Instance => + _bootStrapper ?? throw new InvalidOperationException(NoBootstrapperMessage); + + private BootStrapper(params IModule[] modules) + { + _container = new Container(); + foreach (var module in modules) + { + module.Register(_container); + } + foreach (var module in modules) + { + module.Resolve(_container); + } + } + + public static BootStrapper BootstrapSystem(params IModule[] modules) => + _bootStrapper = new BootStrapper(modules); + + public T Resolve() => _container.Resolve(); + } +} \ No newline at end of file diff --git a/Tello Drone/ConsoleClient.cs b/Tello Drone/ConsoleClient.cs new file mode 100644 index 0000000..9b56c16 --- /dev/null +++ b/Tello Drone/ConsoleClient.cs @@ -0,0 +1,41 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Tello_Drone +{ + public class ConsoleClient + { + private readonly IMissions _missions; + private readonly IConsoleLogger _consoleLogger; + + public ConsoleClient(IMissions missions, IConsoleLogger consoleLogger) + { + _missions = missions; + _consoleLogger = consoleLogger; + } + + public void Run() + { + + _consoleLogger.Log("Choose a mission to run."); + _consoleLogger.Log("1: Mission 1"); + _consoleLogger.Log("2: Mission 2"); + _consoleLogger.Log("3: Mission 3"); + + var userInput = Console.ReadLine(); + + switch (userInput) + { + case "1": + _missions.RunMission1(); + break; + default: + _consoleLogger.Log("Not A Valid Entry...Try Again"); + Run(); + break; + } + + } + + } +} diff --git a/Tello Drone/ConsoleLogger.cs b/Tello Drone/ConsoleLogger.cs new file mode 100644 index 0000000..88e7b4c --- /dev/null +++ b/Tello Drone/ConsoleLogger.cs @@ -0,0 +1,15 @@ +using System; + +namespace Tello_Drone +{ + public class ConsoleLogger : IConsoleLogger + { + public event Action LogReceived; + + public void Log(string message) + { + LogReceived?.Invoke(message); + Console.WriteLine(message); + } + } +} \ No newline at end of file diff --git a/Tello Drone/CoreModule.cs b/Tello Drone/CoreModule.cs new file mode 100644 index 0000000..2a46252 --- /dev/null +++ b/Tello Drone/CoreModule.cs @@ -0,0 +1,21 @@ +using DryIoc; + +namespace Tello_Drone +{ + public class CoreModule : IModule + { + public void Register(IContainer container) + { + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + container.Register(Reuse.Singleton); + } + + public void Resolve(IContainer container) + { + } + } + +} \ No newline at end of file diff --git a/Tello Drone/Drone.cs b/Tello Drone/Drone.cs new file mode 100644 index 0000000..65e00d3 --- /dev/null +++ b/Tello Drone/Drone.cs @@ -0,0 +1,21 @@ +using System.Runtime.CompilerServices; + +namespace Tello_Drone +{ + public class Drone : IDrone + { + private readonly IDroneCommands _droneCommands; + + public Drone(IDroneCommands droneCommands) + { + _droneCommands = droneCommands; + } + + public bool Forward() => _droneCommands.Forward(); + public bool Reverse() => _droneCommands.Reverse(); + public bool Up() => _droneCommands.Up(); + public bool Down() => _droneCommands.Down(); + + + } +} \ No newline at end of file diff --git a/Tello Drone/DroneComands.cs b/Tello Drone/DroneComands.cs new file mode 100644 index 0000000..87240bc --- /dev/null +++ b/Tello Drone/DroneComands.cs @@ -0,0 +1,28 @@ +using System; + +namespace Tello_Drone +{ + public class DroneComands : IDroneCommands + { + private readonly IUdpClientWrapper _udpClient; + + public DroneComands() + { + var udpClient = new UdpClientWrapper(127001, 8000); + _udpClient = udpClient; + } + + public bool Forward() => SendCommand("Forward"); + + public bool Reverse() => SendCommand("Reverse"); + + public bool Up() => SendCommand("Up"); + + public bool Down() => SendCommand("Down"); + + private bool SendCommand(string message) + { + return _udpClient.TrySend(message, 1_500); + } + } +} diff --git a/Tello Drone/DroneFactory.cs b/Tello Drone/DroneFactory.cs new file mode 100644 index 0000000..2d31420 --- /dev/null +++ b/Tello Drone/DroneFactory.cs @@ -0,0 +1,15 @@ +namespace Tello_Drone +{ + public class DroneFactory : IDroneFactory + { + private readonly IDroneCommands _droneCommands; + private Drone _createDrone; + + public DroneFactory(IDroneCommands droneCommands) + { + _droneCommands = droneCommands; + } + + public Drone CreateDrone => new Drone(_droneCommands); + } +} \ No newline at end of file diff --git a/Tello Drone/IConsoleLogger.cs b/Tello Drone/IConsoleLogger.cs new file mode 100644 index 0000000..ecad6bc --- /dev/null +++ b/Tello Drone/IConsoleLogger.cs @@ -0,0 +1,12 @@ +using System; + +namespace Tello_Drone +{ + public interface IConsoleLogger + { + event Action LogReceived; + + void Log(string message); + + } +} \ No newline at end of file diff --git a/Tello Drone/IDrone.cs b/Tello Drone/IDrone.cs new file mode 100644 index 0000000..1142e1e --- /dev/null +++ b/Tello Drone/IDrone.cs @@ -0,0 +1,8 @@ +namespace Tello_Drone +{ + public interface IDrone + { + + + } +} \ No newline at end of file diff --git a/Tello Drone/IDroneCommands.cs b/Tello Drone/IDroneCommands.cs new file mode 100644 index 0000000..a17fd45 --- /dev/null +++ b/Tello Drone/IDroneCommands.cs @@ -0,0 +1,10 @@ +namespace Tello_Drone +{ + public interface IDroneCommands + { + bool Forward(); + bool Reverse(); + bool Up(); + bool Down(); + } +} \ No newline at end of file diff --git a/Tello Drone/IDroneFactory.cs b/Tello Drone/IDroneFactory.cs new file mode 100644 index 0000000..c2b5457 --- /dev/null +++ b/Tello Drone/IDroneFactory.cs @@ -0,0 +1,10 @@ +using System.Dynamic; + +namespace Tello_Drone +{ + public interface IDroneFactory + { + Drone CreateDrone { get; } + + } +} \ No newline at end of file diff --git a/Tello Drone/IMissions.cs b/Tello Drone/IMissions.cs new file mode 100644 index 0000000..54bf17d --- /dev/null +++ b/Tello Drone/IMissions.cs @@ -0,0 +1,7 @@ +namespace Tello_Drone +{ + public interface IMissions + { + void RunMission1(); + } +} \ No newline at end of file diff --git a/Tello Drone/IModule.cs b/Tello Drone/IModule.cs new file mode 100644 index 0000000..1a4d1e0 --- /dev/null +++ b/Tello Drone/IModule.cs @@ -0,0 +1,10 @@ +using DryIoc; + +namespace Tello_Drone +{ + public interface IModule + { + void Register(IContainer container); + void Resolve(IContainer container); + } +} \ No newline at end of file diff --git a/Tello Drone/IUdpClientWrapper.cs b/Tello Drone/IUdpClientWrapper.cs new file mode 100644 index 0000000..aec9b63 --- /dev/null +++ b/Tello Drone/IUdpClientWrapper.cs @@ -0,0 +1,10 @@ +using System; +using System.Net.Sockets; + +namespace Tello_Drone +{ + public interface IUdpClientWrapper : IDisposable + { + bool TrySend(string message, int timeOut); + } +} \ No newline at end of file diff --git a/Tello Drone/Missions.cs b/Tello Drone/Missions.cs new file mode 100644 index 0000000..d285c68 --- /dev/null +++ b/Tello Drone/Missions.cs @@ -0,0 +1,26 @@ +using System.Runtime.CompilerServices; + +namespace Tello_Drone +{ + public class Missions : IMissions + { + private readonly IConsoleLogger _consoleLogger; + private Drone _drone; + + public Missions( IDroneFactory droneFactory, IConsoleLogger consoleLogger) + { + _consoleLogger = consoleLogger; + _drone = droneFactory.CreateDrone; + } + + public void RunMission1() + { + + } + + private void MissionSetup() + { + } + + } +} \ No newline at end of file diff --git a/Tello Drone/Program.cs b/Tello Drone/Program.cs new file mode 100644 index 0000000..f4f6a45 --- /dev/null +++ b/Tello Drone/Program.cs @@ -0,0 +1,17 @@ +using System; + +namespace Tello_Drone +{ + class Program + { + static void Main(string[] args) + { + var bootstrapper = BootStrapper.BootstrapSystem(new CoreModule()); + var missions = bootstrapper.Resolve(); + var consoleLogger = bootstrapper.Resolve(); + var consoleClient = new ConsoleClient(missions, consoleLogger); + + consoleClient.Run(); + } + } +} diff --git a/Tello Drone/Tello Drone.csproj b/Tello Drone/Tello Drone.csproj new file mode 100644 index 0000000..da6d379 --- /dev/null +++ b/Tello Drone/Tello Drone.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp2.2 + Tello_Drone + + + + + + + diff --git a/Tello Drone/UdpClientWrapper.cs b/Tello Drone/UdpClientWrapper.cs new file mode 100644 index 0000000..2e77838 --- /dev/null +++ b/Tello Drone/UdpClientWrapper.cs @@ -0,0 +1,48 @@ +using System; +using System.Diagnostics; +using System.Net; +using System.Net.Sockets; +using System.Text; + +namespace Tello_Drone +{ + 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; + + + public UdpClientWrapper(long ipAddress, int port) + { + _ipEndPoint = new IPEndPoint(ipAddress, port); + _client = new UdpClient(LocalHost, _port); + + } + public bool TrySend(string message, int timeOut) + { + if(retryCount < 3 ) + { + _client.Send(Encoding.UTF8.GetBytes(message), 1, _ipEndPoint.Address.ToString(), _ipEndPoint.Port); + var timer = new Stopwatch(); + timer.Start(); + while (timer.ElapsedMilliseconds <= timeOut) + { + var bytes = _client.Receive(ref _ipEndPoint); + var returnMessage = Encoding.ASCII.GetString(bytes, 0, bytes.Length); + if (returnMessage == "Ok") return true; + } + } + return false; + } + + public void Dispose() + { + _client?.Dispose(); + } + + + } +} \ No newline at end of file