FourGenModuleCheckProcedure.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. return false;
  22. }
  23. if (!UpdateData.SystemID.ModelName.Network.ToString().Contains("4G"))
  24. {
  25. //if does not support 4G then end init
  26. InfoLog += "model name does not support 4g ,skip update process\n";
  27. return true;
  28. }
  29. var fourthGenModuleVersion = await serialPortocol.GetFourGenModuleVersion();
  30. if (string.IsNullOrEmpty(fourthGenModuleVersion))
  31. {
  32. InfoLog += "4G module version read error\n";
  33. Logger.Print("4G module version read error", isError: true);
  34. return false;
  35. }
  36. else
  37. {
  38. InfoLog += $"Get 4G Module version :{fourthGenModuleVersion}\n";
  39. if (fourthGenModuleVersion != UpdateData.FourGenModuleVersion)
  40. {
  41. InfoLog += "4G module version not matched\n";
  42. Logger.Print("4G module version not matched", isError: true);
  43. return false;
  44. }
  45. }
  46. var simstatus = await serialPortocol.GetSimStatus();
  47. if (simstatus == null)
  48. {
  49. InfoLog += "Get sim status failed\n";
  50. Logger.Print("Get sim status failed", isError: true);
  51. return false;
  52. }
  53. else
  54. {
  55. if (simstatus.IsInstalled != UpdateData.IsSimInsert)
  56. {
  57. Logger.Print("sim install status not matched", isError: true);
  58. return false;
  59. }
  60. else
  61. {
  62. if (simstatus.IsInstalled)
  63. {
  64. var ICCIDstring = Encoding.ASCII.GetString(simstatus.ICCID);
  65. var IMSIstring = Encoding.ASCII.GetString(simstatus.IMSI);
  66. InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled},ICCID:{ICCIDstring},IMSI:{IMSIstring}\n";
  67. if (ICCIDstring != UpdateData.ICCID)
  68. {
  69. Logger.Print("sim card ICCID not matched", isError: true);
  70. return false;
  71. }
  72. if (IMSIstring != UpdateData.IMSI)
  73. {
  74. Logger.Print("sim card IMSI not matched", isError: true);
  75. return false;
  76. }
  77. }
  78. else
  79. {
  80. InfoLog += $"Get sim info, inserted:{simstatus.IsInstalled}\n";
  81. if (!simstatus.ICCID.SequenceEqual(new byte[22]))
  82. {
  83. InfoLog += $"ICCID not empty : { BitConverter.ToString(simstatus.ICCID).Replace("-", " ")}\n";
  84. Logger.Print("sim card ICCID not empty", isError: true);
  85. return false;
  86. }
  87. if (!simstatus.IMSI.SequenceEqual(new byte[16]))
  88. {
  89. InfoLog += $"IMSI not empty : { BitConverter.ToString(simstatus.IMSI).Replace("-", " ")}\n";
  90. Logger.Print("sim card IMSI not empty", isError: true);
  91. return false;
  92. }
  93. }
  94. }
  95. }
  96. return true;
  97. }
  98. }
  99. }