private async Task <bool> StartSampleAsync(DevCommandSender sender) { FileResource fs = null; try { //TODO config device ID fs = new FileResource(_currentState, 19801983, 1, BrainDeviceManager.BufMgr); fs.StartRecord(BrainDeviceManager.SampleDataStream); var cmdResult = await sender.Start(); if (cmdResult != CommandError.Success) { AppLogger.Error("Failed to start sampler"); return(false); } return(true); } catch (Exception) { fs?.Dispose(); return(false); } }
private static void OldTest(string[] args) { var endpoint = ProgramArgs.Parse(args, new[] { "127.0.0.1:9211" }).EndPoint; var cts = new CancellationTokenSource(); var bufferManager = SyncBufManager.Create(2 << 16, 128, 32); var encoder = new ClientFrameEncoder(0xA0, 0XC0); var decoder = new FixedLenFrameDecoder(0xA0, 0XC0); endpoint.ToConnectObservable() .ObserveOn(TaskPoolScheduler.Default) .Subscribe(socket => { var frameClientSubject = socket.ToFixedLenFrameSubject(encoder, decoder, bufferManager, cts.Token); var observerDisposable = frameClientSubject .ObserveOn(TaskPoolScheduler.Default) .Subscribe( managedBuffer => { var segment = managedBuffer.Value; if (!ReceivedDataProcessor.Instance.Process(segment) && segment.Array != null) { Console.WriteLine( "Echo: " + Encoding.UTF8.GetString(segment.Array, segment.Offset, segment.Count)); } managedBuffer.Dispose(); }, error => { Console.WriteLine("Error: " + error.Message); cts.Cancel(); }, () => { Console.WriteLine("OnCompleted: Frame Protocol Receiver"); cts.Cancel(); }); var cmdSender = new DevCommandSender(frameClientSubject, bufferManager, null); Console.In.ToLineObservable("exit") .Subscribe( line => { if (string.IsNullOrEmpty(line)) { return; } if (line == "start") { cmdSender.Start(); return; } if (line == "stop") { cmdSender.Stop(); return; } var writeBuffer = Encoding.UTF8.GetBytes(line); frameClientSubject.OnNext( DisposableValue.Create(new ArraySegment <byte>(writeBuffer), Disposable.Empty)); }, error => { Console.WriteLine("Error: " + error.Message); cts.Cancel(); }, () => { Console.WriteLine("OnCompleted: LineReader"); cts.Cancel(); }); cts.Token.WaitHandle.WaitOne(); observerDisposable.Dispose(); }, error => { Console.WriteLine("Failed to connect: " + error.Message); cts.Cancel(); }, cts.Token); cts.Token.WaitHandle.WaitOne(); }