public void Load_Component_Is_Updated_Correctly() { TestStandMapping mapping = new TestStandMapping(); Session session = new Session(mapping); const byte ID = 0; // Value = -200 = 0xFF38 byte valMSB = 0xFF; byte valLSB = 0x38; byte[] buffer = { ID, valMSB, valLSB }; LoadComponent expectedResult = new LoadComponent(0, "", ""); session.UpdateComponents(buffer); expectedResult.Set(-200); Assert.AreEqual(expectedResult.Newtons(), ((LoadComponent)mapping.ComponentsByID()[ID]).Newtons()); // Value = 200 = 0x00C8 valMSB = 0x00; valLSB = 0xC8; buffer = new [] { ID, valMSB, valLSB }; session.UpdateComponents(buffer); expectedResult.Set(200); Assert.AreEqual(expectedResult.Newtons(), ((LoadComponent)mapping.ComponentsByID()[ID]).Newtons()); }
public TestStandMapping() { PT_N2 = new PressureComponent(16, "PT_N2", "PT-N2", 400); PT_IPA = new PressureComponent(17, "PT_IPA", "PT-IPA", 50); PT_N2O = new PressureComponent(18, "PT_N2O", "PT-N2O", 50); PT_FUEL = new PressureComponent(19, "PT_FUEL", "PT-FUEL", 50); PT_OX = new PressureComponent(20, "PT_OX", "PT-OX", 50); PT_CHAM = new PressureComponent(21, "PT_CHAM", "PT-CHAM", 50); TC_IPA = new TemperatureComponent(8, "TC_IPA", "TC-IPA", x => x); TC_N2O = new TemperatureComponent(9, "TC_N2O", "TC-N2O", x => x); TC_1 = new TemperatureComponent(10, "TC_1", "TC-1", x => x); TC_2 = new TemperatureComponent(11, "TC_2", "TC-2", x => x); TC_3 = new TemperatureComponent(12, "TC_3", "TC-3", x => x); TC_4 = new TemperatureComponent(13, "TC_4", "TC-4", x => x); TC_5 = new TemperatureComponent(14, "TC_5", "TC-5", x => x); TC_6 = new TemperatureComponent(15, "TC_6", "TC-6", x => x); LOAD = new LoadComponent(0, "LOAD", "Load cell"); SV_IPA = new SolenoidComponent(4, "SV_IPA", "SV-IPA", "SV_IPA_SYMBOL"); SV_N2O = new SolenoidComponent(5, "SV_N2O", "SV-N2O", "SV_N2O_SYMBOL"); MV_IPA = new ServoComponent(6, "MV_IPA", "MV-IPA", "MV_IPA_SYMBOL"); MV_N2O = new ServoComponent(7, "MV_N2O", "MV-N2O", "MV_N2O_SYMBOL"); TARGET_MV_IPA = new SimpleComponent(25, 2, false, "TARGET-MV-IPA", "TARGET-MV-IPA [%]", x => ((float)x) / ushort.MaxValue * 100.0f); TARGET_MV_N2O = new SimpleComponent(26, 2, false, "TARGET-MV-N20", "TARGET-MV-N20 [%]", x => ((float)x) / ushort.MaxValue * 100.0f); SN_N2O_FILL = new SolenoidComponent(2, "SN_N2O_FILL", "SN-N2O-FILL", "SN_N2O_FILL_SYMBOL"); SN_FLUSH = new SolenoidComponent(3, "SN_FLUSH", "SN-FLUSH", "SN_FLUSH_SYMBOL"); BATTERY = new VoltageComponent(22, "BATTERY", "BATTERY", 12.0f, 14.8f); FLO_IPA = new FlowComponent(100, "FLO_IPA", "FLO-IPA", ref PT_FUEL, ref PT_CHAM, () => PreferenceManager.Manager.Preferences.Fluid.Fuel); FLO_N2O = new FlowComponent(101, "FLO_N2O", "FLO-N2O", ref PT_N2O, ref PT_CHAM, () => PreferenceManager.Manager.Preferences.Fluid.Oxid); T_IPA = new TankComponent(24, "FUEL", "FUEL", "FUEL_GRADIENT", ref FLO_IPA, "Fuel"); T_N2O = new LevelComponent(1, "OXID", "OXID", "OXID_GRADIENT", 20); STACK_HEALTH = new StackHealthComponent(23, "STACK_MAIN", "STACK_ACTUATOR", "STACK_SENSOR", "STACK-HEALTH"); _states = new List <State> { new State(0, "Idle"), new State(1, "Ignition"), new State(2, "Pre-Stage 1"), new State(3, "Pre-Stage 2"), new State(4, "Ramp up"), new State(5, "Regulated"), new State(6, "Shutdown 1"), new State(7, "Shutdown 2"), new State(8, "Flush") }; EmergencyState = _states[6]; PreferenceManager.Manager.Preferences.AutoSequenceComponentIDs.ChamberPressureID = PT_CHAM.BoardID; PreferenceManager.Manager.Preferences.AutoSequenceComponentIDs.FuelLinePressureID = PT_FUEL.BoardID; PreferenceManager.Manager.Preferences.AutoSequenceComponentIDs.OxidizerLinePressureID = PT_OX.BoardID; }
public void Single_Component_Is_Updated_After_Incoming_Data_Without_Logging() { byte ID = 0; // Value = 1337 = 0x539 byte valMSB = 0x05; byte valLSB = 0x39; LoadComponent expectedResult = new LoadComponent(0, "", ""); expectedResult.Set(1337); TestStandMapping mapping = new TestStandMapping(); Session session = new Session(mapping); Mock <IDataLog> dataMock = new Mock <IDataLog>(); Mock <ISerialPort> serialMock = new Mock <ISerialPort>(); byte[] buffer = { 0xAA, 0xBB, 0xFD, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x03, ID, valMSB, valLSB, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xAA, 0xBB }; int i = 0; serialMock.Setup(x => x.IsOpen).Returns(true).Callback(() => Console.WriteLine("IsOpen called")); serialMock.Setup(x => x.BytesToRead).Returns(buffer.Length - i).Callback(() => Console.WriteLine("BytesToRead called")); serialMock.Setup(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <int>())) .Returns((byte[] b, int o, int c) => { int nbytes = Math.Min(c, buffer.Length - i); Array.Copy(buffer, i, b, 0, nbytes); i += nbytes; i = (i >= buffer.Length) ? 0 : i; Console.WriteLine("Got {0} bytes", nbytes); return(nbytes); }).Callback(() => Console.WriteLine("Read called")); bool wait = true; IOThread conn = new IOThread(dataMock.Object, ref session); dataMock.Setup(x => x.Enqueue(It.IsAny <DataPacket>())).Callback((DataPacket dp) => { session.UpdateComponents(dp.Bytes); conn.StopConnection(); wait = false; }); conn.StartConnection(serialMock.Object, null); Console.WriteLine("Thread started"); Stopwatch watch = new Stopwatch(); watch.Start(); while (wait && watch.ElapsedMilliseconds < 2000) { Thread.Sleep(100); } Assert.AreEqual(expectedResult.Newtons(), ((LoadComponent)mapping.ComponentsByID()[ID]).Newtons()); }
private LoadComponent GetLoadComponent(string name) { LoadComponent component = this.m_assemblys[name] as LoadComponent; if (component == null) { component = new LoadComponent(); component.LoadComponentLibrary(name); this.m_LoadComponents[name] = component; } return(component); }
private LoadComponent method_0(string string_0) { LoadComponent item = this._table1[string_0] as LoadComponent; if (item == null) { item = new LoadComponent(); item.LoadComponentLibrary(string_0); this._table2[string_0] = item; } return(item); }
private LoadComponent method_10(string string_0) { LoadComponent component = this.hashtable_1[string_0] as LoadComponent; if (component == null) { component = new LoadComponent(); component.LoadComponentLibrary(string_0); this.hashtable_0[string_0] = component; } return(component); }
public void Single_Component_Is_Updated_By_DataPacket_With_Negative_Value() { byte ID = 0; // Value = -1337 = 0xFAC7 byte valMSB = 0xFA; byte valLSB = 0xC7; LoadComponent expectedResult = new LoadComponent(0, "", ""); expectedResult.Set(-1337); TestStandMapping mapping = new TestStandMapping(); Session session = new Session(mapping); byte[] buffer = { ID, valMSB, valLSB }; session.UpdateComponents(buffer); Assert.AreEqual(expectedResult.Newtons(), ((LoadComponent)mapping.ComponentsByID()[ID]).Newtons()); }
public void Single_Component_Is_Updated_By_DataPacket_Verify_Sign_Extension() { byte ID = 0; // Value = 250 = 0x00FA byte valMSB = 0x00; byte valLSB = 0xFA; LoadComponent expectedResult = new LoadComponent(0, "", ""); expectedResult.Set(250); TestStandMapping mapping = new TestStandMapping(); Session session = new Session(mapping); byte[] buffer = { ID, valMSB, valLSB }; session.UpdateComponents(buffer); Assert.AreEqual(expectedResult.Newtons(), ((LoadComponent)mapping.ComponentsByID()[ID]).Newtons()); }
public void Verify_Tare() { TestStandMapping mapping = new TestStandMapping(); Session session = new Session(mapping); DataStore dataStore = new DataStore(session); Mock <IUserInterface> ui = new Mock <IUserInterface>(); Mock <LogThread> logThread = new Mock <LogThread>(dataStore); IOThread ioThread = new IOThread(dataStore, ref session); Program p = new Program(dataStore, logThread.Object, ioThread, ui.Object); LoadComponent l = (mapping.ComponentsByID()[0] as LoadComponent); Assert.AreEqual(0, l.Newtons()); l.Set(10); Assert.AreEqual(18.83217116, l.Newtons(), 0.01); l.Tare(); l.Set(10); Assert.AreEqual(0, l.Newtons(), 0.01); l.Set(200); Assert.AreEqual(357.8112522, l.Newtons(), 0.01); }
/// <summary> /// Create new Load Combination /// </summary> /// <param name="name">The new Load Combination name</param> /// <param name="typeIndex">The index of new Load Combination Type</param> /// <param name="stateIndex">The index of new Load Combination State</param> /// <returns>true if the creation was successful; otherwise, false</returns> public Boolean NewLoadCombination(String name, int typeIndex, int stateIndex) { // Define some data for creation. List <ElementId> usageIds = new List <ElementId>(); List <LoadComponent> components = new List <LoadComponent>(); double[] factorArray = new double[m_dataBuffer.FormulaMap.Count]; // First check whether the name has been used foreach (String s in m_dataBuffer.LoadCombinationNames) { if (s == name || null == name) { m_dataBuffer.ErrorInformation = "the combination name has been used."; return(false); } } // Get the usage information. foreach (UsageMap usageMap in m_dataBuffer.UsageMap) { if (true == usageMap.Set) { LoadUsage usage = FindUsageByName(usageMap.Name); if (null != usage) { usageIds.Add(usage.Id); } } } // Get the formula information for (int i = 0; i < m_dataBuffer.FormulaMap.Count; i++) { FormulaMap formulaMap = m_dataBuffer.FormulaMap[i]; factorArray[i] = formulaMap.Factor; LoadCase loadCase = FindLoadCaseByName(formulaMap.Case); if (null != loadCase) { LoadComponent component = new LoadComponent(loadCase.Id, formulaMap.Factor); components.Add(component); } } // Begin to new a load combination try { LoadCombination loadCombination = LoadCombination.Create(m_document, name, (LoadCombinationType)typeIndex, (LoadCombinationState)stateIndex); if (null == loadCombination) { m_dataBuffer.ErrorInformation = "Get null reference after usage creation."; return(false); } loadCombination.SetComponents(components); loadCombination.SetUsageIds(usageIds); // Store this load combination information for further use m_dataBuffer.LoadCombinationNames.Add(loadCombination.Name); LoadCombinationMap combinationMap = new LoadCombinationMap(loadCombination); m_dataBuffer.LoadCombinationMap.Add(combinationMap); } catch (Exception e) { m_dataBuffer.ErrorInformation = e.Message; return(false); } // If create combination successful, reset the usage check state and clear the formula foreach (UsageMap usageMap in m_dataBuffer.UsageMap) { usageMap.Set = false; } m_dataBuffer.FormulaMap.Clear(); return(true); }