Network.Telnet and Network.CLP1611.Camera : Skip the first line in the VT terminal when logging on, ver. 2.12.468

This commit is contained in:
Milan Hanajik
2017-02-16 11:42:15 +01:00
parent 463e3fd0aa
commit 1029308b2c
4 changed files with 43 additions and 17 deletions
@@ -38,6 +38,7 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
const string ClpUserName = "tbf"; const string ClpUserName = "tbf";
const string ClpPassword = "C1ern4V0d4"; const string ClpPassword = "C1ern4V0d4";
const string ClpPrompt = "$ "; const string ClpPrompt = "$ ";
const bool ClpSkipFirstLine = true;
public readonly CameraCfg CameraCfg; public readonly CameraCfg CameraCfg;
@@ -144,7 +145,7 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
if (cameraDetected) if (cameraDetected)
{ {
/// Open telnet clint and start the log-in process /// Open telnet clint and start the log-in process
Telnet = new Telnet.TelnetClient(this, CameraCfg.Name, ClpUserName, ClpPassword, ClpPrompt); Telnet = new Telnet.TelnetClient(this, CameraCfg.Name, ClpUserName, ClpPassword, ClpPrompt, ClpSkipFirstLine);
if (CameraCfg.DisplayTerminal) if (CameraCfg.DisplayTerminal)
{ {
@@ -2,6 +2,7 @@
/// Copyright (c) 2017 Sensus Metering Systems /// Copyright (c) 2017 Sensus Metering Systems
/// ///
using TBF.BenchControl.Generic; using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.Network.Camera.CLP1611 namespace TBF.BenchControl.Network.Camera.CLP1611
{ {
@@ -33,7 +34,12 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
public string ToString(int i) public string ToString(int i)
{ {
return string.Format("Name={0}, HWAddr={1}, Parent={2}", Name, HardwareAddress, ParentName); return string.Format("Name={0}, Address={1}, Terminal={2}, Use test images={3}, Parent={4}",
Name,
HardwareAddress,
DisplayTerminal ? Strings.yes : Strings.no,
UseTestImages ? Strings.yes : Strings.no,
ParentName);
} }
} }
} }
@@ -202,14 +202,15 @@ namespace TBF.BenchControl.Network.Telnet
readonly string telnetUserName; readonly string telnetUserName;
readonly string telnetPassword; readonly string telnetPassword;
readonly string defaultPrompt; readonly string defaultPrompt;
readonly bool skipFirstLine; /// Skip the first line when logging in
DateTime cmdStartTime; /// Time of the last Dequeue (= command execution start time). DateTime cmdStartTime; /// Time of the last Dequeue (= command execution start time).
TimeSpan cmdTimeOut; /// Time out period of the last dequeued command. TimeSpan cmdTimeOut; /// Time out period of the last dequeued command.
DateTime connectTimeout; /// Checked when handling NvtEvent.Timeout and in the state NvtState.Login DateTime connectTimeout; /// Checked when handling NvtEvent.Timeout and in the state NvtState.Login
int timeDone = 0; /// Duration of commands in [s] executed so far ... int timeDone = 0; /// Duration of commands in [s] executed so far ...
/// ... starting from Command(CmdAction.NOTIFICATION, "Begin") /// ... starting from Command(CmdAction.NOTIFICATION, "Begin")
Command currentCmd = new Command(CmdAction.VOID); /// The currently executed command, used to calculate timeDone Command currentCmd = new Command(CmdAction.VOID); /// The currently executed command, used to calculate timeDone
@@ -222,12 +223,13 @@ namespace TBF.BenchControl.Network.Telnet
/// Hostname (IP address) and the port number is passed to worker thread /// Hostname (IP address) and the port number is passed to worker thread
/// in a Command with CmdAction.CONNECT and str=hostname. /// in a Command with CmdAction.CONNECT and str=hostname.
/// </summary> /// </summary>
public TelnetClient(object objRef, string threadId, string userName, string password, string defaultPrompt) public TelnetClient(object objRef, string threadId, string userName, string password, string defaultPrompt, bool skipFirstLine)
{ {
this.objRef = objRef; this.objRef = objRef;
this.telnetUserName = userName; this.telnetUserName = userName;
this.telnetPassword = password; this.telnetPassword = password;
this.defaultPrompt = defaultPrompt; this.defaultPrompt = defaultPrompt;
this.skipFirstLine = skipFirstLine;
state = TelnetState.Inactive; /// Device's icon is being updated by HNIP state = TelnetState.Inactive; /// Device's icon is being updated by HNIP
vt = new VirtualTerminal(); /// TODO: pass a VirtualTerminal reference vt = new VirtualTerminal(); /// TODO: pass a VirtualTerminal reference
@@ -792,7 +794,7 @@ namespace TBF.BenchControl.Network.Telnet
/// ///
/// Username /// Username
/// ///
RetVal retval = WaitForLoginPrompt(": "); RetVal retval = WaitForLoginPrompt(": ", skipFirstLine);
if (retval != RetVal.OK) return retval; if (retval != RetVal.OK) return retval;
vt.WriteVt(username + System.Environment.NewLine); vt.WriteVt(username + System.Environment.NewLine);
WriteLineTcp(username); WriteLineTcp(username);
@@ -800,14 +802,14 @@ namespace TBF.BenchControl.Network.Telnet
/// ///
/// Password (hidden on the VT) /// Password (hidden on the VT)
/// ///
retval = WaitForLoginPrompt(": "); retval = WaitForLoginPrompt(": ", false);
if (retval != RetVal.OK) return retval; if (retval != RetVal.OK) return retval;
WriteLineTcp(password); WriteLineTcp(password);
/// ///
/// Reset 'prompt' after (re)login and wait for the prompt /// Reset 'prompt' after (re)login and wait for the prompt
/// ///
retval = WaitForLoginPrompt(prompt); retval = WaitForLoginPrompt(prompt, false);
if (retval != RetVal.OK) return retval; if (retval != RetVal.OK) return retval;
log.Info("Telnet login successfully completed " + hostname); log.Info("Telnet login successfully completed " + hostname);
@@ -820,7 +822,7 @@ namespace TBF.BenchControl.Network.Telnet
/// </summary> /// </summary>
/// <param name="endsWithPattern">Quit condition, login prompt should end with this pattern</param> /// <param name="endsWithPattern">Quit condition, login prompt should end with this pattern</param>
/// <returns></returns> /// <returns></returns>
RetVal WaitForLoginPrompt(string endsWithPattern) RetVal WaitForLoginPrompt(string endsWithPattern, bool skipFirstLine)
{ {
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
@@ -846,9 +848,26 @@ namespace TBF.BenchControl.Network.Telnet
if (ds != null && ds.Length > 0) if (ds != null && ds.Length > 0)
{ {
vt.WriteVt(ds); if (skipFirstLine)
s.Append(ds); {
OnVtTextChanged(); if (ds.Contains(Environment.NewLine))
{
skipFirstLine = false;
string afterNL = ds.Substring(ds.IndexOf(Environment.NewLine) + Environment.NewLine.Length);
if (afterNL.Length > 0)
{
vt.WriteVt(afterNL);
s.Append(afterNL);
OnVtTextChanged();
}
}
}
else
{
vt.WriteVt(ds);
s.Append(ds);
OnVtTextChanged();
}
} }
} }
while (!s.ToString().EndsWith(endsWithPattern)); while (!s.ToString().EndsWith(endsWithPattern));
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number // Build Number
// Revision // Revision
// //
[assembly: AssemblyVersion("2.12.467.1")] [assembly: AssemblyVersion("2.12.468.1")]
[assembly: AssemblyFileVersion("2.12.467.1")] [assembly: AssemblyFileVersion("2.12.468.1")]