using Edge.Core.Processor;using Edge.Core.IndustryStandardInterface.Pump; using Edge.Core.Parser.BinaryParser.Util; using System; using System.Collections.Generic; using System.Linq; using Edge.Core.Processor.Communicator; namespace ShellChina_EPS_Project_CarPlatePay_EpsClient_App { /// /// 报文组成格式:2字节报文长度(binary, 不包含自己的2字节) + 5字节TPDU + 2字节MTI + 8字节位图 + 报文内容 /// public class MessageCutter : IMessageCutter { public byte[] Message { get; private set; } public event EventHandler OnMessageCut; public event EventHandler OnInvalidMessageRead; //static ILog innerLogger = log4net.LogManager.GetLogger("StateMachine"); static NLog.Logger innerLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("Communicator"); private readonly List buffer = new List(); private int fullMsgLength = 0; /// /// Message format: /// ADR CTRL trans_Number trans_Length trans_data CRC-1 CRC-2 ETX(0x03) SF(0xFA) /// public MessageCutter() { } public void Feed(byte[] next) { for (int i = 0; i < next.Length; i++) { this.buffer.Add(next[i]); if (this.buffer.Count == 2) { this.fullMsgLength = (this.buffer[0] << 8) + this.buffer[1] + 2; } if (this.buffer.Count == this.fullMsgLength) { var e = this.OnMessageCut; this.Message = this.buffer.ToArray(); e?.Invoke(this, null); this.fullMsgLength = 0; this.buffer.Clear(); } } } } }