Эх сурвалжийг харах

add CMD6 support for PHP
add NGCode report
update version to v1.2.0

Robert 3 жил өмнө
parent
commit
e49cda0a64

+ 5 - 5
AwInitilizer/Assist/SerialPortocol.cs

@@ -16,7 +16,7 @@ namespace AwInitilizer.Assist
         public event EventHandler<EvseSerialResponseModel> OnMsgReceived;
         public event PropertyChangedEventHandler PropertyChanged;
 
-        public string LatestNullMessage { get; private set; }
+        public string LatestErrorMessage { get; private set; }
 
         private Interface.ISerialPort _serialPort;
 
@@ -180,7 +180,7 @@ namespace AwInitilizer.Assist
             if (signal.CurrentCount == 0)
             {
                 //timeout
-                LatestNullMessage = "Serial portocol timeout";
+                LatestErrorMessage = "Serial portocol timeout";
             }
             return result;
 
@@ -264,12 +264,12 @@ namespace AwInitilizer.Assist
         {
             if(parameter == null)
             {
-                LatestNullMessage = "parameter null exception";
+                LatestErrorMessage = "parameter null exception";
                 return string.Empty;
             }
             if (parameter.Length <= 1)
             {
-                LatestNullMessage = $"parameter legnth {parameter.Length} error";
+                LatestErrorMessage = $"parameter legnth {parameter.Length} error";
                 return string.Empty;
             }
             if(parameter.ToList().Contains(0x00))
@@ -292,7 +292,7 @@ namespace AwInitilizer.Assist
             }
             catch(Exception e)
             {
-                LatestNullMessage = $"string parse exception : {e.Message}";
+                LatestErrorMessage = $"string parse exception : {e.Message}";
                 return string.Empty;
             }
         }

+ 150 - 0
AwInitilizer/Converter/MesErrorCodeMaper.cs

@@ -0,0 +1,150 @@
+using AwInitilizer.Model;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AwInitilizer.Converter
+{
+    public static class MesErrorCodeMaper
+    {
+        public static MesErrorCode GetMesErrorCode(Procedure.ProcedureBase procedure)
+        {
+            switch(procedure.GetType().Name)
+            {
+                case "BasicInfoUpdateProcedure":
+                    return GetMesErrorCode((Procedure.BasicInfoUpdate.BasicInfoUpdateProcedure)procedure);
+                case "FourGenModuleCheckProcedure":
+                    return GetMesErrorCode((Procedure.FourGenModuleCheck.FourGenModuleCheckProcedure)procedure);
+                case "WifRssiCheckProcedure":
+                    return GetMesErrorCode((Procedure.WifRssiCheck.WifRssiCheckProcedure)procedure);
+                case "FirmwareBundleUploadProcedure":
+                    return GetMesErrorCode((Procedure.FirmwareBundleUpload.FirmwareBundleUploadProcedure)procedure);
+                case "FirmwareCheckVersionProcedure":
+                    return GetMesErrorCode((Procedure.FirmwareCheckVersion.FirmwareCheckVersionProcedure)procedure);
+                case "ButtonStatusCheckPorcedure":
+                    return GetMesErrorCode((Procedure.ButtonStatusCheck.ButtonStatusCheckPorcedure)procedure);
+                case "RestarttoIdelProcedure":
+                    return GetMesErrorCode((Procedure.RestarttoIdel.RestarttoIdelProcedure)procedure);
+                case "VersionLogProcedure":
+                    return GetMesErrorCode((Procedure.VersionLog.VersionLogProcedure)procedure);
+                default:
+                    return MesErrorCode.None;
+            }
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.BasicInfoUpdate.BasicInfoUpdateProcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.BasicInfoUpdate.ErrorType.EvseConnectFail:
+                case Procedure.BasicInfoUpdate.ErrorType.SettingSaveFail:
+                case Procedure.BasicInfoUpdate.ErrorType.RestartConnectFail:
+                    return MesErrorCode.ChargerConnectFail;
+                case Procedure.BasicInfoUpdate.ErrorType.ModelNameWriteFail:
+                case Procedure.BasicInfoUpdate.ErrorType.ModelNameGetFail:
+                case Procedure.BasicInfoUpdate.ErrorType.ModelNameMismach:
+                    return MesErrorCode.ModelNameUpadateFail;
+                case Procedure.BasicInfoUpdate.ErrorType.SerialNumberWriteFail:
+                case Procedure.BasicInfoUpdate.ErrorType.SerialNumberGetFail:
+                case Procedure.BasicInfoUpdate.ErrorType.SerialNumberMismach:
+                    return MesErrorCode.ModelNameUpadateFail;
+                case Procedure.BasicInfoUpdate.ErrorType.RtcUpdateFail:
+                case Procedure.BasicInfoUpdate.ErrorType.UtcTimeMismatch:
+                    return MesErrorCode.ModelNameUpadateFail;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.FourGenModuleCheck.FourGenModuleCheckProcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.FourGenModuleCheck.ErrorType.ConnectFail:
+                case Procedure.FourGenModuleCheck.ErrorType.VersionReadFail:
+                case Procedure.FourGenModuleCheck.ErrorType.SimStatusReadFail:
+                    return MesErrorCode.ChargerConnectFail;
+                case Procedure.FourGenModuleCheck.ErrorType.VersionMismatch:
+                    return MesErrorCode.FourthGenModelVersionMismatch;
+                case Procedure.FourGenModuleCheck.ErrorType.SimStatusMismatch:
+                    return MesErrorCode.FourthGenSimInstartionMismatch;
+                case Procedure.FourGenModuleCheck.ErrorType.IccidMistach:
+                case Procedure.FourGenModuleCheck.ErrorType.ImsiMistach:
+                    return MesErrorCode.FourthGenSimInfoMismatch;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.WifRssiCheck.WifRssiCheckProcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.WifRssiCheck.ErrorType.WifiModeDataNotFound:
+                case Procedure.WifRssiCheck.ErrorType.WifiRssiDataNotFound:
+                    return MesErrorCode.ChargerConnectFail;
+                case Procedure.WifRssiCheck.ErrorType.WifiModeNotClient:
+                    return MesErrorCode.WifiModeNotClient;
+                case Procedure.WifRssiCheck.ErrorType.WifiRssiLow:
+                    return MesErrorCode.WifiRssiLow;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.FirmwareBundleUpload.FirmwareBundleUploadProcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.FirmwareBundleUpload.ErrorType.StartWaitTimeout:
+                case Procedure.FirmwareBundleUpload.ErrorType.UploadFailed:
+                    return MesErrorCode.FirmwareUploadFail;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.FirmwareCheckVersion.FirmwareCheckVersionProcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.FirmwareCheckVersion.ErrorType.RestartTimeout:
+                    return MesErrorCode.FirmwareUpdateTimeout;
+                case Procedure.FirmwareCheckVersion.ErrorType.VersionCheckFail:
+                    return MesErrorCode.FirmwareVersionCheckFail;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.ButtonStatusCheck.ButtonStatusCheckPorcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.ButtonStatusCheck.ErrorType.ConnectFail:
+                case Procedure.ButtonStatusCheck.ErrorType.GetStatusFail:
+                    return MesErrorCode.ChargerConnectFail;
+                case Procedure.ButtonStatusCheck.ErrorType.FirstButtonCheckFail:
+                    return MesErrorCode.GreenButtonTestFail;
+                case Procedure.ButtonStatusCheck.ErrorType.SecondButtonCheckFail:
+                    return MesErrorCode.BlueButtonTestFail;
+                case Procedure.ButtonStatusCheck.ErrorType.EmergencyButtonCheckFail:
+                    return MesErrorCode.EmergencyButtonTestFail;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.RestarttoIdel.RestarttoIdelProcedure procedure)
+        {
+            switch(procedure.Error)
+            {
+                case Procedure.RestarttoIdel.ErrorType.SetFail:
+                case Procedure.RestarttoIdel.ErrorType.ConnectorNotIdel:
+                    return MesErrorCode.FactoryResetFail;
+            }
+            return MesErrorCode.None;
+        }
+
+        public static MesErrorCode GetMesErrorCode(Procedure.VersionLog.VersionLogProcedure procedure)
+        {
+            return MesErrorCode.None;
+        }
+    }
+}

+ 73 - 15
AwInitilizer/DLL/SajectConnectSajet.cs

@@ -93,7 +93,7 @@ namespace AwInitilizer.DLL
             return false;
         }
 
-        public static bool SajetTranFinish(bool Result)
+        public static bool SajetTranFinishSuccess()
         {
             if (string.IsNullOrEmpty(userId))
                 return false;
@@ -104,14 +104,24 @@ namespace AwInitilizer.DLL
             if (string.IsNullOrEmpty(msg))
                 return false;
 
-            if (Result)
-            {
-                msg += "OK";
-            }
-            else
-            {
-                msg += "NG;E114;";
-            }
+            msg += "OK";
+
+            return SajetTransData(CMD.Report, ref msg);
+        }
+
+        public static bool SajetTranFinishFail(string errorCode)
+        {
+            if (string.IsNullOrEmpty(userId))
+                return false;
+            if (string.IsNullOrEmpty(SN))
+                return false;
+            string msg = userId + ";" + SN + ";";
+
+            if (string.IsNullOrEmpty(msg))
+                return false;
+
+            msg += $"NG;{errorCode};";
+
             return SajetTransData(CMD.Report, ref msg);
         }
 
@@ -139,24 +149,71 @@ namespace AwInitilizer.DLL
             return null;
         }
 
+        public static bool SajetTransReport(Dictionary<string, string> reportPair)
+        {
+            //build header
+            Dictionary<string, int> valuePairs = new Dictionary<string, int>();
+            foreach (var pair in reportPair)
+            {
+                if (int.TryParse(pair.Value, out int val))
+                {
+                    valuePairs.Add(pair.Key, val);
+                }
+                else if (pair.Value.ToLower().Contains("fail"))
+                {
+                    valuePairs.Add(pair.Key, 0);
+                }
+                else if (pair.Value.ToLower().Contains("success"))
+                {
+                    valuePairs.Add(pair.Key, 1);
+                }
+                else
+                {
+                    valuePairs.Add(string.Format("{0}:{1}", pair.Key, pair.Value), 1);
+                }
+            }
+            //register Header
+            var codePair = new Dictionary<string, string>();
+
+            string model = "";
+            if (Model.SystemID.TryParse(SN,out var systemID))
+            {
+                model = systemID.ModelName.ToString();
+            }
+
+            foreach (var key in valuePairs.Keys)
+            {
+                var code = DLL.SajectConnectSajet.SajetTransRegisterHeader(model, key);
+                if (string.IsNullOrEmpty(code))
+                    continue;
+                codePair.Add(key, code);
+            }
+            //report value
+            var reportResult = DLL.SajectConnectSajet.SajetTransReport(valuePairs, codePair);
+            return reportResult;
+        }
+
         public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
         {
             if (string.IsNullOrEmpty(userId))
                 return false;
             if (string.IsNullOrEmpty(SN))
                 return false;
-            string msg = userId + ";" + SN;
+            string msgHeader = userId + ";" + SN;
+            string msg = "";
+
             foreach (var result in resultPair)
             {
                 if (codePair.Keys.Contains(result.Key))
                 {
-                    msg += string.Format(";{0}:{1}", codePair[result.Key], string.Format("{0}.00", result.Value));
+                    msg = string.Format("{0};{1}:{2};",msgHeader, codePair[result.Key], string.Format("{0}.00", result.Value));
+                    //msg += string.Format(";{0}:{1}", codePair[result.Key], string.Format("{0}.00", result.Value));
                 }
-                msg += ";";
+                //msg += ";";
                 SajetTransData(CMD.ValueReport, ref msg);
-                msg = userId + ";" + SN;
+                //msg = userId + ";" + SN;
             }
-            msg += ";";
+            //msg += ";";
             return true;
         }
 
@@ -181,9 +238,10 @@ namespace AwInitilizer.DLL
             return true;
         }
 
-        public static bool SajetTransLog(string data, bool isError)
+        public static bool SajetTransLog(string data)
         {
             return true;
+
             if (string.IsNullOrEmpty(userId))
                 return false;
             if (string.IsNullOrEmpty(SN))

+ 29 - 13
AwInitilizer/DLL/SajetConnect.cs

@@ -1,4 +1,5 @@
-using System;
+using AwInitilizer.Model;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.InteropServices;
@@ -37,14 +38,20 @@ namespace AwInitilizer.DLL
             => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransWoCheck(ref workOrder) : true;
         public static bool SajetTransSnCheck(ref string serialNumber)
             => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransSnCheck(ref serialNumber) : true;
-        public static bool SajetTranFinish(bool Result)
-            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTranFinish(Result) : true;
+        //public static bool SajetTranFinish(bool Result)
+        //    => IsEmsEnabled ? SajetConnectDLLSelector.SajetTranFinish(Result) : true;
+        public static bool SajetTranFinishSuccess()
+            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTranFinishSuccess() : true;
+        public static bool SajetTranFinishFail(MesErrorCode errorCode)
+            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTranFinishFail(errorCode.ToMesCodeString()) : true;
         public static string SajetTransRegisterHeader(string model, string header)
             => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransRegisterHeader(model, header) : "";
-        public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
-            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransReport(resultPair, codePair) : true;
-        public static bool SajetTransLog(string data, bool isError)
-            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransLog(data, isError) : true;
+        //public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
+        //    => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransReport(resultPair, codePair) : true;
+        public static bool SajetTransReport(Dictionary<string, string> reportPair)
+            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransReport(reportPair) : true;
+        public static bool SajetTransLog(string data)
+            => IsEmsEnabled ? SajetConnectDLLSelector.SajetTransLog(data) : true;
     }
 
     public static class SajetConnectDLLSelector
@@ -69,17 +76,26 @@ namespace AwInitilizer.DLL
         public static bool SajetTransSnCheck(ref string serialNumber)
             => Type == MesType.shinewave ?
             SajetConnectShinewave.SajetTransSnCheck(ref serialNumber) : SajectConnectSajet.SajetTransSnCheck(ref serialNumber);
-        public static bool SajetTranFinish(bool Result)
+        //public static bool SajetTranFinish(bool Result)
+        //    => Type == MesType.shinewave ?
+        //    SajetConnectShinewave.SajetTranFinish(Result) : SajectConnectSajet.SajetTranFinish(Result);
+        public static bool SajetTranFinishSuccess()
             => Type == MesType.shinewave ?
-            SajetConnectShinewave.SajetTranFinish(Result) : SajectConnectSajet.SajetTranFinish(Result);
+            SajetConnectShinewave.SajetTranFinishSuccess() : SajectConnectSajet.SajetTranFinishSuccess();
+        public static bool SajetTranFinishFail(string errorCode)
+            => Type == MesType.shinewave ?
+            SajetConnectShinewave.SajetTranFinishFail(errorCode) : SajectConnectSajet.SajetTranFinishFail(errorCode);
         public static string SajetTransRegisterHeader(string model, string header)
             => Type == MesType.shinewave ?
             SajetConnectShinewave.SajetTransRegisterHeader(model, header) : SajectConnectSajet.SajetTransRegisterHeader(model, header);
-        public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
+        //public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
+        //    => Type == MesType.shinewave ?
+        //    SajetConnectShinewave.SajetTransReport(resultPair, codePair) : SajectConnectSajet.SajetTransReport(resultPair, codePair);
+        public static bool SajetTransReport(Dictionary<string, string> reportPair)
             => Type == MesType.shinewave ?
-            SajetConnectShinewave.SajetTransReport(resultPair, codePair) : SajectConnectSajet.SajetTransReport(resultPair, codePair);
-        public static bool SajetTransLog(string data, bool isError)
+            SajetConnectShinewave.SajetTransReport(reportPair) : SajectConnectSajet.SajetTransReport(reportPair);
+        public static bool SajetTransLog(string data)
             => Type == MesType.shinewave ?
-            SajetConnectShinewave.SajetTransLog(data, isError) : SajectConnectSajet.SajetTransLog(data, isError);
+            SajetConnectShinewave.SajetTransLog(data) : SajectConnectSajet.SajetTransLog(data);
     }
 }

+ 44 - 14
AwInitilizer/DLL/SajetConnectShinewave.cs

@@ -97,7 +97,25 @@ namespace AwInitilizer.DLL
             return false;
         }
 
-        public static bool SajetTranFinish(bool Result)
+        public static bool SajetTranFinishSuccess()
+        {
+            if (string.IsNullOrEmpty(userId))
+                return false;
+            if (string.IsNullOrEmpty(WorkOrder))
+                return false;
+            if (string.IsNullOrEmpty(SN))
+                return false;
+            string msg = userId + "," + WorkOrder + "," + SN + ",";
+
+            if (string.IsNullOrEmpty(msg))
+                return false;
+
+            msg += "OK,";
+
+            return SajetTransData(CMD.Report, ref msg);
+        }
+
+        public static bool SajetTranFinishFail(string errorCode)
         {
             if (string.IsNullOrEmpty(userId))
                 return false;
@@ -109,21 +127,13 @@ namespace AwInitilizer.DLL
 
             if (string.IsNullOrEmpty(msg))
                 return false;
-#if DEBUG
-            Result = false;
 
-            if (!Result)
-                return true;
+            msg += "NG," + errorCode + ",";
+
+#if DEBUG
+            return false;
 #endif
 
-            if (Result)
-            {
-                msg += "OK,";
-            }
-            else
-            {
-                msg += "NG,";
-            }
             return SajetTransData(CMD.Report, ref msg);
         }
 
@@ -151,6 +161,26 @@ namespace AwInitilizer.DLL
             return null;
         }
 
+        public static bool SajetTransReport(Dictionary<string, string> reportPairs)
+        {
+            if (string.IsNullOrEmpty(userId))
+                return false;
+            if (string.IsNullOrEmpty(SN))
+                return false;
+            string msgHeader = userId + "," + SN;
+            string msg;
+            bool result = true;
+
+            foreach (var report in reportPairs)
+            {
+                msg = string.Format("{0},{1}:{2},", msgHeader, report.Key, report.Value);
+                var cmdResult = SajetTransData(CMD.StringValueReport, ref msg);
+                if (!cmdResult)
+                    result = false;
+            }
+            return result;
+        }
+
         public static bool SajetTransReport(Dictionary<string, int> resultPair, Dictionary<string, string> codePair)
         {
             if (string.IsNullOrEmpty(userId))
@@ -185,7 +215,7 @@ namespace AwInitilizer.DLL
             return SajetTransData(CMD.StringValueReport, ref msg);
         }
 
-        public static bool SajetTransLog(string data, bool isError)
+        public static bool SajetTransLog(string data)
         {
             if (string.IsNullOrEmpty(userId))
                 return false;

+ 3 - 0
AwInitilizer/Initilizer.csproj

@@ -68,6 +68,7 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="Converter\MesErrorCodeMaper.cs" />
     <Compile Include="Converter\PressStatusConverter.cs" />
     <Compile Include="Cultures\CulturesHelper.cs" />
     <Compile Include="DLL\SajectConnectSajet.cs" />
@@ -75,6 +76,8 @@
     <Compile Include="DLL\SajetConnectShinewave.cs" />
     <Compile Include="KeyinListener.cs" />
     <Compile Include="Model\ConnectorType.cs" />
+    <Compile Include="Model\MesErrorCode.cs" />
+    <Compile Include="ProcedureLog\LogWriter.cs" />
     <Compile Include="Procedure\FirmwareBundleUploadProcedure.cs" />
     <Compile Include="Procedure\FirmwareCheckVersionProcedure.cs" />
     <Compile Include="Procedure\FirmwareUploadProcedure.cs" />

+ 19 - 51
AwInitilizer/MainWindow.xaml.cs

@@ -337,6 +337,8 @@ namespace AwInitilizer
             ProcedureBase.UpdateData = ViewModel;
             ProcedureBase.Logger = this;
 
+            MesErrorCode mesErrorCode = MesErrorCode.None;
+
             Dictionary<string, string> logPairs = new Dictionary<string, string>();
             //logPairs.Add("ModelName", ViewModel.SystemID.ModelName.ToString());
             //logPairs.Add("SerialNumber", ViewModel.SystemID.SerialNumber);
@@ -360,21 +362,16 @@ namespace AwInitilizer
 
                 foreach (var procedureLog in procedureList[procedureIndex].LogPair)
                 {
-                    if (logPairs.ContainsKey(procedureLog.Key))
-                    {
-                        logPairs[procedureLog.Key] = procedureLog.Value;
-                    }
-                    else
-                    {
-                        logPairs.Add(procedureLog.Key, procedureLog.Value);
-                    }
+                    logPairs[procedureLog.Key] = procedureLog.Value;
                 }
 
                 if (!result)
+                {
+                    mesErrorCode = Converter.MesErrorCodeMaper.GetMesErrorCode(procedureList[procedureIndex]);
                     break;
+                }
             }
 
-
             //report MES result
             ReportMESLog(logPairs);
 
@@ -384,13 +381,15 @@ namespace AwInitilizer
                 uxProgressRate.Content = "100%";
                 UpdateStatus = UpdateStatus.Sucess;
                 //report Success
-                DLL.SajetConnect.SajetTranFinish(true);
+                DLL.SajetConnect.SajetTranFinishSuccess();
             }
             else
             {
                 UpdateStatus = UpdateStatus.Fail;
                 //uxStatusBar.Content = $"Process {procedureList[procedureIndex].Name} Failed";
                 uxStatusBar.Content = string.Format((string)Application.Current.FindResource("StatusBarFailed"), procedureList[procedureIndex].Name);
+                //report Fail
+                DLL.SajetConnect.SajetTranFinishFail(mesErrorCode);
             }
 
             stopTime = DateTime.Now;
@@ -404,39 +403,8 @@ namespace AwInitilizer
 
         private void ReportMESLog(Dictionary<string, string> logPairs)
         {
-            //build header
-            Dictionary<string, int> valuePairs = new Dictionary<string, int>();
-            foreach (var pair in logPairs)
-            {
-                if (int.TryParse(pair.Value, out int val))
-                {
-                    valuePairs.Add(pair.Key, val);
-                }
-                else if (pair.Value.ToLower().Contains("fail"))
-                {
-                    valuePairs.Add(pair.Key, 0);
-                }
-                else if (pair.Value.ToLower().Contains("success"))
-                {
-                    valuePairs.Add(pair.Key, 1);
-                }
-                else
-                {
-                    valuePairs.Add(string.Format("{0}:{1}", pair.Key, pair.Value), 1);
-                }
-            }
-            //register Header
-            var codePair = new Dictionary<string, string>();
-            var model = ViewModel.SystemID.ModelName.ToString();
-            foreach (var key in valuePairs.Keys)
-            {
-                var code = DLL.SajetConnect.SajetTransRegisterHeader(model, key);
-                if (string.IsNullOrEmpty(code))
-                    continue;
-                codePair.Add(key, code);
-            }
             //report value
-            var reportResult = DLL.SajetConnect.SajetTransReport(valuePairs, codePair);
+            var reportResult = DLL.SajetConnect.SajetTransReport(logPairs);
         }
 
         private void CreateLogFile()
@@ -550,7 +518,7 @@ namespace AwInitilizer
 
         public void Print(string msg, bool isError = false)
         {
-            DLL.SajetConnect.SajetTransLog(msg, isError);
+            DLL.SajetConnect.SajetTransLog(msg);
             Dispatcher.Invoke(() =>
             {
                 Span line = new Span();
@@ -647,19 +615,19 @@ namespace AwInitilizer
             List<ProcedureBase> procedures = new List<ProcedureBase>();
 
             //init intilize procedure list
-            procedures.Add(new BasicInfoUpdateProcedure());
-            procedures.Add(new FourGenModuleCheckProcedure());
-            procedures.Add(new WifRssiCheckProcedure());
+            procedures.Add(new Procedure.BasicInfoUpdate.BasicInfoUpdateProcedure());
+            procedures.Add(new Procedure.FourGenModuleCheck.FourGenModuleCheckProcedure());
+            procedures.Add(new Procedure.WifRssiCheck.WifRssiCheckProcedure());
             //for (int firemwareIndex = 0; firemwareIndex < ViewModel.FirmwareUpdateModels.Count ; firemwareIndex++)
             //{
             //    //procedures.Add(new FirmwareUpdateProcedure(ViewModel.FirmwareUpdateModels[firemwareIndex]));
             //    procedures.Add(new FirmwareUploadProcedure(ViewModel.FirmwareUpdateModels[firemwareIndex]));
             //}
-            procedures.Add(new FirmwareBundleUploadProcedure());
-            procedures.Add(new FirmwareCheckVersionProcedure());
-            procedures.Add(new ButtonStatusCheckPorcedure());
-            procedures.Add(new RestarttoIdelProcedure());
-            procedures.Add(new VersionLogProcedure());
+            procedures.Add(new Procedure.FirmwareBundleUpload.FirmwareBundleUploadProcedure());
+            procedures.Add(new Procedure.FirmwareCheckVersion.FirmwareCheckVersionProcedure());
+            procedures.Add(new Procedure.ButtonStatusCheck.ButtonStatusCheckPorcedure());
+            procedures.Add(new Procedure.RestarttoIdel.RestarttoIdelProcedure());
+            procedures.Add(new Procedure.VersionLog.VersionLogProcedure());
 
             ViewModel.UpdateProcedure.Clear();
 

+ 72 - 0
AwInitilizer/Model/MesErrorCode.cs

@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AwInitilizer.Model
+{
+    public enum MesErrorCode
+    {
+        None,
+        ChargerConnectFail,
+        ModelNameUpadateFail,
+        SerilaNumberUpadateFail,
+        UtcDatetimeUpdateFail,
+        FourthGenModelVersionMismatch,
+        FourthGenSimInstartionMismatch,
+        FourthGenSimInfoMismatch,
+        WifiModeNotClient,
+        WifiRssiLow,
+        FirmwareUploadFail,
+        FirmwareUpdateTimeout,
+        FirmwareVersionCheckFail,
+        EmergencyButtonTestFail,
+        GreenButtonTestFail,
+        BlueButtonTestFail,
+        FactoryResetFail,
+    }
+
+    public static class MesErrorCodeExt
+    {
+        public static string ToMesCodeString(this MesErrorCode mesError)
+        {
+            switch(mesError)
+            {
+                case MesErrorCode.ChargerConnectFail:
+                    return "EC001";
+                case MesErrorCode.ModelNameUpadateFail:
+                    return "EC002";
+                case MesErrorCode.SerilaNumberUpadateFail:
+                    return "EC003";
+                case MesErrorCode.UtcDatetimeUpdateFail:
+                    return "EC004";
+                case MesErrorCode.FourthGenModelVersionMismatch:
+                    return "EC005";
+                case MesErrorCode.FourthGenSimInstartionMismatch:
+                    return "EC006";
+                case MesErrorCode.FourthGenSimInfoMismatch:
+                    return "EC007";
+                case MesErrorCode.WifiModeNotClient:
+                    return "EC008";
+                case MesErrorCode.WifiRssiLow:
+                    return "EC009";
+                case MesErrorCode.FirmwareUploadFail:
+                    return "EC0010";
+                case MesErrorCode.FirmwareUpdateTimeout:
+                    return "EC0011";
+                case MesErrorCode.FirmwareVersionCheckFail:
+                    return "EC0012";
+                case MesErrorCode.EmergencyButtonTestFail:
+                    return "EC0013";
+                case MesErrorCode.GreenButtonTestFail:
+                    return "EC0014";
+                case MesErrorCode.BlueButtonTestFail:
+                    return "EC0015";
+                case MesErrorCode.FactoryResetFail:
+                    return "EC0016";
+            }
+            return "EC001";
+        }
+    }
+}

+ 177 - 63
AwInitilizer/Procedure/BasicInfoUpdateProcedure.cs

@@ -5,167 +5,281 @@ using System.Net.Sockets;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.BasicInfoUpdate
 {
+    public enum ErrorType
+    {
+        None,
+        EvseConnectFail,
+        ModelNameWriteFail,
+        SerialNumberWriteFail,
+        RtcUpdateFail,
+        SettingSaveFail,
+        RestartConnectFail,
+        ModelNameGetFail,
+        ModelNameMismach,
+        SerialNumberGetFail,
+        SerialNumberMismach,
+        UtcTimeMismatch,
+    }
+
+    public enum LogEvent
+    {
+        EvseConnect,
+        ModelNameWrite,
+        SerialNumberWrite,
+        RtcUpdate,
+        SettingSave,
+        RestartConnect,
+        ModelNameRead,
+        SerialNumberRead,
+        RtcRead,
+    }
+
     public class BasicInfoUpdateProcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<BasicInfoUpdateProcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+            {LogEvent.EvseConnect,"BaseUpdateSocketConnect" },
+            {LogEvent.ModelNameWrite,"ModelNameWrite" },
+            {LogEvent.SerialNumberWrite,"SerialNumberWrite" },
+            {LogEvent.RtcUpdate,"RtcUpdate" },
+            {LogEvent.SettingSave,"SettingSave" },
+            {LogEvent.RestartConnect,"BaseUpdateSocketReConnect" },
+            {LogEvent.ModelNameRead,"ModelNameRead" },
+            {LogEvent.SerialNumberRead,"SerialNumberRead" },
+            {LogEvent.RtcRead,"RtcRead" },
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+            {LogEvent.EvseConnect,"EVSE connect {0}" },
+            {LogEvent.ModelNameWrite,"Model Name write {0}" },
+            {LogEvent.SerialNumberWrite,"Serial Number write {0}" },
+            {LogEvent.RtcUpdate,"RTC update {0}" },
+            {LogEvent.SettingSave,"Setting save {0}" },
+            {LogEvent.RestartConnect,"Evse reconnect after write {0}" },
+            {LogEvent.ModelNameRead,"Model Name read {0}" },
+            {LogEvent.SerialNumberRead,"Serial Number read {0}" },
+            {LogEvent.RtcRead,"RTC time read {0}" },
+        };
+
         public BasicInfoUpdateProcedure() : base()
         {
             Name = "Basic Intlize";
             Content = "Set and check Model Name,SerilNumber,DateTime.";
+
+            LogWriter = new ProcedureLog.LogWriter<BasicInfoUpdateProcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
         {
             if (!await base.CheckAndCreateSocket())
             {
-                LogPair.Add("BaseUpdateSocketConnect","0");
-                InfoLog += "EVSE connect failed\n";
-                ReportLog.Add("EVSE connect failed");
+                LogWriter.Report(LogEvent.EvseConnect, "fail");
+                Error = ErrorType.EvseConnectFail;
+
+                //LogPair.Add("BaseUpdateSocketConnect", "fail");
+                //InfoLog += "EVSE connect failed\n";
+                //ReportLog.Add("EVSE connect failed");
                 return false;
             }
 
             //base.serialPortocol.OnMsgReceived += SerialPortocol_OnMsgReceived; 
             if (!await serialPortocol.SetModelName(UpdateData.ModelName))
             {
-                InfoLog += "Model Name update failed\n";
-                Logger.Print("Model Name update Failed", isError: true);
-                LogPair.Add("ModelNameWrite", "0");
-                ReportLog.Add("Model Name update Failed");
+                LogWriter.Report(LogEvent.ModelNameWrite, "fail");
+                Error = ErrorType.ModelNameWriteFail;
+
+                //LogPair.Add("ModelNameWrite", "fail");
+                //InfoLog += "Model Name update failed\n";
+                //Logger.Print("Model Name update Failed", isError: true);
+                //ReportLog.Add("Model Name update Failed");
                 return false;
             }
             else
             {
-                Logger.Print("Model Name write Success");
-                LogPair.Add("ModelNameWrite", "1");
+                LogWriter.Report(LogEvent.ModelNameWrite, "success");
+
+                //LogPair.Add("ModelNameWrite", "success");
+                //Logger.Print("Model Name write Success");
             }
 
             if (!await serialPortocol.SetSerialNumber(UpdateData.SerialNumber))
             {
-                InfoLog += "Serial Number update failed\n";
-                Logger.Print("Serial Number update Failed", isError: true);
-                LogPair.Add("SerialNumberWrite", "0");
-                ReportLog.Add("Serial Number update Failed");
+                LogWriter.Report(LogEvent.SerialNumberWrite, "fail");
+                Error = ErrorType.SerialNumberWriteFail;
+
+                //LogPair.Add("SerialNumberWrite", "fail");
+                //InfoLog += "Serial Number update failed\n";
+                //Logger.Print("Serial Number update Failed", isError: true);
+                //ReportLog.Add("Serial Number update Failed");
                 return false;
             }
             else
             {
-                Logger.Print("Serial Number write Success");
-                LogPair.Add("SerialNumberWrite", "1");
+                LogWriter.Report(LogEvent.SerialNumberWrite, "success");
+
+                //LogPair.Add("SerialNumberWrite", "success");
+                //Logger.Print("Serial Number write Success");
             }
 
             var setDateTime = DateTime.Now.ToUniversalTime();
 
             if (!await serialPortocol.SetUTCTime(setDateTime))
             {
-                InfoLog += "RTC update failed\n";
-                Logger.Print("RTC update Failed", isError: true);
-                LogPair.Add("RtcUpdate", "0");
-                ReportLog.Add("RTC update Failed");
+                LogWriter.Report(LogEvent.RtcUpdate, "fail");
+                Error = ErrorType.RtcUpdateFail;
+
+                //LogPair.Add("RtcUpdate", "fail");
+                //InfoLog += "RTC update failed\n";
+                //Logger.Print("RTC update Failed", isError: true);
+                //ReportLog.Add("RTC update Failed");
                 return false;
             }
             else
             {
-                Logger.Print("RTC update write Success");
-                LogPair.Add("RtcUpdate", "1");
+                LogWriter.Report(LogEvent.RtcUpdate, "success");
+
+                //LogPair.Add("RtcUpdate", "success");
+                //Logger.Print("RTC update write Success");
             }
 
             if (!await serialPortocol.SettingChangeConfirm())
             {
-                InfoLog += "Setting save request failed\n";
-                Logger.Print("Setting save Failed", isError: true);
-                LogPair.Add("SettingSave", "0");
-                ReportLog.Add("Setting save request Failed");
+                LogWriter.Report(LogEvent.SettingSave, "fail");
+                Error = ErrorType.SettingSaveFail;
+
+                //LogPair.Add("SettingSave", "fail");
+                //InfoLog += "Setting save request failed\n";
+                //Logger.Print("Setting save Failed", isError: true);
+                //ReportLog.Add("Setting save request Failed");
                 return false;
             }
             else
             {
-                Logger.Print("Setting save Success");
-                LogPair.Add("SettingSave", "1");
+                LogWriter.Report(LogEvent.SettingSave, "success");
+
+                //LogPair.Add("SettingSave", "success");
+                //Logger.Print("Setting save Success");
             }
 
-            Logger.Print("Waiting EVSE reboot...");
+            LogWriter.Log("Waiting EVSE reboot...");
+            //Logger.Print("Waiting EVSE reboot...");
             serialPortocol.Close();
             await Task.Delay(TimeSpan.FromMinutes(1));
 
             if (!await base.CheckAndCreateSocket())
             {
-                InfoLog += "EVSE not found after reboot\n";
-                Logger.Print("EVSE reboot timeout", isError: true);
-                LogPair.Add("BaseUpdateSocketReConnect", "0");
-                ReportLog.Add("EVSE not found after reboot");
+                LogWriter.Report(LogEvent.RestartConnect, "fail");
+                Error = ErrorType.RestartConnectFail;
+
+                //LogPair.Add("BaseUpdateSocketReConnect", "fail");
+                //InfoLog += "EVSE not found after reboot\n";
+                //Logger.Print("EVSE reboot timeout", isError: true);
+                //ReportLog.Add("EVSE not found after reboot");
                 return false;
             }
 
             var receivedModelName = await serialPortocol.GetModelName();
-            LogPair.Add("ModelNameRead", receivedModelName);
+            LogWriter.Report(LogEvent.ModelNameRead, receivedModelName);
+            //LogPair.Add("ModelNameRead", receivedModelName);
             if (string.IsNullOrEmpty(receivedModelName))
             {
-                InfoLog += "Model name get failed after reboot\n";
-                Logger.Print("Model Name read Failed", isError: true);
-                ReportLog.Add("Model name get failed after reboot");
+                LogWriter.Log("Model name get failed after reboot");
+                LogWriter.Log(serialPortocol.LatestErrorMessage, isDebugLog: true);
+                Error = ErrorType.ModelNameGetFail;
+
+                //InfoLog += "Model name get failed after reboot\n";
+                //Logger.Print("Model Name read Failed", isError: true);
+                //ReportLog.Add("Model name get failed after reboot");
                 return false;
             }
             else
             {
-                ReportLog.Add(string.Format("Read Model name : {0} , Expect:{1}", receivedModelName, UpdateData.ModelName));
-                InfoLog += $"Get Updated Model Name { receivedModelName }\n";
+                LogWriter.Log(string.Format("Read Model name : {0} , Expect:{1}", receivedModelName, UpdateData.ModelName));
+                //ReportLog.Add(string.Format("Read Model name : {0} , Expect:{1}", receivedModelName, UpdateData.ModelName));
+                //InfoLog += $"Get Updated Model Name { receivedModelName }\n";
                 if (receivedModelName != UpdateData.ModelName)
                 {
-                    InfoLog += "Updated Model Name Mismatched\n";
-                    Logger.Print("Stored Model Name Mismatched", isError: true);
+                    Error = ErrorType.ModelNameMismach;
+                    //InfoLog += "Updated Model Name Mismatched\n";
+                    //Logger.Print("Stored Model Name Mismatched", isError: true);
                     return false;
                 }
-                Logger.Print("Model Name update Success");
+                //Logger.Print("Model Name update Success");
             }
 
             var receivedSerialNumber = await serialPortocol.GetSerialNumber();
-            LogPair.Add("SerialNumberRead", receivedSerialNumber);
+            LogWriter.Report(LogEvent.SerialNumberRead, receivedSerialNumber);
+            //LogPair.Add("SerialNumberRead", receivedSerialNumber);
             if (string.IsNullOrEmpty(receivedSerialNumber))
             {
-                InfoLog += "Serial number get failed after reboot\n";
-                InfoLog += serialPortocol.LatestNullMessage +"\n";
-                Logger.Print("Stored Serial read Failed", isError: true);
-                Logger.Print(serialPortocol.LatestNullMessage);
-                ReportLog.Add("Serial number get failed after reboot");
+                LogWriter.Log("Serial number get failed after reboot");
+                LogWriter.Log(serialPortocol.LatestErrorMessage, isDebugLog: true);
+
+                Error = ErrorType.SerialNumberGetFail;
+
+                //InfoLog += "Serial number get failed after reboot\n";
+                //InfoLog += serialPortocol.LatestNullMessage +"\n";
+                //Logger.Print("Stored Serial read Failed", isError: true);
+                //Logger.Print(serialPortocol.LatestNullMessage);
+                //ReportLog.Add("Serial number get failed after reboot");
                 return false;
             }
             else
             {
-                ReportLog.Add(string.Format("Read Serial number : {0} , Expect:{1}", receivedSerialNumber, UpdateData.SerialNumber));
-                InfoLog += $"Get Updated serial number { receivedSerialNumber }\n";
+                LogWriter.Log(string.Format("Read Serial number : {0} , Expect:{1}", receivedSerialNumber, UpdateData.SerialNumber));
+                //ReportLog.Add(string.Format("Read Serial number : {0} , Expect:{1}", receivedSerialNumber, UpdateData.SerialNumber));
+                //InfoLog += $"Get Updated serial number { receivedSerialNumber }\n";
                 if (receivedSerialNumber != UpdateData.SerialNumber)
                 {
-                    InfoLog += "Updated serial number mismatched\n";
-                    Logger.Print("Stored Serial Number Mismatched", isError: true);
+                    Error = ErrorType.SerialNumberMismach;
+
+                    //InfoLog += "Updated serial number mismatched\n";
+                    //Logger.Print("Stored Serial Number Mismatched", isError: true);
                     return false;
                 }
-                Logger.Print("Serial Number update Success");
+                //Logger.Print("Serial Number update Success");
             }
 
             var receivedDateTime = await serialPortocol.GetUTCTime();
-            LogPair.Add("RtcRead", receivedDateTime?.ToString("yyyyMMddHHmmss"));
-            if (receivedDateTime==null)
+            //LogPair.Add("RtcRead", receivedDateTime?.ToString("yyyyMMddHHmmss"));
+            LogWriter.Report(LogEvent.RtcRead, receivedDateTime?.ToString("yyyyMMddHHmmss"));
+            if (receivedDateTime == null)
             {
-                InfoLog += "UTC Time receive failed after reboot\n";
-                Logger.Print("UTC Time receive failed", isError: true);
-                ReportLog.Add("UTC Time receive failed after reboot");
+                LogWriter.Log("UTC Time receive failed");
+
+                //InfoLog += "UTC Time receive failed after reboot\n";
+                //Logger.Print("UTC Time receive failed", isError: true);
+                //ReportLog.Add("UTC Time receive failed after reboot");
                 return false;
             }
             else
             {
-                ReportLog.Add(string.Format("Read UTC time : {0} , CurrentTime:{1}", receivedDateTime?.ToString("yyyyMMddHHmmss"), DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss")));
-                InfoLog += $"UTC Time received : {receivedDateTime.Value.ToString("yyyyMMddHHmmss")}\n";
+                LogWriter.Log(string.Format("Read UTC time : {0} , CurrentTime:{1}", receivedDateTime?.ToString("yyyyMMddHHmmss"), DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss")));
+                //ReportLog.Add(string.Format("Read UTC time : {0} , CurrentTime:{1}", receivedDateTime?.ToString("yyyyMMddHHmmss"), DateTime.Now.ToUniversalTime().ToString("yyyyMMddHHmmss")));
+                //InfoLog += $"UTC Time received : {receivedDateTime.Value.ToString("yyyyMMddHHmmss")}\n";
                 var diff = receivedDateTime.Value - DateTime.Now.ToUniversalTime();
                 if (Math.Abs(diff.TotalSeconds) > 10)
                 {
-                    InfoLog += "Stored UTC time Mismatched\n";
-                    Logger.Print("Stored UTC time Mismatched", isError: true);
+                    Error = ErrorType.UtcTimeMismatch;
+
+                    //InfoLog += "Stored UTC time Mismatched\n";
+                    //Logger.Print("Stored UTC time Mismatched", isError: true);
                     return false;
                 }
                 else
                 {
-                    Logger.Print("Model Name update Success");
+                    //Logger.Print("Model Name update Success");
                 }
             }
 

+ 207 - 169
AwInitilizer/Procedure/ButtonStatusCheckPorcedure.cs

@@ -13,101 +13,149 @@ using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Windows;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.ButtonStatusCheck
 {
+    public enum ErrorType
+    {
+        None,
+        ConnectFail,
+        GetStatusFail,
+        FirstButtonCheckFail,
+        SecondButtonCheckFail,
+        EmergencyButtonCheckFail,
+    }
+
+    public enum LogEvent
+    {
+        UnpressButtonTest
+    }
+
     public class ButtonStatusCheckPorcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<ButtonStatusCheckPorcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.UnpressButtonTest, "UnpressButtonTest" }
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.UnpressButtonTest, "Unpress check result" }
+        };
+
         private HintDialog hintDialog = new HintDialog();
         public ButtonStatusCheckPorcedure() : base()
         {
             Name = "Button Press Test";
             Content = "Interaction to test button status";
+
+            LogWriter = new ProcedureLog.LogWriter<ButtonStatusCheckPorcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
         {
-            Logger.Print("Button Unpress Status check Start");
-            //stage 0 - wait system ready
-            //wait restart
-            Logger.Print("Waiting response..");
-
-            //object response = false;
-            //int pollingCnt = 0;
-            //for (pollingCnt = 0; pollingCnt < 14; pollingCnt++)
-            //{
-            //    response = await GetButtonStatus();
-            //    if (response!=null)
-            //        break;
-            //    await Task.Delay(TimeSpan.FromSeconds(30));
-            //}
-
-            //ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.5));
-
-            ////timeout
-            //if (pollingCnt >= 14)
-            //{
-            //    Logger.Print("Wait EVSE timeout", isError: true);
-            //    return false;
-            //}
-
             var response = await GetButtonStatus();
             if (response == null)
             {
-                ReportLog.Add("EVSE connect failed");
-                Logger.Print("EVSE connect failed", isError: true);
+                //ReportLog.Add("EVSE connect failed");
+                //Logger.Print("EVSE connect failed", isError: true);
                 return false;
             }
 
             //stage 1 - unpress all
-            //ShowDialog(
-            //    "Please make sure All button is Unpressed\nPress Ok while complete",
-            //    "Starting Button test",
-            //    "OK","", cancelAble: true);
+            if(!await CheckUnpressAllBtn())
+            {
+                return false;
+            }
+
+            //stage 2 - check press sequence
+            //Logger.Print("Button press Status check Start");
+            //MessageBox.Show("Press Button1,Button2,EmergencyButton in order\neach press continuous 2 secondes\nPress Ok to start", "Starting Button test");
+
+            //Button1,Button2,EmergencyButton in order 0,1,2
+            for (int testType = 0; testType < 3; testType++)
+            {
+                var checkResult = await PressBtnCheck(testType);
+                if (!checkResult)
+                {
+                    if (testType == 0)
+                        Error = ErrorType.FirstButtonCheckFail;
+                    else if (testType == 1)
+                        Error = ErrorType.SecondButtonCheckFail;
+                    else if (testType == 2)
+                        Error = ErrorType.EmergencyButtonCheckFail;
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        private async Task<bool> CheckUnpressAllBtn()
+        {
             ShowDialog(
                 (string)Application.Current.FindResource("BtnPressUnpressHint"),
                 (string)Application.Current.FindResource("BtnPressHintTitle"),
                 (string)Application.Current.FindResource("Confirm"),
                 "", cancelAble: true);
+
             ButtonStatus status = await GetButtonStatus();
 
             if (status == null)
             {
-                InfoLog += "Get Butoon state failed\n";
-                Logger.Print("Get Butoon state failed");
+                //InfoLog += "Get Butoon state failed\n";
+                //Logger.Print("Get Butoon state failed");
                 return false;
             }
 
-            InfoLog += "Unpress check result\n";
-            InfoLog += $"Button1:{status.Button1},Button2:{status.Button2},EmgerncyButton:{status.EmergencyButton}\n";
-            LogPair.Add("UnpressButtonTest", string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton));
+            LogWriter.Report(LogEvent.UnpressButtonTest, string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton));
+            //InfoLog += "Unpress check result\n";
+            //InfoLog += $"Button1:{status.Button1},Button2:{status.Button2},EmgerncyButton:{status.EmergencyButton}\n";
+            //LogPair.Add("UnpressButtonTest", string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton));
 
-            ReportLog.Add(string.Format("Button unpress test result : {0}, Expect:000",
+            LogWriter.Log(string.Format("Button unpress test result : {0}, Expect:000",
                 string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton)
                 ));
+            //ReportLog.Add(string.Format("Button unpress test result : {0}, Expect:000",
+            //    string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton)
+            //    ));
 
             bool isAllMatched = true;
             if (status != null)
             {
-                isAllMatched = true;
                 if (status.Button1 != 0)
                 {
-                    Logger.Print("Button1 status ERROR, unpress is ecpected", isError: true);
+                    Error = ErrorType.FirstButtonCheckFail;
+                    LogWriter.Log("Button1 status ERROR, unpress is ecpected", isError: true);
+                    //Logger.Print("Button1 status ERROR, unpress is ecpected", isError: true);
                     isAllMatched = false;
                 }
                 if (status.Button2 != 0)
                 {
-                    Logger.Print("Button3 status ERROR, unpress is ecpected", isError: true);
+                    Error = ErrorType.SecondButtonCheckFail;
+                    LogWriter.Log("Button2 status ERROR, unpress is ecpected", isError: true);
+                    //Logger.Print("Button2 status ERROR, unpress is ecpected", isError: true);
                     isAllMatched = false;
                 }
                 if (status.EmergencyButton != 0)
                 {
-                    Logger.Print("EmergencyButton status ERROR, unpress is ecpected", isError: true);
+                    Error = ErrorType.EmergencyButtonCheckFail;
+                    LogWriter.Log("EmergencyButton status ERROR, unpress is ecpected", isError: true);
+                    //Logger.Print("EmergencyButton status ERROR, unpress is ecpected", isError: true);
                     isAllMatched = false;
                 }
 
                 if (isAllMatched)
                 {
-                    Logger.Print("Unpress Check passed");
+                    LogWriter.Log("Unpress Check passed");
+                    //Logger.Print("Unpress Check passed");
+                    return true;
                 }
                 else
                 {
@@ -116,144 +164,129 @@ namespace AwInitilizer.Procedure
             }
             else
             {
-                Logger.Print("Get button press status Failed", isError: true);
+                LogWriter.Log("Get button press status Failed", isError: true);
+                //Logger.Print("Get button press status Failed", isError: true);
                 return false;
             }
+        }
 
-            //stage 2 - check press sequence
-            Logger.Print("Button press Status check Start");
-            //MessageBox.Show("Press Button1,Button2,EmergencyButton in order\neach press continuous 2 secondes\nPress Ok to start", "Starting Button test");
+        private async Task<bool> PressBtnCheck(int btnInt)
+        {
 
-            bool isError = false;
-            //Button1,Button2,EmergencyButton in order 0,1,2
+            string btn, btnLang, imgUrl;
+            (btn, btnLang, imgUrl) = GetBtnParam(btnInt);
+
+            ShowBtnPressRequestDialog(btnLang, imgUrl);
+
+            var btnStatus = await WaitAndtGetPressBtn();
+            LogWriter.Report($"{btn}PressTest", string.Format("{0}{1}{2}", btnStatus.Button1, btnStatus.Button2, btnStatus.EmergencyButton));
+            LogWriter.Log($"Press check stage {btn} result");
+            LogWriter.Log($"Button1:{btnStatus.Button1},Button2:{btnStatus.Button2},EmgerncyButton:{btnStatus.EmergencyButton}\n");
+
+            DismisDialog();
+            var btnStatusIsMatchedRequred = CheckBtnStatus(btnInt,btnStatus);
+            return btnStatusIsMatchedRequred;
+        }
+
+        private async Task<ButtonStatus> WaitAndtGetPressBtn()
+        {
             ButtonStatus pressStatus = null;
-            for (int testType = 0; testType < 3; testType++)
+            //retry 20 times, 20*0.5 = 10 seconds 
+            int testCnt;
+            for (testCnt = 0; testCnt < 20; testCnt++)
             {
-                string btn, btnLang, imgUrl;
-                switch (testType)
-                {
-                    case 1:
-                        btn = "Green Button";
-                        btnLang = (string)Application.Current.FindResource("BtnPressGreenBtn");
-                        imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Green.png";
-                        break;
-                    case 0:
-                        btn = "Blue Button";
-                        btnLang = (string)Application.Current.FindResource("BtnPressBlueBtn");
-                        imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Blue.png";
-                        break;
-                    case 2:
-                        btn = "EmergencyButton";
-                        btnLang = (string)Application.Current.FindResource("BtnPressEmergencyBtn");
-                        imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Emergency.png";
-                        break;
-                    default:
-                        btn = "";
-                        btnLang = "";
-                        imgUrl = null;
-                        break;
-                };
-
-                //MessageBox.Show($"press {btn}");
-                //ShowDialog($"PRESS {btn.ToUpper()}", "Button press test", "", imgUrl, cancelAble: false);
-                ShowDialog(
-                    string.Format((string)Application.Current.FindResource("BtnPressPressHint"), btnLang),
-                    (string)Application.Current.FindResource("BtnPressHintTitle"),
-                    "", imgUrl, cancelAble: false);
-
-                //retry 20 times, 20*0.5 = 10 seconds 
-                int testCnt;
-                for (testCnt = 0; testCnt < 20; testCnt++)
+                await Task.Delay(500);
+                pressStatus = await GetButtonStatus();
+                if (pressStatus == null)
                 {
-                    await Task.Delay(500);
-                    pressStatus = await GetButtonStatus();
-                    if (pressStatus == null)
-                    {
-                        InfoLog += "Get Butoon state failed\n";
-                        Logger.Print("Get Butoon state failed");
-                        return false;
-                    }
-
-                    //if any button is pressed
-                    if (pressStatus.Button1 != 0 ||
-                        pressStatus.Button2 != 0 ||
-                        pressStatus.EmergencyButton != 0)
-                    {
-                        bool success = false;
-                        if (pressStatus.Button1 == (testType == 0 ? 1 : 0) &&
-                            pressStatus.Button2 == (testType == 1 ? 1 : 0) &&
-                            pressStatus.EmergencyButton == (testType == 2 ? 1 : 0))
-                        {
-                            //Status correct
-                            success = true;
-                        }
-                        else
-                        {
-                            //Status error
-                            isError = true;
-                            success = false;
-                            break;
-                        }
-
-                        if (success)
-                        {
-                            //wait release
-                            for (var releaseCnt = 0; releaseCnt < 20; releaseCnt++)
-                            {
-                                await Task.Delay(500);
-                                status = await GetButtonStatus();
-                                if (status == null)
-                                {
-                                    InfoLog += "Get Butoon state failed\n";
-                                    Logger.Print("Get Butoon state failed");
-                                    return false;
-                                }
-                                if (status.Button1 == 0 &&
-                                    status.Button2 == 0 &&
-                                    status.EmergencyButton == 0)
-                                {
-                                    break;
-                                }
-                            }
-                            break;
-                        }
-                    }
+                    return null;
                 }
 
-                DismisDialog();
-                InfoLog += $"Press check stage {btn} result\n";
-                InfoLog += $"Button1:{pressStatus.Button1},Button2:{pressStatus.Button2},EmgerncyButton:{pressStatus.EmergencyButton}\n";
-                LogPair.Add($"{btn}PressTest", string.Format("{0}{1}{2}", pressStatus.Button1, pressStatus.Button2, pressStatus.EmergencyButton));
-
-                ReportLog.Add(string.Format("{0} Button press test result : {1}, Expect:{2}{3}{4}",
-                    btn,
-                    string.Format("{0}{1}{2}", status.Button1, status.Button2, status.EmergencyButton),
-                    testType == 0 ? "1" : "0",
-                    testType == 1 ? "1" : "0",
-                    testType == 2 ? "1" : "0"
-                ));
-
-                if (testCnt >= 20)
+                //if any button is pressed
+                if (pressStatus.Button1 != 0 ||
+                    pressStatus.Button2 != 0 ||
+                    pressStatus.EmergencyButton != 0)
                 {
-                    isError = true;
-                    Logger.Print($"{btn} press TIMEOUT", isError: true);
+                    await WaitAllBtnRelease();
                     break;
                 }
-                else if (isError)
-                {
-                    Logger.Print($"{btn} press state ERROR", isError: true);
-                    Logger.Print($"Button1 {GetBtnStatusString(pressStatus.Button1)}, Button2 {GetBtnStatusString(pressStatus.Button2)}, EmergencyButton {GetBtnStatusString(pressStatus.EmergencyButton)}", isError: true);
+            }
+            return pressStatus;
+        }
+
+        private bool CheckBtnStatus(int btnInt, ButtonStatus buttonStatus)
+        {
+            if (buttonStatus.Button1 == (btnInt == 0 ? 1 : 0) &&
+                buttonStatus.Button2 == (btnInt == 1 ? 1 : 0) &&
+                buttonStatus.EmergencyButton == (btnInt == 2 ? 1 : 0))
+            {
+                //Status correct
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        private void ShowBtnPressRequestDialog(string btnLang, string imgUrl)
+        {
+            ShowDialog(
+                string.Format((string)Application.Current.FindResource("BtnPressPressHint"), btnLang),
+                (string)Application.Current.FindResource("BtnPressHintTitle"),
+                "", imgUrl, cancelAble: false);
+        }
+
+        private (string btn, string btnLang, string imgUrl) GetBtnParam(int btnInt)
+        {
+            string btn, btnLang, imgUrl;
+            switch (btnInt)
+            {
+                case 1:
+                    btn = "Green Button";
+                    btnLang = (string)Application.Current.FindResource("BtnPressGreenBtn");
+                    imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Green.png";
+                    break;
+                case 0:
+                    btn = "Blue Button";
+                    btnLang = (string)Application.Current.FindResource("BtnPressBlueBtn");
+                    imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Blue.png";
+                    break;
+                case 2:
+                    btn = "EmergencyButton";
+                    btnLang = (string)Application.Current.FindResource("BtnPressEmergencyBtn");
+                    imgUrl = "pack://application:,,,/AwInitilizer;component/Image/Emergency.png";
+                    break;
+                default:
+                    btn = "";
+                    btnLang = "";
+                    imgUrl = null;
                     break;
+            };
+            return (btn, btnLang, imgUrl);
+        }
+
+        private async Task WaitAllBtnRelease()
+        {
+            ButtonStatus status;
+            //wait release
+            for (var releaseCnt = 0; releaseCnt < 20; releaseCnt++)
+            {
+                await Task.Delay(500);
+                status = await GetButtonStatus();
+                if (status == null)
+                {
+                    //InfoLog += "Get Butoon state failed\n";
+                    //Logger.Print("Get Butoon state failed");
+                    continue;
                 }
-                else
+                if (status.Button1 == 0 &&
+                    status.Button2 == 0 &&
+                    status.EmergencyButton == 0)
                 {
-                    Logger.Print($"{btn} press state passed");
+                    break ;
                 }
             }
-
-            if(isError)
-                return false;
-            return true;
         }
 
         internal async Task<ButtonStatus> GetButtonStatus(bool isConnectTest = false)
@@ -268,7 +301,8 @@ namespace AwInitilizer.Procedure
                     {
                         // 將 StreamReader 所讀到的字元轉為 string
                         string request = reader.ReadToEnd();
-                        InfoLog += $"Get respone : {request}\n";
+                        //InfoLog += $"Get respone : {request}\n";
+                        LogWriter.Log($"Get respone : {request}", isDebugLog: true);
                         var values = JsonConvert.DeserializeObject<ButtonStatus>(request);
 
                         return values;
@@ -279,12 +313,16 @@ namespace AwInitilizer.Procedure
             {
                 if (!isConnectTest)
                 {
-                    InfoLog += "Get Button Status Failed\n";
-                    InfoLog += e.Message;
-                    InfoLog += "\n";
+                    Error = ErrorType.GetStatusFail;
+                    LogWriter.Log("Get Button Status Failed", isError: true);
+                    LogWriter.Log(e.Message, isDebugLog: true);
+
+                    //InfoLog += "Get Button Status Failed\n";
+                    //InfoLog += e.Message;
+                    //InfoLog += "\n";
 
-                    Logger.Print("Get Button Status Failed", isError: true);
-                    Logger.Print(e.Message + "", isError: true);
+                    //Logger.Print("Get Button Status Failed", isError: true);
+                    //Logger.Print(e.Message + "", isError: true);
                 }
             }
 

+ 66 - 16
AwInitilizer/Procedure/FirmwareBundleUploadProcedure.cs

@@ -11,20 +11,55 @@ using System.Net;
 using System.Web;
 using System.IO;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.FirmwareBundleUpload
 {
+    public enum ErrorType
+    {
+        None,
+        StartWaitTimeout,
+        UploadFailed,
+    }
+
+    public enum LogEvent
+    {
+        UploadStartWait,
+        FirmwareUpload
+    }
+
     public class FirmwareBundleUploadProcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<FirmwareBundleUploadProcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.UploadStartWait, "UploadStartWait" },
+            { LogEvent.FirmwareUpload, "FirmwareUpload" },
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.UploadStartWait, "Wait restart {0}" },
+            { LogEvent.FirmwareUpload, "Firmware Upload {0}" },
+        };
+
         public FirmwareBundleUploadProcedure() : base()
         {
             Name = string.Format("Firmware Upload");
             Content = string.Format("Upload all Firemware");
+
+            LogWriter = new ProcedureLog.LogWriter<FirmwareBundleUploadProcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
         {
             //wait restart
-            Logger.Print("Waiting restart..");
+            //Logger.Print("Waiting restart..");
 
             bool response = false;
             int pollingCnt = 0;
@@ -36,23 +71,28 @@ namespace AwInitilizer.Procedure
                     break;
             }
 
-            ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.25));
+            LogWriter.Log(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.25));
+            //ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<14", pollingCnt * 0.25));
 
             //timeout
             if (pollingCnt >= 56)
             {
-                Logger.Print("Wait restart timeout", isError: true);
-                InfoLog += "Wait restart timeout\n";
-                LogPair.Add($"UploadStartWait", "0");
+                LogWriter.Report(LogEvent.UploadStartWait, "fail");
+                Error = ErrorType.StartWaitTimeout;
+
+                //Logger.Print("Wait restart timeout", isError: true);
+                //InfoLog += "Wait restart timeout\n";
+                //LogPair.Add($"UploadStartWait", "0");
                 return false;
             }
 
-            LogPair.Add($"UploadStartWait", "1");
+            LogWriter.Report(LogEvent.UploadStartWait, "success");
+            //LogPair.Add($"UploadStartWait", "1");
 
             //upload firmware
             //return await UploadWithHttpWebRequest();
             bool result = false;
-            for(int tryCnt = 0; tryCnt< 10; tryCnt++)
+            for (int tryCnt = 0; tryCnt < 10; tryCnt++)
             {
                 result = await UploadWithRestSharp();
                 if (result)
@@ -60,6 +100,11 @@ namespace AwInitilizer.Procedure
                 else
                     await Task.Delay(1000);
             }
+            if(!result)
+            {
+                Error = ErrorType.UploadFailed;
+                return false;
+            }
             return result;
         }
 
@@ -153,20 +198,25 @@ namespace AwInitilizer.Procedure
             }
 
             RestSharp.IRestResponse response = await restClient.ExecuteAsync(request);
+
             if (response.IsSuccessful)
             {
-                InfoLog += $"get firmware update response {response.Content}\n";
-                Logger.Print("Firmware Upload Complete", isError: false);
-                LogPair.Add($"FirmwareUpload", "1");
+                LogWriter.Report(LogEvent.FirmwareUpload,"success");
+
+                //InfoLog += $"get firmware update response {response.Content}\n";
+                //Logger.Print("Firmware Upload Complete", isError: false);
+                //LogPair.Add($"FirmwareUpload", "1");
                 return true;
             }
             else
             {
-                InfoLog += $"file upload failed";
-                InfoLog += response.ErrorMessage;
-                Logger.Print("Firmware Upload Failed", isError: true);
-                Logger.Print(response.ErrorMessage,isError:true);
-                LogPair.Add($"FirmwareUpload", "0");
+                LogWriter.Report(LogEvent.FirmwareUpload, "fail");
+
+                //InfoLog += $"file upload failed";
+                //InfoLog += response.ErrorMessage;
+                //Logger.Print("Firmware Upload Failed", isError: true);
+                //Logger.Print(response.ErrorMessage,isError:true);
+                //LogPair.Add($"FirmwareUpload", "0");
                 return false;
             }
         }

+ 104 - 53
AwInitilizer/Procedure/FirmwareCheckVersionProcedure.cs

@@ -9,20 +9,50 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.FirmwareCheckVersion
 {
+    public enum ErrorType
+    {
+        None,
+        RestartTimeout,
+        VersionCheckFail,
+    }
+
+    public enum LogEvent
+    {
+
+    }
+
     public class FirmwareCheckVersionProcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<FirmwareCheckVersionProcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+        };
+
         public FirmwareCheckVersionProcedure() : base()
         {
             Name = "Firmware Version Check";
             Content = "Wait restart and check firmware versions";
+
+            LogWriter = new ProcedureLog.LogWriter<FirmwareCheckVersionProcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
         {
             //wait restart
-            Logger.Print("Waiting restart..");
+            //Logger.Print("Waiting restart..");
 
             bool response = false;
             int pollingCnt = 0;
@@ -35,13 +65,15 @@ namespace AwInitilizer.Procedure
                     break;
             }
 
-            ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<16", (pollingCnt * 0.25) + 2));
+            LogWriter.Log(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<16", (pollingCnt * 0.25) + 2));
+            //ReportLog.Add(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<16", (pollingCnt * 0.25) + 2));
 
             //timeout
             if (pollingCnt >= 56)
             {
-                Logger.Print("Wait restart timeout", isError: true);
-                InfoLog += "Wait restart timeout\n";
+                Error = ErrorType.RestartTimeout;
+                //Logger.Print("Wait restart timeout", isError: true);
+                //InfoLog += "Wait restart timeout\n";
                 return false;
             }
 
@@ -52,59 +84,74 @@ namespace AwInitilizer.Procedure
             //check all version
             foreach (var model in updatedList)
             {
-                if (string.IsNullOrEmpty(model.Module))
-                {
-                    continue;
-                }
+                var checkResult = CheckModelbyList(model, versionPair);
+                if (!checkResult)
+                    Error = ErrorType.VersionCheckFail;
+                    return false;
+            }
 
-                var logPairNmae = $"{model.Module}VersionCheck";
+            return true;
+        }
 
-                if (versionPair.Keys.Contains(model.Module))
-                {
-                    ReportLog.Add(string.Format("Read {0} version : {1} , Expect:{2}", model.Module, versionPair[model.Module], model.Version));
+        private bool CheckModelbyList(Model.FirmwareUpdateModel model, Dictionary<string,string> versionPair)
+        {
+            if (string.IsNullOrEmpty(model.Module))
+            {
+                return true;
+            }
 
-                    bool isVersionMatched = false;
-                    if (model.Module == "CsuRootFsFwRev")
-                    {
-                        isVersionMatched = versionPair[model.Module].StartsWith(model.Version);
-                    }
-                    else
-                    {
-                        isVersionMatched = versionPair[model.Module] == model.Version;
-                    }
+            var logPairName = $"{model.Module}VersionCheck";
 
-                    if (isVersionMatched)
-                    {
-                        Logger.Print($"Model {model.Module} updated", isError: false);
-                        InfoLog += $"{Name}:updated success\n";
-                        if (!LogPair.Keys.Contains(logPairNmae))
-                            LogPair.Add(logPairNmae, "1");
-                    }
-                    else
-                    {
-                        Logger.Print($"Model {model.Module} version mismatch", isError: true);
-                        InfoLog += $"{model.Module}:Updated Version mismatched\n";
-                        if (!LogPair.Keys.Contains(logPairNmae))
-                            LogPair.Add(logPairNmae, "0");
-                        return false;
-                    }
+            if (versionPair.Keys.Contains(model.Module))
+            {
+                LogWriter.Log(string.Format("Read {0} version : {1} , Expect:{2}", model.Module, versionPair[model.Module], model.Version));
+                //ReportLog.Add(string.Format("Read {0} version : {1} , Expect:{2}", model.Module, versionPair[model.Module], model.Version));
+
+                bool isVersionMatched = false;
+                if (model.Module == "CsuRootFsFwRev")
+                {
+                    isVersionMatched = versionPair[model.Module].StartsWith(model.Version);
+                }
+                else
+                {
+                    isVersionMatched = versionPair[model.Module] == model.Version;
                 }
-                else if (model.Module.ToLower() == "dtb")
+
+                if (isVersionMatched)
                 {
-                    //pass
+                    LogWriter.Report(logPairName,"success");
+                    //Logger.Print($"Model {model.Module} updated", isError: false);
+                    //InfoLog += $"{Name}:updated success\n";
+                    //if (!LogPair.Keys.Contains(logPairName))
+                    //    LogPair.Add(logPairName, "1");
+                    return true;
                 }
                 else
                 {
-                    //model name not found
-                    Logger.Print($"Model {model.Module} version not found", isError: true);
-                    InfoLog += $"Model {model.Module} version not found\n";
-                    if (!LogPair.Keys.Contains(logPairNmae))
-                        LogPair.Add(logPairNmae, "0");
+                    LogWriter.Report(logPairName, "fail");
+                    //Logger.Print($"Model {model.Module} version mismatch", isError: true);
+                    //InfoLog += $"{model.Module}:Updated Version mismatched\n";
+                    //if (!LogPair.Keys.Contains(logPairName))
+                    //    LogPair.Add(logPairName, "0");
                     return false;
                 }
             }
-
-            return true;
+            else if (model.Module.ToLower() == "dtb")
+            {
+                //pass
+                return true;
+            }
+            else
+            {
+                //model name not found
+                LogWriter.Report(logPairName, "fail");
+                LogWriter.Log($"Model {model.Module} version not found");
+                //Logger.Print($"Model {model.Module} version not found", isError: true);
+                //InfoLog += $"Model {model.Module} version not found\n";
+                //if (!LogPair.Keys.Contains(logPairName))
+                //    LogPair.Add(logPairName, "0");
+                return false;
+            }
         }
 
         internal async Task<Dictionary<string, string>> GetVersion(bool isConnectTest = false)
@@ -123,7 +170,9 @@ namespace AwInitilizer.Procedure
                     {
                         // 將 StreamReader 所讀到的字元轉為 string
                         string request = reader.ReadToEnd();
-                        InfoLog += $"get version response:{request}\n";
+                        LogWriter.Log($"get version response:{request}", isDebugLog: true);
+                        //InfoLog += $"get version response:{request}\n";
+
                         var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(request);
 
                         var toReturn = new Dictionary<string, string>();
@@ -158,12 +207,14 @@ namespace AwInitilizer.Procedure
             {
                 if (!isConnectTest)
                 {
-                    Logger.Print("Get Version Failed", isError: true);
-                    Logger.Print(e.Message + "", isError: true);
-
-                    InfoLog += "Get Version Failed\n";
-                    InfoLog += e.Message;
-                    InfoLog += "\n";
+                    LogWriter.Log("Get Version Failed");
+                    LogWriter.Log(e.Message, isDebugLog: true);
+                    //Logger.Print("Get Version Failed", isError: true);
+                    //Logger.Print(e.Message + "", isError: true);
+
+                    //InfoLog += "Get Version Failed\n";
+                    //InfoLog += e.Message;
+                    //InfoLog += "\n";
                 }
 
                 return null;

+ 135 - 51
AwInitilizer/Procedure/FourGenModuleCheckProcedure.cs

@@ -4,14 +4,63 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.FourGenModuleCheck
 {
+    public enum ErrorType
+    {
+        None,
+        ConnectFail,
+        VersionReadFail,
+        VersionMismatch,
+        SimStatusReadFail,
+        SimStatusMismatch,
+        IccidMistach,
+        ImsiMistach,
+    }
+
+    public enum LogEvent
+    {
+        FourgenSocketConnect,
+        FourgenModuleVersion,
+        SimStatus,
+        SimICCID,
+        SimIMSI
+    }
+
     public class FourGenModuleCheckProcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<FourGenModuleCheckProcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.FourgenSocketConnect, "FourgenSocketConnect" },
+            { LogEvent.FourgenModuleVersion, "FourgenModuleVersion" },
+            { LogEvent.SimStatus, "SimStatus" },
+            { LogEvent.SimICCID, "SimICCID" },
+            { LogEvent.SimIMSI, "SimIMSI" },
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.FourgenSocketConnect, "EVSE connect {0}" },
+            { LogEvent.FourgenModuleVersion, "Read 4G Module version : {0}" },
+            { LogEvent.SimStatus, "Get sim instert status {0}" },
+            { LogEvent.SimICCID, "Get Sim ICCID : {0}" },
+            { LogEvent.SimIMSI, "Get Sim IMSI : {0}" },
+        };
+
         public FourGenModuleCheckProcedure() : base()
         {
             Name = "4G Check";
             Content = "Check 4G module version and SIM card information matches user input";
+
+            LogWriter = new ProcedureLog.LogWriter<FourGenModuleCheckProcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
@@ -19,61 +68,87 @@ namespace AwInitilizer.Procedure
             if (!UpdateData.SystemID.ModelName.Network.ToString().Contains("4G"))
             {
                 //if does not support 4G then end init
-                InfoLog += "model name does not support 4g ,skip update process\n";
-                ReportLog.Add("4G not supported, skip procedure");
+                LogWriter.Log("4G not supported, skip procedure");
+
+                //InfoLog += "model name does not support 4g ,skip update process\n";
+                //ReportLog.Add("4G not supported, skip procedure");
                 return true;
             }
 
-            Logger.Print("Connecting to EVSE");
+            //Logger.Print("Connecting to EVSE");
             if (!await base.CheckAndCreateSocket())
             {
-                InfoLog += "EVSE connect failed\n";
-                LogPair.Add("FourgenSocketConnect", "0");
-                ReportLog.Add("EVSE connect failed");
+                LogWriter.Report(LogEvent.FourgenSocketConnect,"fail");
+                Error = ErrorType.ConnectFail;
+
+                //InfoLog += "EVSE connect failed\n";
+                //LogPair.Add("FourgenSocketConnect", "0");
+                //ReportLog.Add("EVSE connect failed");
                 return false;
             }
+            LogWriter.Report(LogEvent.FourgenSocketConnect, "success");
 
             var fourthGenModuleVersion = await serialPortocol.GetFourGenModuleVersion();
-            LogPair.Add("FourgenModuleVersion", fourthGenModuleVersion);
+            LogWriter.Report(LogEvent.FourgenModuleVersion, fourthGenModuleVersion);
+            //LogPair.Add("FourgenModuleVersion", fourthGenModuleVersion);
             if (string.IsNullOrEmpty(fourthGenModuleVersion))
             {
-                InfoLog += "4G module version read error\n";
-                Logger.Print("4G module version read error", isError: true);
-                ReportLog.Add("4G module version read error");
+                Error = ErrorType.VersionReadFail;
+                LogWriter.Log("4G module version read error");
+
+                //InfoLog += "4G module version read error\n";
+                //Logger.Print("4G module version read error", isError: true);
+                //ReportLog.Add("4G module version read error");
                 return false;
             }
             else
             {
-                InfoLog += $"Get 4G Module version :{fourthGenModuleVersion}\n";
-                ReportLog.Add(string.Format("Read 4G Module version : {0} , Expect:{1}", fourthGenModuleVersion, UpdateData.FourGenModuleVersion));
+                //InfoLog += $"Get 4G Module version :{fourthGenModuleVersion}\n";
+                //ReportLog.Add(string.Format("Read 4G Module version : {0} , Expect:{1}", fourthGenModuleVersion, UpdateData.FourGenModuleVersion));
                 if (!fourthGenModuleVersion.ToLower().StartsWith(UpdateData.FourGenModuleVersion.ToLower()))
                 {
-                    InfoLog += "4G module version not matched\n";
-                    Logger.Print("4G module version not matched", isError: true);
+                    Error = ErrorType.VersionMismatch;
+                    //InfoLog += "4G module version not matched\n";
+                    //Logger.Print("4G module version not matched", isError: true);
                     return false;
                 }
             }
 
             var simstatus = await serialPortocol.GetSimStatus();
+            if(simstatus == null)
+            {
+                LogWriter.Report(LogEvent.SimStatus, "unknown");
+            }
+            else if(simstatus.IsInstalled)
+            {
+                LogWriter.Report(LogEvent.SimStatus, "inserted");
+            }
+            else
+            {
+                LogWriter.Report(LogEvent.SimStatus, "none");
+            }
+
             if (simstatus == null)
             {
-                InfoLog += "Get sim status failed\n";
-                Logger.Print("Get sim status failed", isError: true);
-                LogPair.Add("SimStatus", "ReadFail");
-                ReportLog.Add("Get sim status failed");
+                Error = ErrorType.SimStatusReadFail;
+                //InfoLog += "Get sim status failed\n";
+                //Logger.Print("Get sim status failed", isError: true);
+                //LogPair.Add("SimStatus", "ReadFail");
+                //ReportLog.Add("Get sim status failed");
                 return false;
             }
             else
             {
-                LogPair.Add("SimStatus", simstatus.IsInstalled? "1":"0");
-                InfoLog += $"iccidBytes,{BitConverter.ToString(simstatus.ICCID).Replace("-","")}\n";
-                InfoLog += $"imsiBytes,{BitConverter.ToString(simstatus.IMSI).Replace("-", "")}\n";
+                //LogPair.Add("SimStatus", simstatus.IsInstalled? "1":"0");
+                //InfoLog += $"iccidBytes,{BitConverter.ToString(simstatus.ICCID).Replace("-","")}\n";
+                //InfoLog += $"imsiBytes,{BitConverter.ToString(simstatus.IMSI).Replace("-", "")}\n";
 
                 if (simstatus.IsInstalled != UpdateData.IsSimInsert)
                 {
-                    ReportLog.Add(string.Format("Get Sim Status : {0} , Expect:{1}", simstatus.IsInstalled ? "installed" : "uninstalled", UpdateData.IsSimInsert ? "installed" : "uninstalled"));
-
-                    Logger.Print("sim install status not matched", isError: true);
+                    LogWriter.Log(string.Format("Get Sim Status : {0} , Expect:{1}", simstatus.IsInstalled ? "installed" : "uninstalled", UpdateData.IsSimInsert ? "installed" : "uninstalled"));
+                    Error = ErrorType.SimStatusMismatch;
+                    //ReportLog.Add(string.Format("Get Sim Status : {0} , Expect:{1}", simstatus.IsInstalled ? "installed" : "uninstalled", UpdateData.IsSimInsert ? "installed" : "uninstalled"));
+                    //Logger.Print("sim install status not matched", isError: true);
                     return false;
                 }
                 else
@@ -92,47 +167,56 @@ namespace AwInitilizer.Procedure
                         var ICCIDstring = Encoding.ASCII.GetString(iccidBytes).Trim();
                         var IMSIstring = Encoding.ASCII.GetString(imsiBytes).Trim();
 
-                        LogPair.Add("SimICCID", ICCIDstring);
-                        LogPair.Add("SimIMSI", IMSIstring);
+                        LogWriter.Report(LogEvent.SimICCID, ICCIDstring);
+                        LogWriter.Report(LogEvent.SimIMSI, IMSIstring);
 
-                        ReportLog.Add(string.Format("Get Sim ICCID : {0} , Expect:{1}", ICCIDstring, UpdateData.ICCID));
-                        ReportLog.Add(string.Format("Get Sim IMSI : {0} , Expect:{1}", IMSIstring, UpdateData.IMSI));
+                        //LogPair.Add("SimICCID", ICCIDstring);
+                        //LogPair.Add("SimIMSI", IMSIstring);
 
-                        InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled},ICCID:{ICCIDstring},IMSI:{IMSIstring}\n";
+                        //ReportLog.Add(string.Format("Get Sim ICCID : {0} , Expect:{1}", ICCIDstring, UpdateData.ICCID));
+                        //ReportLog.Add(string.Format("Get Sim IMSI : {0} , Expect:{1}", IMSIstring, UpdateData.IMSI));
+
+                        //InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled},ICCID:{ICCIDstring},IMSI:{IMSIstring}\n";
 
                         if (ICCIDstring != UpdateData.ICCID)
                         {
-                            Logger.Print("sim card ICCID not matched", isError: true);
-                            InfoLog += $"Sim card ICCID not matched,{ICCIDstring}:{UpdateData.ICCID}\n";
+                            LogWriter.Log("Sim card ICCID not match");
+                            Error = ErrorType.IccidMistach;
+
+                            //Logger.Print("sim card ICCID not matched", isError: true);
+                            //InfoLog += $"Sim card ICCID not matched,{ICCIDstring}:{UpdateData.ICCID}\n";
                             return false;
                         }
 
                         if (IMSIstring != UpdateData.IMSI)
                         {
-                            Logger.Print("sim card IMSI not matched", isError: true);
-                            InfoLog += $"Sim card IMSI not matched,{IMSIstring}:{UpdateData.IMSI}\n";
+                            LogWriter.Log("Sim card IMSI not match");
+                            Error = ErrorType.ImsiMistach;
+
+                            //Logger.Print("sim card IMSI not matched", isError: true);
+                            //InfoLog += $"Sim card IMSI not matched,{IMSIstring}:{UpdateData.IMSI}\n";
                             return false;
                         }
                     }
                     else
                     {
-                        InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled}\n";
-
-                        if (!simstatus.ICCID.SequenceEqual(new byte[22]))
-                        {
-                            InfoLog += $"ICCID not empty : { BitConverter.ToString(simstatus.ICCID).Replace("-", " ")}\n";
-                            ReportLog.Add("ICCID not empty");
-                            Logger.Print("sim card ICCID not empty", isError: true);
-                            return false;
-                        }
-
-                        if (!simstatus.IMSI.SequenceEqual(new byte[16]))
-                        {
-                            InfoLog += $"IMSI not empty : { BitConverter.ToString(simstatus.IMSI).Replace("-", " ")}\n";
-                            ReportLog.Add("IMSI not empty");
-                            Logger.Print("sim card IMSI not empty", isError: true);
-                            return false;
-                        }
+                        //InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled}\n";
+
+                        //if (!simstatus.ICCID.SequenceEqual(new byte[22]))
+                        //{
+                        //    InfoLog += $"ICCID not empty : { BitConverter.ToString(simstatus.ICCID).Replace("-", " ")}\n";
+                        //    ReportLog.Add("ICCID not empty");
+                        //    Logger.Print("sim card ICCID not empty", isError: true);
+                        //    return false;
+                        //}
+
+                        //if (!simstatus.IMSI.SequenceEqual(new byte[16]))
+                        //{
+                        //    InfoLog += $"IMSI not empty : { BitConverter.ToString(simstatus.IMSI).Replace("-", " ")}\n";
+                        //    ReportLog.Add("IMSI not empty");
+                        //    Logger.Print("sim card IMSI not empty", isError: true);
+                        //    return false;
+                        //}
                     }
                 }
 

+ 97 - 37
AwInitilizer/Procedure/RestarttoIdelProcedure.cs

@@ -10,14 +10,46 @@ using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.RestarttoIdel
 {
+    public enum ErrorType
+    {
+        None,
+        SetFail,
+        ConnectorNotIdel,
+    }
+
+    public enum LogEvent
+    {
+        IdelCheck
+    }
+
     public class RestarttoIdelProcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<RestarttoIdelProcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.IdelCheck, "IdelCheck" }
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.IdelCheck, "Connector status is Idel Check :{0}" }
+        };
+
         public RestarttoIdelProcedure() : base()
         {
             Name = "Restart To Idel";
             Content = "Restart EVSSE and check status back to Idel";
+
+            LogWriter = new ProcedureLog.LogWriter<RestarttoIdelProcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
@@ -25,23 +57,27 @@ namespace AwInitilizer.Procedure
             var result = await FactorySet();
             if (!result)
             {
+                Error = ErrorType.SetFail;
                 return false;
             }
             else
             {
-                Logger.Print("Waiting Factory reset complete...");
+                LogWriter.Log("Waiting Factory reset complete...");
+                //Logger.Print("Waiting Factory reset complete...");
                 await Task.Delay(TimeSpan.FromMinutes(2));
-                if(await CheckAllIdel())
+                if (await CheckAllIdel())
                 {
-                    Logger.Print("All Connetor is Idel");
+                    LogWriter.Report(LogEvent.IdelCheck,"success");
+                    //Logger.Print("All Connetor is Idel");
+                    return true;
                 }
                 else
                 {
+                    LogWriter.Report(LogEvent.IdelCheck, "fail");
+                    Error = ErrorType.ConnectorNotIdel;
                     return false;
                 }
             }
-
-            return true;
         }
 
         private async Task<bool> FactorySet()
@@ -71,27 +107,54 @@ namespace AwInitilizer.Procedure
                     using (StreamReader reader = new StreamReader(stream))
                     {
                         // 將 StreamReader 所讀到的字元轉為 string
-                        string request = reader.ReadToEnd();
-                        InfoLog += $"factory set respons:\n{request}\n";
-                        var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(request);
+                        string response = reader.ReadToEnd();
+                        //InfoLog += $"factory set respons:\n{request}\n";
+                        LogWriter.Log($"factory set respons: {response}", isDebugLog: true);
+                        var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(response);
                     }
                 }
                 return true;
             }
-            catch(Exception e)
+            catch (Exception e)
             {
-                InfoLog += "Factory reset command failed\n";
-                InfoLog += e.Message;
-                InfoLog += "\n";
+                LogWriter.Log("Factory reset command failed");
+                LogWriter.Log(e.Message, isDebugLog: true);
+
+                //InfoLog += "Factory reset command failed\n";
+                //InfoLog += e.Message;
+                //InfoLog += "\n";
 
-                Logger.Print("Factory reset command failed", isError: true);
-                Logger.Print(e.Message, isError: true);
+                //Logger.Print("Factory reset command failed", isError: true);
+                //Logger.Print(e.Message, isError: true);
                 return false;
             }
         }
 
         private async Task<bool> CheckAllIdel()
         {
+            var statusPairs = await GetConnectorStatus();
+            if (statusPairs is null)
+                return false;
+            else
+            {
+                foreach (var statusPair in statusPairs)
+                {
+                    if (statusPair.Value != "1")
+                    {
+                        LogWriter.Log($"Connector {statusPair.Key} status not Idel");
+
+                        return false;
+                        //InfoLog += $"Connector {matchIndex} status not Idel\n";
+                        //Logger.Print($"Connector {matchIndex} status not Idel", isError: true);
+                    }
+                }
+                return true;
+            }
+        }
+
+        private async Task<Dictionary<int, string>> GetConnectorStatus()
+        {
+            Dictionary<int, string> connectorStatusPair = new Dictionary<int, string>();
             try
             {
                 using (WebClient webClient = new WebClient())
@@ -106,45 +169,42 @@ namespace AwInitilizer.Procedure
                     {
                         // 將 StreamReader 所讀到的字元轉為 string
                         string request = reader.ReadToEnd();
-                        InfoLog += $"get status respons:\n{request}\n";
-                        LogPair.Add($"EvseStatus", request);
+                        LogWriter.Log($"get status respons:\n{request}\n", isDebugLog: true);
+                        //InfoLog += $"get status respons:\n{request}\n";
+                        //LogPair.Add($"EvseStatus", request);
                         Regex rx = new Regex("(SystemStatus)\\\": (\\d)");
                         var matches = rx.Matches(request);
-                        bool isAllPassed = true;
-                        for(int matchIndex=0; matchIndex< matches.Count; matchIndex++)
+                        for (int matchIndex = 0; matchIndex < matches.Count; matchIndex++)
                         {
                             var match = matches[matchIndex];
                             if (match.Groups.Count != 3)
                             {
-                                InfoLog += $"Connector {matchIndex} status string mismatched\n";
-                                Logger.Print($"Connector {matchIndex} status string mismatched", isError:true);
-                                isAllPassed = false;
+                                LogWriter.Log($"Connector {matchIndex} status string mismatched");
+                                return null;
+                                //InfoLog += $"Connector {matchIndex} status string mismatched\n";
+                                //Logger.Print($"Connector {matchIndex} status string mismatched", isError:true);
                             }
                             else
                             {
-                                if(match.Groups[2].Value != "1")
-                                {
-                                    InfoLog += $"Connector {matchIndex} status not Idel\n";
-                                    Logger.Print($"Connector {matchIndex} status not Idel", isError: true);
-                                    isAllPassed = false;
-                                }
+                                connectorStatusPair.Add(matchIndex, match.Groups[2].Value);
                             }
                         }
-
-                        return isAllPassed;
                     }
                 }
-                return true;
+                return connectorStatusPair;
             }
             catch (Exception e)
             {
-                InfoLog += "Check all idel command failed\n";
-                InfoLog += e.Message;
-                InfoLog += "\n";
+                LogWriter.Log("Get connector status command failed");
+                LogWriter.Log(e.Message, isDebugLog: true);
 
-                Logger.Print("Check all idel command failed", isError:true);
-                Logger.Print(e.Message, isError: true);
-                return false;
+                //InfoLog += "Check all idel command failed\n";
+                //InfoLog += e.Message;
+                //InfoLog += "\n";
+
+                //Logger.Print("Check all idel command failed", isError:true);
+                //Logger.Print(e.Message, isError: true);
+                return null;
             }
         }
     }

+ 61 - 17
AwInitilizer/Procedure/VersionLogProcedure.cs

@@ -8,25 +8,54 @@ using System.Net;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.VersionLog
 {
     public class VersionLogProcedure : ProcedureBase
     {
-        private List<string> excludeHeaderList = new List<string>() { 
-            "FactoryConfiguration", 
-            "AuxPower5V", 
+        private static readonly List<string> excludeHeaderList = new List<string>()
+        {
+            "FactoryConfiguration",
+            "AuxPower5V",
             "AuxPower12V",
-            "AuxPower24V", 
-            "AuxPower48V", 
-            "CsuHwRev", 
-            "FirmwareUpdate", 
-            "FanModuleHwRev", 
-            "RelayModuleHwRev" };
+            "AuxPower24V",
+            "AuxPower48V",
+            "CsuHwRev",
+            "FirmwareUpdate",
+            "FanModuleHwRev",
+            "RelayModuleHwRev"
+        };
+
+        private static readonly Dictionary<string, string> MesReportNamePair = new Dictionary<string, string>
+        {
+            { "CsuBootLoadFwRev","CSU Bootloader" },
+            { "CsuKernelFwRev","CSU Kernel" },
+            { "CsuRootFsFwRev","CSU Rootfs" },
+            { "CsuPrimFwRev","Primary MCU" },
+            { "FanModuleFwRev","FAN Module" },
+            { "LedModuleFwRev","LED Module" },
+            { "LcmFwRev","LCM UI" },
+            { "RelayModuleFwRev","Relay Module" },
+            { "PsuPrimFwRev","PSU Primary" },
+            { "PsuSecFwRev","PSU Secondary" },
+            { "TelcomModemFwRev","Telecom Module" },
+            { "AuxPwrFwRev","Aux Power" },
+            { "FourthGenModuleVersion","Fourth Gen Module" },
+            { "Connector1FwRev","Connector 1" },
+            { "Connector2FwRev","Connector 2" },
+        };
+
+        public enum LogEvent
+        {
+        }
+
+        private ProcedureLog.LogWriter<VersionLogProcedure, LogEvent> LogWriter;
 
         public VersionLogProcedure() : base()
         {
             Name = "Version Logger";
             Content = "Report version back to MES";
+
+            LogWriter = new ProcedureLog.LogWriter<VersionLogProcedure, LogEvent>(this);
         }
 
         internal override async Task<bool> Run()
@@ -38,7 +67,9 @@ namespace AwInitilizer.Procedure
                 {
                     if (!excludeHeaderList.Contains(infoPair.Key))
                     {
-                        LogPair.Add(infoPair.Key, infoPair.Value);
+                        var mesKey = GetMesReportKey(infoPair.Key);
+                        LogWriter.Report(mesKey, infoPair.Value);
+                        //LogPair.Add(infoPair.Key, infoPair.Value);
                     }
                 }
                 return true;
@@ -49,6 +80,15 @@ namespace AwInitilizer.Procedure
             }
         }
 
+        private string GetMesReportKey(string readVersion)
+        {
+            if(MesReportNamePair.ContainsKey(readVersion))
+            {
+                return MesReportNamePair[readVersion];
+            }
+            return readVersion;
+        }
+
         internal async Task<Dictionary<string, string>> GetVersion()
         {
             try
@@ -65,7 +105,8 @@ namespace AwInitilizer.Procedure
                     {
                         // 將 StreamReader 所讀到的字元轉為 string
                         string request = reader.ReadToEnd();
-                        InfoLog += $"get version response:{request}\n";
+                        LogWriter.Log($"get version response:{request}\n", isDebugLog: true);
+                        //InfoLog += $"get version response:{request}\n";
                         var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(request);
 
                         var toReturn = new Dictionary<string, string>();
@@ -98,12 +139,15 @@ namespace AwInitilizer.Procedure
             }
             catch (Exception e)
             {
-                Logger.Print("Get Version Failed", isError: true);
-                Logger.Print(e.Message + "", isError: true);
+                LogWriter.Log("Get Version Failed", isError: true);
+                LogWriter.Log(e.Message, isDebugLog: true);
+
+                //Logger.Print("Get Version Failed", isError: true);
+                //Logger.Print(e.Message + "", isError: true);
 
-                InfoLog += "Get Version Failed\n";
-                InfoLog += e.Message;
-                InfoLog += "\n";
+                //InfoLog += "Get Version Failed\n";
+                //InfoLog += e.Message;
+                //InfoLog += "\n";
 
                 return null;
             }

+ 88 - 24
AwInitilizer/Procedure/WifRssiCheckProcedure.cs

@@ -9,14 +9,48 @@ using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 
-namespace AwInitilizer.Procedure
+namespace AwInitilizer.Procedure.WifRssiCheck
 {
+    public enum ErrorType
+    {
+        None,
+        WifiModeDataNotFound,
+        WifiModeNotClient,
+        WifiRssiDataNotFound,
+        WifiRssiLow,
+    }
+
+    public enum LogEvent
+    {
+        WifiRssi
+    }
+
     public class WifRssiCheckProcedure : ProcedureBase
     {
+        public ErrorType Error { get; set; } = ErrorType.None;
+
+        private ProcedureLog.LogWriter<WifRssiCheckProcedure, LogEvent> LogWriter;
+
+        private readonly static Dictionary<LogEvent, string> ReportDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.WifiRssi, "WifiRssi" }
+        };
+
+        private readonly static Dictionary<LogEvent, string> LogDict = new Dictionary<LogEvent, string>()
+        {
+            { LogEvent.WifiRssi, "Get Wifi Rssi : {0}" }
+        };
+
         public WifRssiCheckProcedure() : base()
         {
             Name = "WiFi Rssi Check";
             Content = "Check Wifi Rssi Signal";
+
+            LogWriter = new ProcedureLog.LogWriter<WifRssiCheckProcedure, LogEvent>(this)
+            {
+                ReportPair = ReportDict,
+                LogPair = LogDict
+            };
         }
 
         internal override async Task<bool> Run()
@@ -24,17 +58,39 @@ namespace AwInitilizer.Procedure
             if (!UpdateData.SystemID.ModelName.Network.ToString().Contains("WiFi"))
             {
                 //if does not support Wifi then end init
-                InfoLog += "model name does not support Wifi ,skip check process\n";
-                ReportLog.Add("Wifi not supported, skip procedure");
+                LogWriter.Log("Wifi not supported, skip procedure");
+
+                //InfoLog += "model name does not support Wifi ,skip check process\n";
+                //ReportLog.Add("Wifi not supported, skip procedure");
                 return true;
             }
 
-            Logger.Print("Connecting to EVSE");
+            LogWriter.Log("Connecting to EVSE");
+            //Logger.Print("Connecting to EVSE");
             var checkResult = await CheckWifiRssi();
             return checkResult;
         }
 
         internal async Task<bool> CheckWifiRssi()
+        {
+            var rssi = await GetWifiRssi();
+            LogWriter.Report(LogEvent.WifiRssi, rssi.ToString());
+            if (rssi == 0)
+                return false;
+            else
+            {
+                var rssiCheckPass = rssi >= -80;
+                if (rssiCheckPass)
+                    return true;
+                else
+                {
+                    Error = ErrorType.WifiRssiLow;
+                    return false;
+                }
+            }
+        }
+
+        internal async Task<int> GetWifiRssi()
         {
             try
             {
@@ -50,8 +106,9 @@ namespace AwInitilizer.Procedure
                     {
                         // 將 StreamReader 所讀到的字元轉為 string
                         string request = reader.ReadToEnd();
-                        InfoLog += $"GetResponse:{request}";
-                        Logger.Print($"GetResponse:{request}", isError: false);
+                        LogWriter.Log($"GetResponse:{request}", isDebugLog: true);
+                        //InfoLog += $"GetResponse:{request}";
+                        //Logger.Print($"GetResponse:{request}", isError: false);
 
                         Regex rx_mode = new Regex("(WifiMode)\\\": ([0-9]*)");
                         var matches_mode = rx_mode.Matches(request);
@@ -61,24 +118,25 @@ namespace AwInitilizer.Procedure
                             var match = matches_mode[0];
                             if (match.Groups.Count != 3)
                             {
-                                return false;
+                                Error = ErrorType.WifiModeDataNotFound;
+                                return 0;
                             }
                             else
                             {
                                 if (int.TryParse(match.Groups[2].Value, out var wifiMode))
                                 {
                                     if (wifiMode != 1)
-                                        return false;
-                                }
-                                else
-                                {
-                                    return false;
+                                    {
+                                        Error = ErrorType.WifiModeNotClient;
+                                        return 0;
+                                    }
                                 }
                             }
                         }
                         else
                         {
-                            return false;
+                            Error = ErrorType.WifiModeDataNotFound;
+                            return 0;
                         }
 
                         Regex rx = new Regex("(WifiRssi)\\\": (-?[0-9]*)");
@@ -89,35 +147,41 @@ namespace AwInitilizer.Procedure
                             var match = matches[0];
                             if (match.Groups.Count != 3)
                             {
-                                return false;
+                                Error = ErrorType.WifiRssiDataNotFound;
+                                return 0;
                             }
                             else
                             {
                                 if (int.TryParse(match.Groups[2].Value, out var rssiSignal))
                                 {
-                                    LogPair.Add("WifiRssi", rssiSignal.ToString());
-                                    return rssiSignal >= -80;
+                                    //LogPair.Add("WifiRssi", rssiSignal.ToString());
+                                    return rssiSignal;
                                 }
-                                return false;
+                                Error = ErrorType.WifiRssiDataNotFound;
+                                return 0;
                             }
                         }
                         else
                         {
-                            return false;
+                            Error = ErrorType.WifiRssiDataNotFound;
+                            return 0;
                         }
                     }
                 }
             }
             catch (Exception e)
             {
-                Logger.Print("Get Wifi Rssi Failed", isError: true);
-                Logger.Print(e.Message + "", isError: true);
+                LogWriter.Log("Get Wifi Rssi Failed");
+                LogWriter.Log(e.Message, isDebugLog: true);
 
-                InfoLog += "Get Wifi Rssi Failed\n";
-                InfoLog += e.Message;
-                InfoLog += "\n";
+                //Logger.Print("Get Wifi Rssi Failed", isError: true);
+                //Logger.Print(e.Message + "", isError: true);
 
-                return false;
+                //InfoLog += "Get Wifi Rssi Failed\n";
+                //InfoLog += e.Message;
+                //InfoLog += "\n";
+
+                return 0;
             }
         }
     }

+ 95 - 0
AwInitilizer/ProcedureLog/LogWriter.cs

@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AwInitilizer.ProcedureLog
+{
+    public class LogWriter<T1,T2> where T1 : Procedure.ProcedureBase where T2 : Enum
+    {
+        public Dictionary<T2, string> ReportPair { get; set; }
+        public Dictionary<T2, string> LogPair { get; set; }
+
+        internal readonly T1 source;
+
+        public LogWriter(T1 source)
+        {
+            this.source = source;
+        }
+
+        public void Report(T2 logEvent, string data,bool isError = false)
+        {
+            string log = "";
+            log = CreateLogMessage(logEvent, data);
+
+            Log(log, isError);
+
+            if (ReportPair != null && ReportPair.ContainsKey(logEvent))
+            {
+                MesReport(ReportPair[logEvent], data);
+            }
+        }
+
+        public void Report(string logEvent, string data, bool isError = false)
+        {
+            string log = "";
+            log = string.Format("{0} {1}", logEvent, data);
+
+            Log(log, isError);
+
+            MesReport(logEvent, data);
+        }
+
+        public virtual void Log(string data, bool isError = false, bool isDebugLog = false)
+        {
+            WriteMyLog(data);
+            if (!isDebugLog)
+            {
+                WriteShortLog(data, isError);
+                WriteFormateLog(data);
+            }
+        }
+
+        private string CreateLogMessage(T2 logEvent, string data)
+        {
+            string log;
+            if (LogPair != null && LogPair.ContainsKey(logEvent))
+            {
+                log = string.Format(LogPair[logEvent], data);
+            }
+            else
+            {
+                log = string.Format("{0} {1}", Enum.GetName(typeof(T2), logEvent), data);
+            }
+
+            return log;
+        }
+
+        private void MesReport(string key,string value)
+        {
+            if (source.LogPair.ContainsKey(key))
+                source.LogPair[key] = value;
+            else
+                source.LogPair.Add(key, value);
+        }
+
+        private void WriteMyLog(string log)
+        {
+            source.InfoLog += string.Format("{0}\n", log);
+        }
+
+        private void WriteShortLog(string log, bool isError = false)
+        {
+            if (log.Length < 100)
+            {
+                Procedure.ProcedureBase.Logger.Print(log, isError);
+            }
+        }
+
+        private void WriteFormateLog(string log)
+        {
+            source.ReportLog.Add(log);
+        }
+    }
+}

+ 4 - 4
AwInitilizer/Properties/AssemblyInfo.cs

@@ -50,7 +50,7 @@ using System.Windows;
 //
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.1.0")]
-[assembly: AssemblyVersion("1.0.1.0")]
-[assembly: AssemblyFileVersion("1.0.1.0")]
-[assembly: AssemblyInformationalVersion("d07cbee")]
+// [assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
+[assembly: AssemblyInformationalVersion("14e654f")]

+ 1 - 1
GitVersion.yml

@@ -1,6 +1,6 @@
 assembly-versioning-scheme: MajorMinorPatch
 assembly-informational-format: '{ShortSha}'
-next-version: 1.1.0
+next-version: 1.2.0
 branches: {}
 ignore:
   sha: []

+ 3 - 3
Initilizer/AssemblyInfo.cs

@@ -9,7 +9,7 @@
                                               // app, or any theme specific resource dictionaries)
 )]
 
-[assembly: AssemblyVersion("1.0.1.0")]
-[assembly: AssemblyFileVersion("1.0.1.0")]
-[assembly: AssemblyInformationalVersion("d07cbee")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
+[assembly: AssemblyInformationalVersion("14e654f")]