using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Wayne.Lib.StateEngine; using Wayne.Lib.StateEngine.Generic; using WayneChina_IcCardReader_SinoChem.MessageEntity; namespace SinochemInternetPlusApp.States.ICCardMode { public abstract class SendCardReaderCommandBase : TimeoutState { protected byte sqNo; protected override void Enter(StateEntry stateEntry, ref Transition transition) { base.Enter(stateEntry, ref transition); var command = CreateCommand(); Main.SendCommand(command, out sqNo); } protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition) { GenericEvent e = stateEngineEvent as GenericEvent; if (e != null && e.EventArgs != null) { if (e.EventArgs.Ack.MessageSeqNumber == sqNo) { e.Handled = true; transition = new Transition(this, TransitionType.Done); } else { DebugLog($"SqNo not matched, Sent: {sqNo}, Received: {e.EventArgs.Ack.MessageSeqNumber}"); e.Handled = true; transition = new Transition(this, TransitionType.Done); } } } protected override void Timeout(ref Transition transition) { transition = new Transition(this, TransitionType.Timeout); } protected abstract IcCardReaderMessageBase CreateCommand(); } }