Переглянути джерело

socket增加多个端口,协议解析增加客户端口号

DOVER-GLOBAL\11047086 4 місяців тому
батько
коміт
9d8b480938

+ 6 - 6
Edge.Core/Processor/Communicator/IMessageCutter.cs

@@ -19,7 +19,7 @@ namespace Edge.Core.Processor.Communicator
         /// </summary>
         event EventHandler<MessageCutterInvalidMessageReadEventArg> OnInvalidMessageRead;
 
-        void Feed(T data);
+        void Feed(T data, int localTcpServerListeningPort = 0);
         T Message { get; }
     }
 
@@ -34,7 +34,7 @@ namespace Edge.Core.Processor.Communicator
     /// <typeparam name="T"></typeparam>
     public class SizableWindow<T> : IList<T>
     {
-        public Action<List<T>> OnWindowFull;
+        public Action<List<T>, int> OnWindowFull;
         private List<T> list = new List<T>();
         private int initialSize;
         private int? size;
@@ -58,20 +58,20 @@ namespace Edge.Core.Processor.Communicator
             if (this.size == null || this.size.Value == 0)
             {
                 if (OnWindowFull != null)
-                    this.OnWindowFull(this.list);
+                    this.OnWindowFull(this.list,0);
             }
             else if (this.list.Count == this.NewSize)
             {
                 if (OnWindowFull != null)
-                    this.OnWindowFull(this.list);
+                    this.OnWindowFull(this.list,0);
             }
         }
         
-        public void Add(List<T> list)
+        public void Add(List<T> list, int localTcpServerListeningPort = 0)
         {
             this.list.AddRange(list);
             if (OnWindowFull != null)
-                this.OnWindowFull(this.list);
+                this.OnWindowFull(this.list, localTcpServerListeningPort);
         }
         
         #region MyRegion

+ 4 - 11
Edge.Core/Processor/Communicator/TcpServerCommunicator.cs

@@ -19,7 +19,7 @@ namespace Edge.Core.Processor.Communicator
     [MetaPartsDescriptor(
         "lang-zh-cn:Tcp(本程序为服务器端)通讯器lang-en-us:Tcp(as server) communicator",
         "lang-zh-cn:基于TCP/IP技术的通讯器, FC作为服务器端等待客户端连接lang-en-us:TCP/IP based communicator, FC as the server and wait for connections")]
-    public class TcpServerCommunicator<T> : IClinet, ICommunicator<byte[], T> where T : MessageTemplateBase
+    public class TcpServerCommunicator<T> : ICommunicator<byte[], T> where T : MessageTemplateBase
     {
         private CancellationTokenSource readAsyncCancellationTokenSource;
         private DateTime? lastReceiveMsgDataFromTcpClientDateTime;
@@ -32,7 +32,7 @@ namespace Edge.Core.Processor.Communicator
 
         private int localTcpServerListeningPort;
         protected TcpListener tcpListener;
-        public TcpClient exclusiveTcpClient { get; set; }
+        private TcpClient exclusiveTcpClient;
         private string exclusiveTcpClient_ClientRemoteEndPoint_Str = "?:?";
         //private bool isTcpConnBrokenDuringWrite = false;
         private object syncObject = new object();
@@ -261,7 +261,7 @@ namespace Edge.Core.Processor.Communicator
                                     {
                                         lock (this.syncObject_Feed)
                                         {
-                                            this.messageCutter.Feed(data);
+                                            this.messageCutter.Feed(data,  this.localTcpServerListeningPort);
                                         }
                                     }
                                     catch (Exception ex)
@@ -298,8 +298,7 @@ namespace Edge.Core.Processor.Communicator
             byte[] rawData;
             try
             {
-                rawData = message.ToCommonByteArray();
-                //rawData = this.parser.Serialize(message);
+                rawData = this.parser.Serialize(message);
                 var arg = new CommunicatorEventArg<byte[], T>() { Data = rawData, Message = message, Continue = true };
                 this.OnRawDataWriting?.Invoke(this, arg);
                 if (this.exclusiveTcpClient == null || !arg.Continue) { this.logger.LogError("Write failed, this.tcpClient is null: " + (this.exclusiveTcpClient is null)); return false; }
@@ -350,11 +349,5 @@ namespace Edge.Core.Processor.Communicator
         {
             throw new NotImplementedException();
         }
-
-
-        public TcpClient? GetTcpClient()
-        {
-            return this.exclusiveTcpClient;
-        }
     }
 }

+ 27 - 0
Edge.Core/Processor/Dispatcher/ProcessorLoader/DbJSonLoader.cs

@@ -61,6 +61,33 @@ namespace Edge.Core.Processor.Dispatcher
             }
         ],
         ""Activated"": true
+    },
+{
+        ""Id"": 17,
+        ""Name"": ""HengshanPaymentTerminal.HengshanPayTerminal.Hengs_938d2e2bd48b45ba_9"",
+        ""Description"": """",
+        ""Type"": 0,
+        ""Parts"": [
+            {
+                ""Id"": 50,
+                ""Type"": 1,
+                ""FullTypeString"": ""HengshanPaymentTerminal.HengshanPayTermHandler, HengshanPaymentTerminal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"",
+                ""ParametersJsonArrayStr"": ""[{\""pumpIds\"":\""1,2,3,4\"",\""pumpSubAddresses\"":[{\""PumpId\"":1,\""SubAddress\"":1},{\""PumpId\"":2,\""SubAddress\"":2},{\""PumpId\"":3,\""SubAddress\"":3},{\""PumpId\"":4,\""SubAddress\"":4}],\""pumpNozzleLogicIds\"":[{\""PumpId\"":1,\""LogicIds\"":\""1\""},{\""PumpId\"":2,\""LogicIds\"":\""1\""},{\""PumpId\"":3,\""LogicIds\"":\""1\""},{\""PumpId\"":4,\""LogicIds\"":\""1\""}],\""pumpSiteNozzleNos\"":[{\""PumpId\"":1,\""SiteNozzleNos\"":\""1\""},{\""PumpId\"":2,\""SiteNozzleNos\"":\""2\""},{\""PumpId\"":3,\""SiteNozzleNos\"":\""3\""},{\""PumpId\"":4,\""SiteNozzleNos\"":\""4\""}],\""nozzleLogicIds\"":[{\""NozzleNo\"":1,\""LogicId\"":1},{\""NozzleNo\"":2,\""LogicId\"":1},{\""NozzleNo\"":3,\""LogicId\"":1},{\""NozzleNo\"":4,\""LogicId\"":1}]}]""
+            },
+            {
+                ""Id"": 51,
+                ""Type"": 0,
+                ""FullTypeString"": ""Edge.Core.Processor.GenericDeviceProcessor`2, Edge.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"",
+                ""ParametersJsonArrayStr"": ""[]""
+            },
+            {
+                ""Id"": 52,
+                ""Type"": 5,
+                ""FullTypeString"": ""Edge.Core.Processor.Communicator.TcpServerCommunicator`1, Edge.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"",
+              ""ParametersJsonArrayStr"": ""[23457, 30, \""enabled\"", \""enabled\"", \""2\""]""
+            }
+        ],
+        ""Activated"": true
     }
 ]";
             IEnumerable<ProcessorMetaConfig> configs = JsonSerializer.Deserialize<IEnumerable<ProcessorMetaConfig>>(json);

+ 1 - 1
HengshanPaymentTerminal/HengshanPayTermHandler.cs

@@ -795,7 +795,7 @@ namespace HengshanPaymentTerminal
             return await SendRequestToMachine("发送取消授权请求", BitConverter.ToString(commandAndNozzle).Replace("-", ""), sendBytes);
         }
 
-        public void SetTcpClinet(TcpClient? tcpClient)
+        public void SetTcpClient(TcpClient? tcpClient)
         {
             this.client = tcpClient;
         }

+ 1 - 0
HengshanPaymentTerminal/MessageEntity/CommonMessage.cs

@@ -109,6 +109,7 @@ namespace HengshanPaymentTerminal.MessageEntity
         /// </summary>
         public string ErrorMessage { get; set; }
 
+
         public CommonMessage getBaseData(byte[] data)
         {
             this.Handle = data[0];

+ 3 - 3
HengshanPaymentTerminal/StateMachineMessageCutter.cs

@@ -48,7 +48,7 @@ namespace HengshanPaymentTerminal
         {
             window = new SizableWindow<byte>();
 
-            window.OnWindowFull += (data) =>
+            window.OnWindowFull += (data, localTcpServerListeningPort) =>
             {
                 byte[] tempBytes = window.ToArray();
                 string receiveStr = BitConverter.ToString(tempBytes).Replace("-", " ");
@@ -109,10 +109,10 @@ namespace HengshanPaymentTerminal
             };
         }
 
-        public void Feed(byte[] data)
+        public void Feed(byte[] data,int localTcpServerListeningPort = 0)
         {
             List<byte> list = new(data);
-            window.Add(list);
+            window.Add(list, localTcpServerListeningPort);
             //for (int i = 0; i < data.Length; i++)
             //{
             //    window.Add(data[i]);

+ 1 - 1
src/FccLife.Web/appsettings.Development.json

@@ -6,7 +6,7 @@
     }
   },
   "ConnectionStrings": {
-    "DefaultConnection": "Server=localhost;Port=3306;Database=qrFueling;User=root;Password=123456",
+    "DefaultConnection": "Server=localhost;Port=3306;Database=qrFueling;User=root;Password=HS1205",
     "isMigrate": "true"
   }
 }