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 { /// /// Pump => PC /// 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 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 CardInsertedStates { get { return this.ParseSubMessages(this.SubMessageRaw, this.Count).Item1; } } public List NozzleOperatingStates { get { return this.ParseSubMessages(this.SubMessageRaw, this.Count).Item2; } } private Tuple, List> ParseSubMessages(List SubMessageRaw, byte SubMessageCount) { var combinedResult = new Tuple, List>( new List(), new List()); 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; } } /// /// 加油机对 PC 机普通查询命令 30H /// PC 机对加油机普通查询命令 30H /// 加油机发送实时信息命令 31H /// 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 IC_DATA { get; set; } } /// /// 加油机对 PC 机普通查询命令 30H /// PC 机对加油机普通查询命令 30H /// 加油机发送实时信息命令 31H /// 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; } } }