예제 #1
0
파일: kl_lib_f0.cpp 프로젝트: Kreyl/nute
void CmdUnit_t::IRQHandler() {
    if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {
        char b = USART1->DR;
        if (b != '\n') switch (CmdState) {  // Ignore \n
            case csNone:
                RXBuf[RxIndx++] = b;
                CmdState = csInProgress;
                break;
            case csInProgress:
                // Check if end of cmd
                if (b == '\r') {
                    CmdState = csReady;
                    RXBuf[RxIndx] = 0;
                }
                else {
                    RXBuf[RxIndx++] = b;
                    // Check if too long
                    if (RxIndx == UART_RXBUF_SIZE) CmdReset();
                }
                break;
            case csReady:   // New byte received, but command still not handled
                break;
        } // switch
    } // if rx
}
예제 #2
0
파일: qUAck-unix.cpp 프로젝트: rjp/qUAck
void CmdStartup(int iSignal)
{
   // short iBackground = COLOR_BLACK, iForeground = COLOR_WHITE;
   // short iF = -1, iB = -1;
   // int iColourNum = 0;

   debug(DEBUGLEVEL_INFO, "CmdStartup entry\n");

   /* if(iSignal == SIGWINCH)
   {
      endwin();

      (*m_pSIGWINCH)(SIGWINCH);
   } */

   if(iSignal != SIGWINCH)
   {
      debug(DEBUGLEVEL_INFO, "CmdStartup init\n");
      initialise_curses();
   }
   else
   {
   /*   (*m_pSIGWINCH)(SIGWINCH); */
      debug(DEBUGLEVEL_INFO, "CmdStartup SIGWINCH\n");
      resize_curses();
   }

   CmdReset(iSignal);

   /* reset the signal */
//   m_pSIGWINCH = signal(SIGWINCH, CmdStartup);
   debug(DEBUGLEVEL_INFO, "CmdStartup exit\n");
}
예제 #3
0
s3DWindow::s3DWindow()
{
  SetEnable(1);

  DragDist = 1.0f;
  GridColor = 0xffffffff;
  CmdReset();
  ScreenshotFlag = 0;
  GearShift = 0;
  GearSpeed = 1;
  GearShiftDisplay = 0;
  GridUnit = 0;

  WireMtrl = new sSimpleMaterial;
  //WireMtrl = new sMaterialBasic;
  WireMtrl->Flags = sMTRL_ZON|sMTRL_CULLON;
  WireMtrl->Prepare(sVertexFormatBasic);
  WireMtrlNoZ = new sSimpleMaterial;
  //WireMtrlNoZ = new sMaterialBasic;
  WireMtrlNoZ->Flags = sMTRL_ZOFF;
  WireMtrlNoZ->Prepare(sVertexFormatBasic);
  WireGeo = new sGeometry;
  WireGeo->Init(sGF_LINELIST,sVertexFormatBasic);

  QuakeSpeed.Init(0,0,0);
  QuakeMask = 0;
  Continuous = 1;
  QuakeTime = sGetTime();

  SideSpeed = ForeSpeed = 0.000020f;
  SpeedDamping = 0.995f;

#if sRENDERER==sRENDER_DX11
  ColorRT = 0;
  DepthRT = 0;
#endif
}
예제 #4
0
NTSTATUS
CBCardPower(
           PSMARTCARD_EXTENSION SmartcardExtension
           )
/*++

CBCardPower:
        callback handler for SMCLIB RDF_CARD_POWER

Arguments:
        SmartcardExtension      context of call

Return Value:
        STATUS_SUCCESS
        STATUS_NO_MEDIA
        STATUS_TIMEOUT
        STATUS_BUFFER_TOO_SMALL

--*/
{
    NTSTATUS                        NTStatus = STATUS_SUCCESS;
    UCHAR                           ATRBuffer[ ATR_SIZE ], TLVList[16];
    ULONG                           Command,
    ATRLength = 0;
    PREADER_EXTENSION       ReaderExtension;
    BYTE                CardState;
    KIRQL               irql;
#if DBG || DEBUG
    static PCHAR request[] = { "PowerDown",  "ColdReset", "WarmReset"};
#endif

    SmartcardDebug(
                  DEBUG_TRACE,
                  ( "PSCR!CBCardPower: Enter, Request = %s\n",
                    request[SmartcardExtension->MinorIoControlCode])
                  );

    ReaderExtension = SmartcardExtension->ReaderExtension;

        //
        //      update actual power state
        //
    Command = SmartcardExtension->MinorIoControlCode;

    switch ( Command ) {
    case SCARD_WARM_RESET:

        //      if the card was not powerd, fall thru to cold reset
        KeAcquireSpinLock(&SmartcardExtension->OsData->SpinLock,
                          &irql);

        if ( SmartcardExtension->ReaderCapabilities.CurrentState >
             SCARD_SWALLOWED ) {
            KeReleaseSpinLock(&SmartcardExtension->OsData->SpinLock,
                              irql);

                                //      reset the card
            ATRLength = ATR_SIZE;
            NTStatus = CmdReset(
                               ReaderExtension,
                               ReaderExtension->Device,
                               TRUE,                           // warm reset
                               ATRBuffer,
                               &ATRLength
                               );

            break;
        } else {
            KeReleaseSpinLock(&SmartcardExtension->OsData->SpinLock,
                              irql);

        }

                        //      warm reset not possible because card was not powerd
    case SCARD_COLD_RESET:

                        //      reset the card
        ATRLength = ATR_SIZE;
        NTStatus = CmdReset(
                           ReaderExtension,
                           ReaderExtension->Device,
                           FALSE,                          // cold reset
                           ATRBuffer,
                           &ATRLength
                           );
        break;

    case SCARD_POWER_DOWN:
        ATRLength = 0;
        NTStatus = CmdDeactivate(
                                ReaderExtension,
                                ReaderExtension->Device
                                );

                        //      discard old card status
        CardState = CBGetCardState(SmartcardExtension);
        CBUpdateCardState(SmartcardExtension, CardState, FALSE);
        break;
    }

    if (NT_SUCCESS(NTStatus)) {

        //
        // Set the 'restart of work waiting time' counter for T=0
        // This will send a WTX request for n NULL bytes received
        //
        TLVList[0] = TAG_SET_NULL_BYTES;
        TLVList[1] = 1;
        TLVList[2] = 0x05;

        NTStatus = CmdSetInterfaceParameter(
                                           ReaderExtension,
                                           DEVICE_READER,
                                           TLVList,
                                           3
                                           );
    }

    // Removing this assert as this causes unnecessary confusion.  The driver
    // passes ifdtest even with an error here.
    // NT_ASSERT(NT_SUCCESS(NTStatus));

        //      finish the request
    if ( NT_SUCCESS( NTStatus )) {
                //      update all neccessary data if an ATR was received
        if ( ATRLength > 2 ) {
                        //
                        //      the lib expects only the ATR, so we skip the
                        //      900x from the reader
                        //
            ATRLength -= 2;

                        //      copy ATR to user buffer buffer
            if ( ATRLength <= SmartcardExtension->IoRequest.ReplyBufferLength ) {
                SysCopyMemory(
                             SmartcardExtension->IoRequest.ReplyBuffer,
                             ATRBuffer,
                             ATRLength
                             );
                *SmartcardExtension->IoRequest.Information = ATRLength;
            }

                        //      copy ATR to card capability buffer
            if ( ATRLength <= MAXIMUM_ATR_LENGTH ) {
                SysCopyMemory(
                             SmartcardExtension->CardCapabilities.ATR.Buffer,
                             ATRBuffer,
                             ATRLength
                             );

                SmartcardExtension->CardCapabilities.ATR.Length =
                ( UCHAR )ATRLength;

                                //      let the lib update the card capabilities
                NTStatus = SmartcardUpdateCardCapabilities(
                                                          SmartcardExtension
                                                          );
            } else {
                NTStatus = STATUS_BUFFER_TOO_SMALL;
            }
        }
    }

    if ( !NT_SUCCESS( NTStatus )) {
        switch ( NTStatus ) {
        case STATUS_NO_MEDIA:
        case STATUS_BUFFER_TOO_SMALL:
            break;

        case STATUS_TIMEOUT:
            NTStatus = STATUS_IO_TIMEOUT;
            break;

        default:
            NTStatus = STATUS_UNRECOGNIZED_MEDIA;
            break;
        }
        if( NTStatus != STATUS_SUCCESS )
        {

            // notify resman if card was removed
            CBUpdateCardState(
                SmartcardExtension,
                CBGetCardState( SmartcardExtension ),
                FALSE
                );

            // resman requires status ok to translate ntstatus to scard... error.
            if( SmartcardExtension->ReaderCapabilities.CurrentState <= SCARD_ABSENT )
            {
                SmartcardUpdateCardCapabilities( SmartcardExtension );
                NTStatus = STATUS_SUCCESS;
            }
        }
    }

    // start freeze routine, if an interrupt was sent, but no freeze data was read
    if( SmartcardExtension->ReaderExtension->RequestInterrupt )
        PscrFreeze( SmartcardExtension );

    // Clearing the buffers
    RtlZeroMemory (ATRBuffer, ATR_SIZE);
    RtlZeroMemory (TLVList, 16);

    SmartcardDebug(
                  DEBUG_TRACE,
                  ( "PSCR!CBCardPower: Exit (%lx)\n", NTStatus )
                  );

    return( NTStatus );
}
예제 #5
0
파일: kl_lib_f0.cpp 프로젝트: Kreyl/nute
void CmdUnit_t::Task() {
    if (CmdState == csReady) {
        NewCmdHandler();
        CmdReset();
    }
}
예제 #6
0
파일: main.cpp 프로젝트: Kreyl/nute
// ========================== Commands handling ================================
void CmdUnit_t::Task() {
    static bool FieldIsOn = false;
    if (CmdState == csReady) {
        // Switch field generator on
        CoilA.Enable();
        CoilB.Enable();
        Delay.Reset(&ITimer);
        FieldIsOn = true;

        // ==== Handle cmd ====
        // Get state
        if (RXBuf[0] == 'S') {    // Get state: "service code","CodeA","CodeB", "Complexity"
            Print2Buf("S:%S,%S,%S,%S\r", Settings.ServiceCode, Settings.CodeA, Settings.CodeB, Settings.Complexity);
        }

        // Kick
        if (RXBuf[0] == 'K') Print2Buf("K\r");

        // Open door
        else if (RXBuf[0] == 'O') {
            if (Door.State == dsClosed) Door.Open();
            Print2Buf("O\r");
        }
        // Close door
        else if (RXBuf[0] == 'C') {
            if (Door.State == dsOpened) Door.Close();
            Print2Buf("C\r");
        }

        // Replace codeA
        else if (RXBuf[0] == 'A') {
            if (RXBuf[1] == ':') {
                if ((RXBuf[2] == 0) || (RXBuf[2] == 'N')) { // Check if empty or None
                    Settings.CodeA[0] = 0;
                    Settings.CodeALength = 0;
                }
                else {
                    strncpy(Settings.CodeA, (char*)&RXBuf[2], 4);
                    if (RXBuf[2] == '-') Settings.CodeALength = -1;
                    else Settings.CodeALength = strlen(Settings.CodeA);
                }
                Print2Buf("A\r");
            }
        }

        // Replace codeB
        else if (RXBuf[0] == 'B') {
            if (RXBuf[1] == ':') {
                if ((RXBuf[2] == 0) || (RXBuf[2] == 'N')) { // Check if empty or None
                    Settings.CodeB[0] = 0;
                    Settings.CodeBLength = 0;
                }
                else {
                    strncpy(Settings.CodeB, (char*)&RXBuf[2], 4);
                    if (RXBuf[2] == '-') Settings.CodeBLength = -1;
                    else Settings.CodeBLength = strlen(Settings.CodeB);
                }
                Print2Buf("B\r");
            }
        }

        // Replace service code
        else if (RXBuf[0] == 'V') {
            if (RXBuf[1] == ':') {
                strncpy(Settings.ServiceCode, (char*)&RXBuf[2], 6);
                Print2Buf("V\r");
            }
        }
        CmdReset();
    } // if ready

    // Check if shutdown field generator
    if (FieldIsOn) if (Delay.Elapsed(&ITimer, FIELD_GENERATOR_TIMEOUT)) {
        CoilA.Disable();
        CoilB.Disable();
        FieldIsOn = false;
    }
}