SendCardReaderCommandBase.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Wayne.Lib.StateEngine;
  7. using Wayne.Lib.StateEngine.Generic;
  8. using WayneChina_IcCardReader_SinoChem.MessageEntity;
  9. namespace SinochemInternetPlusApp.States.ICCardMode
  10. {
  11. public abstract class SendCardReaderCommandBase : TimeoutState<FuelingPoint>
  12. {
  13. protected byte sqNo;
  14. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  15. {
  16. base.Enter(stateEntry, ref transition);
  17. var command = CreateCommand();
  18. Main.SendCommand(command, out sqNo);
  19. }
  20. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  21. {
  22. GenericEvent<CardReaderAckEventArgs> e = stateEngineEvent as GenericEvent<CardReaderAckEventArgs>;
  23. if (e != null && e.EventArgs != null)
  24. {
  25. if (e.EventArgs.Ack.MessageSeqNumber == sqNo)
  26. {
  27. e.Handled = true;
  28. transition = new Transition(this, TransitionType.Done);
  29. }
  30. else
  31. {
  32. DebugLog($"SqNo not matched, Sent: {sqNo}, Received: {e.EventArgs.Ack.MessageSeqNumber}");
  33. e.Handled = true;
  34. transition = new Transition(this, TransitionType.Done);
  35. }
  36. }
  37. }
  38. protected override void Timeout(ref Transition transition)
  39. {
  40. transition = new Transition(this, TransitionType.Timeout);
  41. }
  42. protected abstract IcCardReaderMessageBase CreateCommand();
  43. }
  44. }