CardMessageBase.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. using Edge.Core.Parser.BinaryParser.Attributes;
  2. using Edge.Core.Parser.BinaryParser.MessageEntity;
  3. using Edge.Core.Parser.BinaryParser.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace Dfs.WayneChina.HengshanPayTerminal.MessageEntity
  8. {
  9. public enum Command
  10. {
  11. /// <summary>
  12. /// Regular check command from pump against system.
  13. /// 加油机查询命令。
  14. /// </summary>
  15. Check_cmd = 0x10,
  16. /// <summary>
  17. /// Result of the check command.
  18. /// 查询命令的应答。
  19. /// </summary>
  20. Ver_info = 0x11,
  21. //*************************************************************
  22. /// <summary>
  23. /// Register terminal after power-on.
  24. /// 支付终端上电注册。
  25. /// </summary>
  26. RegisterRequest = 0x13,
  27. /// <summary>
  28. /// 后台回应支付终端上电注册。
  29. /// </summary>
  30. RegisterResult = 0x14,
  31. //*************************************************************
  32. /// <summary>
  33. /// Validate card from terminal to system.
  34. /// 验卡请求。
  35. /// </summary>
  36. ValidateCardRequest = 0x15,
  37. /// <summary>
  38. /// Validate card result from the system.
  39. /// 后台返回验卡结果。
  40. /// </summary>
  41. ValidateCardResult = 0x16,
  42. //*************************************************************
  43. AuthRequest = 0x17,
  44. AuthResult = 0x18,
  45. //*************************************************************
  46. /// <summary>
  47. /// Cancellation of authorization request from terminal to system.
  48. /// 支付终端发起撤销授权请求。
  49. /// </summary>
  50. CancelAuthRequest = 0x19,
  51. /// <summary>
  52. /// The system returns result of cancellation of auth.
  53. /// 后台返回撤销授权结果。
  54. /// </summary>
  55. CancelAuthResult = 0x1A,
  56. //*************************************************************
  57. ChangeAuthMode = 0x1B,
  58. ChangeAuthModeAck = 0x20,
  59. //*************************************************************
  60. FuelingData = 0x1C,
  61. FuelingDataResult = 0x35,
  62. //*************************************************************
  63. /// <summary>
  64. /// Change fuel price from system to pump.
  65. /// 改价命令。
  66. /// </summary>
  67. ChangePrice = 0x1E,
  68. /// <summary>
  69. /// Change fuel price result from pump to system.
  70. /// 油机返回改价结果。
  71. /// </summary>
  72. ChangePriceResult = 0x1F,
  73. //*************************************************************
  74. QueryGrayRecordRequest = 0x21,
  75. GrayRecord = 0x22,
  76. //*************************************************************
  77. ReadVolumeTotalizer = 0x23,
  78. VolumeTotalizerResult = 0x24,
  79. //*************************************************************
  80. DataRequest = 0x25,
  81. DataBytesLength = 0x26,
  82. DataContentRequest = 0x27,
  83. DataContent = 0x28,
  84. //*************************************************************
  85. DispenserInfoRequest = 0x29,
  86. DispenserInfo = 0x2A,
  87. //*************************************************************
  88. SendErrorInfoRequest = 0x2B,
  89. ErrorInfoAck = 0x2C,
  90. //*************************************************************
  91. TransactionData = 0x2D,
  92. TransactionDataAck = 0x32,
  93. //*************************************************************
  94. SystemAuth = 0x2E,
  95. SystemAuthResult = 0x31,
  96. OtherNonCardAuth = 0x2F,
  97. //*************************************************************
  98. /// <summary>
  99. /// Payment request from terminal.
  100. /// 终端发起支付请求,命令字30H。
  101. /// </summary>
  102. PaymentRequest = 0x30,
  103. PaymentData = 0x1D,
  104. //*************************************************************
  105. QueryTransactionInfo = 0x33,
  106. TransactionInfoResult = 0x34,
  107. //*************************************************************
  108. RecordCallback = 0x36,
  109. RecordCallbackAck = 0x37,
  110. //*************************************************************
  111. QueryTransactionData = 0x38,
  112. QueryTransactionDataAck = 0x39,
  113. //*************************************************************
  114. AuthManualCancel = 0x40,
  115. AuthManualCancelAck = 0x41,
  116. //*************************************************************
  117. EnableAuth = 0x42,
  118. EnableAuthAck = 0x43,
  119. //*************************************************************
  120. /// <summary>
  121. /// Lock or unlock a pump.
  122. /// 锁机或解锁命令。
  123. /// </summary>
  124. LockOrUnlockPump = 0x44,
  125. /// <summary>
  126. /// The result of locking or unlocking a pump.
  127. /// 锁机或解锁命令的回复。
  128. /// </summary>
  129. LockOrUnlockPumpAck = 0x45,
  130. //*************************************************************
  131. SystemOperationAck = 0x47,
  132. GetRfTagInfo = 0x46,
  133. VerifyFingerPrint = 0x48,
  134. ReturnTotalizer = 0x49
  135. }
  136. /// <summary>
  137. /// Enumeration of the calling parties, either pump or system
  138. /// 主叫方,加油机或后台
  139. /// </summary>
  140. public enum CallingParty
  141. {
  142. /// <summary>
  143. /// System/后台
  144. /// </summary>
  145. System,
  146. /// <summary>
  147. /// Pump/加油机,实际上是终端
  148. /// </summary>
  149. Pump
  150. }
  151. /// <summary>
  152. /// Base class of IC card terminal messages.
  153. /// IC卡终端与后台交互的消息,基类。
  154. /// </summary>
  155. public abstract class CardMessageBase : MessageTemplateBase
  156. {
  157. public CardMessageBase(Command handle)
  158. {
  159. //Handle = handle;
  160. }
  161. /// <summary>
  162. /// Get the caller (Frame sequence number bit 6 indicates the calling party, 0 = system, 1 = pump)
  163. /// 获取主叫方。命令/数据帧号,第6个bit,0 = 后台, 1 = 加油机
  164. /// </summary>
  165. public CallingParty Caller
  166. {
  167. get
  168. {
  169. if (FrameSqNoByte.GetBit(6) == 1)
  170. return CallingParty.Pump;
  171. return CallingParty.System;
  172. }
  173. }
  174. /// <summary>
  175. /// Static field, 'FA'
  176. /// 数据包头,长度1字节,Hex “FA”
  177. /// </summary>
  178. [Format(1, EncodingType.BIN, -100)]
  179. public virtual byte Prefix { get; set; }
  180. /// <summary>
  181. /// The destination address this message targets.
  182. /// 目标地址,长度1字节
  183. /// </summary>
  184. [Format(1, EncodingType.BIN, -99)]
  185. public virtual byte DestinationAddress { get; set; }
  186. /// <summary>
  187. /// The source address of the message.
  188. /// 源地址,长度1字节
  189. /// </summary>
  190. [Format(1, EncodingType.BIN, -98)]
  191. public virtual byte SourceAddress { get; set; }
  192. /// <summary>
  193. /// Command/Data frame sequence number.
  194. /// 命令/数据帧号
  195. /// 格式:
  196. /// b7=0;b6=0时,后台主叫,b6=1,油机主叫;
  197. /// b5~b0为帧号,主叫方每发送一新帧,此帧号加一,应答方回送此帧号。
  198. /// </summary>
  199. [Format(1, EncodingType.BIN, -97)]
  200. public virtual byte FrameSqNoByte { get; set; }
  201. /// <summary>
  202. /// The frame number is in the FrameSqNoByte bit 5 to bit 0 (6 bits).
  203. /// 帧号为 命令/数据帧号 字节的b5-b0,共6个bit。
  204. /// </summary>
  205. public virtual int FrameNo
  206. {
  207. get { return FrameSqNoByte & 0x3F; }
  208. }
  209. /// <summary>
  210. /// Set the calling party of the message
  211. /// 设置此消息的主叫方
  212. /// </summary>
  213. /// <param name="party"></param>
  214. public void SetCallingParty(CallingParty party)
  215. {
  216. FrameSqNoByte = FrameSqNoByte.SetBit(6, 6, party == CallingParty.Pump ? 1 : 0);
  217. }
  218. public void SetSeqNo(byte sqNo)
  219. {
  220. // sequence number is max 5 bits.
  221. if (sqNo > 63)
  222. throw new ArgumentOutOfRangeException("maximum sequenceNumber is 63(total 6 bits).");
  223. var debug = FrameSqNoByte >> 6 << 6;
  224. FrameSqNoByte = (byte)(debug + sqNo);
  225. }
  226. /// <summary>
  227. /// Length of message body
  228. /// 有效数据长度,2字节,HEX
  229. /// </summary>
  230. [Format(2, "%OnSerializingBytesCount", EncodingType.BIN, -96)]
  231. public virtual int BodyLength { get; set; }
  232. /// <summary>
  233. /// Command type
  234. /// 命令字
  235. /// </summary>
  236. [Format(1, EncodingType.BIN, -95)]
  237. public byte Handle { get; set; }
  238. /// <summary>
  239. /// The meaningful body of the message.
  240. /// 消息有效数据
  241. /// </summary>
  242. //[EnumerableFormat("BodyLength", "-2", 2, EncodingType = EncodingType.BIN)]
  243. //public List<byte> Body { get; set; }
  244. //[Format(1, EncodingType.BIN, -1)]
  245. public byte ETX { get; set; }
  246. /// <summary>
  247. /// CRC of the whole message skipping additional 'FA'
  248. /// 消息的CRC校验,转义'FA'字节不计入
  249. /// </summary>
  250. [EnumerableFormat(2, 1000, EncodingType = EncodingType.BIN)]
  251. public virtual List<byte> CRC { get; set; }
  252. public override string ToLogString()
  253. {
  254. return GetType().Name + " " + base.ToLogString().Replace(
  255. "FrameSqNoByte:", "(Caller: " + Caller + ", FrameNo: " + FrameNo + ")FrameSqNoByte:");
  256. }
  257. }
  258. }