Compare commits

...
2 changed files with 41 additions and 7 deletions
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.1.1642.0")]
[assembly: AssemblyFileVersion("3.1.1642.0")]
[assembly: AssemblyVersion("3.1.1643.0")]
[assembly: AssemblyFileVersion("3.1.1643.0")]
+39 -5
View File
@@ -63,6 +63,8 @@ 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 age0BytesCount; /// Just received bytes count
int age1BytesCount; /// Count of bytes received 1 second ago
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
@@ -223,6 +225,8 @@ namespace TBF.Rig.ControlBoard.Uni
rcvdData = new byte[BUFFER_SIZE];
cumulativeSums = new int[BUFFER_SIZE];
rcvdBytesCount = 0;
age0BytesCount = 0;
age1BytesCount = 0;
serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
serialPort.DtrEnable = true;
@@ -249,16 +253,36 @@ namespace TBF.Rig.ControlBoard.Uni
bool generalDataReceived = false;
if (cbCfg.DebugLevel == DebugMode.Normal && serialPort != null && serialPort.IsOpen)
{
/// Read new received bytes and append them to a buffer
int bytesCount = serialPort.BytesToRead;
if (bytesCount > 0)
int age2BytesCount = age1BytesCount;
age1BytesCount = age0BytesCount;
age0BytesCount = serialPort.BytesToRead;
/// Read new received bytes and append them to an intermediate buffer 'buffer'
if (age0BytesCount > 0)
{
bytesCount = serialPort.Read(buffer, 0, Math.Min(bytesCount, BUFFER_SIZE));
age0BytesCount = serialPort.Read(buffer, 0, Math.Min(age0BytesCount, BUFFER_SIZE));
}
for (int i = 0; i < bytesCount && rcvdBytesCount < BUFFER_SIZE; i++, rcvdBytesCount++)
StringBuilder sb = new StringBuilder();
sb.Append(string.Format("{0}-{1}+{2}={3} bytes:",
rcvdBytesCount, age2BytesCount, age0BytesCount,
rcvdBytesCount - age2BytesCount + age0BytesCount));
/// Remove data 2 seconds old
for (int i = 0; i < age1BytesCount; i++)
{
rcvdData[i] = rcvdData[age2BytesCount + i];
sb.Append(string.Format(" {0:X2}", rcvdData[i]));
}
rcvdBytesCount -= age2BytesCount;
/// Append new received data (0 seconds old)
for (int i = 0; i < age0BytesCount && rcvdBytesCount < BUFFER_SIZE; i++, rcvdBytesCount++)
{
rcvdData[rcvdBytesCount] = buffer[i];
sb.Append(string.Format(" {0:X2}", buffer[i]));
}
log.Debug(sb.ToString());
/// Calculate cumulative sums (to verify checksums easily)
int cumulativeSum = 0;
@@ -330,6 +354,16 @@ namespace TBF.Rig.ControlBoard.Uni
rcvdData[i - lastValidOffset] = rcvdData[i];
}
rcvdBytesCount -= lastValidOffset;
if (lastValidOffset <= age1BytesCount)
{
age1BytesCount -= lastValidOffset;
}
else
{
age1BytesCount = 0;
age0BytesCount -= (lastValidOffset - age1BytesCount);
}
}
///