Пример #1
0
void PingThread(CWlanInfoFileLogDlg* context)
{
	ICMP_ECHO_REPLY     reply;

	while(g_bIsAlivePingThread)
	{
		WriteFileLog(1, _T("[PING] IP : %s\r\n"), g_strPingDestIP);
		CString strPingResult = _T("");

		if( PingTest(g_strPingDestIP, reply) == TRUE )
		{
			if (reply.RoundTripTime < 1)
			{
				strPingResult.Format(_T("[PING] RTT<1ms, TTL=%d, Data=%dbytes\r\n"), reply.Options.Ttl, reply.DataSize);
			}
			else
			{
				strPingResult.Format(_T("[PING] RTT=%dms, TTL=%d, Data=%dbytes\r\n"), reply.RoundTripTime, reply.Options.Ttl, reply.DataSize);
			}
		}
		else
		{
			strPingResult.Format(_T("[PING] Request timeout.\r\n") );
		}

		WriteFileLog(0, strPingResult.GetBuffer(strPingResult.GetLength()) );

		int nLen = context->m_EditPingResult.GetWindowTextLength();
		context->m_EditPingResult.SetSel(nLen, nLen);
		context->m_EditPingResult.ReplaceSel(strPingResult, TRUE);

		Sleep(1000);
	}
}
Пример #2
0
//****************************************************************************
//
//!	\brief start simplelink, wait for the sta to connect to the device and 
//!        run the ping test for that sta
//!
//!	\param  pvparameters is the pointer to the list of parameters that can be
//!         passed to the task while creating it
//!
//!	\return None
//
//****************************************************************************
void WlanAPMode( void *pvParameters )
{   
    int iTestResult = 0;
    unsigned long ulIpAddr = 0;
    unsigned long ulIP;
    unsigned long ulSubnetMask;
    unsigned long ulDefaultGateway;
    unsigned long ulDNSServer;
    unsigned char ucDHCP;
    sl_Start(NULL,NULL,InitCallback);
    while (g_uiIpObtained == 0)
    {
       //looping till ip is acquired
      Z_DelayS(1);
      UART_PRINT("g_uiIpObtained == 0 now \n\r");   
       
    }
    
    SL_STA_IPV4_ADDR_GET(&ulIP,&ulSubnetMask,&ulDefaultGateway,&ulDNSServer,
                       &ucDHCP);
    while((g_uiIpLeased == 0) || (g_uiStaConnected == 0))
    {
        //wating for the STA to connect
    }
    
    ulIpAddr = g_ulStaIp;
    iTestResult = PingTest(ulIpAddr);
    UNUSED(ulIP);
    UNUSED(ulSubnetMask);
    UNUSED(ulDefaultGateway);
    UNUSED(ulDNSServer);
    UNUSED(ucDHCP);
    UNUSED(iTestResult);
}
Пример #3
0
//****************************************************************************
//
//!    \brief start simplelink, wait for the sta to connect to the device and 
//!        run the ping test for that sta
//!
//!    \param  pvparameters is the pointer to the list of parameters that can be
//!         passed to the task while creating it
//!
//!    \return None
//
//****************************************************************************
void WlanAPMode( void *pvParameters )
{   
    int iTestResult = 0;
    unsigned char ucDHCP;
    long retVal = -1;

    InitializeAppVariables();

    //
    // Following function configure the device to default state by cleaning
    // the persistent settings stored in NVMEM (viz. connection profiles &
    // policies, power policy etc)
    //
    // Applications may choose to skip this step if the developer is sure
    // that the device is in its default state at start of applicaton
    //
    // Note that all profiles and persistent settings that were done on the
    // device will be lost
    //
    retVal = ConfigureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            UART_PRINT("Failed to configure the device in its default state \n\r");

        LOOP_FOREVER(__LINE__);
    }

    UART_PRINT("Device is configured in default state \n\r");

    //
    // Asumption is that the device is configured in station mode already
    // and it is in its default state
    //
    retVal = sl_Start(NULL,NULL,NULL);

    if (retVal < 0)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER(__LINE__);
    }

    UART_PRINT("Device started as STATION \n\r");
    
    //
    // Configure the networking mode and ssid name(for AP mode)
    //
    if(retVal != ROLE_AP)
    {
        if(ConfigureMode(retVal) !=ROLE_AP)
        {
            UART_PRINT("Unable to set AP mode, exiting Application...\n\r");
            sl_Stop(SL_STOP_TIMEOUT);
            return;
        }
    }

    while(!IS_IP_ACQUIRED(g_ulStatus))
    {
      //looping till ip is acquired
    }

    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    _NetCfgIpV4Args_t ipV4 = {0};

    retVal = sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&ucDHCP,&len,
                            (unsigned char *)&ipV4);
    if (retVal < 0)
    {
        UART_PRINT("Failed to get network configuration \n\r");
        LOOP_FOREVER(__LINE__);
    }
    
    UART_PRINT("Connect a client to Device\n\r");
    while(!IS_IP_LEASED(g_ulStatus))
    {
      //wating for the client to connect
    }
    UART_PRINT("Client is connected to Device\n\r");

    iTestResult = PingTest(g_ulStaIp);
    UNUSED(ucDHCP);
    UNUSED(iTestResult);
    sl_WlanSetMode(ROLE_STA);

    /* Switch off Network processor */
    sl_Stop(SL_STOP_TIMEOUT);
    UART_PRINT("Application exits\n\r");
    while(1);
}
//****************************************************************************
//
//!	\brief start simplelink, connect to the ap and run the ping test
//!
//! This function starts the simplelink, connect to the ap and start the ping
//! test on the default gateway for the ap
//!
//!	\param  pvparameters is the pointer to the list of parameters that can be
//!         passed to the task while creating it
//!
//!	\return None
//
//****************************************************************************
void WlanStationMode( void *pvParameters )
{
    int iTestResult = 0;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefaultGateway = 0;
    unsigned long ulDNSServer = 0;
    unsigned char ucDHCP = 0;
    char cMode;
    char* buff="hhhhhh\n\r";
    unsigned char currentMacAddress[SL_MAC_ADDR_LEN];
    
    UART_PRINT(" in WlanStationMode  \n\r"); 
    
/*  for(int a = 0; a<5; ++a){
    Z_DelayS(30);
    *buff=a+'0';
    UART_PRINT(buff);   
    }
 */   
    
    

    
    
    
    
    
    
    
    
    
    
    
    sl_Start(NULL,NULL,InitCallback);
    
 /*  if((cMode = sl_Start(NULL,NULL,NULL)) != ROLE_STA){
      UART_PRINT("hellow  \n\r"); 
      
      *buff=cMode+'0';
      UART_PRINT(buff);
      *buff=ROLE_STA+'0';
      UART_PRINT(buff);
      
 //     SL_WLAN_SET_MODE_STA();
    }
     
    UART_PRINT("hellow i am in station mode now \n\r"); 
    
  */   
    
  while(!g_uiSimplelinkstarted)
  {
        //looping till simplelink starts
    Z_DelayS(1);
    
    UART_PRINT("i am starting now \n\r"); 
   } 
             
    UART_PRINT("i am started   \n\r");          
             
    // Connecting to WLAN AP - Set with static parameters defined at the top
	// After this call we will be connected and have IP address */
    WlanConnect();
    
    UART_PRINT("i'm connected! \n\r"); 
    
    //get mac addr from s-flash
    
    SL_MAC_ADDR_GET(currentMacAddress);   
    Z_MACDispaly(currentMacAddress);
    
    
    SL_STA_IPV4_ADDR_GET(&ulIP,&ulSubMask,&ulDefaultGateway,&ulDNSServer,
                       &ucDHCP);
    
    
    
    Z_IPDispaly(&ulIP);
    Z_IPDispaly(&ulSubMask);
    Z_IPDispaly(&ulDefaultGateway);

    
    
    
    /*
    
    UNUSED(ulIP);
    UNUSED(ulSubMask);
    UNUSED(ulDNSServer);
    UNUSED(ucDHCP);
    */
    
    iTestResult = PingTest(ulDefaultGateway);
  //  UNUSED(iTestResult);
    
   if(0 <=  BsdTcpServer(PORT_NUM))
    	 UART_PRINT("ok! \n\r"); 
 
    
    
    
    
    
    
    
    
}