diff --git a/TBF/BenchControl/ControlBoard/Uni/CBoard.cs b/TBF/BenchControl/ControlBoard/Uni/CBoard.cs index 0138cd4be..1bc82e0c8 100644 --- a/TBF/BenchControl/ControlBoard/Uni/CBoard.cs +++ b/TBF/BenchControl/ControlBoard/Uni/CBoard.cs @@ -72,7 +72,9 @@ namespace TBF.BenchControl.ControlBoard.Uni /// Propagated from configurations of other components - UInt128 valvesToInvert; + UInt128 benchModelRoute; + UInt128 valvesToInvert; /// Route = valesToInvert ^ RequiredRouteWithoutInvertedVlaves + readonly UInt128 routeMask; /// This mask masks out virtual valves, routeMask is set in the constructor /// Serial communication SerialPort serialPort; /// Seral port or null: Check serialPort.IsOpen before using the serial port @@ -94,8 +96,6 @@ namespace TBF.BenchControl.ControlBoard.Uni public UInt64 State { get { return Data.State; } } /// Control board state public UInt64 DigitalInputs { get { return Data.Vstupy; } } /// Digital inputs - public UInt128 Route { get { return Data.Vystupy; } } /// Test bench route: states of valves - public Int16 AnalogInput(int channel) { if (Data.AnalogInput != null && channel >= 0 && channel < Data.AnalogInput.Length) @@ -104,7 +104,12 @@ namespace TBF.BenchControl.ControlBoard.Uni } return 0; } - + + /// + /// Route: 128-bit word representing the current state of all valves and pumps + /// + public UInt128 Route { get { return benchModelRoute; } } + /// Values valid during a test public double RefFrequency { get { return Data.ReferenceFreq[0]; } } @@ -174,6 +179,28 @@ namespace TBF.BenchControl.ControlBoard.Uni cumulativeSums = new int[BUFFER_SIZE]; rcvdBytesCount = 0; + routeMask = 0; + for (int i = 0; i < 128; i++) + { + if (i < cBoardCfg.VirtValvesRangeLo || i > cBoardCfg.VirtValvesRangeHi) + { + routeMask = routeMask | ((UInt128)1 << i); + } + } + + TBF.UiBridge.Bridge.RouteChangeHandler += delegate(object sndr, TBF.UiBridge.RouteChangeArgs args) + { + UInt128 mask = ((UInt128)1) << args.BitNr; + if ((benchModelRoute & mask) == 0) + { + benchModelRoute |= mask; + } + else + { + benchModelRoute &= (~mask); + } + }; + log.Warn(this.ToString()); } @@ -184,6 +211,7 @@ namespace TBF.BenchControl.ControlBoard.Uni public void SpecifyInvertedValves(UInt128 valvesToInvert) { this.valvesToInvert = valvesToInvert; + this.benchModelRoute = valvesToInvert; } #region IDevice interface @@ -365,7 +393,17 @@ namespace TBF.BenchControl.ControlBoard.Uni public double TestTimeWM(int wmNr1) { return 0; } public int RefPulsesWM(int wmNr1) { return 0; } public int PulsesWM(int wmNr1) { return 0; } - public UInt128 SetValves(UInt128 valvesToOpen, UInt128 valvesToClose, IList extendedValves) { return 0; } + public UInt128 SetValves(UInt128 valvesToOpen, UInt128 valvesToClose, IList extendedValves) + { + UInt128 oldRoute = benchModelRoute; + benchModelRoute = (((benchModelRoute ^ valvesToInvert) | valvesToOpen) & (~valvesToClose)) ^ valvesToInvert; + foreach (var extV in extendedValves) extV.UpdateRoute(ref benchModelRoute); + log.DebugFormat("SetValves(x,x), new route = {0}", Utils.RouteToStr(benchModelRoute)); + UInt128 retVal = oldRoute ^ benchModelRoute; + + log.DebugFormat("{0}.SetValves({1}, {2}) returns {3}", Name, valvesToOpen.ToString("X"), valvesToClose.ToString("X"), retVal.ToString("X")); + return retVal; + } /// /// Operations