using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AwInitilizer.Procedure { public class FourGenModuleCheckProcedure : ProcedureBase { public FourGenModuleCheckProcedure() : base() { Name = "4G Check"; Content = "Check 4G module version and SIM card information matches user input"; } internal override async Task Run() { 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"); return true; } Logger.Print("Connecting to EVSE"); if (!await base.CheckAndCreateSocket()) { InfoLog += "EVSE connect failed\n"; LogPair.Add("FourgenSocketConnect", "0"); ReportLog.Add("EVSE connect failed"); return false; } var fourthGenModuleVersion = await serialPortocol.GetFourGenModuleVersion(); 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"); return false; } else { 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); return false; } } var simstatus = await serialPortocol.GetSimStatus(); 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"); 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"; 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); return false; } else { if (simstatus.IsInstalled) { var iccidByteList = simstatus.ICCID.ToList(); iccidByteList.RemoveAll(x => x == 0x00); var iccidBytes = iccidByteList.ToArray(); var imsiByteList = simstatus.IMSI.ToList(); imsiByteList.RemoveAll(x => x == 0x00); var imsiBytes = imsiByteList.ToArray(); var ICCIDstring = Encoding.ASCII.GetString(iccidBytes).Trim(); var IMSIstring = Encoding.ASCII.GetString(imsiBytes).Trim(); LogPair.Add("SimICCID", ICCIDstring); LogPair.Add("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)); 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"; 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"; 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; } } } } return true; } } }