InfoCommand.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using Edge.Core.Parser.BinaryParser.MessageEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Dfs.WayneChina.GilbarcoDispenserPayTerminal.MessageEntities.Incoming
  8. {
  9. /// <summary>
  10. /// Pump => PC
  11. /// </summary>
  12. public class InfoCommand : CardMessageBase
  13. {
  14. public InfoCommand() : base(HandleType.Info)
  15. {
  16. }
  17. [Format(1, EncodingType.BIN, -94)]
  18. public byte Count { get; set; }
  19. // minus 3 which include
  20. [EnumerableFormat("BodyLength", "-2", 2, EncodingType = EncodingType.BIN)]
  21. public List<byte> SubMessageRaw { get; set; }
  22. public override string ToLogString()
  23. {
  24. var result = "InfoCommand, SubMessageCount= " + this.Count.ToString() + "." + System.Environment.NewLine;
  25. if (this.NozzleOperatingStates != null && this.NozzleOperatingStates.Any())
  26. foreach (var n in this.NozzleOperatingStates)
  27. result += n.ToLogString() + Environment.NewLine;
  28. if (this.CardInsertedStates != null && this.CardInsertedStates.Any())
  29. foreach (var c in this.CardInsertedStates)
  30. result += c.ToLogString() + Environment.NewLine;
  31. return result;
  32. }
  33. public List<CardInsertedState> CardInsertedStates
  34. {
  35. get
  36. {
  37. return this.ParseSubMessages(this.SubMessageRaw, this.Count).Item1;
  38. }
  39. }
  40. public List<NozzleOperatingState> NozzleOperatingStates
  41. {
  42. get
  43. {
  44. return this.ParseSubMessages(this.SubMessageRaw, this.Count).Item2;
  45. }
  46. }
  47. private Tuple<List<CardInsertedState>, List<NozzleOperatingState>> ParseSubMessages(List<byte> SubMessageRaw, byte SubMessageCount)
  48. {
  49. var combinedResult =
  50. new Tuple<List<CardInsertedState>, List<NozzleOperatingState>>(
  51. new List<CardInsertedState>(),
  52. new List<NozzleOperatingState>());
  53. var offset = 0;
  54. for (int i = 0; i < SubMessageCount; i++)
  55. {
  56. //1:卡插入;2:抬枪或加油中
  57. if (SubMessageRaw[offset] == 1)
  58. {
  59. var restLen = SubMessageRaw[offset + 2];
  60. Parser parser = new Parser();
  61. var cardSubMsg = parser.Deserialize(SubMessageRaw.Skip(offset).Take(3 + restLen).ToArray(),
  62. (MessageTemplateBase)Activator.CreateInstance(typeof(CardInsertedState)));
  63. combinedResult.Item1.Add(cardSubMsg as CardInsertedState);
  64. offset += 3 + restLen;
  65. }
  66. else if (SubMessageRaw[offset] == 2)
  67. {
  68. Parser parser = new Parser();
  69. var cardSubMsg = parser.Deserialize(SubMessageRaw.Skip(offset).Take(11).ToArray(),
  70. (MessageTemplateBase)Activator.CreateInstance(typeof(NozzleOperatingState)));
  71. combinedResult.Item2.Add(cardSubMsg as NozzleOperatingState);
  72. offset += 11;
  73. }
  74. else
  75. {
  76. throw new ArgumentException("只有两种状态需要上传信息。1:卡插入;2:抬枪或加油中, there're neither 1 nor 2 in msg");
  77. }
  78. }
  79. return combinedResult;
  80. }
  81. }
  82. /// <summary>
  83. /// 加油机对 PC 机普通查询命令 30H
  84. /// PC 机对加油机普通查询命令 30H
  85. /// 加油机发送实时信息命令 31H
  86. /// </summary>
  87. public class CardInsertedState : MessageTemplateBase
  88. {
  89. //public enum GenericInquiryRequestType
  90. //{
  91. // //加油机对PC机普通查询命令30H = 0x30,
  92. // //PC机对加油机普通查询命令30H = 0x30,
  93. // 加油机发送实时信息命令31H = 0x31
  94. //}
  95. //public RealTimeInquiryRequest(GenericInquiryRequestType type)
  96. //{
  97. // base.HANDLE = (byte)type;
  98. //}
  99. [Format(1, EncodingType.BIN, 0)]
  100. public byte State { get; set; }
  101. [Format(1, EncodingType.BIN, 1)]
  102. public byte MZN { get; set; }
  103. [Format(1, EncodingType.BIN, 2)]
  104. public byte LEN { get; set; }
  105. [Format(10, EncodingType.BcdString, 3)]
  106. public string ASN { get; set; }
  107. [Format(2, EncodingType.BcdString, 4)]
  108. public string CardState { get; set; }
  109. [Format(4, EncodingType.BIN, 5)]
  110. public int BAL { get; set; }
  111. [EnumerableFormat("LEN", "-16", 6, EncodingType = EncodingType.BIN)]
  112. public List<byte> IC_DATA { get; set; }
  113. }
  114. /// <summary>
  115. /// 加油机对 PC 机普通查询命令 30H
  116. /// PC 机对加油机普通查询命令 30H
  117. /// 加油机发送实时信息命令 31H
  118. /// </summary>
  119. public class NozzleOperatingState : MessageTemplateBase
  120. {
  121. public enum PumpStateChangeCode
  122. {
  123. Inserted = 1,
  124. NozzleLiftOrFueling = 2
  125. }
  126. //public RealTimeInquiryRequest(GenericInquiryRequestType type)
  127. //{
  128. // base.HANDLE = (byte)type;
  129. //}
  130. [Format(1, EncodingType.BIN, 0)]
  131. public PumpStateChangeCode State { get; set; }
  132. [Format(1, EncodingType.BIN, 1)]
  133. public byte MZN { get; set; }
  134. [Format(1, EncodingType.BIN, 2)]
  135. public byte P_UNIT { get; set; }
  136. [Format(3, EncodingType.BIN, 3)]
  137. public int AMN { get; set; }
  138. [Format(3, EncodingType.BIN, 4)]
  139. public int VOL { get; set; }
  140. [Format(2, EncodingType.BIN, 5)]
  141. public int PRC { get; set; }
  142. }
  143. public class DetailInfoCard
  144. {
  145. [Format(1, EncodingType.BIN, 1)]
  146. public byte State { get; set; }
  147. [Format(1, EncodingType.BIN, 2)]
  148. public byte Mzn { get; set; }
  149. [Format(1, EncodingType.BIN, 3)]
  150. public byte Length { get; set; }
  151. [Format(1, EncodingType.BcdString, 4)]
  152. public string Asn { get; set; }
  153. [Format(1, EncodingType.BcdString, 5)]
  154. public ushort CardState { get; set; }
  155. [Format(1, EncodingType.BIN, 6)]
  156. public uint CardBalance { get; set; }
  157. [Format(1, EncodingType.HexString, 7)]
  158. public string IcData { get; set; }
  159. }
  160. public class DetailInfoNozzle
  161. {
  162. [Format(1, EncodingType.BIN, 1)]
  163. public byte State { get; set; }
  164. [Format(1, EncodingType.BIN, 2)]
  165. public byte NozzleNo { get; set; }
  166. [Format(1, EncodingType.BIN, 3)]
  167. public byte PayUnit { get; set; }
  168. [Format(1, EncodingType.BIN, 4)]
  169. public int Amount { get; set; }
  170. [Format(1, EncodingType.BIN, 5)]
  171. public int Volume { get; set; }
  172. [Format(1, EncodingType.BIN, 6)]
  173. public short Price { get; set; }
  174. }
  175. }