Need to work on Getting the Missions running, There is currently an issue with the UDP Client sending to a bad IP

This commit is contained in:
2019-09-02 23:13:05 -06:00
commit 8c9bebb783
28 changed files with 453 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
bin/
obj/
/packages/

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/.idea.Tello Drone/.idea/workspace.xml

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelStore">
<e p="$USER_HOME$/.nuget/packages/dryioc/4.0.6/contentFiles/cs/netstandard2.0/dryioc" t="Include">
<e p="Container.cs" t="Include" />
<e p="Expression.cs" t="Include" />
<e p="FastExpressionCompiler.cs" t="Include" />
<e p="ImTools.cs" t="Include" />
</e>
<e p="$USER_HOME$/Library/Caches/Rider2019.2/extResources" t="IncludeRecursive" />
<e p="$USER_HOME$/Library/Caches/Rider2019.2/resharper-host/local/Transient/ReSharperHost/v192/SolutionCaches/_Tello Drone.1285879164.00" t="ExcludeRecursive" />
<e p="$PROJECT_DIR$" t="IncludeFlat">
<e p="packages" t="ExcludeRecursive" />
<e p="Tello Drone" t="IncludeRecursive">
<e p="bin" t="ExcludeRecursive" />
<e p="BootStrapper.cs" t="Include" />
<e p="ConsoleClient.cs" t="Include" />
<e p="ConsoleLogger.cs" t="Include" />
<e p="CoreModule.cs" t="Include" />
<e p="Drone.cs" t="Include" />
<e p="DroneComands.cs" t="Include" />
<e p="DroneFactory.cs" t="Include" />
<e p="IConsoleLogger.cs" t="Include" />
<e p="IDrone.cs" t="Include" />
<e p="IDroneCommands.cs" t="Include" />
<e p="IDroneFactory.cs" t="Include" />
<e p="IMissions.cs" t="Include" />
<e p="IModule.cs" t="Include" />
<e p="IUdpClientWrapper.cs" t="Include" />
<e p="Missions.cs" t="Include" />
<e p="obj" t="ExcludeRecursive">
<e p="Debug" t="Include">
<e p="netcoreapp2.2" t="Include">
<e p="Tello Drone.AssemblyInfo.cs" t="Include" />
</e>
</e>
</e>
<e p="Program.cs" t="Include" />
<e p="Tello Drone.csproj" t="IncludeRecursive" />
<e p="UdpClientWrapper.cs" t="Include" />
</e>
<e p="Tello Drone.sln" t="IncludeFlat" />
</e>
</component>
</project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.Tello Drone/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.Tello Drone/riderModule.iml" />
</modules>
</component>
</project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="1" />
</component>
</project>

6
.idea/.idea.Tello Drone/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

8
.idea/.idea.Tello Drone/riderModule.iml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$USER_HOME$/.nuget/packages/dryioc/4.0.6/contentFiles/cs/netstandard2.0/DryIoc" />
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

16
Tello Drone.sln Normal file
View File

@@ -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

View File

@@ -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<T>() => _container.Resolve<T>();
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
namespace Tello_Drone
{
public class ConsoleLogger : IConsoleLogger
{
public event Action<string> LogReceived;
public void Log(string message)
{
LogReceived?.Invoke(message);
Console.WriteLine(message);
}
}
}

21
Tello Drone/CoreModule.cs Normal file
View File

@@ -0,0 +1,21 @@
using DryIoc;
namespace Tello_Drone
{
public class CoreModule : IModule
{
public void Register(IContainer container)
{
container.Register<IDroneFactory, DroneFactory>(Reuse.Singleton);
container.Register<IDroneCommands, DroneComands>(Reuse.Singleton);
container.Register<IDrone, Drone>(Reuse.Singleton);
container.Register<IMissions, Missions>(Reuse.Singleton);
container.Register<IConsoleLogger, ConsoleLogger>(Reuse.Singleton);
}
public void Resolve(IContainer container)
{
}
}
}

21
Tello Drone/Drone.cs Normal file
View File

@@ -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();
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,12 @@
using System;
namespace Tello_Drone
{
public interface IConsoleLogger
{
event Action<string> LogReceived;
void Log(string message);
}
}

8
Tello Drone/IDrone.cs Normal file
View File

@@ -0,0 +1,8 @@
namespace Tello_Drone
{
public interface IDrone
{
}
}

View File

@@ -0,0 +1,10 @@
namespace Tello_Drone
{
public interface IDroneCommands
{
bool Forward();
bool Reverse();
bool Up();
bool Down();
}
}

View File

@@ -0,0 +1,10 @@
using System.Dynamic;
namespace Tello_Drone
{
public interface IDroneFactory
{
Drone CreateDrone { get; }
}
}

7
Tello Drone/IMissions.cs Normal file
View File

@@ -0,0 +1,7 @@
namespace Tello_Drone
{
public interface IMissions
{
void RunMission1();
}
}

10
Tello Drone/IModule.cs Normal file
View File

@@ -0,0 +1,10 @@
using DryIoc;
namespace Tello_Drone
{
public interface IModule
{
void Register(IContainer container);
void Resolve(IContainer container);
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Net.Sockets;
namespace Tello_Drone
{
public interface IUdpClientWrapper : IDisposable
{
bool TrySend(string message, int timeOut);
}
}

26
Tello Drone/Missions.cs Normal file
View File

@@ -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()
{
}
}
}

17
Tello Drone/Program.cs Normal file
View File

@@ -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<IMissions>();
var consoleLogger = bootstrapper.Resolve<IConsoleLogger>();
var consoleClient = new ConsoleClient(missions, consoleLogger);
consoleClient.Run();
}
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RootNamespace>Tello_Drone</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DryIoc" Version="4.0.6" />
</ItemGroup>
</Project>

View File

@@ -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();
}
}
}