PetroChinaSilentPumpHandler.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using Edge.Core.Processor;
  2. using Edge.Core.IndustryStandardInterface.Pump;
  3. using HengShan_Pump_TQC_IFSF.MessageEntity;
  4. using HengShan_Pump_TQC_IFSF.MessageEntity.Incoming;
  5. using HengShan_Pump_TQC_IFSF.MessageEntity.Outgoing;
  6. using Edge.Core.Parser.BinaryParser.Util;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Globalization;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using System.Threading.Tasks;
  14. using System.Xml;
  15. using Wayne.FDCPOSLibrary;
  16. using Timer = System.Timers.Timer;
  17. namespace HengShan_Pump_TQC_IFSF
  18. {
  19. public class PetroChinaSilentPumpHandler : PumpHandler
  20. {
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. /// <param name="pumpId"></param>
  25. /// <param name="ifsfFuelPointId">range from 0x21 to 0x24</param>
  26. /// <param name="recipientSubnet">used to locate the remote tqc pump, must a value different from FC</param>
  27. /// <param name="recipientNode">used to locate the remote tqc pump</param>
  28. /// <param name="nozzlesXmlConfiguration"></param>
  29. public PetroChinaSilentPumpHandler(PumpGroupHandler parent, int pumpId, byte ifsfFuelPointId, byte recipientSubnet, byte recipientNode, string nozzlesXmlConfiguration, Func<byte> msgTokenGenerator)
  30. : base(parent, pumpId, ifsfFuelPointId, recipientSubnet, recipientNode, nozzlesXmlConfiguration, msgTokenGenerator)
  31. {
  32. //sample of nozzlesXmlConfiguration
  33. // <Pump id='3'>
  34. // <Nozzles>
  35. // <Nozzle logicalId='1' physicalId='1' ifsfLogicalNozzleId="0x11"/>
  36. // <Nozzle logicalId='2' physicalId='2' ifsfLogicalNozzleId="0x12"/>
  37. // </Nozzles>
  38. // </Pump>
  39. }
  40. public override Task Process(IContext<byte[], IfsfMessageBase> context)
  41. {
  42. this.context = context;
  43. //if (context.Incoming.Message is IfsfMessage ifsfMsg
  44. // && ifsfMsg.MessageType == MessageType.IFSF_MESSAGE_TYPE_UNSOLICITED_ACK)
  45. //{
  46. // //logger.Debug("PumpHandlerSilent with ifsfFpId 0x" + base.ifsfFuelPointId.ToHexLogString() + " will ack the Ack requried event!");
  47. // context.Outgoing.Write(
  48. // new AcknowledgeMessage(
  49. // ifsfMsg.OriginatorSubnet,
  50. // ifsfMsg.OriginatorNode,
  51. // PumpGroupHandler.originatorSubnet, PumpGroupHandler.originatorNode,
  52. // ifsfMsg.MessageToken,
  53. // ifsfMsg.DatabaseId,
  54. // MessageAcknowledgeStatus.ACK_PositiveAcknowledgeDataReceived
  55. // ));
  56. //}
  57. switch (context.Incoming.Message)
  58. {
  59. case FuellingPointDb_FpRunningTransaction_Event fpRunningTrxEvent:
  60. {
  61. logger.Debug("Pump " + this.pumpId + ", fpRunningTrxEvent ifsf FpId: 0x" + fpRunningTrxEvent.TargetFuelPointId.ToHexLogString()
  62. + ", CurAmt and CurVol(no decimal points): " + fpRunningTrxEvent.CurrentAmount
  63. + " - " + fpRunningTrxEvent.CurrentVolume);
  64. var operatingNozzle = this.nozzles.First(f => f.LogicalId == this.currentCallingNozzleLogicalId);
  65. //fire fuelling progress.
  66. base.FireOnCurrentFuellingStatusChangeEvent(new FdcTransaction()
  67. {
  68. Nozzle = operatingNozzle,
  69. Amount = fpRunningTrxEvent.CurrentAmount,
  70. Volumn = fpRunningTrxEvent.CurrentVolume,
  71. Price = 0,
  72. Finished = false,
  73. });
  74. break;
  75. }
  76. case FuellingTrxDb_TransactionBufferStatus_Answer trxBufferStatusAnswer:
  77. {
  78. //if (trxBufferStatusAnswer.State.HasValue
  79. // && trxBufferStatusAnswer.State == FuellingTrxDb_TransactionBufferStatus_Event.TransactionState.PAYABLE)
  80. //{
  81. logger.Debug("Pump " + this.pumpId + ", received a Payable trx from TQC with Vol and Amount(without decimal points): "
  82. + trxBufferStatusAnswer.Volume + " - " + trxBufferStatusAnswer.Amount
  83. + ", sequenceNo.: " + trxBufferStatusAnswer.TransactionSeqNumber);
  84. var operatingNozzle = this.nozzles.First(f => f.LogicalId == this.currentCallingNozzleLogicalId);
  85. base.FireOnCurrentFuellingStatusChangeEvent(new FdcTransaction()
  86. {
  87. Nozzle = operatingNozzle,
  88. Amount = trxBufferStatusAnswer.Amount,
  89. Volumn = trxBufferStatusAnswer.Volume,
  90. Price = int.Parse(trxBufferStatusAnswer.Price ?? "0"),
  91. SequenceNumberGeneratedOnPhysicalPump = trxBufferStatusAnswer.TransactionSeqNumber,
  92. VolumeTotalizer = Convert.ToInt32(trxBufferStatusAnswer.VolumeTotalizerAfterTrx ?? 0 * Math.Pow(10, this.VolumeTotalizerDecimalDigits)),
  93. Finished = true,
  94. });
  95. //}
  96. break;
  97. }
  98. case FuellingTrxDb_TransactionBufferStatus_Event trx_done_evt:
  99. {
  100. // mute this event to base which will popup a new fdc fuel trx by this event.
  101. // for this project, FuellingTrxDb_TransactionBufferStatus_Answer is the one used for popup fdc fuel trx.
  102. return Task.CompletedTask;
  103. }
  104. default:
  105. base.Process(context);
  106. break;
  107. }
  108. return Task.CompletedTask;
  109. }
  110. public override void HandleFpStatusChange(FuellingPointStatus newStatus, LogicalNozzle stateChangedNozzle)
  111. {
  112. switch (newStatus)
  113. {
  114. case FuellingPointStatus.Idle:
  115. {
  116. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_READY)
  117. {
  118. this.lastLogicalDeviceState = LogicalDeviceState.FDC_READY;
  119. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_READY, stateChangedNozzle);
  120. }
  121. break;
  122. }
  123. case FuellingPointStatus.CALLING:
  124. {
  125. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_CALLING)
  126. {
  127. this.lastLogicalDeviceState = LogicalDeviceState.FDC_CALLING;
  128. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_CALLING, stateChangedNozzle);
  129. }
  130. break;
  131. }
  132. case FuellingPointStatus.AUTHORISED:
  133. {
  134. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_AUTHORISED)
  135. {
  136. this.lastLogicalDeviceState = LogicalDeviceState.FDC_AUTHORISED;
  137. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_AUTHORISED, stateChangedNozzle);
  138. }
  139. break;
  140. }
  141. case FuellingPointStatus.STARTED:
  142. {
  143. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_STARTED)
  144. {
  145. this.lastLogicalDeviceState = LogicalDeviceState.FDC_STARTED;
  146. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_STARTED, stateChangedNozzle);
  147. }
  148. break;
  149. }
  150. case FuellingPointStatus.FUELLING:
  151. {
  152. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_FUELLING)
  153. {
  154. this.lastLogicalDeviceState = LogicalDeviceState.FDC_FUELLING;
  155. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_FUELLING, stateChangedNozzle);
  156. }
  157. break;
  158. }
  159. case FuellingPointStatus.Inoperative:
  160. {
  161. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_OFFLINE)
  162. {
  163. this.lastLogicalDeviceState = LogicalDeviceState.FDC_OFFLINE;
  164. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_OFFLINE, stateChangedNozzle);
  165. }
  166. break;
  167. }
  168. case FuellingPointStatus.Closed:
  169. {
  170. if (this.lastLogicalDeviceState != LogicalDeviceState.FDC_CLOSED)
  171. {
  172. this.lastLogicalDeviceState = LogicalDeviceState.FDC_CLOSED;
  173. this.FireOnStateChangeEvent(LogicalDeviceState.FDC_CLOSED, stateChangedNozzle);
  174. }
  175. break;
  176. }
  177. }
  178. }
  179. public override async Task<LogicalDeviceState> QueryStatusAsync()
  180. {
  181. return await Task.FromResult(base.lastLogicalDeviceState);
  182. }
  183. public override async Task<bool> AuthorizeAsync(byte logicalNozzleId)
  184. {
  185. return false;
  186. }
  187. public override async Task<bool> AuthorizeWithAmountAsync(int moneyAmountWithoutDecimalPoint, byte logicalNozzleId)
  188. {
  189. return false;
  190. }
  191. public override async Task<bool> AuthorizeWithVolumeAsync(int volumnWithoutDecimalPoint, byte logicalNozzleId)
  192. {
  193. return false;
  194. }
  195. public override async Task<bool> ChangeFuelPriceAsync(int newPriceWithoutDecimalPoint, byte logicalNozzleId)
  196. {
  197. return false;
  198. }
  199. public override async Task<bool> FuelingRoundUpByAmountAsync(int amount)
  200. {
  201. return false;
  202. }
  203. public override async Task<bool> FuelingRoundUpByVolumeAsync(int volume)
  204. {
  205. return false;
  206. }
  207. public override async Task<System.Tuple<int, int>> QueryTotalizerAsync(byte logicalNozzleId)
  208. {
  209. return new System.Tuple<int, int>(-1, -1);
  210. }
  211. }
  212. }