/// <summary> /// Removes the given ExternalDevice from this stream. /// </summary> /// <param name="device">Device to remove</param> public void RemoveDevice(ExternalDeviceBase device) { if (Device == device) { Device.UnbindStream(Name); Device = null; } }
/// <summary> /// Removes the given ExternalDevice from this stream's connected devices. /// </summary> /// <param name="device">Device to remove</param> public void RemoveDevice(ExternalDeviceBase device) { if (device.Streams.ContainsKey(Name)) { device.UnbindStream(Name); } Devices.Remove(device); }
/// <summary> /// Removes the given ExternalDevice from this stream. /// </summary> /// <param name="device">Device to remove</param> public void RemoveDevice(ExternalDeviceBase device) { if (device.Streams.ContainsKey(Name)) device.UnbindStream(Name); Devices.Remove(device); }
public void BlowAwayTestEpoch() { testEpoch = null; dev1 = dev2 = null; }
public void Setup() { const string protocolID = "Epoch.Fixture"; var parameters = new Dictionary<string, object>(); parameters[param1] = value1; parameters[param2] = value2; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary<string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); var samples = Enumerable.Range(0, 1000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "V")).ToList(); var stimData = new OutputData(samples, srate, false); RenderedStimulus stim1 = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) stimParameters, (IOutputData) stimData); //.Data does not need to be persisted RenderedStimulus stim2 = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) stimParameters, (IOutputData) stimData); //.Data does not need to be persisted Epoch e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; var start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe<DateTimeOffset>.Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary<string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary<string, object>(); devConfig[param2] = value2; var responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); var responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); testEpoch = e; }
public void ShouldAllowNumericEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowNumericEpochParameters.h5")) File.Delete("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowNumericEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary<string, object>(); props["int"] = 2; props["float"] = 2.0f; props["double"] = 2.0d; props["decimal"] = 2.0m; props["array"] = new[] {1.0, 2.0, 3.0}; props["short"] = (short) 2; props["unit16"] = (UInt16) 1; props["uint32"] = (UInt32) 2; props["byte"] = (byte) 1; props["bool"] = true; const string protocolID = "Epoch.Fixture"; Dictionary<string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary<string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List<Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal) Math.Sin((double) i/100), "V")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe<DateTimeOffset>.Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary<string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary<string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); }
private static Epoch CreateTestEpoch(out ExternalDeviceBase dev1, out ExternalDeviceBase dev2) { dev1 = new UnitConvertingExternalDevice("dev1", "man1", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice("dev2", "man2", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary<string, object>(); stimParameters["param1"] = 1; stimParameters["param2"] = 2; var srate = new Measurement(1000, "Hz"); List<Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "V")).ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData) { ShouldDataBePersisted = true }; var protocolParameters = new Dictionary<string, object> { {"one", 1}, {"two", "second"}, {"three", 5.55} }; var epoch = new TestEpoch("protocol.banana", protocolParameters); epoch.Stimuli[dev1] = stim1; epoch.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Now; epoch.SetStartTime(Maybe<DateTimeOffset>.Yes(start)); epoch.Backgrounds[dev1] = new Background(new Measurement(0, "V"), new Measurement(1000, "Hz")); epoch.Backgrounds[dev2] = new Background(new Measurement(1, "V"), new Measurement(1000, "Hz")); epoch.Responses[dev1] = new Response(); epoch.Responses[dev2] = new Response(); var streamConfig = new Dictionary<string, object>(); streamConfig["configParam1"] = 1; var devConfig = new Dictionary<string, object>(); devConfig["configParam2"] = 2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start + TimeSpanExtensions.FromSamples((uint) samples.Count, srate)) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData3 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); IInputData responseData4 = new InputData(samples, srate, start + TimeSpanExtensions.FromSamples((uint)samples.Count, srate)) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); epoch.Responses[dev1].AppendData(responseData1); epoch.Responses[dev1].AppendData(responseData2); epoch.Responses[dev2].AppendData(responseData3); epoch.Responses[dev2].AppendData(responseData4); epoch.Properties.Add("prop1", 5); epoch.Properties.Add("prop2", "banana"); epoch.Keywords.Add("word1"); epoch.Keywords.Add("word2"); return epoch; }
public void ShouldAllowNumericEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowNumericEpochParameters.h5")) { File.Delete("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using (var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowNumericEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["int"] = 2; props["float"] = 2.0f; props["double"] = 2.0d; props["decimal"] = 2.0m; props["array"] = new[] { 1.0, 2.0, 3.0 }; props["short"] = (short)2; props["unit16"] = (UInt16)1; props["uint32"] = (UInt32)2; props["byte"] = (byte)1; props["bool"] = true; const string protocolID = "Epoch.Fixture"; Dictionary <string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary <string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List <Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "V")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe <DateTimeOffset> .Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary <string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary <string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(); exp.Close(); } H5.Close(); Approvals.VerifyFile("..\\..\\..\\ShouldAllowNumericEpochParameters.h5"); }
public void ShouldAllowLongStringEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5")) File.Delete("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5"); var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using ( var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary<string, object>(); props["key1"] = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; //100 elements props["key2"] = 2; const string protocolID = "Epoch.Fixture"; Dictionary<string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary<string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List<Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal) Math.Sin((double) i/100), "mV")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe<DateTimeOffset>.Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary<string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary<string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] {"keyword1", "keyword2"}, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(time.AddMilliseconds(100)); exp.Close(); } H5.Close(); var startInfo = new ProcessStartInfo(@"..\..\..\..\..\..\externals\HDF5\bin\h5dump", @" --xml ..\..\..\ShouldAllowLongStringEpochParameters.h5"); startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; Process proc = Process.Start(startInfo); Approvals.VerifyXml(proc.StandardOutput.ReadToEnd()); }
public void Setup() { const string protocolID = "Epoch.Fixture"; var parameters = new Dictionary <string, object>(); parameters[param1] = value1; parameters[param2] = value2; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary <string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); var samples = Enumerable.Range(0, 1000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "V")).ToList(); var stimData = new OutputData(samples, srate, false); RenderedStimulus stim1 = new RenderedStimulus((string)"RenderedStimulus", (IDictionary <string, object>)stimParameters, (IOutputData)stimData); //.Data does not need to be persisted RenderedStimulus stim2 = new RenderedStimulus((string)"RenderedStimulus", (IDictionary <string, object>)stimParameters, (IOutputData)stimData); //.Data does not need to be persisted Epoch e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; var start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe <DateTimeOffset> .Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary <string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary <string, object>(); devConfig[param2] = value2; var responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); var responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); testEpoch = e; }
public void ShouldAllowLongStringEpochParameters() { if (File.Exists("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5")) { File.Delete("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5"); } var gID = new Guid("{2F2719F7-4A8C-4C22-9698-BE999DBC5385}"); using ( var exp = new EpochHDF5Persistor("..\\..\\..\\ShouldAllowLongStringEpochParameters.h5", null, () => gID) ) { var time = new DateTimeOffset(1000, TimeSpan.Zero); var guid = new Guid("053C64D4-ED7A-4128-AA43-ED115716A97D"); var props = new Dictionary <string, object>(); props["key1"] = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; //100 elements props["key2"] = 2; const string protocolID = "Epoch.Fixture"; Dictionary <string, object> parameters = props; dev1 = new UnitConvertingExternalDevice(dev1Name, "DEVICECO", new Measurement(0, "V")); dev2 = new UnitConvertingExternalDevice(dev2Name, "DEVICECO", new Measurement(0, "V")); var stream1 = new DAQInputStream("Stream1"); var stream2 = new DAQInputStream("Stream2"); var stimParameters = new Dictionary <string, object>(); stimParameters[param1] = value1; stimParameters[param2] = value2; var srate = new Measurement(1000, "Hz"); List <Measurement> samples = Enumerable.Range(0, 10000).Select(i => new Measurement((decimal)Math.Sin((double)i / 100), "mV")). ToList(); var stimData = new OutputData(samples, srate, false); var stim1 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var stim2 = new RenderedStimulus("RenderedStimulus", stimParameters, stimData); //.Data does not need to be persisted var e = new Epoch(protocolID, parameters); e.Stimuli[dev1] = stim1; e.Stimuli[dev2] = stim2; DateTimeOffset start = DateTimeOffset.Parse("1/11/2011 6:03:29 PM -08:00"); // Do this to match the XML stored in the EpochXML.txt resource e.StartTime = Maybe <DateTimeOffset> .Yes(start); e.Background[dev1] = new Epoch.EpochBackground(new Measurement(0, "V"), new Measurement(1000, "Hz")); e.Background[dev2] = new Epoch.EpochBackground(new Measurement(1, "V"), new Measurement(1000, "Hz")); e.Responses[dev1] = new Response(); e.Responses[dev2] = new Response(); var streamConfig = new Dictionary <string, object>(); streamConfig[param1] = value1; var devConfig = new Dictionary <string, object>(); devConfig[param2] = value2; IInputData responseData1 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream1, streamConfig) .DataWithExternalDeviceConfiguration(dev1, devConfig); IInputData responseData2 = new InputData(samples, srate, start) .DataWithStreamConfiguration(stream2, streamConfig) .DataWithExternalDeviceConfiguration(dev2, devConfig); e.Responses[dev1].AppendData(responseData1); e.Responses[dev2].AppendData(responseData2); e.Keywords.Add(kw1); e.Keywords.Add(kw2); exp.BeginEpochGroup("label", "source identifier", new[] { "keyword1", "keyword2" }, props, guid, time); exp.Serialize(e); exp.EndEpochGroup(time.AddMilliseconds(100)); exp.Close(); } H5.Close(); var startInfo = new ProcessStartInfo(@"..\..\..\..\..\..\externals\HDF5\bin\h5dump", @" --xml ..\..\..\ShouldAllowLongStringEpochParameters.h5"); startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; Process proc = Process.Start(startInfo); Approvals.VerifyXml(proc.StandardOutput.ReadToEnd()); }
/// <summary> /// Push IInputData from a given ExternalDevice to the appropriate Response of the current /// Epoch. /// </summary> /// <param name="device">ExternalDevice providing the data</param> /// <param name="inData">Input data instsance</param> public virtual void PushInputData(ExternalDeviceBase device, IInputData inData) { //TODO update this to let Epoch use _completionLock around Response duration and appending var currentEpoch = CurrentEpoch; if (currentEpoch != null && currentEpoch.Responses.ContainsKey(device)) { if (!UnusedInputData.ContainsKey(device)) { UnusedInputData[device] = new InputDataPair(); } lock (UnusedInputData[device]) { UnusedInputData[device].Queue.Enqueue(inData); if (UnusedInputData[device].Fragment != null) //null indicates no fragment present { var fragment = UnusedInputData[device].Fragment; var splitFragment = fragment.SplitData(currentEpoch.Duration - currentEpoch.Responses[device].Duration); currentEpoch.Responses[device].AppendData(splitFragment.Head); if (splitFragment.Rest.Duration > TimeSpan.Zero) { UnusedInputData[device] = new InputDataPair(splitFragment.Rest, UnusedInputData[device].Queue); } else { UnusedInputData[device] = new InputDataPair(null, UnusedInputData[device].Queue); } } while (UnusedInputData[device].Queue.Any() && currentEpoch.Responses[device].Duration < currentEpoch.Duration) { if (UnusedInputData[device].Fragment != null) { throw new SymphonyControllerException("Input data fragment should be empty"); } var cData = UnusedInputData[device].Queue.Dequeue(); var splitData = cData.SplitData(currentEpoch.Duration - currentEpoch.Responses[device].Duration); currentEpoch.Responses[device].AppendData(splitData.Head); if (splitData.Rest.Duration > TimeSpan.Zero) { UnusedInputData[device] = new InputDataPair(splitData.Rest, UnusedInputData[device].Queue); } } try { OnReceivedInputData(currentEpoch); } catch (Exception e) { log.ErrorFormat("Unable to notify observers of incoming data: {0}", e); } } } }
private void BindStreams(IDAQController c, ExternalDeviceBase outDevice, ExternalDeviceBase inDevice) { outDevice.BindStream("OUT", OutStream); inDevice.BindStream("IN", InputStream); Assert.True(InputStream.Active); Assert.True(OutStream.Active); }
public Controller ParseConfiguration(string input, Dictionary <string, IClock> additionalClockProviders) { Controller controller = new Controller(); var devices = new List <ExternalDeviceBase>(); var streams = new List <IDAQStream>(); var clockProviders = new Dictionary <string, IClock>(additionalClockProviders); var controllerConfig = ControllerParser.Parse(input); controller.Configuration[ClockKey] = controllerConfig.Clock; if (!string.IsNullOrEmpty(controllerConfig.ProvidesClock)) { clockProviders[controllerConfig.ProvidesClock] = controller as IClock; } var daqControllerConfig = controllerConfig.DAQController; IDAQController daqController = (IDAQController)Construct(daqControllerConfig.Type); foreach (var nvp in daqControllerConfig.Config.ConfigValues) { var key = nvp.Name; var value = nvp.Value; uint uintValue; if (UInt32.TryParse(value, out uintValue)) { daqController.Configuration[key] = uintValue; } else { daqController.Configuration[key] = value; } } daqController.Configuration.Add(new KeyValuePair <string, object>(ClockKey, daqControllerConfig.Clock)); if (!string.IsNullOrEmpty(daqControllerConfig.ProvidesClock)) { clockProviders[daqControllerConfig.ProvidesClock] = daqController as IClock; } daqController.BeginSetup(); foreach (var s in daqControllerConfig.Streams) { IDAQStream stream; if (daqController.GetStreams(s.Name).Count() > 1) { throw new ParserException("More than one stream with name" + s.Name); } //If we can find the named stream, use the one created by DAQController, otherwise we'll add it. if (daqController.GetStreams(s.Name).Count() == 0) { stream = (IDAQStream)Construct(s.Type, s.Name); } else { stream = daqController.GetStreams(s.Name).First(); } foreach (var nvp in s.Config.ConfigValues) { var key = nvp.Name; var value = nvp.Value; stream.Configuration.Add(new KeyValuePair <string, object>(key, value)); } stream.Configuration.Add(new KeyValuePair <string, object>(ClockKey, s.Clock)); try { stream.SampleRate = s.SampleRate; } catch (NotSupportedException) { //Heka streams don't support setting sample rate } streams.Add(stream); } foreach (var d in daqControllerConfig.Devices) { ExternalDeviceBase ed = (ExternalDeviceBase)(Construct(d.Type, d.Name, d.Manufacturer, controller, d.Background)); foreach (var nvp in d.Config.ConfigValues) { var key = nvp.Name; var value = nvp.Value; ed.Configuration.Add(new KeyValuePair <string, object>(key, value)); } ed.Configuration.Add(new KeyValuePair <string, object>(ClockKey, d.Clock)); foreach (var bindCfg in d.Binds) { IDAQStream st = streams.Find((s) => s.Name == bindCfg.Name); if (st == null) { throw new Exception(String.Format("Attempting to bind {0} which does not exist in configuration", bindCfg.Name)); } else { if (st is IDAQInputStream) { ed.BindStream((IDAQInputStream)st); } else if (st is IDAQOutputStream) { ed.BindStream((IDAQOutputStream)st); } else { throw new Exception(String.Format("Attempting to bind {0} which is neither an Input or Output stream", bindCfg.Name)); } } } foreach (var connectCfg in d.Connects) { if (ed is CoalescingDevice) { ((CoalescingDevice)ed).Connect(connectCfg.Values.ToArray()); } else { throw new Exception( String.Format("Attempting to connect {0} to a non-CoalescingDevice {1}", connectCfg.Values.ToString(), ed)); } } devices.Add(ed); } foreach (IDAQStream s in streams) { //if the stream came from DAQController.GetStreams, we don't need to add it if (!daqController.Streams.Contains(s) && (daqController as IMutableDAQController != null)) { (daqController as IMutableDAQController).AddStream(s); } } daqController.Clock = clockProviders[daqControllerConfig.Clock] as IClock; InjectClock(controller, clockProviders); controller.DAQController = daqController; return(controller); }