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 { public string ocppmessage = String.Empty; public delegate void OCPPClientDataEventHandler(ClientData clientdata, String msg); public event OCPPClientDataEventHandler 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; } /// /// 每個client有他自己的指令序號 2 byte /// private ushort _cmdSerNum = 0; /// /// 傳送的封包序號 1 byte /// private byte _serNum = 0; /// /// 傳送的chargingProfileId 1 byte /// private byte _chargingProfileId = 0; /// /// 取得指令序號 0-65535 /// /// public ushort GetCmdSerNum() { if (_cmdSerNum == ushort.MaxValue) _cmdSerNum = 0; return ++_cmdSerNum; } /// /// 取得封包序號 1-255 /// /// public byte GetSerNum() { if (_serNum == byte.MaxValue) { _serNum = 0; } return ++_serNum; } public byte GetCurrentSerNum() { return _serNum; } /// /// 取得封包序號 1-255 /// /// public byte GetChargingProfileId() { if (_chargingProfileId == byte.MaxValue) { _chargingProfileId = 0; } return ++_chargingProfileId; } public byte GetCurrentChargingProfileId() { return _chargingProfileId; } /// /// 客戶自訂的樁id /// public string MachineCustomId { get; set; } /// /// 客戶自訂的樁id /// public string MachineCustomIdTemp { get; set; } /// /// 根據unique id來儲存.取出OCPP Request /// public Queue queue; /// /// 根據 GetConfiguration Key來儲存. /// public List configurationKey; /// /// 車輛類別 /// 0:默認樁體設定 , 1:小車(12V) , 2:大車(24V) /// public int CarType; /// /// 上一個Heartbeat日期封包 /// public DateTime? heartbeatDate { get; set; } /// /// 當 Heartbeat 與 上一個 Heartbeat相差值小於2秒,判斷是否送出ChangeConfiguration.req(HeartbeatInterval: 15) 給電樁 /// public bool IsSendHeartbeatChangeConfiguration { get; set; } /// /// Gets the app server. /// public new OCPPWSServer AppServer { get { return (OCPPWSServer)base.AppServer; } } /// /// Sends the raw binary data to client. /// /// The data. /// The offset. /// The length. 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); } /// /// Called when [session closed]. /// /// The reason. 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(); 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 } } }