Browse Source

fix not EndOfMessage not copy previous msg

Robert 1 year ago
parent
commit
e953c14804

+ 4 - 2
EVCB_OCPP.WSServer/Service/WsService/WsClientData.cs

@@ -78,17 +78,19 @@ public class WsClientData : WsSession
     public event EventHandler<string> m_ReceiveData;
 
     private string stringBuffer = string.Empty;
-
+    private readonly ILogger<WsClientData> logger;
 
     public WsClientData(ILogger<WsClientData> logger) : base(logger)
     {
         ChargeBoxId = SessionID;
         MachineId = SessionID;
+        this.logger = logger;
     }
 
     internal override void HandleReceivedData(string data)
     {
         stringBuffer += data;
+        //logger.LogInformation("{StringBuffer}", stringBuffer);
         while (TryGetOCPPMsg(ref stringBuffer, out var msg))
         {
             m_ReceiveData?.Invoke(this, msg);
@@ -128,7 +130,7 @@ public class WsClientData : WsSession
         if (startIndex is not null && stopIndex is not null)
         {
             msg = buffer.Substring(startIndex.Value, stopIndex.Value - startIndex.Value);
-            buffer = buffer.Substring(stopIndex.Value);
+            buffer = buffer.Substring(stopIndex.Value + 1);
             return true;
         }
 

+ 3 - 0
EVCB_OCPP.WSServer/Service/WsService/WsSession.cs

@@ -54,6 +54,7 @@ public class WsSession
     {
         logger.LogInformation("{id} {func} {Path} Start", SessionID, nameof(StartReceivd), Path);
 
+        byte[] prevBuffer = new byte[0];
         byte[] receivdBuffer = new byte[0];
         int bufferExpand = 1;
         int receivedBytes = 0;
@@ -80,7 +81,9 @@ public class WsSession
                 break;
             }
 
+            prevBuffer = receivdBuffer;
             receivdBuffer = new byte[1024 * 4 * bufferExpand];
+            Array.Copy(prevBuffer, 0, receivdBuffer, 0, receivedBytes);
             Array.Copy(tempReceiveBuffer, 0, receivdBuffer, receivedBytes, result.Count);
             receivedBytes += result.Count;
 

+ 4 - 4
EVCB_OCPP.WSServer/appsettings.json

@@ -66,14 +66,14 @@
     },
     "rules": [
       {
-        "ruleName": "OCPPServer",
-        "logger": "OCPPServer.*",
+        "ruleName": "HttpRecord",
+        "logger": "HeaderRecord*",
         "minLevel": "Info",
         "writeTo": "ws"
       },
       {
-        "ruleName": "SuperWebSocket",
-        "logger": "SuperWebSocket.*",
+        "ruleName": "WsRecord",
+        "logger": "EVCB_OCPP.WSServer.Service.WsService*",
         "minLevel": "Info",
         "writeTo": "ws"
       },