Browse Source

1. 移除測試LOG
2.加入電樁連上後會先進入Pending 5 秒邏輯 (協助電樁測試Pending功能需求)

Jessica Tseng 4 years ago
parent
commit
e650f04e96

+ 72 - 58
EVCB_OCPP.WSServer/Message/CoreProfileHandler.cs

@@ -74,8 +74,9 @@ namespace EVCB_OCPP.WSServer.Message
                                     int.TryParse(configVaule, out heartbeat_interval);
                                 }
                             }
-                            var confirm = new BootNotificationConfirmation() { currentTime = DateTime.Now, interval = heartbeat_interval, status = Packet.Messages.SubTypes.RegistrationStatus.Accepted };
+                            var confirm = new BootNotificationConfirmation() { currentTime = DateTime.Now, interval = session.IsPending ? heartbeat_interval : 5, status = session.IsPending ? Packet.Messages.SubTypes.RegistrationStatus.Accepted : RegistrationStatus.Pending };
 
+                            session.IsPending = !session.IsPending;
                             result.Message = confirm;
                             result.Success = true;
                         }
@@ -451,6 +452,7 @@ namespace EVCB_OCPP.WSServer.Message
         internal MessageResult ExecuteCoreConfirm(Actions action, ClientData session, IConfirmation confirm, string requestId)
         {
             MessageResult result = new MessageResult() { Success = true };
+
             switch (action)
             {
                 case Actions.DataTransfer:
@@ -640,92 +642,102 @@ namespace EVCB_OCPP.WSServer.Message
                     break;
                 case Actions.GetConfiguration:
                     {
-                        GetConfigurationConfirmation _confirm = confirm as GetConfigurationConfirmation;
-                        GetConfigurationRequest _request = _confirm.GetRequest() as GetConfigurationRequest;
 
-                        using (var db = new MainDBContext())
+                        try
                         {
-                            var configure = db.MachineConfiguration.Where(x => x.ChargeBoxId == session.ChargeBoxId).ToList();
+                            GetConfigurationConfirmation _confirm = confirm as GetConfigurationConfirmation;
+                            //  GetConfigurationRequest _request = _confirm.GetRequest() as GetConfigurationRequest;
 
-                            if (_confirm.configurationKey != null)
+                            using (var db = new MainDBContext())
                             {
-                                foreach (var item in _confirm.configurationKey)
-                                {
-                                    string oldValue = string.Empty;
-                                    var foundConfig = configure.Find(x => x.ConfigureName == item.key);
+                                var configure = db.MachineConfiguration.Where(x => x.ChargeBoxId == session.ChargeBoxId).ToList();
 
-                                    if (foundConfig != null)
+                                if (_confirm.configurationKey != null)
+                                {
+                                    foreach (var item in _confirm.configurationKey)
                                     {
-                                        if (foundConfig.ConfigureName == "SecurityProfile")
+                                        string oldValue = string.Empty;
+                                        if (item.key == null)
                                         {
-                                            oldValue = foundConfig.ConfigureSetting;
+                                            Console.WriteLine("*********************");
                                         }
+                                        var foundConfig = configure.Find(x => x.ConfigureName == item.key);
 
-                                        foundConfig.ReadOnly = item.IsReadOnly;
-                                        foundConfig.ConfigureSetting = string.IsNullOrEmpty(item.value) ? string.Empty : item.value;
-                                    }
-                                    else
-                                    {
-                                        db.MachineConfiguration.Add(new MachineConfiguration()
+
+                                        if (foundConfig != null)
                                         {
-                                            ChargeBoxId = session.ChargeBoxId,
-                                            ConfigureName = item.key,
-                                            ReadOnly = item.IsReadOnly,
-                                            ConfigureSetting = string.IsNullOrEmpty(item.value) ? string.Empty : item.value,
-                                            Exists = true
-                                        });
-                                    }
+                                            if (foundConfig.ConfigureName == null)
+                                            {
+                                                Console.WriteLine("*********************");
+                                            }
 
-                                    if (foundConfig.ConfigureName == "SecurityProfile")
-                                    {
+                                            if (foundConfig.ConfigureName == "SecurityProfile")
+                                            {
+                                                oldValue = foundConfig.ConfigureSetting;
+                                            }
 
-                                        if (foundConfig.ConfigureSetting != oldValue)
+                                            foundConfig.ReadOnly = item.IsReadOnly;
+                                            foundConfig.ConfigureSetting = string.IsNullOrEmpty(item.value) ? string.Empty : item.value;
+                                        }
+                                        else
                                         {
-                                            session.ResetSecurityProfile = true;
+                                            db.MachineConfiguration.Add(new MachineConfiguration()
+                                            {
+                                                ChargeBoxId = session.ChargeBoxId,
+                                                ConfigureName = item.key,
+                                                ReadOnly = item.IsReadOnly,
+                                                ConfigureSetting = string.IsNullOrEmpty(item.value) ? string.Empty : item.value,
+                                                Exists = true
+                                            });
                                         }
 
+
                                     }
                                 }
-                            }
-                            if (_confirm.unknownKey != null)
-                            {
-                                foreach (var item in _confirm.unknownKey)
+                                if (_confirm.unknownKey != null)
                                 {
-                                    var foundConfig = configure.Find(x => x.ConfigureName == item);
-                                    if (foundConfig != null)
-                                    {
-                                        foundConfig.ReadOnly = true;
-                                        foundConfig.ConfigureSetting = string.Empty;
-                                        foundConfig.Exists = false;
-                                    }
-                                    else
+
+                                    foreach (var item in _confirm.unknownKey)
                                     {
-                                        db.MachineConfiguration.Add(new MachineConfiguration()
+                                        var foundConfig = configure.Find(x => x.ConfigureName == item);
+                                        if (foundConfig != null)
+                                        {
+                                            foundConfig.ReadOnly = true;
+                                            foundConfig.ConfigureSetting = string.Empty;
+                                            foundConfig.Exists = false;
+                                        }
+                                        else
                                         {
-                                            ChargeBoxId = session.ChargeBoxId,
-                                            ConfigureName = item
-                                        });
+                                            db.MachineConfiguration.Add(new MachineConfiguration()
+                                            {
+                                                ChargeBoxId = session.ChargeBoxId,
+                                                ConfigureName = item
+                                            });
+                                        }
                                     }
                                 }
-                            }
 
 
 
+                                var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
+                               x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
 
-                            var operation = db.MachineOperateRecord.Where(x => x.SerialNo == requestId &&
-                           x.ChargeBoxId == session.ChargeBoxId && x.Status == 0).FirstOrDefault();
-
-                            if (operation != null)
-                            {
-                                operation.FinishedOn = DateTime.Now;
-                                operation.Status = 1;//電樁有回覆
-                                operation.EVSE_Status = 1;
-                                operation.EVSE_Value = JsonConvert.SerializeObject(_confirm.configurationKey, Formatting.None);
+                                if (operation != null)
+                                {
+                                    operation.FinishedOn = DateTime.Now;
+                                    operation.Status = 1;//電樁有回覆
+                                    operation.EVSE_Status = 1;
+                                    operation.EVSE_Value = JsonConvert.SerializeObject(_confirm.configurationKey, Formatting.None);
 
-                            }
+                                }
 
-                            db.SaveChanges();
+                                db.SaveChanges();
 
+                            }
+                        }
+                        catch (Exception ex)
+                        {
+                            logger.Error(ex.ToString());
                         }
 
                     }
@@ -757,6 +769,8 @@ namespace EVCB_OCPP.WSServer.Message
                     }
                     break;
             }
+
+
             return result;
         }
 

+ 2 - 8
EVCB_OCPP.WSServer/ProtalServer.cs

@@ -241,8 +241,6 @@ namespace EVCB_OCPP.WSServer
             }
         }
 
-
-
         internal void Stop()
         {
             if (_cts != null)
@@ -308,8 +306,6 @@ namespace EVCB_OCPP.WSServer
             }
         }
 
-
-
         private void OpenNetwork()
         {
 
@@ -1242,8 +1238,7 @@ namespace EVCB_OCPP.WSServer
             for (; ; )
             {
                 if (_ct.IsCancellationRequested)
-                {
-                    Console.WriteLine("----------********************************************************");
+                {                   
                     break;
                 }
 
@@ -1252,8 +1247,7 @@ namespace EVCB_OCPP.WSServer
 
                     if (DateTime.Now.Subtract(lastcheckdt).TotalSeconds > 30)
                     {
-                        lastcheckdt = DateTime.Now;
-                        Console.WriteLine("===========================");
+                        lastcheckdt = DateTime.Now;                      
                         Stopwatch watch = new Stopwatch();
                         Dictionary<string, ClientData> _copyClientDic = null;
                         lock (_lockClientDic)

+ 2 - 0
EVCB_OCPP.WSServer/SuperSocket.Protocol/ClientData.cs

@@ -14,6 +14,7 @@ namespace OCPPServer.Protocol
 
         public EVCB_OCPP20.Packet.Messages.Basic.Queue queue20 = new EVCB_OCPP20.Packet.Messages.Basic.Queue();
 
+        public bool IsPending { set; get; }
         public bool IsCheckIn { set; get; }
 
         public string ChargeBoxId { set; get; }
@@ -34,6 +35,7 @@ namespace OCPPServer.Protocol
 
         public ClientData()
         {
+            IsPending = false;
             IsCheckIn = false;
             ChargeBoxId = SessionID;
             MachineId = SessionID;

+ 1 - 2
SuperWebSocket/Protocol/WebSocketHeaderReceiveFilter.cs

@@ -23,8 +23,7 @@ namespace SuperWebSocket.Protocol
         }
 
         public override IWebSocketFragment Filter(byte[] readBuffer, int offset, int length, bool isReusableBuffer, out int rest)
-        {
-            Console.WriteLine("Inside.............");
+        {          
             rest = 0;
 
             int prevMatched = m_SearchState.Matched;