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 ShouldSupplyEpochBackgroundForExternalDevicesWithoutStimuli() { Converters.Register("V", "V", (IMeasurement m) => m); int baseSamples = 1000; var daq = new SimpleDAQController(); var c = new NonValidatingController { DAQController = daq }; var dev1 = new UnitConvertingExternalDevice("dev1", "co", c, new Measurement(0, "V")) { OutputSampleRate = new Measurement(baseSamples, "Hz") }; var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V")) { OutputSampleRate = new Measurement(baseSamples, "Hz") }; dev1.BindStream(new DAQOutputStream("out1")); dev2.BindStream(new DAQOutputStream("out2")); IList<IMeasurement> data = (IList<IMeasurement>)Enumerable.Range(0, baseSamples) .Select(i => new Measurement(i, "V") as IMeasurement) .ToList(); Measurement sampleRate = new Measurement(baseSamples, "Hz"); var config = new Dictionary<string, object>(); IOutputData data1 = new OutputData(data, sampleRate, true); var e = new Epoch(""); e.Stimuli[dev1] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) config, data1); var backgroundMeasurement = new Measurement(3.2m, "V"); e.Backgrounds[dev2] = new Background(backgroundMeasurement, sampleRate); IOutputData out1 = null; IOutputData out2 = null; bool pulled = false; daq.Started += (evt, args) => { out1 = c.PullOutputData(dev1, e.Duration); out2 = c.PullOutputData(dev2, e.Duration); pulled = true; c.RequestStop(); }; c.EnqueueEpoch(e); c.StartAsync(null); while (!pulled) { Thread.Sleep(1); } Assert.NotNull(out1); Assert.NotNull(out2); Assert.AreEqual((TimeSpan)e.Duration, out2.Duration); Assert.AreEqual(backgroundMeasurement, out2.Data.First()); }
public void PullsOutputData() { const int srate = 1000; var daq = new SimpleDAQController(); var c = new NonValidatingController { DAQController = daq }; var dev = new UnitConvertingExternalDevice(UNUSED_DEVICE_NAME, UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND) { OutputSampleRate = new Measurement(srate, "Hz") }; dev.BindStream(new DAQOutputStream("out")); IList<IMeasurement> data = (IList<IMeasurement>) Enumerable.Range(0, srate * 2).Select(i => new Measurement(i, "V") as IMeasurement).ToList(); var sampleRate = new Measurement(srate, "Hz"); IOutputData data1 = new OutputData(data, sampleRate, false); var e = new Epoch(""); e.Stimuli[dev] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(), data1); TimeSpan d1 = TimeSpan.FromSeconds(0.75); IOutputData pull1 = null; IOutputData pull2 = null; IOutputData pull3 = null; bool pulled = false; daq.Started += (evt, args) => { pull1 = c.PullOutputData(dev, d1); pull2 = c.PullOutputData(dev, d1); pull3 = c.PullOutputData(dev, d1); pulled = true; c.RequestStop(); }; c.EnqueueEpoch(e); c.StartAsync(null); while (!pulled) { Thread.Sleep(1); } var samples = (int)d1.Samples(new Measurement(srate, "Hz")); Assert.AreEqual(data.Take(samples).ToList(), pull1.Data); Assert.AreEqual(data.Skip(samples).Take(samples).ToList(), pull2.Data); Assert.AreEqual(data.Skip(2 * samples) .Take(samples) .Concat(Enumerable.Range(0, srate - samples).Select(i => dev.Background)) .ToList(), pull3.Data); }
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))); }
public void PullOutputDataShouldReturnBackgroundStreamWithNoRemainingEpochs() { var daq = new SimpleDAQController(); Controller c = new NonValidatingController() { DAQController = daq }; IExternalDevice dev = new UnitConvertingExternalDevice(UNUSED_DEVICE_NAME, UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND) { OutputSampleRate = new Measurement(1000, "Hz") }; dev.BindStream(new DAQOutputStream("out")); var srate = dev.OutputSampleRate; TimeSpan dur = TimeSpan.FromSeconds(0.5); var samples = (int)dur.Samples(srate); var e = new Epoch(""); e.Stimuli[dev] = new RenderedStimulus("RenderedStimulus", new Dictionary<string, object>(), new OutputData(Enumerable.Repeat(new Measurement(0, "V"), samples), srate)); IOutputData pull1 = null; IOutputData pull2 = null; bool pulled = false; daq.Started += (evt, args) => { // Pull out epoch data c.PullOutputData(dev, dur); pull1 = c.PullOutputData(dev, dur); pull2 = c.PullOutputData(dev, dur); pulled = true; c.RequestStop(); }; c.EnqueueEpoch(e); c.StartAsync(null); while (!pulled) { Thread.Sleep(1); } var expected = Enumerable.Repeat(dev.Background, samples).ToList(); Assert.AreEqual(expected, pull1.Data); Assert.AreEqual(expected, pull2.Data); }