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 ClpPassword = "C1ern4V0d4";
const string ClpPrompt = "$ ";
const bool ClpSkipFirstLine = true;
public readonly CameraCfg CameraCfg;
@@ -144,7 +145,7 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
if (cameraDetected)
{
/// 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)
{
@@ -2,6 +2,7 @@
/// Copyright (c) 2017 Sensus Metering Systems
///
using TBF.BenchControl.Generic;
using TBF.Resources;
namespace TBF.BenchControl.Network.Camera.CLP1611
{
@@ -33,7 +34,12 @@ namespace TBF.BenchControl.Network.Camera.CLP1611
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,6 +202,7 @@ namespace TBF.BenchControl.Network.Telnet
readonly string telnetUserName;
readonly string telnetPassword;
readonly string defaultPrompt;
readonly bool skipFirstLine; /// Skip the first line when logging in
DateTime cmdStartTime; /// Time of the last Dequeue (= command execution start time).
@@ -222,12 +223,13 @@ namespace TBF.BenchControl.Network.Telnet
/// Hostname (IP address) and the port number is passed to worker thread
/// in a Command with CmdAction.CONNECT and str=hostname.
/// </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.telnetUserName = userName;
this.telnetPassword = password;
this.defaultPrompt = defaultPrompt;
this.skipFirstLine = skipFirstLine;
state = TelnetState.Inactive; /// Device's icon is being updated by HNIP
vt = new VirtualTerminal(); /// TODO: pass a VirtualTerminal reference
@@ -792,7 +794,7 @@ namespace TBF.BenchControl.Network.Telnet
///
/// Username
///
RetVal retval = WaitForLoginPrompt(": ");
RetVal retval = WaitForLoginPrompt(": ", skipFirstLine);
if (retval != RetVal.OK) return retval;
vt.WriteVt(username + System.Environment.NewLine);
WriteLineTcp(username);
@@ -800,14 +802,14 @@ namespace TBF.BenchControl.Network.Telnet
///
/// Password (hidden on the VT)
///
retval = WaitForLoginPrompt(": ");
retval = WaitForLoginPrompt(": ", false);
if (retval != RetVal.OK) return retval;
WriteLineTcp(password);
///
/// Reset 'prompt' after (re)login and wait for the prompt
///
retval = WaitForLoginPrompt(prompt);
retval = WaitForLoginPrompt(prompt, false);
if (retval != RetVal.OK) return retval;
log.Info("Telnet login successfully completed " + hostname);
@@ -820,7 +822,7 @@ namespace TBF.BenchControl.Network.Telnet
/// </summary>
/// <param name="endsWithPattern">Quit condition, login prompt should end with this pattern</param>
/// <returns></returns>
RetVal WaitForLoginPrompt(string endsWithPattern)
RetVal WaitForLoginPrompt(string endsWithPattern, bool skipFirstLine)
{
StringBuilder s = new StringBuilder();
@@ -845,12 +847,29 @@ namespace TBF.BenchControl.Network.Telnet
}
if (ds != null && ds.Length > 0)
{
if (skipFirstLine)
{
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));
return RetVal.OK;
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.12.467.1")]
[assembly: AssemblyFileVersion("2.12.467.1")]
[assembly: AssemblyVersion("2.12.468.1")]
[assembly: AssemblyFileVersion("2.12.468.1")]