WaitForFueling.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Wayne.Lib;
  5. using Wayne.Lib.StateEngine;
  6. using Wayne.Lib.StateEngine.Generic;
  7. namespace SinochemInternetPlusApp.States.CarPlateMode
  8. {
  9. public class WaitForFueling : TimeoutState<FuelingPoint>
  10. {
  11. private byte sqNo;
  12. private bool cardReaderBackToIdle = false;
  13. private bool nozzleLifted = false;
  14. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  15. {
  16. base.Enter(stateEntry, ref transition);
  17. cardReaderBackToIdle = false;
  18. nozzleLifted = false;
  19. Main.SetICCardReaderToCarPlateIdle(out sqNo);
  20. DebugLog($"Start to set card reader back to CarPlateIdle, SqNo={sqNo}\n Waiting for Ack");
  21. }
  22. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  23. {
  24. if (stateEngineEvent.Type.Equals(EventType.NozzleLifted))
  25. {
  26. var nlEvent = stateEngineEvent as GenericEvent<NozzleLiftedEventArgs>;
  27. if (nlEvent.EventArgs.NozzleId == Main.CurrentNozzleId)
  28. {
  29. DebugLog("Nozzle correctly lifted");
  30. nozzleLifted = true;
  31. }
  32. else
  33. {
  34. DebugLog("Nozzle lifted, but the nozzle was wrong: " + nlEvent.EventArgs.NozzleId);
  35. }
  36. stateEngineEvent.Handled = true;
  37. }
  38. if (stateEngineEvent.Type.Equals(EventType.NozzleReplaced))
  39. {
  40. var nrEvent = stateEngineEvent as GenericEvent<NozzleReplacedEventArgs>;
  41. if(nrEvent.EventArgs.NozzleId != Main.CurrentNozzleId)
  42. {
  43. DebugLog("Nozzle replaced, but the nozzle was wrong: " + nrEvent.EventArgs.NozzleId);
  44. stateEngineEvent.Handled = true;
  45. }
  46. }
  47. GenericEvent<CardReaderAckEventArgs> ackEvent = stateEngineEvent as GenericEvent<CardReaderAckEventArgs>;
  48. if (ackEvent != null && ackEvent.EventArgs != null)
  49. {
  50. if (ackEvent.EventArgs.Ack.MessageSeqNumber == sqNo)
  51. {
  52. DebugLog($" Set CardReader to CarPlateIdle ack'ed, SqNo={sqNo}\n");
  53. ackEvent.Handled = true;
  54. cardReaderBackToIdle = true;
  55. }
  56. }
  57. if (stateEngineEvent.Type.Equals(EventType.TrxOpRequest))
  58. {
  59. GenericEvent<TransactionOperationEventArgs> trxOpEvent = stateEngineEvent as GenericEvent<TransactionOperationEventArgs>;
  60. if (trxOpEvent != null && trxOpEvent.EventArgs != null && Main.ActiveTrx != null)
  61. {
  62. trxOpEvent.Handled = true;
  63. if (trxOpEvent.EventArgs.TrxOp.OpType == OpType.Delete)
  64. {
  65. int trxId = trxOpEvent.EventArgs.TrxOp.TrxId;
  66. foreach (var trx in Main.ActiveTrx)
  67. {
  68. if ((trx.id == trxId) && (Main.AssociatedNozzles.Contains(trx.jihao)))
  69. {
  70. EpsTransaction.RestroeEpsTrxFrom(trx).UpdateTrxStatusToDb(EpsTrxStatus.Removed);
  71. Main.CurrentEpsTrx = null;
  72. transition = new Transition(this, TransitionType.FuelingRemoved);
  73. }
  74. }
  75. }
  76. }
  77. }
  78. if (nozzleLifted && cardReaderBackToIdle)
  79. {
  80. transition = new Transition(this, TransitionType.NozzleLifted);
  81. }
  82. }
  83. protected override void Timeout(ref Transition transition)
  84. {
  85. transition = new Transition(this, TransitionType.Timeout);
  86. }
  87. protected override int TimeoutInterval =>
  88. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_WaitForFueling, 30 * 60);
  89. }
  90. }