Can successfully send messages
This commit is contained in:
1
.idea/.idea.Tello Drone/.idea/contentModel.xml
generated
1
.idea/.idea.Tello Drone/.idea/contentModel.xml
generated
@@ -22,7 +22,6 @@
|
||||
<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" />
|
||||
|
||||
@@ -8,10 +8,8 @@ namespace Tello_Drone
|
||||
{
|
||||
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);
|
||||
//container.Register<IUdpClientWrapper, UdpClientWrapper>(Reuse.Singleton);
|
||||
}
|
||||
|
||||
public void Resolve(IContainer container)
|
||||
|
||||
@@ -2,7 +2,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Tello_Drone
|
||||
{
|
||||
public class Drone : IDrone
|
||||
public class Drone
|
||||
{
|
||||
private readonly IDroneCommands _droneCommands;
|
||||
|
||||
@@ -11,10 +11,17 @@ namespace Tello_Drone
|
||||
_droneCommands = droneCommands;
|
||||
}
|
||||
|
||||
public bool Forward() => _droneCommands.Forward();
|
||||
public bool Reverse() => _droneCommands.Reverse();
|
||||
public bool Up() => _droneCommands.Up();
|
||||
public bool Down() => _droneCommands.Down();
|
||||
public void Forward(int x) => _droneCommands.Forward(x);
|
||||
public void Reverse(int x) => _droneCommands.Reverse(x);
|
||||
public void Up(int z) => _droneCommands.Up(z);
|
||||
public void Down(int z) => _droneCommands.Down(z);
|
||||
public void Left(int y) => _droneCommands.Left(y);
|
||||
public void Right(int y) => _droneCommands.Right(y);
|
||||
public bool Command() => _droneCommands.Command();
|
||||
public bool InitialTakeOff() => _droneCommands.InitialTakeOff();
|
||||
public void TakeOff() => _droneCommands.TakeOff();
|
||||
public void Land() => _droneCommands.Land();
|
||||
public void RotateClockWise(int r) => _droneCommands.RotateClockWise(r);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Xml.Schema;
|
||||
|
||||
namespace Tello_Drone
|
||||
{
|
||||
@@ -13,17 +15,38 @@ namespace Tello_Drone
|
||||
_udpClient = udpClient;
|
||||
}
|
||||
|
||||
public bool Forward() => SendCommand("Forward");
|
||||
public void Forward(int x) => SendCommand($"forward {x}");
|
||||
public void Reverse(int x) => SendCommand($"back {x}");
|
||||
public void Up(int z) => SendCommand($"up {z}");
|
||||
public void Down(int z) => SendCommand($"down {z}");
|
||||
public void Left(int y) => SendCommand($"left {y}");
|
||||
public void Right(int y) => SendCommand($"right {y}");
|
||||
public bool Command() => TrySendCommand("command");
|
||||
public bool InitialTakeOff() => TrySendCommand("takeoff");
|
||||
public void TakeOff() => SendCommand("takeoff");
|
||||
public void Land() => SendCommand("land");
|
||||
public void RotateClockWise(int r) => SendCommand($"cw {r}");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public bool Reverse() => SendCommand("Reverse");
|
||||
|
||||
public bool Up() => SendCommand("Up");
|
||||
|
||||
public bool Down() => SendCommand("Down");
|
||||
|
||||
private bool SendCommand(string message)
|
||||
private void SendCommand(string message)
|
||||
{
|
||||
return _udpClient.TrySend(message, 1_500);
|
||||
var returnValue = _udpClient.TrySend(message, 0_500);
|
||||
if (returnValue == false)
|
||||
SendCommand("land");
|
||||
}
|
||||
|
||||
private bool TrySendCommand(string message)
|
||||
{
|
||||
return _udpClient.TrySend(message, 0_500);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,7 @@ namespace Tello_Drone
|
||||
public class DroneFactory : IDroneFactory
|
||||
{
|
||||
private readonly IDroneCommands _droneCommands;
|
||||
private Drone _createDrone;
|
||||
|
||||
|
||||
public DroneFactory(IDroneCommands droneCommands)
|
||||
{
|
||||
_droneCommands = droneCommands;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Tello_Drone
|
||||
{
|
||||
public interface IDrone
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,17 @@ namespace Tello_Drone
|
||||
{
|
||||
public interface IDroneCommands
|
||||
{
|
||||
bool Forward();
|
||||
bool Reverse();
|
||||
bool Up();
|
||||
bool Down();
|
||||
void Forward(int x);
|
||||
void Reverse(int x);
|
||||
void Up(int z);
|
||||
void Down(int z);
|
||||
void Left(int y);
|
||||
void Right(int y);
|
||||
bool Command();
|
||||
bool InitialTakeOff();
|
||||
void TakeOff();
|
||||
void Land();
|
||||
void RotateClockWise(int r);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using DryIoc;
|
||||
|
||||
namespace Tello_Drone
|
||||
{
|
||||
@@ -6,6 +8,7 @@ namespace Tello_Drone
|
||||
{
|
||||
private readonly IConsoleLogger _consoleLogger;
|
||||
private Drone _drone;
|
||||
private int setupRetry = 0;
|
||||
|
||||
public Missions( IDroneFactory droneFactory, IConsoleLogger consoleLogger)
|
||||
{
|
||||
@@ -15,12 +18,20 @@ namespace Tello_Drone
|
||||
|
||||
public void RunMission1()
|
||||
{
|
||||
_drone.Down();
|
||||
_drone.Up();
|
||||
MissionSetup();
|
||||
_drone.Down(3);
|
||||
_drone.Up(3);
|
||||
}
|
||||
|
||||
private void MissionSetup()
|
||||
{
|
||||
var inCommandMode = false;
|
||||
while (inCommandMode != true && setupRetry < 3)
|
||||
{
|
||||
inCommandMode = _drone.Command();
|
||||
setupRetry++;
|
||||
_consoleLogger.Log(inCommandMode.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Tello_Drone
|
||||
{
|
||||
private readonly UdpClient _client;
|
||||
private int retryCount = 0;
|
||||
private IPEndPoint _ipEndPoint;
|
||||
private IPEndPoint _sendIpEndPoint;
|
||||
private IDroneConstants _droneConstants;
|
||||
private IConsoleLogger _consoleLogger;
|
||||
|
||||
@@ -28,27 +28,28 @@ namespace Tello_Drone
|
||||
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);
|
||||
_sendIpEndPoint = new IPEndPoint(IPAddress.Parse(_droneConstants.DroneIPAddress), _droneConstants.DronePortNumber);
|
||||
}
|
||||
public bool TrySend(string message, int timeOut)
|
||||
public bool TrySend(string message, int timeout)
|
||||
{
|
||||
bool successfullFlag = false;
|
||||
while(retryCount < 3 && successfullFlag == false)
|
||||
{
|
||||
_client.Client.ReceiveTimeout = 1_500;
|
||||
_client.Send(Encoding.UTF8.GetBytes(message), 1);
|
||||
_client.Client.ReceiveTimeout = timeout;
|
||||
_client.Send(Encoding.ASCII.GetBytes(message), message.Length);
|
||||
|
||||
try
|
||||
{
|
||||
var bytes = _client.Receive(ref _ipEndPoint);
|
||||
var bytes = _client.Receive(ref _sendIpEndPoint);
|
||||
var returnMessage = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
|
||||
if (returnMessage == "Ok")
|
||||
if (returnMessage == "ok")
|
||||
successfullFlag = true;
|
||||
_consoleLogger.Log($"successfull flag = {successfullFlag}");
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
_consoleLogger.Log("SHIT BROKE");
|
||||
_consoleLogger.Log("Did not get a response from the drone retrying.");
|
||||
}
|
||||
retryCount++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user