ProcedureBase.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using AwInitilizer.Assist;
  2. using AwInitilizer.Interface;
  3. using AwInitilizer.Model;
  4. using MesAdaptor;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.Specialized;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Net.Sockets;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading.Tasks;
  15. namespace AwInitilizer.Procedure
  16. {
  17. public enum ProcedureStatus
  18. {
  19. IDLE,PASS,FAIL
  20. }
  21. public class ProcedureBase
  22. {
  23. public string Name { get; set; }
  24. public string Content { get; set; }
  25. public bool IsActivated { get; set; } = true;
  26. public ProcedureStatus Status { get; private set; }
  27. public string InfoLog { get; internal set; }
  28. public static UpdateData UpdateData { get; set; }
  29. public static IIogger Logger { get; set; }
  30. public ValueReportDatas MesLogData { get; private set; } = new ValueReportDatas();
  31. public List<string> ReportLog { get; private set; } = new List<string>();
  32. internal SerialPortocol serialPortocol { get; private set; }
  33. internal static string ServerIpAddress = "192.168.1.10";
  34. //internal static string ServerIpAddress = "172.18.13.84";
  35. public async Task<bool> DoWork() {
  36. if (!IsActivated)
  37. return false;
  38. InfoLog = "";
  39. Logger.Print(Name + "Started");
  40. var result = await Run();
  41. Dispose();
  42. Status = result ? ProcedureStatus.PASS : ProcedureStatus.FAIL;
  43. Logger.Print(Name + "Complete");
  44. return result;
  45. }
  46. internal virtual async Task<bool> Run()
  47. {
  48. return true;
  49. }
  50. public void Reset()
  51. {
  52. Status = ProcedureStatus.IDLE;
  53. InfoLog = "";
  54. }
  55. internal async Task<bool> CheckAndCreateSocket()
  56. {
  57. string ipAddress = null;
  58. if (!string.IsNullOrEmpty(UpdateData.IpAddress))
  59. {
  60. ipAddress = UpdateData.IpAddress;
  61. }
  62. else
  63. {
  64. ipAddress = ServerIpAddress;
  65. }
  66. TcpSerializer socketConnection = null;
  67. if (socketConnection == null || socketConnection.ConnectStatus == ConnectStatus.ConnectionFail ||
  68. socketConnection.ConnectStatus == ConnectStatus.DisConnected)
  69. {
  70. socketConnection = new Assist.TcpSerializer(ip: ipAddress);
  71. await socketConnection.OpenAsync();
  72. if(socketConnection.ConnectStatus != ConnectStatus.Connected)
  73. {
  74. Logger.Print("EVSE tcp connection Failed,Check EVSE is connected", isError: true);
  75. return false;
  76. }
  77. Logger.Print("Connected");
  78. serialPortocol = new SerialPortocol(socketConnection);
  79. return true;
  80. }
  81. return true;
  82. }
  83. public async Task<bool> ChekCsuBootCompelete()
  84. {
  85. var result = await EvApi.ChekCsuBootCompelete();
  86. return result.Result;
  87. }
  88. public async Task<bool> CheckGetQueryAction()
  89. {
  90. var result = await EvApi.CheckGetQueryAction();
  91. return result.Result;
  92. }
  93. private void Dispose()
  94. {
  95. if(serialPortocol!=null)
  96. {
  97. try
  98. {
  99. serialPortocol.Close();
  100. }catch
  101. {
  102. }
  103. }
  104. }
  105. }
  106. }