public void ShouldTruncateResponseAtEpochBoundary() { Converters.Register("V", "V", (IMeasurement m) => m); var daq = new SimpleDAQController(); var c = new NonValidatingController { DAQController = daq }; var dev = new UnitConvertingExternalDevice("dev", UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND); var outStream = new DAQOutputStream("out"); var inStream = new DAQInputStream("in"); dev.BindStream(outStream).BindStream(inStream); var sampleRate = new Measurement(1, "Hz"); var samples = new List<IMeasurement> { new Measurement(1, "V"), new Measurement(2, "V"), new Measurement(3, "V") }; var data = new OutputData(samples, sampleRate, true); var e = new Epoch(UNUSED_PROTOCOL); e.Stimuli[dev] = new RenderedStimulus((string) "ID1", (IDictionary<string, object>) new Dictionary<string, object>(), (IOutputData) data); e.Responses[dev] = new Response(); bool pushed = false; daq.Started += (evt, args) => { c.PullOutputData(dev, data.Duration); c.PushInputData(dev, new InputData(samples.Concat(samples).ToList(), sampleRate, DateTimeOffset.Now) .DataWithStreamConfiguration(streamFake, new Dictionary<string, object>()) .DataWithExternalDeviceConfiguration(devFake, new Dictionary<string, object>())); pushed = true; c.RequestStop(); }; c.EnqueueEpoch(e); c.StartAsync(null); while (!pushed) { Thread.Sleep(1); } Assert.That(((TimeSpan)e.Responses[dev].Duration), Is.EqualTo((TimeSpan)e.Duration)); }
public void PushesDataToEpoch() { const string UNUSED_NAME = "UNUSED"; var daq = new SimpleDAQController(); var c = new NonValidatingController { DAQController = daq }; var dev = new UnitConvertingExternalDevice(UNUSED_NAME, UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND); var outStream = new DAQOutputStream("out"); var inStream = new DAQInputStream("in"); dev.BindStream(outStream).BindStream(inStream); var srate = new Measurement(100, "Hz"); var samples = Enumerable.Range(0, 100).Select(i => new Measurement(1, "V")).ToList(); var e = new Epoch("PushesDataToEpoch"); e.Responses[dev] = new Response(); e.Stimuli[dev] = new RenderedStimulus((string) "ID1", (IDictionary<string, object>) new Dictionary<string, object>(), (IOutputData) new OutputData(samples, srate, false)); var data = new InputData(samples, srate, DateTimeOffset.Now).DataWithStreamConfiguration(inStream, new Dictionary<string, object>()); bool pushed = false; daq.Started += (evt, args) => { c.PushInputData(dev, data); pushed = true; c.RequestStop(); }; c.EnqueueEpoch(e); c.StartAsync(null); while (!pushed) { Thread.Sleep(1); } Assert.That(e.Responses[dev].Data, Is.EqualTo(data.Data)); Assert.That(e.Responses[dev].InputTime, Is.EqualTo(data.InputTime)); Assert.That(e.Responses[dev].DataConfigurationSpans.First().Nodes.First(), Is.EqualTo(data.NodeConfigurationWithName(inStream.Name))); }