From d6ae50f4dd2334b73283cb6619e8e5d55e86be8a Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 31 Mar 2021 16:23:12 +0200 Subject: [PATCH] Uni : Buffering of the last combined action arguments, ver. 3.1.1618 --- TBF/Properties/AssemblyInfo.cs | 4 +-- TBF/Rig/ControlBoard/Uni/Action.cs | 38 +++++++++++++---------- TBF/Rig/ControlBoard/Uni/OutputMessage.cs | 32 +++++++++++++------ 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 6badef981..27fe8942e 100644 --- a/TBF/Properties/AssemblyInfo.cs +++ b/TBF/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("3.1.1617.0")] -[assembly: AssemblyFileVersion("3.1.1617.0")] +[assembly: AssemblyVersion("3.1.1618.0")] +[assembly: AssemblyFileVersion("3.1.1618.0")] diff --git a/TBF/Rig/ControlBoard/Uni/Action.cs b/TBF/Rig/ControlBoard/Uni/Action.cs index d011d4b81..1f2e12e1a 100644 --- a/TBF/Rig/ControlBoard/Uni/Action.cs +++ b/TBF/Rig/ControlBoard/Uni/Action.cs @@ -492,29 +492,33 @@ namespace TBF.Rig.ControlBoard.Uni } ///---------------------------------------------------------------------------------------------- - void SetArgs(Action action) + public void SetArgs(Action action, ActionID actionId) { - ActionId |= action.ActionId; - - switch (action.ActionId) + switch (actionId) { - case ActionID.ChangeRoute: SetChangeRouteArgs(action); return; - case ActionID.MeasureFlow: SetMeasureFlowArgs(action); return; - case ActionID.SetFlow: SetSetFlowArgs(action); return; - case ActionID.StartTest: SetStartTestArgs(action); return; - case ActionID.Stop: SetStopArgs(action); return; - case ActionID.RegVlvIncrMove: SetRegVlvIncrMoveArgs(action); return; - case ActionID.RegVlvMoveToPos: SetRegVlvMoveToPosArgs(action); return; - case ActionID.RegVlvStop: SetRegVlvStopArgs(action); return; - case ActionID.SwitchDiverter: SetSwitchDiverterArgs(action); return; - case ActionID.DelayStartOrStop: SetDelayStartOrStopArgs(action); return; + case ActionID.ChangeRoute: SetChangeRouteArgs(action); return; + case ActionID.MeasureFlow: SetMeasureFlowArgs(action); return; + case ActionID.SetFlow: SetSetFlowArgs(action); return; + case ActionID.StartTest: SetStartTestArgs(action); return; + case ActionID.Stop: SetStopArgs(action); return; + case ActionID.RegVlvIncrMove: SetRegVlvIncrMoveArgs(action); return; + case ActionID.RegVlvMoveToPos: SetRegVlvMoveToPosArgs(action); return; + case ActionID.RegVlvStop: SetRegVlvStopArgs(action); return; + case ActionID.SwitchDiverter: SetSwitchDiverterArgs(action); return; + case ActionID.DelayStartOrStop: SetDelayStartOrStopArgs(action); return; case ActionID.GetDiverterTransitionData: SetGetDiverterTransitionDataArgs(action); return; - case ActionID.GetScopeAnalyzerData: SetGetScopeAnalyzerDataArgs(action); return; - case ActionID.ResetScopeAnalyzer: SetResetScopeAnalyzerArgs(action); return; - case ActionID.GetSwitchCounterData: SetGetSwitchCounterDataArgs(action); return; + case ActionID.GetScopeAnalyzerData: SetGetScopeAnalyzerDataArgs(action); return; + case ActionID.ResetScopeAnalyzer: SetResetScopeAnalyzerArgs(action); return; + case ActionID.GetSwitchCounterData: SetGetSwitchCounterDataArgs(action); return; default: return; } } + void SetArgs(Action action) + { + ActionId |= action.ActionId; + SetArgs(action, action.ActionId); + } + /// /// Check whether new action arguments are compatible with alredy collected arguments diff --git a/TBF/Rig/ControlBoard/Uni/OutputMessage.cs b/TBF/Rig/ControlBoard/Uni/OutputMessage.cs index ce3110b78..d3fad84ef 100644 --- a/TBF/Rig/ControlBoard/Uni/OutputMessage.cs +++ b/TBF/Rig/ControlBoard/Uni/OutputMessage.cs @@ -15,8 +15,22 @@ namespace TBF.Rig.ControlBoard.Uni public const int PayloadLen = 38; public const byte MessageCode = (byte)' '; + + static Action arguments = new Action(); + /// + static void FetchArguments(Action combinedAction) + { + foreach (var aId in (ActionID[])Enum.GetValues(typeof(ActionID))) + { + if ((combinedAction.ActionId & aId) != 0) arguments.SetArgs(combinedAction, aId); + } + } + + public static byte[] GetMessage(Action action, short config, ulong bitsToInvert) { + FetchArguments(action); + byte[] message = new byte[PayloadLen + 5]; /// headed 3 bytes, checksum 2 bytes /// Header + message code (4 bytes) @@ -28,14 +42,14 @@ namespace TBF.Rig.ControlBoard.Uni /// Command message[4] = GetCommand(action); message[5] = action.IsStart() ? GetStartParams(action) : action.IsStop() ? GetStopParams(action) : (byte)0; - message[6] = (action.DivId <= 0) ? (byte)0 : (byte)(action.DivId - 1); + message[6] = (arguments.DivId <= 0) ? (byte)0 : (byte)(arguments.DivId - 1); - int totalPulsesCount = (action.TotalPulsesCount < 0) ? 0 : action.TotalPulsesCount; + int totalPulsesCount = (arguments.TotalPulsesCount < 0) ? 0 : arguments.TotalPulsesCount; message[7] = (byte)(totalPulsesCount & 0xFF); message[8] = (byte)((totalPulsesCount >> 8) & 0xFF); message[9] = (byte)((totalPulsesCount >> 16) & 0xFF); - - int massPulsesCount = (action.MassPulsesCount < 0) ? 0 : action.MassPulsesCount; + + int massPulsesCount = (arguments.MassPulsesCount < 0) ? 0 : arguments.MassPulsesCount; message[10] = (byte)(massPulsesCount & 0xFF); message[11] = (byte)((massPulsesCount >> 8) & 0xFF); message[12] = (byte)((massPulsesCount >> 16) & 0xFF); @@ -46,7 +60,7 @@ namespace TBF.Rig.ControlBoard.Uni message[15] = (byte)((config >> 8) & 0xff); /// Route - ulong routeOut = action.Route ^ bitsToInvert; + ulong routeOut = arguments.Route ^ bitsToInvert; message[16] = ((action.ActionId & ActionID.ChangeRoute) != 0) ? (byte)1 : (byte)0; /// Route change flag message[17] = (byte)(routeOut & 0xFF); message[18] = (byte)((routeOut >> 8) & 0xFF); @@ -72,11 +86,11 @@ namespace TBF.Rig.ControlBoard.Uni /// DA1 message[33] = 0; /// PrudParL message[34] = 0; /// PrudParH - - message[35] = (byte)Math.Max(1, Math.Min(255, action.PID)); /// PIDRV + + message[35] = (byte)Math.Max(1, Math.Min(255, arguments.PID)); /// PIDRV message[36] = 0; // (byte)Math.Max(4, Math.Min(255, action.TolerRV)); /// TolerRV (4..20 mA reg.valve only) - message[37] = (byte)Math.Max(0, Math.Min(255, action.StabTime)); /// StabRV - message[38] = (byte)((action.DivThreshold >> 2) & 0xFF); + message[37] = (byte)Math.Max(0, Math.Min(255, arguments.StabTime)); /// StabRV + message[38] = (byte)((arguments.DivThreshold >> 2) & 0xFF); message[39] = 0; message[40] = 0;