From 931a4bcc00b1fa3e16317af5ff6dde37a381f10b Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Thu, 1 Apr 2021 15:13:17 +0200 Subject: [PATCH] UniCB : Prevent too early sending of data, ver. 3.1.1619 --- TBF/Properties/AssemblyInfo.cs | 4 ++-- TBF/Rig/ControlBoard/Uni/UniCB.cs | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/TBF/Properties/AssemblyInfo.cs b/TBF/Properties/AssemblyInfo.cs index 27fe8942e..72b218a9b 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.1618.0")] -[assembly: AssemblyFileVersion("3.1.1618.0")] +[assembly: AssemblyVersion("3.1.1619.0")] +[assembly: AssemblyFileVersion("3.1.1619.0")] diff --git a/TBF/Rig/ControlBoard/Uni/UniCB.cs b/TBF/Rig/ControlBoard/Uni/UniCB.cs index a023c4909..4a4f42592 100644 --- a/TBF/Rig/ControlBoard/Uni/UniCB.cs +++ b/TBF/Rig/ControlBoard/Uni/UniCB.cs @@ -63,7 +63,9 @@ namespace TBF.Rig.ControlBoard.Uni byte[] rcvdData; /// Buffer for all recevied but nut processed data. May contain data from several read attempts int[] cumulativeSums; /// Cumulative sums to verify checksums easily int rcvdBytesCount; /// Count of valid bytes in rcvdData buffer - int lastReceivedTime; /// StateMachine.Time time stamp of the last received valid frame + DateTime lastSentTime; /// Time stamp of the last sent command/request frame + DateTime lastReceivedTime; /// Time stamp of the last received valid frame + int lastRcvdStMTime; /// StateMachine.Time time stamp of the last received valid frame bool outputsInitialized; /// Flag indicating that outputs were sent at least once /// @@ -203,7 +205,9 @@ namespace TBF.Rig.ControlBoard.Uni /// public void Initialize() { - lastReceivedTime = StateMachine.Time; /// To indicate the serial connection state + lastRcvdStMTime = StateMachine.Time; /// To indicate the serial connection state + lastSentTime = DateTime.Now; + lastReceivedTime = DateTime.Now; if (cbCfg.DebugLevel == DebugMode.Normal) { @@ -305,7 +309,8 @@ namespace TBF.Rig.ControlBoard.Uni if (anyProcessed) { lastValidOffset = offset; - lastReceivedTime = StateMachine.Time; + lastRcvdStMTime = StateMachine.Time; + lastReceivedTime = DateTime.Now; Debug.WriteLine(msg); log.Debug(msg); } @@ -338,7 +343,7 @@ namespace TBF.Rig.ControlBoard.Uni } } - if (cbCfg.DebugLevel == DebugMode.Normal && (StateMachine.Time - lastReceivedTime) >= 5) + if (cbCfg.DebugLevel == DebugMode.Normal && (StateMachine.Time - lastRcvdStMTime) >= 5) { /// No connection to control board ... set indicator bit route |= ((UInt128)1) << cbCfg.BitNr; @@ -369,6 +374,14 @@ namespace TBF.Rig.ControlBoard.Uni /// public void RunDeviceAfter() { + DateTime now = DateTime.Now; + if (now < lastSentTime + TimeSpan.FromSeconds(0.8) || + (lastReceivedTime < lastSentTime && now < lastSentTime + TimeSpan.FromSeconds(2.5))) + { + log.Error("RunDeviceAfter() ... skipping too early write of a serial command or a data requect"); + return; + } + /// /// Combine data from the current route and from UI /// @@ -450,6 +463,7 @@ namespace TBF.Rig.ControlBoard.Uni if (cbCfg.DebugLevel == DebugMode.Normal) { serialPort.Write(outData, 0, outData.Length); + lastSentTime = DateTime.Now; } string s = Telegram.LogTelegram("Sent: ", outData);