FourGenModuleCheckProcedure.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace AwInitilizer.Procedure
  7. {
  8. public class FourGenModuleCheckProcedure : ProcedureBase
  9. {
  10. public FourGenModuleCheckProcedure() : base()
  11. {
  12. Name = "4G Check";
  13. Content = "Check 4G module version and SIM card information matches user input";
  14. }
  15. internal override async Task<bool> Run()
  16. {
  17. Logger.Print("Connecting to EVSE");
  18. if (!await base.CheckAndCreateSocket())
  19. {
  20. InfoLog += "EVSE connect failed\n";
  21. LogPair.Add("FourgenSocketConnect", "0");
  22. return false;
  23. }
  24. if (!UpdateData.SystemID.ModelName.Network.ToString().Contains("4G"))
  25. {
  26. //if does not support 4G then end init
  27. InfoLog += "model name does not support 4g ,skip update process\n";
  28. return true;
  29. }
  30. var fourthGenModuleVersion = await serialPortocol.GetFourGenModuleVersion();
  31. LogPair.Add("FourgenModuleVersion", fourthGenModuleVersion);
  32. if (string.IsNullOrEmpty(fourthGenModuleVersion))
  33. {
  34. InfoLog += "4G module version read error\n";
  35. Logger.Print("4G module version read error", isError: true);
  36. return false;
  37. }
  38. else
  39. {
  40. InfoLog += $"Get 4G Module version :{fourthGenModuleVersion}\n";
  41. if (fourthGenModuleVersion != UpdateData.FourGenModuleVersion)
  42. {
  43. InfoLog += "4G module version not matched\n";
  44. Logger.Print("4G module version not matched", isError: true);
  45. return false;
  46. }
  47. }
  48. var simstatus = await serialPortocol.GetSimStatus();
  49. if (simstatus == null)
  50. {
  51. InfoLog += "Get sim status failed\n";
  52. Logger.Print("Get sim status failed", isError: true);
  53. LogPair.Add("SimStatus", "ReadFail");
  54. return false;
  55. }
  56. else
  57. {
  58. LogPair.Add("SimStatus", simstatus.IsInstalled? "1":"0");
  59. InfoLog += $"iccidBytes,{BitConverter.ToString(simstatus.ICCID).Replace("-","")}\n";
  60. InfoLog += $"imsiBytes,{BitConverter.ToString(simstatus.IMSI).Replace("-", "")}\n";
  61. if (simstatus.IsInstalled != UpdateData.IsSimInsert)
  62. {
  63. Logger.Print("sim install status not matched", isError: true);
  64. return false;
  65. }
  66. else
  67. {
  68. if (simstatus.IsInstalled)
  69. {
  70. var iccidByteList = simstatus.ICCID.ToList();
  71. iccidByteList.RemoveAll(x => x == 0x00);
  72. var iccidBytes = iccidByteList.ToArray();
  73. var imsiByteList = simstatus.IMSI.ToList();
  74. imsiByteList.RemoveAll(x => x == 0x00);
  75. var imsiBytes = imsiByteList.ToArray();
  76. var ICCIDstring = Encoding.ASCII.GetString(iccidBytes).Trim();
  77. var IMSIstring = Encoding.ASCII.GetString(imsiBytes).Trim();
  78. LogPair.Add("SimICCID", ICCIDstring);
  79. LogPair.Add("SimIMSI", IMSIstring);
  80. InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled},ICCID:{ICCIDstring},IMSI:{IMSIstring}\n";
  81. if (ICCIDstring != UpdateData.ICCID)
  82. {
  83. Logger.Print("sim card ICCID not matched", isError: true);
  84. InfoLog += $"Sim card ICCID not matched,{ICCIDstring}:{UpdateData.ICCID}\n";
  85. return false;
  86. }
  87. if (IMSIstring != UpdateData.IMSI)
  88. {
  89. Logger.Print("sim card IMSI not matched", isError: true);
  90. InfoLog += $"Sim card IMSI not matched,{IMSIstring}:{UpdateData.IMSI}\n";
  91. return false;
  92. }
  93. }
  94. else
  95. {
  96. InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled}\n";
  97. if (!simstatus.ICCID.SequenceEqual(new byte[22]))
  98. {
  99. InfoLog += $"ICCID not empty : { BitConverter.ToString(simstatus.ICCID).Replace("-", " ")}\n";
  100. Logger.Print("sim card ICCID not empty", isError: true);
  101. return false;
  102. }
  103. if (!simstatus.IMSI.SequenceEqual(new byte[16]))
  104. {
  105. InfoLog += $"IMSI not empty : { BitConverter.ToString(simstatus.IMSI).Replace("-", " ")}\n";
  106. Logger.Print("sim card IMSI not empty", isError: true);
  107. return false;
  108. }
  109. }
  110. }
  111. }
  112. return true;
  113. }
  114. }
  115. }