public void InputDataConversion() { IDictionary <string, object> config = new Dictionary <string, object>(2); config["param1"] = 10; config["param2"] = 1; IMeasurement srate = new Measurement(1000, "Hz"); IInputData data = new InputData(this.Data, srate, DateTimeOffset.Now, new PipelineNodeConfiguration(IOData.STREAM_CONFIGURATION_NAME, new Dictionary <string, object>())) .DataWithExternalDeviceConfiguration(devFake, new Dictionary <string, object>()); Converters.Clear(); ConvertProc fooConversion = (m) => new Measurement(m.QuantityInBaseUnit * 10, 1, "foo"); Converters.Register("V", "foo", fooConversion); IInputData expected = new InputData(data, data.Data.Select(m => new Measurement(m.QuantityInBaseUnit * 10, 1, "foo")).ToList()); Assert.NotNull(expected.NodeConfigurationWithName(IOData.STREAM_CONFIGURATION_NAME)); IInputData actual = data.DataWithUnits("foo"); Assert.AreEqual(expected.Data, actual.Data); Assert.That(actual.NodeConfigurationWithName(IOData.EXTERNAL_DEVICE_CONFIGURATION_NAME), Is.EqualTo(expected.NodeConfigurationWithName(IOData.EXTERNAL_DEVICE_CONFIGURATION_NAME))); Assert.That(actual.NodeConfigurationWithName(IOData.STREAM_CONFIGURATION_NAME), Is.EqualTo(expected.NodeConfigurationWithName(IOData.STREAM_CONFIGURATION_NAME))); Assert.AreEqual(expected.InputTime, actual.InputTime); }
public void RegisterConverters() { Converters.Clear(); Converters.Register("V", "V", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); }
public void MinimalRigValidates() { // How do Converters get registered? Converters.Clear(); Converters.Register("units", "units", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); Converters.Register("Hz", "Hz", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); Converters.Register("V", "units", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); ValidateObjectGraph(Resources.MinimalRigConfig); }
public void InputDataConversionViaProc() { IDictionary <string, object> config = new Dictionary <string, object>(2); config["param1"] = 10; config["param2"] = 1; IMeasurement srate = new Measurement(1000, "Hz"); IOutputData outData = new OutputData(this.Data, srate, false) .DataWithExternalDeviceConfiguration(devFake, new Dictionary <string, object>()) .DataWithStreamConfiguration(streamFake, new Dictionary <string, object>()); outData.OutputTime = DateTimeOffset.Now; Converters.Clear(); ConvertProc fooConversion = (m) => new Measurement(m.QuantityInBaseUnit * 10, 1, "foo"); Converters.Register("V", "foo", fooConversion); IOutputData expected = new OutputData(outData, outData.Data.Select(m => new Measurement(m.QuantityInBaseUnit * 10, 1, "foo")).ToList()) { OutputTime = outData.OutputTime }; IOutputData actual = outData.DataWithConversion((m) => new Measurement(m.QuantityInBaseUnit * 10, 1, "foo")); Assert.AreEqual(expected.Data, actual.Data); Assert.AreEqual(expected.NodeConfigurationWithName(IOData.EXTERNAL_DEVICE_CONFIGURATION_NAME), actual.NodeConfigurationWithName(IOData.EXTERNAL_DEVICE_CONFIGURATION_NAME)); Assert.AreEqual(expected.NodeConfigurationWithName(IOData.STREAM_CONFIGURATION_NAME), actual.NodeConfigurationWithName(IOData.STREAM_CONFIGURATION_NAME)); Assert.AreEqual(expected.OutputTime, actual.OutputTime); }
public void CreatePipeline() { // Based on the "Minimal Rig.pdf" in the docs folder Converters.Clear(); // We need an IClock IClock clock = new FakeClock(); // We need a controller ... Controller con = new Controller(); Converters.Register("units", "units", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); Converters.Register("V", "units", // just an identity conversion for now, to pass Validate() (IMeasurement m) => m); con.Clock = clock; // Three ExternalDevices CoalescingDevice amp = new CoalescingDevice("Amp", UNUSED_DEVICE_MANUFACTURER, con, UNUSED_BACKGROUND) { MeasurementConversionTarget = "units" }; var LED = new UnitConvertingExternalDevice("LED", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND) { MeasurementConversionTarget = "units" }; var temp = new UnitConvertingExternalDevice("Temp", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND) { MeasurementConversionTarget = "units" }; amp.Clock = clock; LED.Clock = clock; temp.Clock = clock; con.AddDevice(LED).AddDevice(temp); // There should be no difference whether we use the // ExternalDevice constructor to wire up the Controller // to the ExternalDevice, or the explicit Add() call Assert.IsNotNull(amp.Controller); Assert.IsNotNull(LED.Controller); Assert.IsNotNull(temp.Controller); Assert.IsTrue(amp.Controller == con); Assert.IsTrue(LED.Controller == con); Assert.IsTrue(temp.Controller == con); // Five DAQStreams DAQInputStream in0 = new DAQInputStream("In-0"); in0.Clock = clock; DAQInputStream in1 = new DAQInputStream("In-1"); in1.Clock = clock; DAQInputStream in2 = new DAQInputStream("In-2"); in2.Clock = clock; DAQOutputStream out0 = new DAQOutputStream("Out-0"); out0.Clock = clock; DAQOutputStream out1 = new DAQOutputStream("Out-1"); out1.Clock = clock; in0.MeasurementConversionTarget = "units"; in1.MeasurementConversionTarget = "units"; in2.MeasurementConversionTarget = "units"; out0.MeasurementConversionTarget = "units"; out1.MeasurementConversionTarget = "units"; //amp.Coalesce = CoalescingDevice.OneItemCoalesce; amp.Configuration["CoalesceProc"] = "Symphony.Core.CoalescingDevice.OneItemCoalesce"; LED.BindStream(out0); amp.BindStream(out1).BindStream(in0).BindStream(in1); amp.Connect(in0, in1); temp.BindStream(in2); Assert.IsTrue(LED.Streams.Count == 1); Assert.IsTrue(amp.Streams.Count == 3); Assert.IsTrue(temp.Streams.Count == 1); Assert.IsTrue(in0.Devices.Contains(amp)); Assert.IsTrue(in1.Devices.Contains(amp)); Assert.IsTrue(in2.Devices.Contains(temp)); Assert.IsTrue(out0.Device == LED); Assert.IsTrue(out1.Device == amp); // One DAQController IDAQController dc = new SimpleDAQController(new IDAQStream[] { in0, in1, in2, out0, out1 }); con.DAQController = dc; // DAQController-to-streams Assert.IsTrue(dc.InputStreams.Contains(in0)); Assert.IsTrue(dc.InputStreams.Contains(in1)); Assert.IsTrue(dc.InputStreams.Contains(in2)); Assert.IsTrue(dc.OutputStreams.Contains(out0)); Assert.IsTrue(dc.OutputStreams.Contains(out0)); // Validate and report the validation results Maybe <string> conVal = con.Validate(); Assert.IsTrue(conVal, conVal.Item2); Assert.IsTrue(amp.Coalesce == CoalescingDevice.OneItemCoalesce); }
public void Reset() { Converters.Clear(); }