almost there
This commit is contained in:
2
.idea/.idea.Tello Drone/.idea/contentModel.xml
generated
2
.idea/.idea.Tello Drone/.idea/contentModel.xml
generated
@@ -19,10 +19,12 @@
|
||||
<e p="CoreModule.cs" t="Include" />
|
||||
<e p="Drone.cs" t="Include" />
|
||||
<e p="DroneComands.cs" t="Include" />
|
||||
<e p="DroneConstants.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="IDroneConstants.cs" t="Include" />
|
||||
<e p="IDroneFactory.cs" t="Include" />
|
||||
<e p="IMissions.cs" t="Include" />
|
||||
<e p="IModule.cs" t="Include" />
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Tello_Drone
|
||||
container.Register<IDrone, Drone>(Reuse.Singleton);
|
||||
container.Register<IMissions, Missions>(Reuse.Singleton);
|
||||
container.Register<IConsoleLogger, ConsoleLogger>(Reuse.Singleton);
|
||||
//container.Register<IUdpClientWrapper, UdpClientWrapper>(Reuse.Singleton);
|
||||
}
|
||||
|
||||
public void Resolve(IContainer container)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
8
Tello Drone/DroneConstants.cs
Normal file
8
Tello Drone/DroneConstants.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Tello_Drone
|
||||
{
|
||||
public class DroneConstants : IDroneConstants
|
||||
{
|
||||
public string DroneIPAddress { get; set; }
|
||||
public int DronePortNumber { get; set; }
|
||||
}
|
||||
}
|
||||
10
Tello Drone/IDroneConstants.cs
Normal file
10
Tello Drone/IDroneConstants.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using DryIoc;
|
||||
|
||||
namespace Tello_Drone
|
||||
{
|
||||
public interface IDroneConstants
|
||||
{
|
||||
string DroneIPAddress { get; set; }
|
||||
int DronePortNumber { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,8 @@ namespace Tello_Drone
|
||||
|
||||
public void RunMission1()
|
||||
{
|
||||
|
||||
_drone.Down();
|
||||
_drone.Up();
|
||||
}
|
||||
|
||||
private void MissionSetup()
|
||||
|
||||
@@ -9,8 +9,10 @@ namespace Tello_Drone
|
||||
var bootstrapper = BootStrapper.BootstrapSystem(new CoreModule());
|
||||
var missions = bootstrapper.Resolve<IMissions>();
|
||||
var consoleLogger = bootstrapper.Resolve<IConsoleLogger>();
|
||||
var droneConstants = new DroneConstants();
|
||||
droneConstants.DronePortNumber = 1;
|
||||
droneConstants.DroneIPAddress = "d";
|
||||
var consoleClient = new ConsoleClient(missions, consoleLogger);
|
||||
|
||||
consoleClient.Run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user