SendCalculateMacRequest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Wayne.Lib.StateEngine;
  2. using WayneChina_IcCardReader_SinoChem.MessageEntity;
  3. using WayneChina_IcCardReader_SinoChem.MessageEntity.Outgoing;
  4. namespace SinochemInternetPlusApp.States.ICCardMode
  5. {
  6. public class SendCalculateMacRequest : SendCardReaderCommandBase
  7. {
  8. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  9. {
  10. base.Enter(stateEntry, ref transition);
  11. CreateCommand();
  12. transition = new Transition(this, TransitionType.Done); //Transition out directly, WT30.
  13. }
  14. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  15. {
  16. //First step, an ACK expected.
  17. var e = stateEngineEvent as GenericEvent<CardReaderAckEventArgs>;
  18. if (e != null && e.EventArgs != null)
  19. {
  20. if (e.EventArgs.Ack.MessageSeqNumber == sqNo)
  21. {
  22. e.Handled = true;
  23. transition = new Transition(this, TransitionType.Done);
  24. }
  25. else
  26. {
  27. DebugLog($"SqNo not matched, Sent: {sqNo}, Received: {e.EventArgs.Ack.MessageSeqNumber}");
  28. e.Handled = true;
  29. transition = new Transition(this, TransitionType.Done);
  30. }
  31. }
  32. }
  33. protected override IcCardReaderMessageBase CreateCommand()
  34. {
  35. byte[] targetBytes = Main.GetMAC(Main.CurrentEpsTrx.Model);
  36. return new SignDataRequest(targetBytes);
  37. }
  38. protected override int TimeoutInterval =>
  39. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.ICCardMode_SendCalculateMacRequest, 10);
  40. }
  41. }