diff --git a/OATCommunications/CommunicationHandlers/TcpCommunicationHandler.cs b/OATCommunications/CommunicationHandlers/TcpCommunicationHandler.cs index ce54515..e0bf371 100644 --- a/OATCommunications/CommunicationHandlers/TcpCommunicationHandler.cs +++ b/OATCommunications/CommunicationHandlers/TcpCommunicationHandler.cs @@ -3,9 +3,10 @@ using System.Net; using System.Net.Sockets; using System.Text; +using System.Threading; namespace OATCommunications.CommunicationHandlers -{ +{ public class TcpCommunicationHandler : CommunicationHandler { private IPAddress _ip; @@ -50,7 +51,7 @@ public TcpCommunicationHandler(IPAddress ip, int port) } protected override void RunJob(Job job) - { + { if (_client == null) { Log.WriteLine($"TCP: Configuration error, IP [{_ip}] or port [{_port}] is invalid."); @@ -147,11 +148,21 @@ public override bool Connected public override void Disconnect() { - if (_client != null && _client.Connected) + if (_client != null) { + Log.WriteLine("TCP: Stopping Jobs processor."); + StopJobsProcessor(); + + Log.WriteLine("TCP: Port is open, sending shutdown command [:Qq#]"); + ManualResetEvent waitQuit = new ManualResetEvent(false); + var quitJob = new Job(":Qq#", ResponseType.NoResponse, (s) => { waitQuit.Set(); }); + RunJob(quitJob); + waitQuit.WaitOne(); + Log.WriteLine("TCP: Closing port."); _client.Close(); _client = null; + Log.WriteLine("TCP: Disconnected..."); } } } diff --git a/OATControl/DlgChooseOat.xaml.cs b/OATControl/DlgChooseOat.xaml.cs index a9ff910..b257919 100644 --- a/OATControl/DlgChooseOat.xaml.cs +++ b/OATControl/DlgChooseOat.xaml.cs @@ -426,6 +426,19 @@ private async void ProcessStateMachine(object sender, EventArgs e) { ShowManualLocation = true; CurrentStep = Steps.ConfirmLocation; + // Let's get teh coordinate stored on the OAT + var locDoneEvent = new AutoResetEvent(false); + bool gotLoc = false; + float lat = 0, lng = 0; + _sendCommand(":Gt#,#", (a) => { gotLoc = a.Success && TryParseLatLong(a.Data, ref lat); }); + _sendCommand(":Gg#,#", (a) => { gotLoc = gotLoc && a.Success && TryParseLatLong(a.Data, ref lng); locDoneEvent.Set(); }); + locDoneEvent.WaitOne(); + if (gotLoc) + { + Latitude = lat; + Longitude = 180.0f - lng; + } + break; } } break; diff --git a/OATControl/MainWindow.xaml b/OATControl/MainWindow.xaml index 936c811..d4fa63d 100644 --- a/OATControl/MainWindow.xaml +++ b/OATControl/MainWindow.xaml @@ -544,7 +544,6 @@