123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using Edge.Core.Parser.BinaryParser.Attributes;
- using Edge.Core.Parser.BinaryParser.MessageEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Dfs.WayneChina.GilbarcoDispenserPayTerminal.MessageEntities.Incoming
- {
- /// <summary>
- /// Pump => PC
- /// </summary>
- public class InfoCommand : CardMessageBase
- {
- public InfoCommand() : base(HandleType.Info)
- {
- }
- [Format(1, EncodingType.BIN, -94)]
- public byte Count { get; set; }
- // minus 3 which include
- [EnumerableFormat("BodyLength", "-2", 2, EncodingType = EncodingType.BIN)]
- public List<byte> SubMessageRaw { get; set; }
- public override string ToLogString()
- {
- var result = "InfoCommand, SubMessageCount= " + this.Count.ToString() + "." + System.Environment.NewLine;
- if (this.NozzleOperatingStates != null && this.NozzleOperatingStates.Any())
- foreach (var n in this.NozzleOperatingStates)
- result += n.ToLogString() + Environment.NewLine;
- if (this.CardInsertedStates != null && this.CardInsertedStates.Any())
- foreach (var c in this.CardInsertedStates)
- result += c.ToLogString() + Environment.NewLine;
- return result;
- }
- public List<CardInsertedState> CardInsertedStates
- {
- get
- {
- return this.ParseSubMessages(this.SubMessageRaw, this.Count).Item1;
- }
- }
- public List<NozzleOperatingState> NozzleOperatingStates
- {
- get
- {
- return this.ParseSubMessages(this.SubMessageRaw, this.Count).Item2;
- }
- }
- private Tuple<List<CardInsertedState>, List<NozzleOperatingState>> ParseSubMessages(List<byte> SubMessageRaw, byte SubMessageCount)
- {
- var combinedResult =
- new Tuple<List<CardInsertedState>, List<NozzleOperatingState>>(
- new List<CardInsertedState>(),
- new List<NozzleOperatingState>());
- var offset = 0;
- for (int i = 0; i < SubMessageCount; i++)
- {
- //1:卡插入;2:抬枪或加油中
- if (SubMessageRaw[offset] == 1)
- {
- var restLen = SubMessageRaw[offset + 2];
- Parser parser = new Parser();
- var cardSubMsg = parser.Deserialize(SubMessageRaw.Skip(offset).Take(3 + restLen).ToArray(),
- (MessageTemplateBase)Activator.CreateInstance(typeof(CardInsertedState)));
- combinedResult.Item1.Add(cardSubMsg as CardInsertedState);
- offset += 3 + restLen;
- }
- else if (SubMessageRaw[offset] == 2)
- {
- Parser parser = new Parser();
- var cardSubMsg = parser.Deserialize(SubMessageRaw.Skip(offset).Take(11).ToArray(),
- (MessageTemplateBase)Activator.CreateInstance(typeof(NozzleOperatingState)));
- combinedResult.Item2.Add(cardSubMsg as NozzleOperatingState);
- offset += 11;
- }
- else
- {
- throw new ArgumentException("只有两种状态需要上传信息。1:卡插入;2:抬枪或加油中, there're neither 1 nor 2 in msg");
- }
- }
- return combinedResult;
- }
- }
- /// <summary>
- /// 加油机对 PC 机普通查询命令 30H
- /// PC 机对加油机普通查询命令 30H
- /// 加油机发送实时信息命令 31H
- /// </summary>
- public class CardInsertedState : MessageTemplateBase
- {
- //public enum GenericInquiryRequestType
- //{
- // //加油机对PC机普通查询命令30H = 0x30,
- // //PC机对加油机普通查询命令30H = 0x30,
- // 加油机发送实时信息命令31H = 0x31
- //}
- //public RealTimeInquiryRequest(GenericInquiryRequestType type)
- //{
- // base.HANDLE = (byte)type;
- //}
- [Format(1, EncodingType.BIN, 0)]
- public byte State { get; set; }
- [Format(1, EncodingType.BIN, 1)]
- public byte MZN { get; set; }
- [Format(1, EncodingType.BIN, 2)]
- public byte LEN { get; set; }
- [Format(10, EncodingType.BcdString, 3)]
- public string ASN { get; set; }
- [Format(2, EncodingType.BcdString, 4)]
- public string CardState { get; set; }
- [Format(4, EncodingType.BIN, 5)]
- public int BAL { get; set; }
- [EnumerableFormat("LEN", "-16", 6, EncodingType = EncodingType.BIN)]
- public List<byte> IC_DATA { get; set; }
- }
- /// <summary>
- /// 加油机对 PC 机普通查询命令 30H
- /// PC 机对加油机普通查询命令 30H
- /// 加油机发送实时信息命令 31H
- /// </summary>
- public class NozzleOperatingState : MessageTemplateBase
- {
- public enum PumpStateChangeCode
- {
- Inserted = 1,
- NozzleLiftOrFueling = 2
- }
- //public RealTimeInquiryRequest(GenericInquiryRequestType type)
- //{
- // base.HANDLE = (byte)type;
- //}
- [Format(1, EncodingType.BIN, 0)]
- public PumpStateChangeCode State { get; set; }
- [Format(1, EncodingType.BIN, 1)]
- public byte MZN { get; set; }
- [Format(1, EncodingType.BIN, 2)]
- public byte P_UNIT { get; set; }
- [Format(3, EncodingType.BIN, 3)]
- public int AMN { get; set; }
- [Format(3, EncodingType.BIN, 4)]
- public int VOL { get; set; }
- [Format(2, EncodingType.BIN, 5)]
- public int PRC { get; set; }
- }
- public class DetailInfoCard
- {
- [Format(1, EncodingType.BIN, 1)]
- public byte State { get; set; }
- [Format(1, EncodingType.BIN, 2)]
- public byte Mzn { get; set; }
- [Format(1, EncodingType.BIN, 3)]
- public byte Length { get; set; }
- [Format(1, EncodingType.BcdString, 4)]
- public string Asn { get; set; }
- [Format(1, EncodingType.BcdString, 5)]
- public ushort CardState { get; set; }
- [Format(1, EncodingType.BIN, 6)]
- public uint CardBalance { get; set; }
- [Format(1, EncodingType.HexString, 7)]
- public string IcData { get; set; }
- }
- public class DetailInfoNozzle
- {
- [Format(1, EncodingType.BIN, 1)]
- public byte State { get; set; }
- [Format(1, EncodingType.BIN, 2)]
- public byte NozzleNo { get; set; }
- [Format(1, EncodingType.BIN, 3)]
- public byte PayUnit { get; set; }
- [Format(1, EncodingType.BIN, 4)]
- public int Amount { get; set; }
- [Format(1, EncodingType.BIN, 5)]
- public int Volume { get; set; }
- [Format(1, EncodingType.BIN, 6)]
- public short Price { get; set; }
- }
- }
|