MachineOperateRecord.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace EVCB_OCPP.TaskScheduler.Models
  7. {
  8. public class MachineOperateRecord
  9. {
  10. public MachineOperateRecord()
  11. {
  12. EVSE_Value = string.Empty;
  13. FinishedOn = new DateTime(1991, 1, 1);
  14. ReportedOn = new DateTime(1991, 1, 1);
  15. }
  16. public int Id { get; set; }
  17. /// <summary>
  18. ///Action
  19. /// </summary>
  20. public string Action { get; set; }
  21. /// <summary>
  22. /// 機器的客戶自訂ID
  23. /// </summary>
  24. public string ChargeBoxId { get; set; }
  25. /// <summary>
  26. /// 隨機序號 和ServerCommand是同一個組序號
  27. /// </summary>
  28. public string SerialNo { get; set; }
  29. /// <summary>
  30. /// 請求類型
  31. /// </summary>
  32. public int RequestType { get; set; }
  33. /// <summary>
  34. /// 請求內容
  35. /// </summary>
  36. public string RequestContent { get; set; }
  37. /// <summary>
  38. /// 狀態
  39. /// </summary>
  40. public int Status { get; set; }
  41. /// <summary>
  42. /// EVSE回覆值
  43. /// </summary>
  44. public string EVSE_Value { get; set; }
  45. /// <summary>
  46. /// EVSE狀態
  47. /// </summary>
  48. public int EVSE_Status { get; set; }
  49. /// <summary>
  50. /// 建立時間
  51. /// </summary>
  52. public DateTime CreatedOn { set; get; }
  53. /// <summary>
  54. /// 結束時間
  55. /// </summary>
  56. public DateTime FinishedOn { set; get; }
  57. /// <summary>
  58. /// 回報時間
  59. /// </summary>
  60. public DateTime ReportedOn { set; get; }
  61. public string ActionConverttoCommandType()
  62. {
  63. string cmdTypeName = "Unknown";
  64. if (string.IsNullOrEmpty(Action))
  65. return cmdTypeName;
  66. switch (Action)
  67. {
  68. case "RemoteStartTransaction":
  69. {
  70. cmdTypeName = "Start_Session";
  71. }
  72. break;
  73. case "RemoteStopTransaction":
  74. {
  75. cmdTypeName = "Stop_Session";
  76. }
  77. break;
  78. case "ReserveNow":
  79. {
  80. cmdTypeName = "Reserve_Now";
  81. }
  82. break;
  83. case "CancelReservation":
  84. {
  85. cmdTypeName = "CancelReservation";
  86. }
  87. break;
  88. case "SetChargingProfile":
  89. {
  90. cmdTypeName = "SetChargingProfile";
  91. }
  92. break;
  93. case "ClearChargingProfile":
  94. {
  95. cmdTypeName = "ClearChargingProfile";
  96. }
  97. break;
  98. case "SendLocalList":
  99. {
  100. cmdTypeName = "SetLocalList";
  101. }
  102. break;
  103. case "GetLocalListVersion":
  104. {
  105. cmdTypeName = "GetLocalListVersion";
  106. }
  107. break;
  108. case "GetCompositeSchedule":
  109. {
  110. cmdTypeName = "GetAcitveChargingProfile";
  111. }
  112. break;
  113. default:
  114. break;
  115. }
  116. return cmdTypeName;
  117. }
  118. public ComandExecution GetExecution()
  119. {
  120. ComandExecution execution = new ComandExecution();
  121. if (EVSE_Status > 0)
  122. {
  123. execution.IsRepliedbyEVSE = true;
  124. if (Action == "GetLocalListVersion")
  125. {
  126. execution.Code = 1;
  127. execution.Detail = EVSE_Value;
  128. }
  129. else
  130. {
  131. execution.Code = ConverttoCode(EVSE_Value);
  132. execution.Code = execution.Code == -1 ? (EVSE_Status == 1 ? 1 : (EVSE_Status == 255 ? 254 : execution.Code)) : execution.Code;
  133. execution.Detail = EVSE_Value;
  134. }
  135. }
  136. else
  137. {
  138. execution.IsRepliedbyEVSE = false;
  139. if (Status == 0)
  140. {
  141. execution.Code = 0;
  142. execution.IsWaited = true;
  143. }
  144. if (Status == -1)
  145. {
  146. execution.IsTimeout = true;
  147. execution.Code = 0;
  148. execution.Detail = "Timeout";
  149. }
  150. }
  151. switch (execution.Code)
  152. {
  153. case 1:
  154. {
  155. execution.Result = CommandResultType.Accepted.ToString();
  156. }
  157. break;
  158. case 9:
  159. {
  160. execution.Result = CommandResultType.Notsupported.ToString();
  161. }
  162. break;
  163. case 10:
  164. {
  165. execution.Result = CommandResultType.Unknown.ToString();
  166. }
  167. break;
  168. case 26:
  169. {
  170. execution.Result = CommandResultType.Occupied.ToString();
  171. }
  172. break;
  173. case 31:
  174. {
  175. execution.Result = CommandResultType.Rejected.ToString();
  176. }
  177. break;
  178. case 32:
  179. {
  180. execution.Result = CommandResultType.Failed.ToString();
  181. }
  182. break;
  183. case 254:
  184. {
  185. execution.Result = CommandResultType.EVSE_ERROR.ToString();
  186. }
  187. break;
  188. default:
  189. {
  190. if (execution.IsTimeout.HasValue && execution.IsTimeout.Value) execution.Result = CommandResultType.Timeout.ToString(); ;
  191. if (execution.IsWaited.HasValue && execution.IsWaited.Value) execution.Result = CommandResultType.Waited.ToString(); ;
  192. }
  193. break;
  194. }
  195. return execution;
  196. }
  197. private int ConverttoCode(string statusName)
  198. {
  199. int code = -1;
  200. if (string.IsNullOrEmpty(statusName)) return code;
  201. Internal_ExecutionCode result = Internal_ExecutionCode.Accepted;
  202. if (Enum.TryParse<Internal_ExecutionCode>(statusName, out result))
  203. {
  204. code = (int)result;
  205. }
  206. return code;
  207. }
  208. }
  209. }