123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EVCB_OCPP.TaskScheduler.Models
- {
- public class MachineOperateRecord
- {
- public MachineOperateRecord()
- {
- EVSE_Value = string.Empty;
- FinishedOn = new DateTime(1991, 1, 1);
- ReportedOn = new DateTime(1991, 1, 1);
- }
- public int Id { get; set; }
- /// <summary>
- ///Action
- /// </summary>
- public string Action { get; set; }
- /// <summary>
- /// 機器的客戶自訂ID
- /// </summary>
- public string ChargeBoxId { get; set; }
- /// <summary>
- /// 隨機序號 和ServerCommand是同一個組序號
- /// </summary>
- public string SerialNo { get; set; }
- /// <summary>
- /// 請求類型
- /// </summary>
- public int RequestType { get; set; }
- /// <summary>
- /// 請求內容
- /// </summary>
- public string RequestContent { get; set; }
- /// <summary>
- /// 狀態
- /// </summary>
- public int Status { get; set; }
- /// <summary>
- /// EVSE回覆值
- /// </summary>
- public string EVSE_Value { get; set; }
- /// <summary>
- /// EVSE狀態
- /// </summary>
- public int EVSE_Status { get; set; }
- /// <summary>
- /// 建立時間
- /// </summary>
- public DateTime CreatedOn { set; get; }
- /// <summary>
- /// 結束時間
- /// </summary>
- public DateTime FinishedOn { set; get; }
- /// <summary>
- /// 回報時間
- /// </summary>
- public DateTime ReportedOn { set; get; }
- public string ActionConverttoCommandType()
- {
- string cmdTypeName = "Unknown";
- if (string.IsNullOrEmpty(Action))
- return cmdTypeName;
- switch (Action)
- {
- case "RemoteStartTransaction":
- {
- cmdTypeName = "Start_Session";
- }
- break;
- case "RemoteStopTransaction":
- {
- cmdTypeName = "Stop_Session";
- }
- break;
- case "ReserveNow":
- {
- cmdTypeName = "Reserve_Now";
- }
- break;
- case "CancelReservation":
- {
- cmdTypeName = "CancelReservation";
- }
- break;
- case "SetChargingProfile":
- {
- cmdTypeName = "SetChargingProfile";
- }
- break;
- case "ClearChargingProfile":
- {
- cmdTypeName = "ClearChargingProfile";
- }
- break;
- case "SendLocalList":
- {
- cmdTypeName = "SetLocalList";
- }
- break;
- case "GetLocalListVersion":
- {
- cmdTypeName = "GetLocalListVersion";
- }
- break;
- case "GetCompositeSchedule":
- {
- cmdTypeName = "GetAcitveChargingProfile";
- }
- break;
- default:
- break;
- }
- return cmdTypeName;
- }
- public ComandExecution GetExecution()
- {
- ComandExecution execution = new ComandExecution();
- if (EVSE_Status > 0)
- {
- execution.IsRepliedbyEVSE = true;
- if (Action == "GetLocalListVersion")
- {
- execution.Code = 1;
- execution.Detail = EVSE_Value;
- }
- else
- {
- execution.Code = ConverttoCode(EVSE_Value);
- execution.Code = execution.Code == -1 ? (EVSE_Status == 1 ? 1 : (EVSE_Status == 255 ? 254 : execution.Code)) : execution.Code;
- execution.Detail = EVSE_Value;
- }
- }
- else
- {
- execution.IsRepliedbyEVSE = false;
- if (Status == 0)
- {
- execution.Code = 0;
- execution.IsWaited = true;
- }
- if (Status == -1)
- {
- execution.IsTimeout = true;
- execution.Code = 0;
- execution.Detail = "Timeout";
- }
- }
- switch (execution.Code)
- {
- case 1:
- {
- execution.Result = CommandResultType.Accepted.ToString();
- }
- break;
- case 9:
- {
- execution.Result = CommandResultType.Notsupported.ToString();
- }
- break;
- case 10:
- {
- execution.Result = CommandResultType.Unknown.ToString();
- }
- break;
- case 26:
- {
- execution.Result = CommandResultType.Occupied.ToString();
- }
- break;
- case 31:
- {
- execution.Result = CommandResultType.Rejected.ToString();
- }
- break;
- case 32:
- {
- execution.Result = CommandResultType.Failed.ToString();
- }
- break;
- case 254:
- {
- execution.Result = CommandResultType.EVSE_ERROR.ToString();
- }
- break;
- default:
- {
- if (execution.IsTimeout.HasValue && execution.IsTimeout.Value) execution.Result = CommandResultType.Timeout.ToString(); ;
- if (execution.IsWaited.HasValue && execution.IsWaited.Value) execution.Result = CommandResultType.Waited.ToString(); ;
- }
- break;
- }
- return execution;
- }
- private int ConverttoCode(string statusName)
- {
- int code = -1;
- if (string.IsNullOrEmpty(statusName)) return code;
- Internal_ExecutionCode result = Internal_ExecutionCode.Accepted;
- if (Enum.TryParse<Internal_ExecutionCode>(statusName, out result))
- {
- code = (int)result;
- }
- return code;
- }
- }
- }
|