123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- using OCPPPacket.Packet.Messages.Basic;
- using Packet.Cmd;
- using SuperSocket.SocketBase;
- using SuperWebSocket;
- using System;
- using System.Collections.Generic;
- namespace OCPPServer.Protocol
- {
- public class ClientData : WebSocketSession<ClientData>
- {
- public string ocppmessage = String.Empty;
- public delegate void OCPPClientDataEventHandler<ClientData, String>(ClientData clientdata, String msg);
- public event OCPPClientDataEventHandler<ClientData, String> m_ReceiveData;
- public CmdHelper CmdHelper;
- public bool IsCheckIn { get; set; }
- public string MachineId { get; set; }
- public Guid CustomerId { get; set; }
- public string CustomerName { get; set; }
- /// <summary>
- /// 每個client有他自己的指令序號 2 byte
- /// </summary>
- private ushort _cmdSerNum = 0;
- /// <summary>
- /// 傳送的封包序號 1 byte
- /// </summary>
- private byte _serNum = 0;
- /// <summary>
- /// 傳送的chargingProfileId 1 byte
- /// </summary>
- private byte _chargingProfileId = 0;
- /// <summary>
- /// 取得指令序號 0-65535
- /// </summary>
- /// <returns></returns>
- public ushort GetCmdSerNum()
- {
- if (_cmdSerNum == ushort.MaxValue)
- _cmdSerNum = 0;
- return ++_cmdSerNum;
- }
- /// <summary>
- /// 取得封包序號 1-255
- /// </summary>
- /// <returns></returns>
- public byte GetSerNum()
- {
- if (_serNum == byte.MaxValue)
- {
- _serNum = 0;
- }
- return ++_serNum;
- }
- public byte GetCurrentSerNum()
- {
- return _serNum;
- }
- /// <summary>
- /// 取得封包序號 1-255
- /// </summary>
- /// <returns></returns>
- public byte GetChargingProfileId()
- {
- if (_chargingProfileId == byte.MaxValue)
- {
- _chargingProfileId = 0;
- }
- return ++_chargingProfileId;
- }
- public byte GetCurrentChargingProfileId()
- {
- return _chargingProfileId;
- }
- /// <summary>
- /// 客戶自訂的樁id
- /// </summary>
- public string MachineCustomId
- {
- get; set;
- }
- /// <summary>
- /// 客戶自訂的樁id
- /// </summary>
- public string MachineCustomIdTemp
- {
- get; set;
- }
- /// <summary>
- /// 根據unique id來儲存.取出OCPP Request
- /// </summary>
- public Queue queue;
- /// <summary>
- /// 根據 GetConfiguration Key來儲存.
- /// </summary>
- public List<KeyValueType> configurationKey;
- /// <summary>
- /// 車輛類別
- /// 0:默認樁體設定 , 1:小車(12V) , 2:大車(24V)
- /// </summary>
- public int CarType;
- /// <summary>
- /// 上一個Heartbeat日期封包
- /// </summary>
- public DateTime? heartbeatDate { get; set; }
- /// <summary>
- /// 當 Heartbeat 與 上一個 Heartbeat相差值小於2秒,判斷是否送出ChangeConfiguration.req(HeartbeatInterval: 15) 給電樁
- /// </summary>
- public bool IsSendHeartbeatChangeConfiguration { get; set; }
- /// <summary>
- /// Gets the app server.
- /// </summary>
- public new OCPPWSServer AppServer
- {
- get { return (OCPPWSServer)base.AppServer; }
- }
- /// <summary>
- /// Sends the raw binary data to client.
- /// </summary>
- /// <param name="data">The data.</param>
- /// <param name="offset">The offset.</param>
- /// <param name="length">The length.</param>
- public void SendRawData(byte[] data, int offset, int length)
- {
- base.Send(data, offset, length);
- }
- //receive data event trigger
- public void ReceiveData(ClientData clientdata, string msg)
- {
- if (m_ReceiveData != null)
- m_ReceiveData(clientdata, msg);
- }
- /// <summary>
- /// Called when [session closed].
- /// </summary>
- /// <param name="reason">The reason.</param>
- protected override void OnSessionClosed(CloseReason reason)
- {
- }
- public void InitialPileData()
- {
- this.queue = new Queue();
- this.MachineCustomId = Guid.NewGuid().ToString();
- this.MachineCustomIdTemp = Guid.NewGuid().ToString();
- this.IsCheckIn = false;
- this.configurationKey = new List<KeyValueType>();
- this.CarType = 0; // 默認樁體設定
- heartbeatDate = null;
- IsSendHeartbeatChangeConfiguration = false;
- #region Core
- configurationKey.Add(new KeyValueType { key = "AllowOfflineTxForUnknownId", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "AuthorizationCacheEnabled", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "AuthorizeRemoteTxRequests", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "BlinkRepeat", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ClockAlignedDataInterval", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ConnectionTimeOut", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "GetConfigurationMaxKeys", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "HeartbeatInterval", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "LightIntensity", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "LocalAuthorizeOffline", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "LocalPreAuthorize", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "MaxEnergyOnInvalidId", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "MeterValuesAlignedData", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "MeterValuesAlignedDataMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "MeterValuesSampledData", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "MeterValuesSampledDataMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "MeterValueSampleInterval", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "MinimumStatusDuration", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "NumberOfConnectors", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ResetRetries", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ConnectorPhaseRotation", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ConnectorPhaseRotationMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "StopTransactionOnEVSideDisconnect", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "StopTransactionOnInvalidId", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "StopTxnAlignedData", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "StopTxnAlignedDataMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "StopTxnSampledData", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "StopTxnSampledDataMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "SupportedFeatureProfiles", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "SupportedFeatureProfilesMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "TransactionMessageAttempts", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "TransactionMessageRetryInterval", keyreadonly = false, value = "0" });
- configurationKey.Add(new KeyValueType { key = "UnlockConnectorOnEVSideDisconnect", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "WebSocketPingInterval", keyreadonly = false, value = "0" });
- #endregion Core
- #region Local Auth List Management
- configurationKey.Add(new KeyValueType { key = "LocalAuthListEnabled", keyreadonly = false, value = "false" });
- configurationKey.Add(new KeyValueType { key = "LocalAuthListMaxLength", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "SendLocalListMaxLength", keyreadonly = true, value = "0" });
- #endregion Local Auth List Management
- #region Reservation Profile
- configurationKey.Add(new KeyValueType { key = "ReserveConnectorZeroSupported", keyreadonly = true, value = "false" });
- #endregion Reservation Profile
- #region Smart Charging Profile
- configurationKey.Add(new KeyValueType { key = "ChargeProfileMaxStackLevel", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ChargingScheduleAllowedChargingRateUnit", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ChargingScheduleMaxPeriods", keyreadonly = true, value = "0" });
- configurationKey.Add(new KeyValueType { key = "ConnectorSwitch3to1PhaseSupported", keyreadonly = true, value = "false" });
- configurationKey.Add(new KeyValueType { key = "MaxChargingProfilesInstalled", keyreadonly = true, value = "0" });
- #endregion Smart Charging Profile
- }
- }
- }
|