123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
-
- using AwInitilizer.Assist;
- using InitializerModel;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- 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
- bool response = false;
- int pollingCnt = 0;
- await Task.Delay(TimeSpan.FromMinutes(2));
- for (pollingCnt = 0; pollingCnt < 56; pollingCnt++)
- {
- await Task.Delay(TimeSpan.FromSeconds(15));
- response = await ChekCsuBootCompelete();
- if (response)
- break;
- }
- LogWriter.Log(string.Format("EVSE connet elapsed minute(s) : {0}, Expect:<16", (pollingCnt * 0.25) + 2));
- //timeout
- if (pollingCnt >= 56)
- {
- Error = ErrorType.RestartTimeout;
- return false;
- }
- await Task.Delay(5_000);
- //get version
- var versionPair = await GetVersion();
- var updatedList = UpdateData.FirmwareUpdateModels;
- if (versionPair == null)
- {
- Error = ErrorType.VersionCheckFail;
- return false;
- }
- //check all version
- foreach (var model in updatedList)
- {
- var checkResult = CheckModelbyList(model, versionPair);
- if (!checkResult)
- {
- Error = ErrorType.VersionCheckFail;
- return false;
- }
- }
- return true;
- }
- private bool CheckModelbyList(FirmwareUpdateModel model, Dictionary<string,string> versionPair)
- {
- if (string.IsNullOrEmpty(model.Module))
- {
- return true;
- }
- var logPairName = $"{model.Module}VersionCheck";
- if (versionPair.Keys.Contains(model.Module))
- {
- LogWriter.Log(string.Format("Read {0} version : {1} , Expect:{2}", model.Module, versionPair[model.Module], model.Version));
- bool isVersionMatched = false;
- if (model.Module == "CsuRootFsFwRev" ||
- model.Module.StartsWith("DDCsuRootFsFwRev"))
- {
- isVersionMatched = versionPair[model.Module].StartsWith(model.Version);
- }
- else
- {
- isVersionMatched = versionPair[model.Module] == model.Version;
- }
- if (isVersionMatched)
- {
- LogWriter.Report(logPairName,"success");
- return true;
- }
- else
- {
- LogWriter.Report(logPairName, "fail", isError: true);
- return false;
- }
- }
- else if (model.Module.ToLower() == "dtb")
- {
- //pass
- return true;
- }
- else
- {
- //model name not found
- LogWriter.Report(logPairName, "fail", isError: true);
- LogWriter.Log($"Model {model.Module} version not found");
- return false;
- }
- }
- internal async Task<Dictionary<string, string>> GetVersion(bool isConnectTest = false)
- {
- try
- {
- var result = await EvApi.GetVersion();
- LogWriter.Log($"get version response:{result.Response}", isDebugLog: true);
- return result.Result;
- }
- catch (Exception e)
- {
- if (!isConnectTest)
- {
- LogWriter.Log("Get Version Failed");
- LogWriter.Log(e.Message, isDebugLog: true);
- }
- return null;
- }
- }
- }
- }
|