ControlBoard.Uni : (1) 2s old serial data removed from the input buffer, (2) improved serial data logging.

This commit is contained in:
Milan Hanajik
2021-05-11 14:21:04 +02:00
parent 4f1e7507f9
commit 2642e3cc46
7 changed files with 154 additions and 16 deletions
+2 -2
View File
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("3.1.1642.0")] [assembly: AssemblyVersion("3.1.1644.0")]
[assembly: AssemblyFileVersion("3.1.1642.0")] [assembly: AssemblyFileVersion("3.1.1644.0")]
@@ -157,5 +157,21 @@ namespace TBF.Rig.ControlBoard.Uni
return transitionEndIdx - transitionStartIdx; return transitionEndIdx - transitionStartIdx;
} }
public static string Caption()
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
return " [---- Diverter transition data ----------------------------------------------------------------------------------------------------------------------" +
// 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 100 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 150 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 200 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 250 51 52 53 54
"---------- Sum]";
}
} }
} }
+18
View File
@@ -243,6 +243,24 @@ namespace TBF.Rig.ControlBoard.Uni
return lastPulses[wmNr1]; return lastPulses[wmNr1];
} }
public static string Caption()
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
return " [. .. .. .. .. (-- state ---) (------ vystupy ------) (DA2) (-- vstupy --) (---------------------------------------------- analogy ------------------" +
// 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"--------------------) (------------- meracia ustredna --------------) (--Et1-) (--EtK-) xx (s56) xx (---- reg.ventily ----) (--- citace --------------" +
// 100 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"---------------------------------------------------------------------------------------- citace ------------------------------------------------------" +
// 150 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"---------------------------------------------------------------------------------------- citace ------------------------------------------------------" +
// 200 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"--------------------- citace ---) (------------------------------------------------------------- citace 2 --------------------------------------------" +
// 250 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"--) (test-time) (SDA) xx (-period1-) (-period2-) (-period3-) xx KL xx CH (---Tim2--) (---------------- cas koh. -------------------) (-ETX2-) (-ETX3-)" +
// 300 01 02
" xx Sum ]";
}
} }
/// <summary> /// <summary>
@@ -27,6 +27,12 @@ namespace TBF.Rig.ControlBoard.Uni
} }
public static string Caption()
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
return " [. .. .. ..Cmd P1 P2 (pulses) (mass.p) xx (cfg) Xg (------- route -------) (DA2) RV Rpar1 Rpar2 St (DA1) PID x ST Div Sum ]";
}
public static byte[] GetMessage(Action action, short config, ulong bitsToInvert) public static byte[] GetMessage(Action action, short config, ulong bitsToInvert)
{ {
FetchArguments(action); FetchArguments(action);
@@ -53,5 +53,51 @@ namespace TBF.Rig.ControlBoard.Uni
return data; return data;
} }
public static string Caption()
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
return " [---- Scope analyzer data ---------------------------------------------------------------------------------------------------------------------------" +
// 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 100 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 150 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 200 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 250 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 300 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 350 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 400 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 450 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 500 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 550 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 600 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 650 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 700 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 750 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 800 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 850 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 900 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 950 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 1000 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"---------------------------------------------------------------------------------------------- Sum]";
}
} }
} }
@@ -49,5 +49,21 @@ namespace TBF.Rig.ControlBoard.Uni
return data; return data;
} }
public static string Caption()
{
// 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
return " [---- Switch counters data --------------------------------------------------------------------------------------------------------------------------" +
// 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 100 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 150 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 200 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
"------------------------------------------------------------------------------------------------------------------------------------------------------" +
// 250 51 52 53 54
"---------- Sum]";
}
} }
} }
+50 -14
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 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 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 lastSentTime; /// Time stamp of the last sent command/request frame
DateTime lastReceivedTime; /// Time stamp of the last received valid frame DateTime lastReceivedTime; /// Time stamp of the last received valid frame
int lastRcvdStMTime; /// StateMachine.Time 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]; rcvdData = new byte[BUFFER_SIZE];
cumulativeSums = new int[BUFFER_SIZE]; cumulativeSums = new int[BUFFER_SIZE];
rcvdBytesCount = 0; rcvdBytesCount = 0;
age0BytesCount = 0;
age1BytesCount = 0;
serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One); serialPort = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One);
serialPort.DtrEnable = true; serialPort.DtrEnable = true;
@@ -249,15 +253,36 @@ namespace TBF.Rig.ControlBoard.Uni
bool generalDataReceived = false; bool generalDataReceived = false;
if (cbCfg.DebugLevel == DebugMode.Normal && serialPort != null && serialPort.IsOpen) if (cbCfg.DebugLevel == DebugMode.Normal && serialPort != null && serialPort.IsOpen)
{ {
/// Read new received bytes and append them to a buffer int age2BytesCount = age1BytesCount;
int bytesCount = serialPort.BytesToRead; age1BytesCount = age0BytesCount;
if (bytesCount > 0) 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 dataLog = new StringBuilder();
StringBuilder caption = new StringBuilder();
string summary = string.Format("{0}-{1}+{2}={3} bytes:", rcvdBytesCount, age2BytesCount, age0BytesCount,
rcvdBytesCount - age2BytesCount + age0BytesCount);
dataLog.Append(summary);
for (int i = 0; i < summary.Length; i++) caption.Append(" ");
/// Remove data 2 seconds old
for (int i = 0; i < age1BytesCount; i++)
{
rcvdData[i] = rcvdData[age2BytesCount + i];
dataLog.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]; rcvdData[rcvdBytesCount] = buffer[i];
dataLog.Append(string.Format(" {0:X2}", buffer[i]));
} }
/// Calculate cumulative sums (to verify checksums easily) /// Calculate cumulative sums (to verify checksums easily)
@@ -279,7 +304,7 @@ namespace TBF.Rig.ControlBoard.Uni
{ {
/// Scope analyzer data received /// Scope analyzer data received
scopeAnalyzerData = ScopeAnalyzerData.GetData(rcvdData, offset); scopeAnalyzerData = ScopeAnalyzerData.GetData(rcvdData, offset);
msg = Telegram.LogTelegram("Scope analyzer data ", rcvdData, offset, ScopeAnalyzerData.MessageLen); caption.Append(ScopeAnalyzerData.Caption());
offset += ScopeAnalyzerData.MessageLen; offset += ScopeAnalyzerData.MessageLen;
anyProcessed = true; anyProcessed = true;
} }
@@ -288,7 +313,7 @@ namespace TBF.Rig.ControlBoard.Uni
/// Regular data received /// Regular data received
generalDataReceived = true; generalDataReceived = true;
Data.UpdateData(rcvdData, offset); Data.UpdateData(rcvdData, offset);
msg = Telegram.LogTelegram("General data ", rcvdData, offset, GeneralData.MessageLen); caption.Append(GeneralData.Caption());
offset += GeneralData.MessageLen; offset += GeneralData.MessageLen;
anyProcessed = true; anyProcessed = true;
} }
@@ -296,7 +321,7 @@ namespace TBF.Rig.ControlBoard.Uni
{ {
/// Switch counter data received /// Switch counter data received
switchCounterData = SwitchCountersData.GetData(rcvdData, offset); switchCounterData = SwitchCountersData.GetData(rcvdData, offset);
msg = Telegram.LogTelegram("Switch counter data ", rcvdData, offset, SwitchCountersData.MessageLen); caption.Append(SwitchCountersData.Caption());
offset += SwitchCountersData.MessageLen; offset += SwitchCountersData.MessageLen;
anyProcessed = true; anyProcessed = true;
} }
@@ -304,7 +329,7 @@ namespace TBF.Rig.ControlBoard.Uni
{ {
/// Diverter transition data received /// Diverter transition data received
divTransitionData = DivTransitionData.GetData(rcvdData, offset); divTransitionData = DivTransitionData.GetData(rcvdData, offset);
msg = Telegram.LogTelegram("Diverter transition data ", rcvdData, offset, DivTransitionData.MessageLen); caption.Append(DivTransitionData.Caption());
offset += DivTransitionData.MessageLen; offset += DivTransitionData.MessageLen;
anyProcessed = true; anyProcessed = true;
} }
@@ -314,22 +339,34 @@ namespace TBF.Rig.ControlBoard.Uni
lastValidOffset = offset; lastValidOffset = offset;
lastRcvdStMTime = StateMachine.Time; lastRcvdStMTime = StateMachine.Time;
lastReceivedTime = DateTime.Now; lastReceivedTime = DateTime.Now;
Debug.WriteLine(msg);
log.Debug(msg);
} }
else else
{ {
caption.Append(" ");
offset++; offset++;
} }
} }
while (offset < rcvdBytesCount); while (offset < rcvdBytesCount);
log.Debug(caption.ToString());
log.Debug(dataLog.ToString());
/// Remove processed data from the receive buffer /// Remove processed data from the receive buffer
for (int i = lastValidOffset; i < rcvdBytesCount; i++) for (int i = lastValidOffset; i < rcvdBytesCount; i++)
{ {
rcvdData[i - lastValidOffset] = rcvdData[i]; rcvdData[i - lastValidOffset] = rcvdData[i];
} }
rcvdBytesCount -= lastValidOffset; rcvdBytesCount -= lastValidOffset;
if (lastValidOffset <= age1BytesCount)
{
age1BytesCount -= lastValidOffset;
}
else
{
age1BytesCount = 0;
age0BytesCount -= (lastValidOffset - age1BytesCount);
}
} }
/// ///
@@ -474,9 +511,8 @@ namespace TBF.Rig.ControlBoard.Uni
lastSentTime = DateTime.Now; lastSentTime = DateTime.Now;
} }
string s = Telegram.LogTelegram("Sent: ", outData); log.Debug(" " + OutputMessage.Caption());
Debug.WriteLine(s); log.Debug(Telegram.LogTelegram("Sent: ", outData));
log.Debug(s);
} }
log.DebugFormat(" Queue content:"); log.DebugFormat(" Queue content:");