|
@@ -35,6 +35,7 @@ using EVCB_OCPP.Packet.Messages.SmartCharging;
|
|
|
using System.Security.Authentication;
|
|
|
using NLog.Fluent;
|
|
|
using System.Diagnostics;
|
|
|
+using Packet20 = EVCB_OCPP.Packet20;
|
|
|
|
|
|
namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
@@ -85,6 +86,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
"GetCompositeSchedule",
|
|
|
"ReserveNow",
|
|
|
"CancelReservation",
|
|
|
+ "ExtendedTriggerMessage"
|
|
|
};
|
|
|
private List<Profile> profiles = new List<Profile>()
|
|
|
{
|
|
@@ -93,7 +95,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
new ReservationProfile(),
|
|
|
new RemoteTriggerProfile(),
|
|
|
new SmartChargingProfile(),
|
|
|
- new LocalAuthListManagementProfile()
|
|
|
+ new LocalAuthListManagementProfile(),
|
|
|
+ new SecurityProfile(),
|
|
|
};
|
|
|
private CancellationTokenSource _cts = new CancellationTokenSource();
|
|
|
private CancellationToken _ct;
|
|
@@ -274,8 +277,6 @@ namespace EVCB_OCPP.WSServer
|
|
|
private void CheckEVSEConfigure(string chargeBoxId)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(chargeBoxId)) return;
|
|
|
- int skipCount = 0;
|
|
|
- int takeCount = 8;
|
|
|
using (var db = new MainDBContext())
|
|
|
{
|
|
|
db.ServerMessage.Add(new ServerMessage()
|
|
@@ -298,60 +299,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
db.SaveChanges();
|
|
|
|
|
|
- //string maxKeys = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
- //if (maxKeys == StandardConfiguration.GetConfigurationMaxKeys)
|
|
|
- //{
|
|
|
- // var _Configure = db.MachineConfiguration.Where(x => x.ChargeBoxId == chargeBoxId && x.ConfigureName == maxKeys).Select(x => new { ConfigureSetting = x.ConfigureSetting, ConfigureName = x.ConfigureName }).FirstOrDefault();
|
|
|
- // if (_Configure != null)
|
|
|
- // {
|
|
|
- // int cp_ConfiureCount = 0;
|
|
|
- // int.TryParse(_Configure.ConfigureSetting, out cp_ConfiureCount);
|
|
|
- // takeCount = takeCount > cp_ConfiureCount ? cp_ConfiureCount : takeCount;
|
|
|
- // skipCount = 1;
|
|
|
- // if (string.IsNullOrEmpty(_Configure.ConfigureSetting)) return;
|
|
|
- // }
|
|
|
-
|
|
|
- //}
|
|
|
-
|
|
|
- //while (StandardConfiguration.AllConfigs.Count > skipCount)
|
|
|
- //{
|
|
|
- // string _key = StandardConfiguration.AllConfigs.Skip(skipCount).Take(1).FirstOrDefault();
|
|
|
- // var _Configure = db.MachineConfiguration.Where(x => x.ChargeBoxId == chargeBoxId && x.ConfigureName == _key).Select(x => new { ConfigureSetting = x.ConfigureSetting, ConfigureName = x.ConfigureName }).FirstOrDefault();
|
|
|
- // takeCount = StandardConfiguration.AllConfigs.Count - skipCount > takeCount ? takeCount : StandardConfiguration.AllConfigs.Count - skipCount;
|
|
|
-
|
|
|
- // var _keys = StandardConfiguration.AllConfigs.Skip(skipCount).Take(takeCount).ToList();
|
|
|
- // // Console.WriteLine("===============Skip:" + skipCount);
|
|
|
- // if (_Configure == null)
|
|
|
- // {
|
|
|
- // // Console.WriteLine("_Configure == null===============Skip:" + skipCount);
|
|
|
- // db.ServerMessage.Add(new ServerMessage()
|
|
|
- // {
|
|
|
- // ChargeBoxId = chargeBoxId,
|
|
|
- // CreatedBy = "Server",
|
|
|
- // CreatedOn = DateTime.Now,
|
|
|
- // OutAction = Actions.GetConfiguration.ToString(),
|
|
|
- // OutRequest = JsonConvert.SerializeObject(
|
|
|
- // new GetConfigurationRequest()
|
|
|
- // {
|
|
|
- // key = _keys
|
|
|
-
|
|
|
- // },
|
|
|
- // new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.None }),
|
|
|
- // SerialNo = Guid.NewGuid().ToString(),
|
|
|
- // InMessage = string.Empty
|
|
|
-
|
|
|
- // });
|
|
|
-
|
|
|
- // db.SaveChanges();
|
|
|
- // }
|
|
|
-
|
|
|
- // skipCount = skipCount + takeCount;
|
|
|
-
|
|
|
- //}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void OpenNetwork()
|
|
|
{
|
|
|
|
|
@@ -363,6 +315,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
// llistener.Add(new ListenerConfig { Ip = "", Port = Convert.ToInt32(wssserverPort), Backlog = 100, Security = serverSecurity });
|
|
|
llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = Convert.ToInt32(GlobalConfig.GetWS_Port()), Backlog = 100, Security = "None" });
|
|
|
llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = Convert.ToInt32(GlobalConfig.GetWSS_Port()), Backlog = 100, Security = SslProtocols.Tls12.ToString() });
|
|
|
+
|
|
|
// llistener.Add(new ListenerConfig { Ip = System.Net.IPAddress.Any.ToString(), Port = Convert.ToInt32(GlobalConfig.GetWSS_Port()), Backlog = 100, Security = SslProtocols.Tls11.ToString() });
|
|
|
var config = ConfigurationManager.GetSection("superSocket") as IConfigurationSource;
|
|
|
ICertificateConfig Certificate = config.Servers.ElementAt(0).Certificate;
|
|
@@ -378,9 +331,9 @@ namespace EVCB_OCPP.WSServer
|
|
|
//Security = serverSecurity,
|
|
|
Certificate = Certificate,
|
|
|
Listeners = listeners,
|
|
|
- // LogAllSocketException = true,
|
|
|
+ // LogAllSocketException = true,
|
|
|
KeepAliveTime = 10,
|
|
|
- // LogBasicSessionActivity = true
|
|
|
+ // LogBasicSessionActivity = true
|
|
|
|
|
|
|
|
|
};
|
|
@@ -455,8 +408,8 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- // CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
+
|
|
|
+ // CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -477,7 +430,12 @@ namespace EVCB_OCPP.WSServer
|
|
|
WriteMachineLog(session, rawdata,
|
|
|
string.Format("{0} {1}", string.IsNullOrEmpty(analysisResult.Action) ? "unknown" : analysisResult.Action, analysisResult.Id == 2 ? "Request" : (analysisResult.Id == 3 ? "Confirmation" : "Error")), analysisResult.Exception == null ? "" : analysisResult.Exception.Message);
|
|
|
|
|
|
-
|
|
|
+ if(session.ResetSecurityProfile)
|
|
|
+ {
|
|
|
+ logger.Error(string.Format("[{0}] ChargeBoxId:{1} ResetSecurityProfile", DateTime.Now, session.ChargeBoxId));
|
|
|
+ RemoveClient(session);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
if (!analysisResult.Success)
|
|
@@ -491,7 +449,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
if (analysisResult.Message == null)
|
|
|
{
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Empty;
|
|
|
if (analysisResult.Exception != null)
|
|
|
{
|
|
@@ -505,7 +463,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
BaseMessage _baseMsg = analysisResult.Message as BaseMessage;
|
|
|
|
|
|
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(_baseMsg.Id, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(_baseMsg.Id, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Empty;
|
|
|
if (analysisResult.Exception != null)
|
|
|
{
|
|
@@ -521,11 +479,81 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
|
|
|
Actions action = Convertor.GetAction(analysisResult.Action);
|
|
|
+
|
|
|
+ if (!session.IsOCPP16 && !(action != Actions.BootNotification || action != Actions.Heartbeat))
|
|
|
+ {
|
|
|
+ Send(session, "Backend doesn't support this message.", string.Format("{0} {1}", analysisResult.Action, "Error"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
switch (analysisResult.Id)
|
|
|
{
|
|
|
case BasicMessageHandler.TYPENUMBER_CALL:
|
|
|
{
|
|
|
- ProcessRequestMessage(analysisResult, session, action);
|
|
|
+ if (session.IsOCPP16)
|
|
|
+ {
|
|
|
+ ProcessRequestMessage(analysisResult, session, action);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageResult result = new MessageResult() { Success = true };
|
|
|
+ //ocpp20 處理
|
|
|
+ switch (action)
|
|
|
+ {
|
|
|
+ case Actions.Heartbeat:
|
|
|
+ {
|
|
|
+ var confirm = new Packet20.Messages.HeartbeatResponse() { CurrentTime = DateTime.Now };
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
+
|
|
|
+ string response = BasicMessageHandler.GenerateConfirmationofOCPP20(analysisResult.UUID, (Packet20.Messages.IConfirmation)result.Message);
|
|
|
+ Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Response"), result.Exception == null ? string.Empty : result.Exception.ToString());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case Actions.BootNotification:
|
|
|
+ {
|
|
|
+ Packet20.Messages.BootNotificationRequest _request = (Packet20.Messages.IRequest)analysisResult.Message as Packet20.Messages.BootNotificationRequest;
|
|
|
+ int heartbeat_interval = GlobalConfig.GetHEARTBEAT_INTERVAL();
|
|
|
+ //using (var db = new MainDBContext())
|
|
|
+ //{
|
|
|
+ // var _machine = db.Machine.Where(x => x.ChargeBoxId == session.ChargeBoxId).FirstOrDefault();
|
|
|
+ // _machine.ChargeBoxSerialNumber = string.IsNullOrEmpty(_request.chargeBoxSerialNumber) ? string.Empty : _request.chargeBoxSerialNumber;
|
|
|
+ // _machine.ChargePointModel = string.IsNullOrEmpty(_request.chargePointModel) ? string.Empty : _request.chargePointModel;
|
|
|
+ // _machine.ChargePointVendor = string.IsNullOrEmpty(_request.chargePointVendor) ? string.Empty : _request.chargePointVendor;
|
|
|
+ // _machine.FW_CurrentVersion = string.IsNullOrEmpty(_request.firmwareVersion) ? string.Empty : _request.firmwareVersion;
|
|
|
+ // _machine.Iccid = string.IsNullOrEmpty(_request.iccid) ? string.Empty : _request.iccid;
|
|
|
+ // _machine.Imsi = string.IsNullOrEmpty(_request.imsi) ? string.Empty : _request.imsi;
|
|
|
+ // _machine.MeterSerialNumber = string.IsNullOrEmpty(_request.meterSerialNumber) ? string.Empty : _request.meterSerialNumber;
|
|
|
+ // _machine.MeterType = string.IsNullOrEmpty(_request.meterType) ? string.Empty : _request.meterType;
|
|
|
+
|
|
|
+ // db.SaveChanges();
|
|
|
+
|
|
|
+ // var configVaule = db.MachineConfiguration.Where(x => x.ChargeBoxId == session.ChargeBoxId && x.ConfigureName == StandardConfiguration.HeartbeatInterval)
|
|
|
+ // .Select(x => x.ConfigureSetting).FirstOrDefault();
|
|
|
+
|
|
|
+ // if (configVaule != null)
|
|
|
+ // {
|
|
|
+ // int.TryParse(configVaule, out heartbeat_interval);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ var confirm = new Packet20.Messages.BootNotificationResponse() { CurrentTime = DateTime.Now, Interval = heartbeat_interval, Status = Packet20.DataTypes.EnumTypes.RegistrationStatusEnumType.Accepted };
|
|
|
+
|
|
|
+ result.Message = confirm;
|
|
|
+ result.Success = true;
|
|
|
+
|
|
|
+ string response = BasicMessageHandler.GenerateConfirmationofOCPP20(analysisResult.UUID, (Packet20.Messages.IConfirmation)result.Message);
|
|
|
+ Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Response"), result.Exception == null ? string.Empty : result.Exception.ToString());
|
|
|
+
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ logger.Error(string.Format("We don't implement messagetype:{0} of raw data :{1} by {2}", analysisResult.Id, rawdata, session.ChargeBoxId));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
break;
|
|
@@ -570,14 +598,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
async private void ProcessRequestMessage(MessageResult analysisResult, ClientData session, Actions action)
|
|
|
{
|
|
|
BasicMessageHandler msgAnalyser = new BasicMessageHandler();
|
|
|
if (!session.IsCheckIn && action != Actions.BootNotification)
|
|
|
{
|
|
|
- string response = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.GenericError, OCPPErrorDescription.NotChecked);
|
|
|
+ string response = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.GenericError, OCPPErrorDescription.NotChecked);
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Error"));
|
|
|
}
|
|
|
else
|
|
@@ -589,11 +617,11 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
var replyResult = await profileHandler.ExecuteCoreRequest(action, session, (IRequest)analysisResult.Message).ConfigureAwait(false);
|
|
|
if (replyResult.Success)
|
|
|
{
|
|
|
- string response = msgAnalyser.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
|
+ string response = BasicMessageHandler.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
|
|
|
|
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Confirmation"), replyResult.Exception == null ? string.Empty : replyResult.Exception.ToString());
|
|
@@ -613,15 +641,23 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- CheckVersion(session.ChargeBoxId);
|
|
|
- CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
+ if (session.ResetSecurityProfile)
|
|
|
+ {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CheckVersion(session.ChargeBoxId);
|
|
|
+ CheckEVSEConfigure(session.ChargeBoxId);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string response = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string response = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = replyResult.Exception != null ? replyResult.Exception.ToString() : string.Empty;
|
|
|
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
@@ -704,13 +740,13 @@ namespace EVCB_OCPP.WSServer
|
|
|
var replyResult = profileHandler.ExecuteFirmwareManagementRequest(action, session, (IRequest)analysisResult.Message);
|
|
|
if (replyResult.Success)
|
|
|
{
|
|
|
- string response = msgAnalyser.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
|
+ string response = BasicMessageHandler.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Confirmation", replyResult.Exception == null ? string.Empty : replyResult.Exception.ToString()));
|
|
|
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string response = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string response = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = replyResult.Exception != null ? replyResult.Exception.ToString() : string.Empty;
|
|
|
|
|
|
Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
@@ -718,9 +754,27 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
}
|
|
|
break;
|
|
|
+ case "Security":
|
|
|
+ {
|
|
|
+ var replyResult = profileHandler.ExecuteSecurityRequest(action, session, (IRequest)analysisResult.Message);
|
|
|
+ if (replyResult.Success)
|
|
|
+ {
|
|
|
+ string response = BasicMessageHandler.GenerateConfirmation(analysisResult.UUID, (IConfirmation)replyResult.Message);
|
|
|
+ Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Confirmation", replyResult.Exception == null ? string.Empty : replyResult.Exception.ToString()));
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ string response = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string errorMsg = replyResult.Exception != null ? replyResult.Exception.ToString() : string.Empty;
|
|
|
+
|
|
|
+ Send(session, response, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
{
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Format("Couldn't find action name: {0} of profile", action);
|
|
|
Send(session, replyMsg, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
}
|
|
@@ -769,9 +823,14 @@ namespace EVCB_OCPP.WSServer
|
|
|
confirmResult = profileHandler.ExecuteSmartChargingConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
}
|
|
|
break;
|
|
|
+ case "Security":
|
|
|
+ {
|
|
|
+ confirmResult = profileHandler.ExecuteSecurityConfirm(action, session, (IConfirmation)analysisResult.Message, analysisResult.RequestId);
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
{
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Format("Couldn't find action name: {0} of profile", action);
|
|
|
Send(session, replyMsg, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
}
|
|
@@ -787,7 +846,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Format("Action:{0} MessageId:{1} didn't exist in confirm message", analysisResult.Action, analysisResult.UUID);
|
|
|
Send(session, replyMsg, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
}
|
|
@@ -833,7 +892,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
break;
|
|
|
default:
|
|
|
{
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Format("Couldn't find action name: {0} of profile", action);
|
|
|
Send(session, replyMsg, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
}
|
|
@@ -843,7 +902,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- string replyMsg = msgAnalyser.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
+ string replyMsg = BasicMessageHandler.GenerateCallError(analysisResult.UUID, OCPPErrorCodes.InternalError, OCPPErrorDescription.InternalError);
|
|
|
string errorMsg = string.Format("Action:{0} MessageId:{1} didn't exist in confirm message", analysisResult.Action, analysisResult.UUID);
|
|
|
Send(session, replyMsg, string.Format("{0} {1}", analysisResult.Action, "Error"), errorMsg);
|
|
|
|
|
@@ -915,7 +974,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
string requestId = Guid.NewGuid().ToString();
|
|
|
// using (var db = new MainDBContext())
|
|
|
|
|
|
- if (session.IsCheckIn)
|
|
|
+ if (session.IsCheckIn && session.IsOCPP16)
|
|
|
{
|
|
|
|
|
|
var _request = new TriggerMessageRequest()
|
|
@@ -924,7 +983,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
};
|
|
|
|
|
|
var uuid = session.queue.store(_request);
|
|
|
- string rawRequest = msgAnalyser.GenerateRequest(uuid, _request.Action, _request);
|
|
|
+ string rawRequest = BasicMessageHandler.GenerateRequest(uuid, _request.Action, _request);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", _request.Action, "Request"), "");
|
|
|
|
|
|
#region OCTT ,測試韌體更新方式
|
|
@@ -1019,13 +1078,15 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
DateTime startDt = DateTime.Now.AddSeconds(-30);
|
|
|
DateTime dt = new DateTime(1991, 1, 1);
|
|
|
- //Console.WriteLine(string.Format("{0} IN", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
|
|
- var commandList = db.ServerMessage.Where(c => c.ReceivedOn == dt && c.UpdatedOn == dt && c.CreatedOn >= startDt && c.CreatedOn <= DateTime.Now).AsNoTracking().ToList();
|
|
|
+ DateTime currentTime = DateTime.Now;
|
|
|
+ var commandList = db.ServerMessage.Where(c => c.ReceivedOn == dt && c.UpdatedOn == dt && c.CreatedOn >= startDt && c.CreatedOn <= currentTime).AsNoTracking().ToList();
|
|
|
+
|
|
|
+
|
|
|
//處理主機傳送的有指令
|
|
|
var cmdMachineList = commandList.Select(c => c.ChargeBoxId).Distinct().ToList();
|
|
|
if (commandList.Count > 0)
|
|
|
{
|
|
|
- // Console.WriteLine(string.Format("Now:{0} commandList Count:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), commandList.Count));
|
|
|
+ // Console.WriteLine(string.Format("Now:{0} commandList Count:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), commandList.Count));
|
|
|
}
|
|
|
|
|
|
foreach (var charger_SN in cmdMachineList)
|
|
@@ -1036,7 +1097,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
{
|
|
|
Console.WriteLine(string.Format("charger_SN:{0} startDt:{1} CreatedOn:{2}", charger_SN, startDt.ToString("yyyy/MM/dd HH:mm:ss"), DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
|
|
|
|
|
|
- if (session.IsCheckIn)
|
|
|
+ if (session.IsCheckIn && session.IsOCPP16)
|
|
|
{
|
|
|
var cmdList = commandList.Where(c => c.ChargeBoxId == charger_SN).ToList();
|
|
|
|
|
@@ -1058,22 +1119,22 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (_RequestType != null && item.CreatedBy!= "Destroyer")
|
|
|
+ if (_RequestType != null && item.CreatedBy != "Destroyer")
|
|
|
{
|
|
|
request = JsonConvert.DeserializeObject(item.OutRequest, _RequestType) as IRequest;
|
|
|
uuid = session.queue.store(request);
|
|
|
- string rawRequest = msgAnalyser.GenerateRequest(uuid, item.OutAction, request);
|
|
|
+ string rawRequest = BasicMessageHandler.GenerateRequest(uuid, item.OutAction, request);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
if (_RequestType != null && item.CreatedBy == "Destroyer")
|
|
|
{
|
|
|
Console.WriteLine("********************************");
|
|
|
request = Activator.CreateInstance(_RequestType) as IRequest;
|
|
|
Console.WriteLine("++++++++++++++++++++++++++++++++++++++++");
|
|
|
uuid = session.queue.store(request);
|
|
|
- string rawRequest = msgAnalyser.GenerateDestroyRequest(uuid, item.OutAction, item.OutRequest);
|
|
|
+ string rawRequest = BasicMessageHandler.GenerateDestroyRequest(uuid, item.OutAction, item.OutRequest);
|
|
|
Send(session, rawRequest, string.Format("{0} {1}", action, "Request"), "");
|
|
|
}
|
|
|
|
|
@@ -1098,7 +1159,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
await Task.Delay(1000);
|
|
@@ -1135,7 +1196,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
|
|
|
var cdt = DateTime.Now;
|
|
|
var clients = _copyClientDic.Where(x => x.Value.LastActiveTime > cdt.AddSeconds(-30)).Select(x => x.Value).ToList();
|
|
|
-
|
|
|
+
|
|
|
watch.Start();
|
|
|
foreach (var session in clients)
|
|
|
{
|
|
@@ -1278,7 +1339,7 @@ namespace EVCB_OCPP.WSServer
|
|
|
sc.InMessage = JsonConvert.SerializeObject(analysisResult.Message, Formatting.None);
|
|
|
sc.ReceivedOn = DateTime.Now;
|
|
|
db.SaveChanges();
|
|
|
- // Console.WriteLine(string.Format("Now:{0} ServerMessage Id:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), foundRequest.Id));
|
|
|
+ // Console.WriteLine(string.Format("Now:{0} ServerMessage Id:{1} ", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), foundRequest.Id));
|
|
|
|
|
|
}
|
|
|
confirmed = true;
|