266 lines
9.2 KiB
C#
266 lines
9.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Threading;
|
|
using Newtonsoft.Json;
|
|
using ProductionUiCordonelLegacy.ProductionProcesses.Enum;
|
|
using ProductionUiCordonelLegacy.UserControls.FinalTest;
|
|
using Xylem.Common.CommonCore.Configuration;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus;
|
|
using Xylem.Common.Logic.SoftwareAccessHelper;
|
|
|
|
namespace ProductionUiCordonelLegacy.ProductionProcesses.Actions
|
|
{
|
|
public class ProductionCheckShippingState : BaseProductionProcess
|
|
{
|
|
private UcPlain UserControl;
|
|
public ProductionCheckShippingState()
|
|
{
|
|
name = "Prüfe versandbereitschaft des Zählers";
|
|
currentProcessState = ProductionProcessState.Waiting;
|
|
}
|
|
public override void InitUserControl()
|
|
{
|
|
UserControl = new UcPlain();
|
|
UserControl.lblHl.Content = name;
|
|
UserControl.lblText.Content = "Hydraulisch geprüft? Batterie i.O?";
|
|
}
|
|
|
|
public override UserControl GetControl()
|
|
{
|
|
if (UserControl == null)
|
|
{
|
|
throw new Exception($"UserControl {GetType()} not Ready");
|
|
}
|
|
return UserControl;
|
|
}
|
|
|
|
|
|
public override void ProcessDone()
|
|
{
|
|
//clear
|
|
}
|
|
private void setTxt(string msg, bool log, bool msgbox)
|
|
{
|
|
if (log)
|
|
{
|
|
Meter.WriteLog(msg);
|
|
}
|
|
UserControl.lblText.Dispatcher.Invoke(DispatcherPriority.Send,
|
|
new Action(() =>
|
|
{
|
|
if (msgbox)
|
|
{
|
|
|
|
UserControl.MessageBox(msg);
|
|
}
|
|
UserControl.lblText.Content = msg;
|
|
}
|
|
));
|
|
|
|
}
|
|
|
|
|
|
private void doStartProcessLoop()
|
|
{
|
|
var retriesRemaining = 1;
|
|
while (retriesRemaining >= 0)
|
|
{
|
|
try
|
|
{
|
|
Progress = 0;
|
|
//var url = $"http://localhost:56011/api/FinalCheck/GetProgrammingParameters?PcbID={Meter.PcbId}";
|
|
var url = $"{ServiceUrls.MeterInfoForTestBench()}{Meter.PcbId}";
|
|
var csdRet = LocalWebRequest.GetRequest(url);
|
|
|
|
var res = JsonConvert.DeserializeObject<String[]>(csdRet);
|
|
|
|
|
|
|
|
|
|
var CalibrationRun = res[4];
|
|
var LastTestBechState = 0;
|
|
Boolean? HyState;
|
|
Boolean? preState = null;
|
|
if (!string.IsNullOrEmpty(res[5]))
|
|
{
|
|
int.TryParse(res[5], out var tmp);
|
|
LastTestBechState = tmp;
|
|
}
|
|
|
|
if (LastTestBechState <= 20)
|
|
{
|
|
HyState = null;
|
|
}
|
|
else if (LastTestBechState >= 30)
|
|
{
|
|
HyState = true;
|
|
}
|
|
else
|
|
{
|
|
HyState = false;
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(CalibrationRun))
|
|
{
|
|
preState = true;
|
|
}
|
|
|
|
|
|
if (!HyState.HasValue || !HyState.Value)
|
|
{
|
|
setTxt("Zähler nicht erfolgreich geprüft", true, true);
|
|
|
|
|
|
currentProcessState = ProductionProcessState.Error;
|
|
}
|
|
if (!preState.HasValue || !preState.Value)
|
|
{
|
|
setTxt("Zähler nicht erfolgreich vorbehandelt", true, true);
|
|
currentProcessState = ProductionProcessState.Error;
|
|
}
|
|
|
|
Progress = 50;
|
|
|
|
var genesisStatus = new GenesisStatus();
|
|
//TODO Roland: Check this implementation --- START
|
|
if (Meter.Region.Equals("EMEA"))
|
|
{
|
|
genesisStatus.QuiescentCurrent_uA = 119.8;
|
|
genesisStatus.EstimatedProductionBatteryLoadPercent = 1.0;
|
|
}
|
|
else
|
|
{
|
|
genesisStatus.QuiescentCurrent_uA = 77.7;
|
|
genesisStatus.EstimatedProductionBatteryLoadPercent = 1.0;
|
|
}
|
|
|
|
// this calculates all lifetime values
|
|
if (!GenesisStatusHandler.BuildLifeTimeInformation(Meter, genesisStatus, out _))
|
|
{
|
|
|
|
setTxt("Batterie nicht lesbar", true, true);
|
|
|
|
break;
|
|
}
|
|
|
|
Meter.ReLogin();
|
|
//lastFrame
|
|
Meter.WriteLog($"totalUsed at EOL {genesisStatus.DrainedBatteryLoadPercent:F2}");
|
|
if (res[1] == "3212095")
|
|
{
|
|
currentProcessState = ProductionProcessState.Done;
|
|
return;
|
|
}
|
|
|
|
if (genesisStatus.AlternativeRequiredBatteryLoadPercent != null &&
|
|
genesisStatus.DrainedBatteryLoadPercent < genesisStatus.AlternativeRequiredBatteryLoadPercent)
|
|
{
|
|
setTxt($"{Meter.Region} limit OK ", true, true);
|
|
}
|
|
else
|
|
{
|
|
setTxt($"{Meter.Region} limit überschritten ", true, true);
|
|
}
|
|
setTxt($"Maximum drained battery load: {genesisStatus.AlternativeRequiredBatteryLoadPercent} % - " +
|
|
$" Meter reports drained battery load: {genesisStatus.DrainedBatteryLoadPercent} %", true, true);
|
|
//if (!genesisStatus.UNTStatus)
|
|
//{
|
|
// if (Meter.Region == "NA")
|
|
// {
|
|
|
|
|
|
// currentProcessState = ProductionProcessState.Error;
|
|
// }
|
|
|
|
// //
|
|
// setTxt($"UNT Limit überschritten Limit{genesisStatus.UNTLimit} vs {genesisStatus.DrainedBatteryLoad_uAs}", true, true);
|
|
|
|
|
|
//}
|
|
//TODO Roland: Check this implementation --- STOP
|
|
|
|
if (genesisStatus.RemainingLifeTimeYears < 20)
|
|
{
|
|
if (genesisStatus.DrainedBatteryLoadPercent > 9)
|
|
{
|
|
currentProcessState = ProductionProcessState.Error;
|
|
setTxt($"EMEA Limit überschritten Limit 8% vs {genesisStatus.DrainedBatteryLoadPercent}", true, true);
|
|
|
|
|
|
Meter.WriteLog("Batterie über 10% entladen");
|
|
}
|
|
|
|
|
|
}
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
//;
|
|
//TODO ROLAND only new meters can be tested which have a LUT installed
|
|
if (Meter.LutCrc != $@"0x{int.Parse(res[8]):X4}")
|
|
{
|
|
currentProcessState = ProductionProcessState.Error;
|
|
|
|
|
|
setTxt("Lut not correct", true, true);
|
|
|
|
}
|
|
|
|
var meterFWApp = Meter.MeterAppListVersion.First(a => a.AppId == 24);
|
|
|
|
if (string.IsNullOrEmpty(res[9]) || !Meter.InstalledFwVersion.HasValue || Meter.InstalledFwVersion.Value != uint.Parse(res[9]))
|
|
{
|
|
if (!string.IsNullOrEmpty(res[9]) && Meter.InstalledFwVersion.HasValue && uint.Parse(res[9]) == 8194 && Meter.InstalledFwVersion.Value == 8198)
|
|
{
|
|
UserControl.MessageBox($"Achtung FW 2.0.06");
|
|
}
|
|
else
|
|
{
|
|
if (res[1] != "3239216" && res[1] != "3239217")
|
|
{
|
|
currentProcessState = ProductionProcessState.Error;
|
|
|
|
}
|
|
setTxt($"FW not correct Meter has {meterFWApp.Version} and should have {uint.Parse(res[9])}", true, true);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentProcessState != ProductionProcessState.Error)
|
|
{
|
|
currentProcessState = ProductionProcessState.Done;
|
|
return;
|
|
}
|
|
retriesRemaining -= 1;
|
|
|
|
currentProcessState = ProductionProcessState.Error;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Meter.WriteLog($"{ex}");
|
|
currentProcessState = ProductionProcessState.Error;
|
|
retriesRemaining -= 1;
|
|
}
|
|
}
|
|
currentProcessState = ProductionProcessState.Error;
|
|
}
|
|
|
|
public override void StartProcess()
|
|
{
|
|
doStartProcessLoop();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|