Exemplo n.º 1
0
/***    void ServerSetup()
 *
 *    Parameters:
 *          None
 *              
 *    Return Values:
 *          None
 *
 *    Description: 
 *    
 *      Initialized the Web Server Network parameters
 *      
 *      
 * ------------------------------------------------------------ */
void ServerSetup(void) 
{
    uint32_t i = 0;

    // Set the LED off, for not initialized
    //pinMode(PIN_LED_SAFE, OUTPUT);
    SetLED(SLED::NOTREADY);     

#if defined(USING_WIFI)
    state = WIFISCAN;          // Scan WiFi First, verify the WiFi connection
    xil_printf("Start WiFi Scan\r\n");
    RestartTimer();
    cNetworks = 0;
#else
    state = DYNAMICIPBEGIN;         // just start with the wired network
#endif

    SetTimeout(cSecDefault);
    stateNext = RESTARTREST;
    stateTimeOut = RESTARTREST;
    RestartTimer();

    cSecRest = cSecInitRest;

    // make sure no clients appear to be in use
    for(i=0; i<cMaxSocketsToListen; i++)
    {
        rgClient[i].pTCPClient = NULL;
        rgTCPClient[i].close();
    }
    cWorkingClients = 0;

    // initialize our temp DNS array
    // initialize them all to the Google NS
    // that way there is something in all of the slots
    // this will get over written if DHCP is used.
    for(i=0; i<sizeof(rgTempDNS)/sizeof(IPv4); i++)
    {
        if((i % 2) == 0)
        {
            rgTempDNS[i].u32 = 0x04040808; // Google public DNS server
        }
        else
        {
            rgTempDNS[i].u32 = 0x08080808; // Google public DNS server
        }
    }

    // now put in the ones that were requested
    memcpy(rgTempDNS, rgIpDNS, min(sizeof(rgTempDNS), sizeof(rgIpDNS)));

    if(sizeof(rgIpDNS) < sizeof(rgTempDNS))
    {
        rgTempDNS[sizeof(rgIpDNS)/sizeof(IPv4)] = ipGateway;
    }
 }
Exemplo n.º 2
0
void SupervisionListener::SetTimeout(uint16_t aTimeout)
{
    if (mTimeout != aTimeout)
    {
        mTimeout = aTimeout;
        RestartTimer();
    }
}
Exemplo n.º 3
0
void PodcastUpdater::ReloadSettings() {
  QSettings s;
  s.beginGroup(kSettingsGroup);

  last_full_update_ = s.value("last_full_update").toDateTime();
  update_interval_secs_ = s.value("update_interval_secs").toInt();

  RestartTimer();
}
Exemplo n.º 4
0
bool RestartTimerCB(const CVar* hook, const char* newval)
{
	if (! newval)
		return false;

	RestartTimer(atoi(newval));
	
	return true;
}
Exemplo n.º 5
0
void SupervisionListener::HandleTimer(void)
{
    VerifyOrExit((Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_CHILD) &&
                 (Get<MeshForwarder>().GetRxOnWhenIdle() == false));

    otLogWarnUtil("Supervision timeout. No frame from parent in %d sec", mTimeout);

    Get<Mle::MleRouter>().SendChildUpdateRequest();

exit:
    RestartTimer();
}
Exemplo n.º 6
0
void SupervisionListener::UpdateOnReceive(const Mac::Address &aSourceAddress, bool aIsSecure)
{
    // If listener is enabled and device is a child and it received a secure frame from its parent, restart the timer.

    VerifyOrExit(mTimer.IsRunning() && aIsSecure && (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_CHILD) &&
                 (Get<Mle::MleRouter>().GetNeighbor(aSourceAddress) == Get<Mle::MleRouter>().GetParent()));

    RestartTimer();

exit:
    return;
}
Exemplo n.º 7
0
void ModemGSM_ProcessaMensagens( BYTE bData ){
  RestartTimer( ModemGSM_TimerHandle, MODEMGSM_TIMEROVF );

  if ( ModemGSM_DataCounter >= /*sizeof( ModemGSM_Buffer )*/ BUFFER_GSM_LEN - 1 ){
    ModemGSM_DataCounter = 0;
  }  

  ModemGSM_Buffer[ModemGSM_DataCounter] = bData;
  ModemGSM_DataCounter++;
  
  return;
}
Exemplo n.º 8
0
void HandleTimer(void)
{
    WaitIO((struct IORequest *)glob->timereq);
    glob->timer_active = 0;
    if (glob->restart_timer) {
        D(bug("Timer restart queued\n"));
        glob->restart_timer = 0;
        RestartTimer();
    } else {
        D(bug("Updating disk\n"));
        UpdateDisk();
    }
}
Exemplo n.º 9
0
void SupervisionListener::HandleTimer(void)
{
    ThreadNetif &netif = GetNetif();

    VerifyOrExit((netif.GetMle().GetRole() == OT_DEVICE_ROLE_CHILD) &&
                 (netif.GetMeshForwarder().GetRxOnWhenIdle() == false));

    otLogWarnUtil(netif.GetInstance(), "Supervision timeout. No frame from parent in %d sec", mTimeout);

    netif.GetMle().SendChildUpdateRequest();

exit:
    RestartTimer();
}
Exemplo n.º 10
0
void PodcastUpdater::PodcastLoaded(PodcastUrlLoaderReply* reply, const Podcast& podcast,
                                   bool one_of_many) {
  reply->deleteLater();

  if (one_of_many) {
    if (--pending_replies_ == 0) {
      // This was the last reply we were waiting for.  Save this time as being
      // the last sucessful update and restart the timer.
      last_full_update_ = QDateTime::currentDateTime();
      SaveSettings();
      RestartTimer();
    }
  }

  if (!reply->is_success()) {
    qLog(Warning) << "Error fetching podcast at" << podcast.url() << ":"
                  << reply->error_text();
    return;
  }

  if (reply->result_type() != PodcastUrlLoaderReply::Type_Podcast) {
    qLog(Warning) << "The URL" << podcast.url() << "no longer contains a podcast";
    return;
  }

  // Get the episode URLs we had for this podcast already.
  QSet<QUrl> existing_urls;
  foreach (const PodcastEpisode& episode,
           app_->podcast_backend()->GetEpisodes(podcast.database_id())) {
    existing_urls.insert(episode.url());
  }

  // Add any new episodes
  PodcastEpisodeList new_episodes;
  foreach (const Podcast& reply_podcast, reply->podcast_results()) {
    foreach (const PodcastEpisode& episode, reply_podcast.episodes()) {
      if (!existing_urls.contains(episode.url())) {
        PodcastEpisode episode_copy(episode);
        episode_copy.set_podcast_database_id(podcast.database_id());
        new_episodes.append(episode_copy);
      }
    }
  }

  app_->podcast_backend()->AddEpisodes(&new_episodes);
  qLog(Info) << "Added" << new_episodes.count() << "new episodes for" << podcast.url();
}
Exemplo n.º 11
0
BYTE ModemGSM_Off( void ){
  BYTE bTimer;
  bTimer = GetTimer( DELAY_POWER_OFF );

  if ( GSM_STATUS == 1 ){
    GSM_PWRKEY_OFF();
    delay( 2000 );
    GSM_PWRKEY_ON();
  
    RestartTimer( bTimer, DELAY_POWER_OFF );

    do{
    } while( (IsTimerTimeOut( bTimer ) == FALSE) && (GSM_STATUS == 1));
    ModemGSM_ResetStateSIMCARD();

  }
  ReleaseTimer( &bTimer );
  return TRUE;
}
Exemplo n.º 12
0
void ProcessaCMD_SONDA( BYTE * buffer ){
#ifdef USE_SONDA
  BYTE bufOut[4];
  BYTE bLog;

  if ( !IsConnected() ){
    return;          
  }
  
  bLog = EVT_SW_SONDA;
  Log( EVT_SW, &bLog, sizeof( BYTE ));

  RestartTimer( serialPC_SondaTimer, SONDA_TIMEOUT );

  MakeHeader( bufOut, sizeof( bufOut ), buffer[EO_FIELD], CMD_SONDA );

  enviarPacotePC( bufOut, sizeof( bufOut ));
#endif
}
Exemplo n.º 13
0
void SupervisionListener::Start(void)
{
    RestartTimer();
}
Exemplo n.º 14
0
void ModemGSM_ChangeCheckONOFFTimer( DWORD dwTime )
{
  RestartTimer( timerCheckONOFF, dwTime );
  return;
}
Exemplo n.º 15
0
void CheckGSM_ONOffState( void ){

  static BYTE bState_ONOffState = 0;
  BYTE bDevState = 0xFF;

//  if ( timer == TIMER_NULL ){
//    timer = GetTimer( TIMEOUT_START_MODEM );
//  }

  switch( bState_ONOffState ) {
    case 0:
      if ( IsTimerTimeOut( timerCheckONOFF ) == TRUE ){       
        if ( ModemGSM_IsReady() == FALSE ){
          bState_ONOffState = 1;
          return;
        }
        RestartTimer( timerCheckONOFF, TIMEOUT_CHECK_ONOFF );
      }
      return;

    case 1:
      if ( ModemGSM_IsReady() == FALSE ) {
        if( ModemGSM_IsOn() == TRUE ){
          switch( ModemGSM_OffNoBlk() ){
            case GSM_OK            :
              //Dev_ChangeState( DEV_GSM_PWR_KEY, OFF );
              bState_ONOffState = 2;
              return;

            case GSM_IDLE          :
              return;

            case GSM_MODEM_ERROR   :
            case GSM_MODEM_NTENPT  :
            case GSM_MODEM_TIMEOUT :
              bState_ONOffState = 0;
              RestartTimer( timerCheckONOFF, TIMEOUT_CHECK_ONOFF );
              return;
          }
        }
      }
      else{
        bState_ONOffState = 0;
        RestartTimer( timerCheckONOFF, TIMEOUT_CHECK_ONOFF );
        return;
      }

    case 2:
      if ( ModemGSM_IsReady() == FALSE ){
        switch( ModemGSM_OnNoBlk() ){
            case GSM_OK            :
              bState_ONOffState = 0;
              ReleaseTimer( &timerCheckONOFF );
              //Dev_ChangeState( DEV_GSM_PWR_KEY, ON );
              return;

            case GSM_IDLE          :
              return;

            case GSM_MODEM_ERROR   :
            case GSM_MODEM_NTENPT  :
            case GSM_MODEM_TIMEOUT :
              bState_ONOffState = 0;
              RestartTimer( timerCheckONOFF, TIMEOUT_CHECK_ONOFF );
              return;
        }    
      }
      else{
        bState_ONOffState = 0;
        RestartTimer( timerCheckONOFF, TIMEOUT_CHECK_ONOFF );
        return;
      }
      return; 
  }
  return;
}
Exemplo n.º 16
0
BYTE ModemGSM_OffNoBlk( void ){
  BYTE bTmp;
  static BYTE           bState = 0;
  static TIMER_HANDLE   bTimer = TIMER_NULL;
#ifndef _BAUDRATE_AUTOBAUD
  return TRUE;
#else

  //! há um erro na atualização da variável bState_OffNoBlk. Após o módulo retornar GSM_OK


  switch( bState ){
    case 0:
      //!
      //! desliga o PowerKey
      //!
      if ( bTimer != TIMER_NULL ){
        ReleaseTimer( &bTimer );
      }
      
      if ( bTimer == TIMER_NULL ){
        bTimer = GetTimer( 2000 /*DELAY_POWER_OFF*/ );
      }

      bState = 1;
      GSM_PWRKEY_OFF();
      
      return GSM_IDLE;

    case 1:
      // espera tempo de desligamento do powerkey
      if ( IsTimerTimeOut( bTimer ) == TRUE ){
        RestartTimer( bTimer, DELAY_POWER_OFF );
        GSM_PWRKEY_ON();
        bState = 100;
      }
      return GSM_IDLE;

      case 100:
        //!
        //! Espera o tempo para GSM_STATUS (VDD_EXT) ir para o nível lógico 0
        //!
        bTmp = GSM_STATUS;
        if ( (IsTimerTimeOut( bTimer ) == TRUE) || (GSM_STATUS == 0) ) {
          if ( GSM_STATUS == 0 ) {
            bState = 0;
            ReleaseTimer( &bTimer );
            //teste
            ModemGSM_Ready = FALSE;
            CleanStatus( ST_MODEM_RDY );
            //teste
            return GSM_OK;
          }
          //else
          //{
          //  // reinicia o processo de desligar o modem
          //  bState_OffNoBlk = 0; 
          //}
        }
        return GSM_IDLE;


      default:
        if ( bTimer != TIMER_NULL ){
          bState = 0;
          ReleaseTimer( &bTimer );
        }
        return GSM_MODEM_ERROR;
  }
  return GSM_IDLE;
#endif
}
Exemplo n.º 17
0
BYTE ModemGSM_OnNoBlk( void ){

#ifndef _BAUDRATE_AUTOBAUD
  return TRUE;
#else

  char cBuffer[16];
  static BYTE contTent = 0;
  static BYTE bState = 0;
  static TIMER_HANDLE bTimer = TIMER_NULL;

  if ( contTent > 4 ) {
    contTent = 0;
    return GSM_MODEM_NTENPT;    
  }

  switch( bState ){
    case 0:
      if ( bTimer == TIMER_NULL ){
        bTimer = GetTimer( DELAY_POWER_ON );
      }

      GSM_PWRKEY_OFF();     // coloca o PWR_KEY para nível zero. 
      bState = 1;
      return GSM_IDLE;

    case 1 :
     if ( IsTimerTimeOut( bTimer ) == TRUE ) {
        // ocorreu o timeout da operação com o modem
        // deve verificar o valor de GSM_STATUS
        GSM_PWRKEY_ON();
        contTent++;

        if ( GSM_STATUS == 0 ){
          // não foi possível ligar o modem.
          delay( 10 );
          GSM_PWRKEY_OFF();
          bState = 2;
          bTimer = GetTimer( DELAY_POWER_ON );
          return GSM_IDLE;
        }
        else{
          contTent = 0;
          bState = 3;
          RestartTimer( bTimer, TIMEOUT_START_MODEM );
          return GSM_IDLE;
        }
     }

    case 2:
      if ( IsTimerTimeOut( bTimer ) == TRUE ){ 
        bState = 1; 
      }
      return GSM_IDLE;


    case 3:
      
      if ( IsTimerTimeOut( bTimer ) == TRUE ){
        
        // Send a .AT. string to modem to detect the baudrate
        strcpypgm2ram( (char*)cBuffer, (const MEM_MODEL rom char*)".AT." );
        ModemGSM_SendATCMD( (BYTE*)cBuffer, strlen( cBuffer ) );   

        RestartTimer( bTimer, TIMEOUT_START_MODEM );
        bState = 4;
      }
      return GSM_IDLE;
  
    case 4:
      if ( IsTimerTimeOut( bTimer ) == TRUE ){
        
        // Send a .AT. string to modem to detect the baudrate
        strcpypgm2ram( (char*)cBuffer, (const MEM_MODEL rom char*)"AT+IPR=?\r\n" );
        ModemGSM_SendATCMD( (BYTE*)cBuffer, strlen( cBuffer ) );

        bState = 5;
        RestartTimer( bTimer, 10000 );        
      }
      return GSM_IDLE;

    case 5:
      
      if ( (IsTimerTimeOut( bTimer ) == TRUE) || ( ModemGSM_IsReady( ) == TRUE ) ){
        ReleaseTimer( &bTimer );
        bState = 0;

        if ( ModemGSM_IsReady( ) == TRUE ) {
          SetStatus( ST_MODEM_RDY );
          return GSM_OK;
        }        
        else{
          return GSM_MODEM_TIMEOUT;      
        }
      }
      return GSM_IDLE;

    default:
      return GSM_MODEM_ERROR;
  }
#endif
}
Exemplo n.º 18
0
/***    void ProcessServer()
 *
 *    Parameters:
 *          None
 *              
 *    Return Values:
 *          None
 *
 *    Description: 
 *    
 *      This is the main server loop. It:
 *          1. Scans for WiFi connections
 *          2. Connects to a WiFi by SSID
 *          3. Optionally creates a server IP on the detected subnet and dynamically assigns DNS and subnets.
 *          4. Or uses the static IP you assign; then you must supply DNS and subnet
 *          5. Starts listening on the supplied server port.
 *          6. Accepts client connections
 *          7. Schedules the processing on client connections in a round robin yet fashion (cooperative execution).
 *          8. Automatically restart if the network goes down
 *      
 *      This illistrates how to write a state machine like loop
 *      so that the PeriodicTask is called everytime through the loop
 *      so the stack stay alive and responsive.
 *
 *      In the loop we listen for a request, verify it to a limited degree
 *      and then broadcast the Magic Packet to wake the request machine.
 *      
 * ------------------------------------------------------------ */
void ProcessServer(void)
{   
    uint32_t i               = 0;

  // see if we exceeded our timeout value.
  // then just be done and close the socket 
  // by default, a closed client is never connected
  // so it is safe to call isConnected() even if it is closed 
  if(stateTimeOut != NONE && TooMuchTime())
  {
	  xil_printf("Timeout occured\r\n");
    state = stateTimeOut;
    stateTimeOut = NONE;
    stateNext = RESTARTREST;
  }

  switch(state)
  {    

#if defined(USING_WIFI)

        case WIFISCAN:
            if(deIPcK.wfScan(&cNetworks, &status))
            {
            	xil_printf("Scan Done, %d Networks Found\r\n", cNetworks);
                state = PRINTAPINFO;
                RestartTimer();
                iNetwork = 0;
            }
            else if(IsIPStatusAnError(status))
            {
            	xil_printf("Scan Failed\r\n\n");
                state = WIFICONNECT;
                RestartTimer();
            }
            break;

        case PRINTAPINFO:
            if(iNetwork < cNetworks)
            {
                SCANINFO scanInfo;
                uint32_t j = 0;

// this is MRF24 specific code
// this will not run in all implemenations
#if MRFVERSION
                {
                    t_deviceInfo dvInfo;
                    WF_DeviceInfoGet(&dvInfo);

                    Serial.println("Device Info");
                    Serial.print("DeviceType: 0x");
                    Serial.print((int) dvInfo.deviceType, HEX);
                    Serial.print(" Rom Version: 0x");
                    Serial.print((int) dvInfo.romVersion, HEX);
                    Serial.print(" Patch Version: 0x");
                    Serial.println((int) dvInfo.patchVersion, HEX);
               }
#endif

                if(deIPcK.getScanInfo(iNetwork, &scanInfo))
                {
                	xil_printf("\r\nScan info for index: %d\r\n", iNetwork);

                	xil_printf("SSID: %s\r\n", scanInfo.ssid);

                    xil_printf("\r\nBSSID / MAC: ");
                    for(j=0; j<sizeof(scanInfo.bssid); j++)
                    {
                        if(scanInfo.bssid[j] < 16)
                        {
                        	xil_printf("0");
                        }
                        xil_printf("%X",scanInfo.bssid[j]);
                    }

                    xil_printf("\r\nChannel: %d\r\nSignal Strength: %d\r\n", scanInfo.channel, scanInfo.rssi);

                    if(scanInfo.bssType == DEWF_INFRASTRUCTURE)
                    {
                    	xil_printf("Infrastructure Network\r\n");
                    }
                    else if(scanInfo.bssType == DEWF_ADHOC)
                    {
                    	xil_printf("AdHoc Network\r\n");
                    }
                    else
                    {
                    	xil_printf("Unknown Network Type\r\n");
                    }

                    xil_printf("Beacon Period: %d\r\ndtimPeriod: %d\r\natimWindow: %d\r\n", scanInfo.beaconPeriod, scanInfo.dtimPeriod, scanInfo.atimWindow);


                    xil_printf("Security info: WPA2  WPA  Preamble  Privacy  Reserved  Reserved  Reserved  IE\r\n");
                    xil_printf("                %d    %d       %d        %d         %d         %d         %d      %d\r\n",(scanInfo.apConfig & 0b10000000) >> 7,(scanInfo.apConfig & 0b01000000) >> 6,(scanInfo.apConfig & 0b00100000) >> 5,(scanInfo.apConfig & 0b00010000) >> 4,(scanInfo.apConfig & 0b00001000) >> 3,(scanInfo.apConfig & 0b00000100) >> 2,(scanInfo.apConfig & 0b00000010) >> 1,(scanInfo.apConfig & 0b00000001));
//                      Serial.print((scanInfo.apConfig & 0b10000000) >> 7, DEC);
//                                       Serial.print("    ");
//                                       Serial.print((scanInfo.apConfig & 0b01000000) >> 6, DEC);
//                                            Serial.print("       ");
//                                            Serial.print((scanInfo.apConfig & 0b00100000) >> 5, DEC);
//                                                    Serial.print("        ");
//                                                    Serial.print((scanInfo.apConfig & 0b00010000) >> 4, DEC);
//                                                             Serial.print("         ");
//                                                             Serial.print((scanInfo.apConfig & 0b00001000) >> 3, DEC);
//                                                                       Serial.print("         ");
//                                                                        Serial.print((scanInfo.apConfig & 0b00000100) >> 2, DEC);
//                                                                                 Serial.print("         ");
//                                                                                 Serial.print((scanInfo.apConfig & 0b00000010) >> 1, DEC);
//                                                                                           Serial.print("      ");
//                                                                                           Serial.println((scanInfo.apConfig & 0b00000001), DEC);

                    xil_printf("Count of support bit rates: %d\r\n", scanInfo.cBasicRates);
                    xil_printf("Supported Rates: ");
                    for( j= 0; j< scanInfo.cBasicRates; j++)
                    {
                        uint32_t rate = (scanInfo.basicRateSet[j] & 0x7F) * 500;
                        xil_printf("\t%d kbps", rate);
                    }
                    xil_printf("\r\n");
                }
                else
                {
Exemplo n.º 19
0
//----------------------------------------
//CDantas -> Alterada função para trabalhar com Serial Emulada
void ProcessaProtocolo( BYTE bData ){

  if ( serialPC_DataCounter >= sizeof( serialPC_Buffer ) ) {
    serialPC_DataCounter = 0;
    stSerialPC = ST_STX;
    return;
  }

  switch( stSerialPC  ) {
    case ST_STX:
      serialPC_CRC = 0;
      serialPC_DataLen = 0;
      serialPC_DataCounter = 0;

      #ifdef _USE_SERIALPC_TIMEOUT
      serialPC_timer = GetTimer( TIMEOUT_COM_PC );
      #endif

      if ( bData == STX ){
        stSerialPC = ST_ED;
      }
      break;

    case ST_ED:
    case ST_EO:
    case ST_LEN:
    case ST_DATA:
    case ST_LRC:
      
      if ( stSerialPC == ST_DATA ) {

        if ( serialPC_DLE == 1 ){
          serialPC_Buffer[serialPC_DataCounter] = bData ^ DLE_CHAR;
          serialPC_CRC ^= bData;
          serialPC_DataCounter++;

          serialPC_DLE = 0;
        }     
        else{
          if ( (bData == DLE)||(bData == ETX)||(bData == STX) ){
            serialPC_DLE = 1;
          }
          else{
            serialPC_Buffer[serialPC_DataCounter] = bData;
            serialPC_CRC ^= bData;
            serialPC_DataCounter++;
          }
        }
      }
      else{
        serialPC_Buffer[serialPC_DataCounter] = bData;
        serialPC_CRC ^= bData;
        serialPC_DataCounter++;
      }

      #ifdef _USE_SERIALPC_TIMEOUT
      RestartTimer( serialPC_timer , TIMEOUT_COM_PC );
      #endif

      switch( stSerialPC ){ 
        case ST_ED:
          if ( bData != GetID() ){
            //pacote não é para este SMS Box
            serialPC_CRC = 0;
            serialPC_DataCounter = 0;
            stSerialPC = ST_STX;
            serialPC_ProcessaPkt = FALSE;
      
            #ifdef _USE_SERIALPC_TIMEOUT
            ReleaseTimer( &serialPC_timer  );        
            #endif
          }
          else{
            stSerialPC = ST_EO;
          }
          break;

        case ST_EO:
          stSerialPC = ST_LEN;
          break;
        case ST_LEN:
          stSerialPC = ST_DATA;
          break; 
        case ST_DATA:
          if ( serialPC_Buffer[LEN_FIELD] == ( serialPC_DataCounter - DATA_FIELD )){
            stSerialPC = ST_LRC;          
          }
          break; 
        
        case ST_LRC:
          if ( serialPC_CRC ){
            serialPC_CRC = 0;
            serialPC_DataCounter = 0;
            stSerialPC = ST_STX;
            serialPC_ProcessaPkt = FALSE;
          }
          stSerialPC = ST_ETX;
          break;
      }
      break;


   case ST_ETX:
      serialPC_CRC = 0;
      serialPC_DataCounter = 0;
      stSerialPC = ST_STX;
      serialPC_ProcessaPkt = TRUE;

      if ( bData != ETX ){
        serialPC_ProcessaPkt = FALSE;
      }
      
      #ifdef _USE_SERIALPC_TIMEOUT  
      ReleaseTimer( &serialPC_timer  );
      #endif

      break;

    default:
      serialPC_CRC = 0;
      serialPC_DataCounter = 0;
      stSerialPC = ST_STX;
      serialPC_ProcessaPkt = FALSE;

      #ifdef _USE_SERIALPC_TIMEOUT
      ReleaseTimer( &serialPC_timer  );
      #endif
  }
  return;
}
Exemplo n.º 20
0
void CSkypeMessageQueue::ProcessQueue()
{
	std::wstring strFull;
	std::wstring str;
	std::wstring strID;

	// Retrieve the next change in status
	if(! m_queueStatus.empty()) {
		SkypeAPIAttachmentStatus status = m_queueStatus.front();
		m_queueStatus.pop();

		for(CSkypeMessageSinkList::iterator it = m_MessageSinks.begin(); it != m_MessageSinks.end(); it++) {
			(*it)->ProcessAPIStatusChange(status);
		}
	}
	
	// Retrieve the next response, if there is one
	if(! m_queueIncoming.empty()) {
		strFull = m_queueIncoming.front();
		str = strFull;
		strID = L"";
		m_queueIncoming.pop();

		if(str[0] == L'#') {
			size_t iSpace = str.find(L" ");
			if(iSpace != -1) {
				strID = str.substr(0, iSpace + 1);
				str = str.substr(iSpace + 1, str.length() - iSpace);
			}
		}

		if(_wcsicmp(str.c_str(), L"CONNSTATUS LOGGEDOUT") == 0) {
			// When connection status is logged out, start rechecking for skype
			gSkypeQueue.DeleteAllBinaryTransfers();
			RestartTimer();
		}

		if(_wcsnicmp(str.c_str(), L"PROTOCOL ", 9) == 0) {
 			if(str.length() > 8) {
				bool bSendProtocol = (m_lSupportedProtocol == -1);
				m_lSupportedProtocol = _wtol(& str.c_str()[9]);
				if(bSendProtocol) {
					WCHAR strMsg[16];
					swprintf_s(strMsg, 16, L"PROTOCOL %d", SUPPORTED_PROTOCOL);
					InternalProcessCommand(strMsg);
				}
			}
		}

#ifndef _NO_USE_LIST
		if(! m_bNeedRebuildCallList) {
			if(_wcsnicmp(str.c_str(), L"CALL", 4) == 0) {
				WCHAR * ptrStatus;
				WCHAR * ptrStatusInd = wcsstr(str.c_str(), L" STATUS ");
				if(ptrStatusInd != NULL) {
					ptrStatus = & ptrStatusInd[8];
					if(ptrStatus != NULL) { 
						long lCallID = 0;
						if(swscanf_s(str.c_str(), L"CALL %d STATUS", & lCallID) == 1) {
							if(lCallID > 0) {
								SkypeCallProgress progress = TextToSkypeCallProgress(ptrStatus);
								UpdateCallProgress(lCallID, progress);
							}
						}
					}
				}
			}
		}
		if(! m_bNeedRebuildUserList) {
			if(_wcsnicmp(str.c_str(), L"USER", 4) == 0) {
				WCHAR * ptrOnlineStatus;
				WCHAR * ptrOnlineStatusInd = wcsstr(str.c_str(), L" ONLINESTATUS ");
				if(ptrOnlineStatusInd != NULL) {
					ptrOnlineStatus = & ptrOnlineStatusInd[14];
					if(ptrOnlineStatus != NULL) {
						WCHAR userID[_MAX_LINE];
						if(swscanf_s(str.c_str(), L"USER %s ONLINESTATUS", userID, _MAX_LINE) == 1) {
							if(wcslen(userID) > 0) {
								SkypeOnlineStatus status = TextToSkypeOnlineStatus(ptrOnlineStatus);
								UpdateUserOnlineStatus(userID, status);
							}
						}
					}
				}
			}
		}
#endif
		
		bool bProcessCallbacks = ! m_bBlocking;
		bool bMatch = false;
	
		// If we are waiting on a blocking call, set up the response
		if(m_bBlocking) {
			if((m_strDesiredResult.empty()) && (! m_blockingCommandID)) {
				m_strCommandResult = str;
			} else {
				if(m_blockingCommandID) {
					if(_wcsicmp(strID.c_str(), m_strCommandID) == 0) {
						m_strCommandResult = str;
						ATLTRACE(L"Response received: %s\n", strID.c_str());
						bMatch = true;	// イベントのブロックを解除
						
						if(_wcsnicmp(str.c_str(), L"ERROR", 5) == 0) {
							ATLTRACE(L"Error for %s detected: %s\n", strID.c_str(),
								str.c_str());
							m_bBlockingError = true;
						}
					}
				} else {
					WCHAR * pCopy = _wcsdup(m_strDesiredResult.c_str());
					WCHAR *next_token = NULL;
					WCHAR * pSearch = wcstok_s(pCopy, L"|", &next_token);
					while(pSearch && (! bMatch)) {
						if(wcsstr(str.c_str(), pSearch) != NULL) {
							m_strCommandResult = str;
							bMatch = true;
							break;
						}
						pSearch = wcstok_s(NULL, L"|", &next_token);
					}
					try {
						free(pCopy);
					} catch(...) {
					}

					if(! bMatch) {
						if(_wcsnicmp(str.c_str(), L"ERROR", 5) == 0) {
							m_strCommandResult = str;
							m_bBlockingError = true;
							bMatch = true;
						}
					}
				}
			}
		}	

		// Let the blocking routine know if a match was found
		if(m_bBlocking) {
			m_bBlocking = ! bMatch;
		}

// paak
// ブロックコマンド実行中のイベントの抑制は行わない。
// イベントは常に発生させ、コールバック内で有効性をチェックすべき。
bProcessCallbacks = true;

		// Trigger the response event sinks
		for(CSkypeMessageSinkList::iterator it = m_MessageSinks.begin(); it != m_MessageSinks.end(); it++) {
			(*it)->ProcessResponse(strFull.c_str(), bProcessCallbacks);
		}
	}

	if((! m_queueOutgoing.empty()) && (m_hWndSkype != NULL)) {

		str = m_queueOutgoing.front();
		m_queueOutgoing.pop();
		
		InternalProcessCommand(str.c_str());
	}

}