123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using Edge.Core.Parser.BinaryParser;
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using Edge.Core.Parser.BinaryParser.Util;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace FuRen_Sinopec_IcCardReader
- {
- public class MessageTemplateLookup : IMessageTemplateLookup
- {
- /// <summary>
- /// Gets the default singleton instance of type MessageTemplateLookup.
- /// </summary>
- public static MessageTemplateLookup Default { get; } = new MessageTemplateLookup();
- /// <summary>
- /// Create a message entity based on input whole message raw bytes which is: 2bytes Len + 1 byte AppId + 1 byte SSK
- /// + variable length message code + variable length message body
- /// </summary>
- /// <param name="bytes">whole message raw bytes</param>
- /// <returns>new created message entity</returns>
- public MessageTemplateBase GetMessageTemplateByRawBytes(byte[] bytes)
- {
- // from protocol definition, the msg body started at 7th byte, and the 7th bytes is always the msg type code.
- var msgHandleCode = bytes.Skip(6).First();
- switch (msgHandleCode)
- {
- //case 0x30:
- // return new PumpGenericInquiryCommand();
- case 0x31:
- return new PumpStateChangeCommand();
- case 0x32:
- return new PumpNotifyTransactionDoneCommand();
- case 0x3A:
- return new FuRen_PcActivelyReadPumpConfigurationInfoResponse();
- }
- throw new ArgumentException("Can't find correlated message entity type for incoming raw message bytes: " + bytes.Select(s => s.ToString("X").PadLeft(2, '0')).Aggregate((n, acc) => n + " " + acc));
- }
- }
- }
|