123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 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<bool> Run()
- {
- Logger.Print("Connecting to EVSE");
- if (!await base.CheckAndCreateSocket())
- {
- InfoLog += "EVSE connect failed\n";
- LogPair.Add("FourgenSocketConnect", "0");
- return false;
- }
- 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";
- return true;
- }
- 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);
- return false;
- }
- else
- {
- InfoLog += $"Get 4G Module version :{fourthGenModuleVersion}\n";
- if (fourthGenModuleVersion != UpdateData.FourGenModuleVersion)
- {
- 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");
- 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)
- {
- 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);
- 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";
- 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";
- Logger.Print("sim card IMSI not empty", isError: true);
- return false;
- }
- }
- }
- }
- return true;
- }
- }
- }
|