UniCB : Prevent too early sending of data, ver. 3.1.1619

This commit is contained in:
Milan Hanajik
2021-04-01 15:14:15 +02:00
parent d6ae50f4dd
commit 931a4bcc00
2 changed files with 20 additions and 6 deletions
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("3.1.1618.0")] [assembly: AssemblyVersion("3.1.1619.0")]
[assembly: AssemblyFileVersion("3.1.1618.0")] [assembly: AssemblyFileVersion("3.1.1619.0")]
+18 -4
View File
@@ -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 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[] cumulativeSums; /// Cumulative sums to verify checksums easily
int rcvdBytesCount; /// Count of valid bytes in rcvdData buffer 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 bool outputsInitialized; /// Flag indicating that outputs were sent at least once
/// ///
@@ -203,7 +205,9 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary> /// </summary>
public void Initialize() 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) if (cbCfg.DebugLevel == DebugMode.Normal)
{ {
@@ -305,7 +309,8 @@ namespace TBF.Rig.ControlBoard.Uni
if (anyProcessed) if (anyProcessed)
{ {
lastValidOffset = offset; lastValidOffset = offset;
lastReceivedTime = StateMachine.Time; lastRcvdStMTime = StateMachine.Time;
lastReceivedTime = DateTime.Now;
Debug.WriteLine(msg); Debug.WriteLine(msg);
log.Debug(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 /// No connection to control board ... set indicator bit
route |= ((UInt128)1) << cbCfg.BitNr; route |= ((UInt128)1) << cbCfg.BitNr;
@@ -369,6 +374,14 @@ namespace TBF.Rig.ControlBoard.Uni
/// </summary> /// </summary>
public void RunDeviceAfter() 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 /// Combine data from the current route and from UI
/// ///
@@ -450,6 +463,7 @@ namespace TBF.Rig.ControlBoard.Uni
if (cbCfg.DebugLevel == DebugMode.Normal) if (cbCfg.DebugLevel == DebugMode.Normal)
{ {
serialPort.Write(outData, 0, outData.Length); serialPort.Write(outData, 0, outData.Length);
lastSentTime = DateTime.Now;
} }
string s = Telegram.LogTelegram("Sent: ", outData); string s = Telegram.LogTelegram("Sent: ", outData);