Changed password and PcbId handling
This commit is contained in:
@@ -933,25 +933,27 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
return responseRecord;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Acquires the password from WEB-API.
|
||||
/// </summary>
|
||||
/// <returns>password</returns>
|
||||
/// <remarks date="2018JAN08" author="R.Drabesch">
|
||||
/// - Initial.
|
||||
/// </remarks>
|
||||
/// <remarks date="2022-Nov-02" author="T.Wiedebusch">
|
||||
/// - PcbId handling improved.
|
||||
/// </remarks>
|
||||
private String GetPassword()
|
||||
{
|
||||
var url = ServiceUrls.GenesisGetPasswordServiceUrl();
|
||||
String password;
|
||||
|
||||
//without PCB ID it is not possible to login
|
||||
var firstPcbId = GetPcbId();
|
||||
if (string.IsNullOrEmpty(firstPcbId) || firstPcbId.Length < 8)
|
||||
//without PCB ID it is not possible to login,
|
||||
//but if it is already assigned to this Gensis, don't read it again
|
||||
if (string.IsNullOrEmpty(PcbId))
|
||||
{
|
||||
if (firstPcbId != null && firstPcbId.Length < 8)
|
||||
{
|
||||
|
||||
Thread.Sleep(250);
|
||||
}
|
||||
if (string.IsNullOrEmpty(GetPcbId()))
|
||||
{
|
||||
|
||||
return "";
|
||||
}
|
||||
//GetPcbId fills the PsbId property
|
||||
GetPcbId();
|
||||
}
|
||||
|
||||
url += PcbId;
|
||||
@@ -969,8 +971,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
{
|
||||
var responseJson = sr.ReadToEnd();
|
||||
password = responseJson.Trim('"');
|
||||
|
||||
|
||||
}
|
||||
_logger.Info($"Slot:{Slot} - Got password from GenesisPasswordServiceUrl, URL({url})");
|
||||
}
|
||||
@@ -995,8 +995,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// </remarks>
|
||||
public Boolean Login()
|
||||
{
|
||||
var password = GetPassword();
|
||||
return !string.IsNullOrEmpty(password) && Login(password);
|
||||
if (string.IsNullOrEmpty(_password) || string.IsNullOrEmpty(PcbId))
|
||||
{
|
||||
var password = GetPassword();
|
||||
return !string.IsNullOrEmpty(password) && Login(password);
|
||||
}
|
||||
|
||||
return Login(_password);
|
||||
}
|
||||
|
||||
/// <remarks date="2018JAN08" author="drabesch">
|
||||
@@ -1004,8 +1009,13 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// </remarks>
|
||||
public Boolean QuickLogin()
|
||||
{
|
||||
var password = GetPassword();
|
||||
return !string.IsNullOrEmpty(password) && Login(password, true, true);
|
||||
if (string.IsNullOrEmpty(_password) || string.IsNullOrEmpty(PcbId))
|
||||
{
|
||||
var password = GetPassword();
|
||||
return !string.IsNullOrEmpty(password) && Login(password, true, true);
|
||||
}
|
||||
|
||||
return Login(_password, true, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1627,14 +1637,16 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// Read Privilege is always needed to BUGFIX read access to PCB ID
|
||||
/// </summary>
|
||||
/// <returns>PCB ID</returns>
|
||||
/// <remarks date="2022-Okt-20" author="T.Wiedebusch">
|
||||
/// - PcbId handling corrected:
|
||||
/// - read pcbId locally,
|
||||
/// <remarks date="2018JAN08" author="R.Drabesch">
|
||||
/// - PcbId handling improved.
|
||||
/// </remarks>
|
||||
public String GetPcbId(Int32 expectedLength = 12, Int32 retriesLeft = 2)
|
||||
/// <remarks date="2022-Nov-02" author="T.Wiedebusch">
|
||||
/// - PcbId handling improved,
|
||||
/// - Removed retries as these are handled by the protocol.
|
||||
/// </remarks>
|
||||
public String GetPcbId(Int32 expectedLength = 12)
|
||||
{
|
||||
|
||||
var pcbId = "";
|
||||
if (RequestPort == null)
|
||||
{
|
||||
return "Request port not assigned";
|
||||
@@ -1643,50 +1655,17 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
_logger.Info($"Slot:{Slot} - Get privilege level");
|
||||
ReadRegister(Register.Configexchange.Privilege);
|
||||
|
||||
_logger.Info($"Slot:{Slot} - Get PCB identification old{PcbId}");
|
||||
|
||||
var listPcb = new List<Byte>();
|
||||
var hasZero = false;
|
||||
var maxReads = 4;
|
||||
while (!hasZero)
|
||||
{
|
||||
var chunk = ReadRegister(Register.Configexchange.PcbSerialNumber, 4);
|
||||
maxReads -= 1;
|
||||
if (chunk == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
listPcb.AddRange(chunk);
|
||||
_logger.Info($"Slot:{Slot} - Old PCB identification was {PcbId}");
|
||||
|
||||
if (listPcb.Contains(0))
|
||||
var pcbIdRaw = ReadRegister(Register.Configexchange.PcbSerialNumber, expectedLength);
|
||||
if (pcbIdRaw != null)
|
||||
{
|
||||
hasZero = true;
|
||||
}
|
||||
if (maxReads == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Info("First read ");
|
||||
if (listPcb.Any())
|
||||
{
|
||||
var response = listPcb.ToArray();
|
||||
PcbId = Encoding.ASCII.GetString(response).Split('\0')[0];
|
||||
|
||||
if (PcbId.Length < 8 && retriesLeft >= 1)
|
||||
{
|
||||
return GetPcbId(expectedLength, retriesLeft - 1);
|
||||
PcbId = Encoding.ASCII.GetString(pcbIdRaw).Split('\0')[0];
|
||||
_logger.Info($"Slot:{Slot} - Get PCB identification {PcbId}");
|
||||
return PcbId;
|
||||
}
|
||||
|
||||
return PcbId;
|
||||
}
|
||||
|
||||
if (retriesLeft >= 1)
|
||||
{
|
||||
return GetPcbId(expectedLength, retriesLeft - 1);
|
||||
}
|
||||
return string.Empty;
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1845,33 +1824,21 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
if (IsLoggedOn)
|
||||
{
|
||||
_logger.Debug($"Slot:{Slot} - Authorization is required");
|
||||
// Logout();
|
||||
// ReLogin();
|
||||
//removed because this stops all processing which is critical on FW-Update!
|
||||
//if (!_autoLogon || !RequestProtocol.ContainsRegisterIdent("password"))
|
||||
//{
|
||||
// throw new AuthenticationException("Can not access meter. " +
|
||||
// "Reason AuthorizationRequired");
|
||||
//}
|
||||
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(_password))
|
||||
{
|
||||
IsLoggedOn = false;
|
||||
if (Login(_password, false))
|
||||
{
|
||||
}
|
||||
|
||||
// //removed because this stops all processing which is critical on FW-Update!
|
||||
// //throw new AuthenticationException("Login failed");
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RequestAcknowledgeState.Ok:
|
||||
break;
|
||||
|
||||
//try out this
|
||||
case RequestAcknowledgeState.CommandError:
|
||||
case RequestAcknowledgeState.MeterError:
|
||||
@@ -2091,7 +2058,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
|
||||
/// apps will have a new register.
|
||||
/// </remarks>
|
||||
/// <remarks date="2022-Jul-22" author="Thomas Wiedebusch">
|
||||
/// - Removed temporary NA2ALARMS readback as this has no handler in the FW.
|
||||
/// - Removed temporary NA2ALARMS read back as this has no handler in the FW.
|
||||
/// </remarks>
|
||||
public Boolean StoreAllConfigurations()
|
||||
{
|
||||
|
||||
@@ -368,6 +368,9 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
/// - Wakeup message handling changed,
|
||||
/// - Multiple replies on wakeup message allowed.
|
||||
/// </remarks>
|
||||
/// <remarks date="2022-Oct-02" author="T.Wiedebusch">
|
||||
/// - On wakeup message 5 retires are allowed to avoid an infinite loop.
|
||||
/// </remarks>
|
||||
public override void DecodeRecord(IPortDataEventArgs data)
|
||||
{
|
||||
//the request response record covers the entire request protocol
|
||||
@@ -402,10 +405,10 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.RequestProtocol
|
||||
{
|
||||
_recordInProcess.Acknowledge = RequestAcknowledgeState.WakeupMessage;
|
||||
//initiate a single retry on wakeup message response
|
||||
//if ( _recordInProcess.WakeupMessageRetryCtr == 0)
|
||||
if ( _recordInProcess.WakeupMessageRetryCtr < 10)
|
||||
{
|
||||
_logger.Debug($"{_ident} Wakeup message received");
|
||||
_recordInProcess.WakeupMessageRetryCtr = 1;
|
||||
_recordInProcess.WakeupMessageRetryCtr++;
|
||||
// reset retry counter to get all required retries
|
||||
_recordInProcess.RetryCtr = -1;
|
||||
//reset timeout to a normal value if timeout is extremely high but response received
|
||||
|
||||
Reference in New Issue
Block a user