public SiDriver(ISiPort siPort, SiHandler siHandler) { this.siPort = siPort; messageQueue = siPort.CreateMessageQueue(); writer = siPort.CreateWriter(); this.siHandler = siHandler; }
private static SiDriverState DispatchSicard8Plus(SiMessage message, SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { if (message.Sequence(SiMessage.SI3_NUMBER_INDEX) == SiMessage.SI_CARD_10_PLUS_SERIES) { return(RETRIEVE_SICARD_10_PLUS_DATA.Retrieve(queue, writer, siHandler)); } return(RETRIEVE_SICARD_8_9_DATA.Retrieve(queue, writer, siHandler)); }
public virtual SiDriverState Send(ICommWriter writer, SiHandler siHandler) { WrongCall(); return(this); }
public override SiDriverState Receive(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { try { PollAnswer(queue, SiMessage.SI_CARD_REMOVED); return(DISPATCH_READY); } catch (TimeoutException e) { GecoSiLogger.Info("Timeout on SiCard removal"); return(DISPATCH_READY); } catch (InvalidMessage e) { return(ErrorFallback(siHandler, "Invalid message: " + e.ReceivedMessage())); } }
public override SiDriverState Send(ICommWriter writer, SiHandler siHandler) { writer.Write(SiMessage.STARTUP_SEQUENCE); return(STARTUP_CHECK); }
public override SiDriverState Receive (SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { PollAnswer(queue, SiMessage.SET_MASTER_MODE); return(GET_CONFIG.Send(writer, siHandler)); }
public override SiDriverState Send(ICommWriter writer, SiHandler siHandler) { writer.Write(SiMessage.BEEP_TWICE); siHandler.Notify(CommStatus.On); return(DISPATCH_READY); }
public override SiDriverState Receive(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { SiMessage message = PollAnswer(queue, SiMessage.GET_SYSTEM_VALUE); si6_192PunchesMode = (message.Sequence(6) & 0xFF) == 0xFF; GecoSiLogger.Info("SiCard6 192 Punches Mode " + (si6_192PunchesMode ? "Enabled" : "Disabled")); return(STARTUP_COMPLETE.Send(writer, siHandler)); }
protected SiDriverState ErrorFallback(SiHandler siHandler, String errorMessage) { GecoSiLogger.Error(errorMessage); siHandler.Notify(CommStatus.ProcessingError); return(DISPATCH_READY); }
public override SiDriverState Retrieve(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { int nbPunchesIndex = Si6DataFrame.NB_PUNCHES_INDEX + 6; return(RetrieveDataMessages(queue, writer, siHandler, readoutCommands, nbPunchesIndex, "Timeout on retrieving SiCard 6 data")); }
public override SiDriverState Send(ICommWriter writer, SiHandler siHandler) { writer.Write(SiMessage.GET_CARDBLOCKS_CONFIGURATION); return(SI6_CARDBLOCKS_SETTING); }
public override SiDriverState Send(ICommWriter writer, SiHandler siHandler) { writer.Write(SiMessage.GET_PROTOCOL_CONFIGURATION); return(CONFIG_CHECK); }
public override SiDriverState Receive(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { siHandler.Notify(CommStatus.Ready); SiMessage message = queue.Take(); siHandler.Notify(CommStatus.Processing); if (!message.Valid()) { return(DISPATCH_READY); } if (message.CommandByte() == SiMessage.SI_CARD_5_DETECTED || message.CommandByte() == SiMessage.SI_CARD_6_PLUS_DETECTED || message.CommandByte() == SiMessage.SI_CARD_8_PLUS_DETECTED) { var bytes = new ByteFrame(message.Data()); if (!siHandler.OnEcardDown(bytes.Block3At(5).ToString())) { return(ACK_READ.Send(writer, siHandler)); } } switch (message.CommandByte()) { case SiMessage.SI_CARD_5_DETECTED: return(RETRIEVE_SICARD_5_DATA.Retrieve(queue, writer, siHandler)); case SiMessage.SI_CARD_6_PLUS_DETECTED: return(RETRIEVE_SICARD_6_DATA.Retrieve(queue, writer, siHandler)); case SiMessage.SI_CARD_8_PLUS_DETECTED: return(DispatchSicard8Plus(message, queue, writer, siHandler)); case SiMessage.BEEP: break; case SiMessage.SI_CARD_REMOVED: GecoSiLogger.Debug("Late removal " + message); break; default: GecoSiLogger.Debug("Unexpected message " + message); break; } return(DISPATCH_READY); }
public override SiDriverState Receive(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { SiMessage message = PollAnswer(queue, SiMessage.GET_SYSTEM_VALUE); byte cpcByte = message.Sequence(6); if ((cpcByte & CONFIG_CHECK_MASK) == CONFIG_CHECK_MASK) { return(GET_SI6_CARDBLOCKS.Send(writer, siHandler)); } if ((cpcByte & EXTENDED_PROTOCOL_MASK) == 0) { return(EXTENDED_PROTOCOL_ERROR); } return(HANDSHAKE_MODE_ERROR); }
public override SiDriverState Send(ICommWriter writer, SiHandler siHandler) { writer.Write(SiMessage.ACK_SEQUENCE); return(WAIT_SICARD_REMOVAL); }
public virtual SiDriverState Retrieve(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { WrongCall(); return(this); }
public override SiDriverState Retrieve(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler) { return(RetrieveDataMessages(queue, writer, siHandler, new[] { SiMessage.READ_SICARD_8_PLUS_B0, SiMessage.READ_SICARD_8_PLUS_B1 }, -1, "Timeout on retrieving SiCard 8/9 data")); }
protected SiDriverState RetrieveDataMessages(SiMessageQueue queue, ICommWriter writer, SiHandler siHandler, SiMessage[] readoutCommands, int nbPunchesIndex, String timeoutMessage) { try { GecoSiLogger.StateChanged(GetType().Name); SiMessage readoutCommand = readoutCommands[0]; writer.Write(readoutCommand); SiMessage firstDataBlock = PollAnswer(queue, readoutCommand.CommandByte()); int nbDataBlocks = (nbPunchesIndex == -1) ? readoutCommands.Length : ExtractNumberOfDataBlocks(firstDataBlock, nbPunchesIndex); var dataMessages = new SiMessage[nbDataBlocks]; dataMessages[0] = firstDataBlock; for (int i = 1; i < nbDataBlocks; i++) { readoutCommand = readoutCommands[i]; writer.Write(readoutCommand); dataMessages[i] = PollAnswer(queue, readoutCommand.CommandByte()); } siHandler.Notify(CreateDataFrame(dataMessages)); return(ACK_READ.Send(writer, siHandler)); } catch (TimeoutException e) { return(ErrorFallback(siHandler, timeoutMessage)); } catch (InvalidMessage e) { return(ErrorFallback(siHandler, "Invalid message: " + e.ReceivedMessage())); } }