|
@@ -75,6 +75,8 @@ namespace EVCB_OCPP.WSServer.Service.WsService
|
|
|
|
|
|
public event EventHandler<string> m_ReceiveData;
|
|
|
|
|
|
+ private string stringBuffer = string.Empty;
|
|
|
+
|
|
|
|
|
|
public WsClientData()
|
|
|
{
|
|
@@ -93,9 +95,53 @@ namespace EVCB_OCPP.WSServer.Service.WsService
|
|
|
Send(data, offset, length);
|
|
|
}
|
|
|
|
|
|
- internal override void HandleReceivedData(string msg)
|
|
|
+ internal override void HandleReceivedData(string data)
|
|
|
+ {
|
|
|
+ stringBuffer += data;
|
|
|
+ while (TryGetOCPPMsg(ref stringBuffer, out var msg))
|
|
|
+ {
|
|
|
+ m_ReceiveData?.Invoke(this, msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool TryGetOCPPMsg(ref string buffer, out string msg)
|
|
|
{
|
|
|
- m_ReceiveData?.Invoke(this, msg);
|
|
|
+ msg = string.Empty;
|
|
|
+ int? startIndex = null;
|
|
|
+ int? stopIndex = null;
|
|
|
+ uint cnt = 0;
|
|
|
+
|
|
|
+ for (int index = 0; index < buffer.Length; index++)
|
|
|
+ {
|
|
|
+ if (buffer[index] == '[')
|
|
|
+ {
|
|
|
+ cnt++;
|
|
|
+ if (startIndex == null)
|
|
|
+ {
|
|
|
+ startIndex = index;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startIndex != null && buffer[index] == ']')
|
|
|
+ {
|
|
|
+ cnt--;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startIndex != null && cnt == 0)
|
|
|
+ {
|
|
|
+ stopIndex = index;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startIndex is not null && stopIndex is not null)
|
|
|
+ {
|
|
|
+ msg = buffer.Substring(startIndex.Value, stopIndex.Value - startIndex.Value);
|
|
|
+ buffer = buffer.Substring(stopIndex.Value);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
}
|