123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- 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
- {
- /// <summary>
- /// 报文组成格式:2字节报文长度(binary, 不包含自己的2字节) + 5字节TPDU + 2字节MTI + 8字节位图 + 报文内容
- /// </summary>
- public class MessageCutter : IMessageCutter<byte[]>
- {
- public byte[] Message { get; private set; }
- public event EventHandler OnMessageCut;
- public event EventHandler<MessageCutterInvalidMessageReadEventArg> OnInvalidMessageRead;
- //static ILog innerLogger = log4net.LogManager.GetLogger("StateMachine");
- static NLog.Logger innerLogger = NLog.LogManager.LoadConfiguration("nlog.config").GetLogger("Communicator");
- private readonly List<byte> buffer = new List<byte>();
- private int fullMsgLength = 0;
- ///
- /// Message format:
- /// ADR CTRL trans_Number trans_Length trans_data CRC-1 CRC-2 ETX(0x03) SF(0xFA)
- /// </summary>
- 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();
- }
- }
- }
- }
- }
|