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