diff --git a/AgroBase/OperationControl/Services/ManualControlSender.cs b/AgroBase/OperationControl/Services/ManualControlSender.cs index 4494b59cb..14104d7cc 100644 --- a/AgroBase/OperationControl/Services/ManualControlSender.cs +++ b/AgroBase/OperationControl/Services/ManualControlSender.cs @@ -73,7 +73,7 @@ public sealed class ManualControlSender : IDisposable // fora do lock if (isNeutral) - _ = SendStopBurstIfNeededAsync(); + _ = SendStopBurstIfNeededAsync(msg); else _ = SendBurstAsync(msg, BurstStartCount, BurstStartIntervalMs); } @@ -112,12 +112,12 @@ public sealed class ManualControlSender : IDisposable var ms = (DateTime.UtcNow - _lastSendOkUtc).TotalMilliseconds; if (_lastSendOkUtc != DateTime.MinValue && ms > SendFailDeadmanMs) { + await SendStopBurstIfNeededAsync(_currentMsg); lock (_lock) { _armed = false; _currentMsg = null; } - await SendStopBurstIfNeededAsync(); } } } @@ -133,7 +133,7 @@ public sealed class ManualControlSender : IDisposable private Task SendOnceAsync(UdpCtrlMessage msg) => _udp.SendBurstAsync(UdpReliableChannel.TYPE_COMMAND, msg.ToBytes(), count: 1, intervalMs: 25, requestAck: false); - private async Task SendStopBurstIfNeededAsync() + private async Task SendStopBurstIfNeededAsync(UdpCtrlMessage msg) { var now = DateTime.UtcNow; if ((now - _lastStopSentUtc).TotalMilliseconds < MinStopIntervalMs) @@ -141,7 +141,7 @@ public sealed class ManualControlSender : IDisposable _lastStopSentUtc = now; - var stop = BuildStopMsg(); + var stop = BuildStopMsg(msg.Key); try { await SendBurstAsync(stop, BurstStopCount, BurstStopIntervalMs); } catch { /* não derruba */ } } @@ -149,14 +149,14 @@ public sealed class ManualControlSender : IDisposable private static bool IsNeutral(UdpCtrlMessage msg) => msg.Key == AgroBase.Models.Enums.BotoesJoystick.Vazio || msg.released; - private UdpCtrlMessage BuildStopMsg() + private UdpCtrlMessage BuildStopMsg(AgroBase.Models.Enums.BotoesJoystick botao) { return new UdpCtrlMessage { Device = _device, Flags = UdpCtrlFlags.HasKey | UdpCtrlFlags.HasPayload, - Key = AgroBase.Models.Enums.BotoesJoystick.Vazio, - released = false, + Key = botao, + released = true, P1 = 0, P2 = 0 };