Measured data extracted from Telnet data, ver.2.12.449

This commit is contained in:
Milan Hanajik
2017-01-27 12:47:32 +01:00
parent 20b3840445
commit 3b13756db9
5 changed files with 99 additions and 53 deletions
@@ -104,6 +104,7 @@ namespace TBF.BenchControl.Network.Telnet
AwaitingConnect = 0, /// Awaits CONNECT command from the cmdQueue, no session is active, TCP is not polled
Login, /// Retries a login after REBOOT_RECONNECT or EXIT_RECONNECT commands, queue is not polled
Session, /// Telnet session: awaits commands from the cmdQueue, receives characters from TCP (full-duplex)
Measurement, /// Telnet session: awaits CTRL-C command from the cmdQueue, receives characters from TCP and extracts data
WaitResponse, /// Receives characters from TCP, builds a response str., awaiting the prompt, queue is not polled
WaitReboot, /// Wait until TCP connection is terminated and reboot starts
NvtStatesCount
@@ -295,7 +296,7 @@ namespace TBF.BenchControl.Network.Telnet
while (true)
{
bool pollCmd = (nvtState == NvtState.AwaitingConnect || nvtState == NvtState.Session);
bool pollCmd = (nvtState == NvtState.AwaitingConnect || nvtState == NvtState.Session || nvtState == NvtState.Measurement);
bool pollTcp = (nvtState != NvtState.AwaitingConnect && nvtState != NvtState.Login);
///
@@ -356,7 +357,7 @@ namespace TBF.BenchControl.Network.Telnet
nvtState = NvtState.Login;
continue;
}
else if (nvtState == NvtState.Session)
else if (nvtState == NvtState.Session || nvtState == NvtState.Measurement)
{
switch (cmd.Action)
{
@@ -366,12 +367,21 @@ namespace TBF.BenchControl.Network.Telnet
OnVtTextChanged();
break;
case CmdAction.SEND_MSRMNT_CMD:
vt.WriteVt(cmd.Str + System.Environment.NewLine);
WriteLineTcp(cmd.Str);
OnVtTextChanged();
/// state change
responseBuilder.Clear();
nvtState = NvtState.Measurement;
break;
case CmdAction.SEND_COMMAND:
vt.WriteVt(cmd.Str + System.Environment.NewLine);
WriteLineTcp(cmd.Str);
OnVtTextChanged();
/// state change
responseBuilder.Length = 0;
responseBuilder.Clear();
nvtState = NvtState.WaitResponse;
break;
@@ -394,7 +404,7 @@ namespace TBF.BenchControl.Network.Telnet
OnVtTextChanged();
connectTimeout = cmdStartTime + cmdTimeOut; /// Both were set when REBOOT_RECONNECT was dequeued
cmdTimeOut = TimeSpan.FromMilliseconds(DelayAfterRebootMs);
responseBuilder.Length = 0;
responseBuilder.Clear();
nvtState = NvtState.WaitReboot;
break;
@@ -431,6 +441,29 @@ namespace TBF.BenchControl.Network.Telnet
}
break;
case NvtState.Measurement:
if (ds.Length > 0)
{
vt.WriteVt(ds);
responseBuilder.Append(ds);
OnVtTextChanged();
}
{
/// Extract measurements
int from = responseBuilder.ToString().IndexOf('[');
if (from >= 0)
{
int len = responseBuilder.ToString(from + 1, responseBuilder.Length - from - 1).IndexOf(']');
if (len >= 0)
{
OnMeasurementDataReceived(this, new MeasuredDataEventArgs(responseBuilder.ToString(from + 1, len)));
responseBuilder.Remove(0, from + len + 2);
}
}
}
break;
case NvtState.WaitResponse:
if (ds.Length > 0)
{
@@ -442,9 +475,8 @@ namespace TBF.BenchControl.Network.Telnet
/// Raise OnPromptReceived(response) and clear responseBuilder when prompt detected.
if (responseBuilder.ToString().EndsWith(prompt))
{
responseBuilder.Length = responseBuilder.Length - prompt.Length;
completeResponse = responseBuilder.ToString();
responseBuilder.Length = 0;
completeResponse = responseBuilder.ToString(0, responseBuilder.Length - prompt.Length);
responseBuilder.Clear();
cmdStartTime = DateTime.Now; /// Reset timeout
cmdTimeOut = TimeSpan.MaxValue;
@@ -500,7 +532,7 @@ namespace TBF.BenchControl.Network.Telnet
/// Check the expected response after 'reboot' command.
if (responseBuilder.ToString().EndsWith("Sending SIGTERM to all processes.\r\n"))
{
responseBuilder.Length = 0;
responseBuilder.Clear();
if (RetVal.OK == DisconnectTcp())
{
cmdTimeOut = TimeSpan.FromMilliseconds(DelayAfterRebootMs);
@@ -786,7 +818,7 @@ namespace TBF.BenchControl.Network.Telnet
/// <summary>
/// One part of login which is reused.
/// </summary>
/// <param name="endsWithPattern">Quit condition, received data should end with this pattern</param>
/// <param name="endsWithPattern">Quit condition, login prompt should end with this pattern</param>
/// <returns></returns>
RetVal WaitForLoginPrompt(string endsWithPattern)
{
@@ -1149,6 +1181,23 @@ namespace TBF.BenchControl.Network.Telnet
///
/// MeasurementDataReceivedHandler handler
///
public event EventHandler<MeasuredDataEventArgs> MeasurementDataReceivedHandler;
/// <summary>
/// This method is called from within this class when measurement data were extracted.
/// </summary>
public void OnMeasurementDataReceived(object sender, MeasuredDataEventArgs msrmtData)
{
if (MeasurementDataReceivedHandler == null) return;
try { MeasurementDataReceivedHandler(sender, msrmtData); }
catch (Exception e) { log.Error("MeasurementDataReceivedHandler(...) failed", e); }
}
///
/// PromptReceviedEventHandler delegate and handler
///
@@ -1296,5 +1345,5 @@ namespace TBF.BenchControl.Network.Telnet
}
}
}
}
}
}