FourGenModuleCheckProcedure.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if (simstatus.IsInstalled != UpdateData.IsSimInsert)
  60. {
  61. Logger.Print("sim install status not matched", isError: true);
  62. return false;
  63. }
  64. else
  65. {
  66. if (simstatus.IsInstalled)
  67. {
  68. var ICCIDstring = Encoding.ASCII.GetString(simstatus.ICCID);
  69. var IMSIstring = Encoding.ASCII.GetString(simstatus.IMSI);
  70. LogPair.Add("SimICCID", ICCIDstring);
  71. LogPair.Add("SimIMSI", IMSIstring);
  72. InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled},ICCID:{ICCIDstring},IMSI:{IMSIstring}\n";
  73. if (ICCIDstring != UpdateData.ICCID)
  74. {
  75. Logger.Print("sim card ICCID not matched", isError: true);
  76. return false;
  77. }
  78. if (IMSIstring != UpdateData.IMSI)
  79. {
  80. Logger.Print("sim card IMSI not matched", isError: true);
  81. return false;
  82. }
  83. }
  84. else
  85. {
  86. InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled}\n";
  87. if (!simstatus.ICCID.SequenceEqual(new byte[22]))
  88. {
  89. InfoLog += $"ICCID not empty : { BitConverter.ToString(simstatus.ICCID).Replace("-", " ")}\n";
  90. Logger.Print("sim card ICCID not empty", isError: true);
  91. return false;
  92. }
  93. if (!simstatus.IMSI.SequenceEqual(new byte[16]))
  94. {
  95. InfoLog += $"IMSI not empty : { BitConverter.ToString(simstatus.IMSI).Replace("-", " ")}\n";
  96. Logger.Print("sim card IMSI not empty", isError: true);
  97. return false;
  98. }
  99. }
  100. }
  101. }
  102. return true;
  103. }
  104. }
  105. }