private void ProcessQueue() { _processing = true; Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(10)).TakeUntil(_stopSubject).Subscribe( l => { if ((SystemCommands.TryPeekCommand(out var cmd) || ManualCommands.TryPeekCommand(out cmd) || FileCommands.TryPeekCommand(out cmd) || FileCommands.State != CommandSourceState.Running && _waitingCommandQueue.Count == 0 && MacroCommands.TryPeekCommand(out cmd)) && cmd != null && cmd.Data.RemoveSpace().Length + CommandQueueLength <= _bufferSizeLimit) { var continueProcess = cmd.Source switch { CommandSourceType.System => SystemCommands.TryGetCommand(out cmd), CommandSourceType.Macros => MacroCommands.TryGetCommand(out cmd), CommandSourceType.Manual => ManualCommands.TryGetCommand(out cmd), CommandSourceType.File => FileCommands.TryGetCommand(out cmd), _ => false }; if (!continueProcess) { return; } _commandPreProcessor.Process(ref cmd); Send(cmd); } }); }
public void Send(string command, string onResult = null) { lock (_lockObject) { _uiContext.Send( x => { CommunicationLog.Insert(0, "grbl <=" + command); if (CommunicationLog.Count > 500) { CommunicationLog.Remove(CommunicationLog.Last()); } }, null); } OnCommunicationLogUpdated(); var cmd = new Command { Data = command, CommandOnResult = onResult }; _commandPreProcessor.Process(ref cmd); switch (cmd.Type) { case RequestType.Realtime: Send(cmd); break; case RequestType.System: { lock (_lockObject) { if (!SystemCommands.DataInQueue(cmd.Data, 3)) { SystemCommands.Add(command); } } break; } default: { lock (_lockObject) { ManualCommands.Add(command); } break; } } }
public void PurgeQueues() { while (_waitingCommandQueue.Count > 0) { _waitingCommandQueue.TryDequeue(out var dummy); CommandQueueLengthChanged?.Invoke(this, CommandQueueLength); } SystemCommands.Purge(); ManualCommands.Purge(); FileCommands.Purge(); MacroCommands.Purge(); }
private void ComServiceConnectionStateChanged(object sender, ConnectionState e) { if (e == ConnectionState.Online) { if (!_processing) { ProcessQueue(); } SystemCommands.StartProcessing(); ManualCommands.StartProcessing(); MacroCommands.StartProcessing(); } else { _stopSubject.OnNext(Unit.Default); _processing = false; SystemCommands.PauseProcessing(); ManualCommands.PauseProcessing(); MacroCommands.PauseProcessing(); } }