GilbarcoPumpHandler.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using Edge.Core.IndustryStandardInterface.Pump;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Wayne.FDCPOSLibrary;
  7. namespace Dfs.WayneChina.GilbarcoDispenserPayTerminal
  8. {
  9. public class GilbarcoPumpHandler : IFdcPumpController
  10. {
  11. #region Fields
  12. private LogicalNozzle nozzle;
  13. private LogicalDeviceState state = LogicalDeviceState.FDC_READY;
  14. #endregion
  15. #region Properties
  16. public string Name => "GilbarcoPumpHandler";
  17. public int PumpId { get; }
  18. //Always use 1, since it's controlled by the terminal.
  19. public int PumpPhysicalId => 1;
  20. public IEnumerable<LogicalNozzle> Nozzles => new List<LogicalNozzle> { nozzle };
  21. #endregion
  22. #region Decimal point settings, China domestic standard is: 2
  23. public int AmountDecimalDigits => 2;
  24. public int VolumeDecimalDigits => 2;
  25. public int PriceDecimalDigits => 2;
  26. public int VolumeTotalizerDecimalDigits => 2;
  27. #endregion
  28. #region Events
  29. public event EventHandler<FdcPumpControllerOnStateChangeEventArg> OnStateChange;
  30. public event EventHandler<FdcTransactionDoneEventArg> OnCurrentFuellingStatusChange;
  31. #endregion
  32. #region Logger
  33. private static NLog.Logger logger = NLog.LogManager.LoadConfiguration("NLog.config").GetLogger("IPosPlusApp");
  34. #endregion
  35. #region Construction
  36. public GilbarcoPumpHandler(int pumpId)
  37. {
  38. PumpId = pumpId;
  39. nozzle = new LogicalNozzle(pumpId, Convert.ToByte(pumpId), 1, null);
  40. }
  41. #endregion
  42. #region IC card terminal handler
  43. public GilbarcoPayTerminalHandler GilbarcoPayTerminalHandler { get; }
  44. #endregion
  45. #region Methods
  46. public Task<bool> AuthorizeAsync(byte logicalNozzleId)
  47. {
  48. return Task.FromResult(true);
  49. }
  50. public Task<bool> AuthorizeWithAmountAsync(int moneyAmountWithoutDecimalPoint, byte logicalNozzleId)
  51. {
  52. return Task.FromResult(true);
  53. }
  54. public Task<bool> AuthorizeWithVolumeAsync(int volumnWithoutDecimalPoint, byte logicalNozzleId)
  55. {
  56. return Task.FromResult(true);
  57. }
  58. public Task<bool> ChangeFuelPriceAsync(int newPriceWithoutDecimalPoint, byte logicalNozzleId)
  59. {
  60. throw new NotImplementedException();
  61. }
  62. public Task<bool> FuelingRoundUpByAmountAsync(int amount)
  63. {
  64. return Task.FromResult(true);
  65. }
  66. public Task<bool> FuelingRoundUpByVolumeAsync(int volume)
  67. {
  68. return Task.FromResult(true);
  69. }
  70. public Task<bool> LockNozzleAsync(byte logicalNozzleId)
  71. {
  72. return Task.FromResult(true);
  73. }
  74. public void OnFdcServerInit(Dictionary<string, object> parameters)
  75. {
  76. }
  77. public Task<LogicalDeviceState> QueryStatusAsync()
  78. {
  79. return Task.FromResult(LogicalDeviceState.FDC_READY);
  80. }
  81. public Task<Tuple<int, int>> QueryTotalizerAsync(byte logicalNozzleId)
  82. {
  83. return Task.FromResult(new Tuple<int, int>(-1, -1));
  84. }
  85. public Task<bool> ResumeFuellingAsync()
  86. {
  87. //Not supported, return false;
  88. return Task.FromResult(false);
  89. }
  90. public Task<bool> SuspendFuellingAsync()
  91. {
  92. //Not supported, return false;
  93. return Task.FromResult(false);
  94. }
  95. public Task<bool> UnAuthorizeAsync(byte logicalNozzleId)
  96. {
  97. //Not supported, return false;
  98. return Task.FromResult(false);
  99. }
  100. public Task<bool> UnlockNozzleAsync(byte logicalNozzleId)
  101. {
  102. return Task.FromResult(true);
  103. }
  104. #endregion
  105. #region Pump State and Fueling Status
  106. public void FirePumpStateChange(LogicalDeviceState state)
  107. {
  108. var logicalNozzle = new LogicalNozzle(PumpId, Convert.ToByte(PumpPhysicalId), 1, null);
  109. this.state = state;
  110. if (state == LogicalDeviceState.FDC_READY)
  111. OnStateChange?.Invoke(this, new FdcPumpControllerOnStateChangeEventArg(LogicalDeviceState.FDC_READY));
  112. else
  113. OnStateChange?.Invoke(this, new FdcPumpControllerOnStateChangeEventArg(state, logicalNozzle));
  114. }
  115. public void FireNozzleStateChange(LogicalDeviceState? state)
  116. {
  117. nozzle = new LogicalNozzle(PumpId, Convert.ToByte(PumpPhysicalId), 1, null);
  118. if (state.HasValue)
  119. nozzle.LogicalState = state;
  120. else
  121. nozzle.LogicalState = null;
  122. OnStateChange?.Invoke(this, new FdcPumpControllerOnStateChangeEventArg(LogicalDeviceState.FDC_READY, nozzle));
  123. }
  124. public void FireFuelingStatusChange(FdcTransaction fuelingTransaction)
  125. {
  126. OnCurrentFuellingStatusChange?.Invoke(this, new FdcTransactionDoneEventArg(fuelingTransaction));
  127. }
  128. #endregion
  129. }
  130. }