Example #1
0
//****************************************************************************
//
//! \brief Display the IP Adderess of device
//!
//! \param[in]      none
//!
//! \return         none
//!
//
//****************************************************************************
static void DisplayIP()
{
    unsigned long mask, dns, gateway;
    unsigned char len, dhcpIsOn;

    if(g_ulDeviceIp == 0)
    {
        /* Device is in GO mode, Get the IP of Device */
        len = sizeof(_NetCfgIpV4Args_t);
		dhcpIsOn = 0;
		_NetCfgIpV4Args_t ipV4 = {0};
		sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,&len,(unsigned char *)&ipV4);
		g_ulDeviceIp=ipV4.ipV4;
		mask=ipV4.ipV4Mask;
		gateway=ipV4.ipV4Gateway;
		dns=ipV4.ipV4DnsServer;
    }

    UNUSED(mask);
    UNUSED(gateway);
    UNUSED(dns);

    UART_PRINT("CC3200 Device IP : IP=%d.%d.%d.%d \n\r", SL_IPV4_BYTE(g_ulDeviceIp,3),
                SL_IPV4_BYTE(g_ulDeviceIp,2), SL_IPV4_BYTE(g_ulDeviceIp,1),
                SL_IPV4_BYTE(g_ulDeviceIp,0));
}
Example #2
0
//*****************************************************************************
//
//! \brief This function handles network events such as IP acquisition, IP
//!           leased, IP released etc.
//!
//! \param[in]  pNetAppEvent - Pointer to NetApp Event Info 
//!
//! \return None
//!
//*****************************************************************************
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
    switch(pNetAppEvent->Event)
    {
        case SL_NETAPP_IPV4_ACQUIRED:
        case SL_NETAPP_IPV6_ACQUIRED:
        {
            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        }
        break;
        
        case SL_NETAPP_IP_LEASED:
        {
            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_LEASED);
        
            g_ulStaIp = (pNetAppEvent)->EventData.ipLeased.ip_address;
            
            UART_PRINT("[NETAPP EVENT] IP Leased to Client: IP=%d.%d.%d.%d , ",
                        SL_IPV4_BYTE(g_ulStaIp,3), SL_IPV4_BYTE(g_ulStaIp,2),
                        SL_IPV4_BYTE(g_ulStaIp,1), SL_IPV4_BYTE(g_ulStaIp,0));
        }
        break;
        
        default:
        {
            UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r",
                       pNetAppEvent->Event);
        }
        break;
    }
}
Example #3
0
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *e) {
  if (e->Event == SL_NETAPP_IPV4_IPACQUIRED_EVENT) {
    SlIpV4AcquiredAsync_t *ed = &e->EventData.ipAcquiredV4;
    asprintf(&s_wifi_sta_config.ip, "%lu.%lu.%lu.%lu", SL_IPV4_BYTE(ed->ip, 3),
             SL_IPV4_BYTE(ed->ip, 2), SL_IPV4_BYTE(ed->ip, 1),
             SL_IPV4_BYTE(ed->ip, 0));
    s_wifi_sta_config.status = SJ_WIFI_IP_ACQUIRED;
    sj_wifi_on_change_callback(SJ_WIFI_IP_ACQUIRED);
  }
}
Example #4
0
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size) {
  int res;
  struct in_addr *in = (struct in_addr *) src;
  if (af != AF_INET || size != sizeof(struct in_addr)) {
    errno = EAFNOSUPPORT;
    return NULL;
  }
  res = sprintf(dst, "%lu.%lu.%lu.%lu", SL_IPV4_BYTE(in->s_addr, 0),
                SL_IPV4_BYTE(in->s_addr, 1), SL_IPV4_BYTE(in->s_addr, 2),
                SL_IPV4_BYTE(in->s_addr, 3));
  return res > 0 ? dst : NULL;
}
Example #5
0
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *e) {
  if (e->Event == SL_NETAPP_IPV4_IPACQUIRED_EVENT) {
    SlIpV4AcquiredAsync_t *ed = &e->EventData.ipAcquiredV4;
    LOG(LL_INFO, ("IP acquired: %lu.%lu.%lu.%lu", SL_IPV4_BYTE(ed->ip, 3),
                  SL_IPV4_BYTE(ed->ip, 2), SL_IPV4_BYTE(ed->ip, 1),
                  SL_IPV4_BYTE(ed->ip, 0)));
    ip_acquired = 1;
  } else if (e->Event == SL_NETAPP_IP_LEASED_EVENT) {
    LOG(LL_INFO, ("IP leased"));
  } else {
    LOG(LL_INFO, ("NetApp event %d", e->Event));
  }
}
Example #6
0
//*****************************************************************************
//
//! \brief This function handles network events such as IP acquisition, IP
//!           leased, IP released etc.
//!
//! \param[in]  pNetAppEvent - Pointer to NetApp Event Info 
//!
//! \return None
//!
//*****************************************************************************
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) {
	switch (pNetAppEvent->Event) {
	case SL_NETAPP_IPV4_ACQUIRED: {
		SlIpV4AcquiredAsync_t *pEventData = NULL;

		SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);

		//Ip Acquired Event Data
		pEventData = &pNetAppEvent->EventData.ipAcquiredV4;

		//Gateway IP address
		g_ulGatewayIP = pEventData->gateway;

		UART_PRINT("[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , "
				"Gateway=%d.%d.%d.%d\n\r",
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 3),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 2),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 1),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 0),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 3),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 2),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 1),
				SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 0));
	}
		break;

	default: {
		UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r",
				pNetAppEvent->Event);
	}
		break;
	}
}
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
    switch(pNetAppEvent->Event)
    {
        case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
        {
            SlIpV4AcquiredAsync_t *pEventData = NULL;
            s_flAcquiredIP = 1;
            pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
            TRACE("[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , "
            "Gateway=%d.%d.%d.%d\n\r",
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,3),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,2),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,1),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,0),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,3),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,2),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,1),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,0));
        }
        break;

        default: TRACE("[NETAPP EVENT] Unexpected event [0x%x] \n\r", pNetAppEvent->Event); break;
    }
}
//*****************************************************************************
//
//! Network_IF_GetHostIP
//!
//! \brief  This function obtains the server IP address using a DNS lookup
//!
//! \param[in]  pcHostName        The server hostname
//! \param[out] pDestinationIP    This parameter is filled with host IP address.
//!
//! \return On success, +ve value is returned. On error, -ve value is returned
//!
//
//*****************************************************************************
long Network_IF_GetHostIP( char* pcHostName,unsigned long * pDestinationIP )
{
    long lStatus = 0;

    lStatus = sl_NetAppDnsGetHostByName((signed char *) pcHostName,
                                            strlen(pcHostName),
                                            pDestinationIP, SL_AF_INET);
    ASSERT_ON_ERROR(lStatus);

    UART_PRINT("Get Host IP succeeded.\n\rHost: %s IP: %d.%d.%d.%d \n\r\n\r",
                    pcHostName, SL_IPV4_BYTE(*pDestinationIP,3),
                    SL_IPV4_BYTE(*pDestinationIP,2),
                    SL_IPV4_BYTE(*pDestinationIP,1),
                    SL_IPV4_BYTE(*pDestinationIP,0));
    return lStatus;

}
Example #9
0
//*****************************************************************************
//
//! Network_IF_GetHostIP
//!
//! \brief  This function obtains the server IP address using a DNS lookup
//!
//! \param  The server hostname
//!
//! \return IP address: Success or 0: Failure.
//!
//
//*****************************************************************************
unsigned long Network_IF_GetHostIP( char* pcHostName )
{
    int iStatus = 0;
    unsigned long ulDestinationIP;

    iStatus = sl_NetAppDnsGetHostByName(
                  pcHostName, strlen(pcHostName),
                  &ulDestinationIP, SL_AF_INET);
    if (iStatus == 0)
    {
        UART_PRINT("Get Host IP succeeded.\n\rHost: %s IP: %d.%d.%d.%d \n\r\n\r",
                   pcHostName, SL_IPV4_BYTE(ulDestinationIP,3),
                   SL_IPV4_BYTE(ulDestinationIP,2),
                   SL_IPV4_BYTE(ulDestinationIP,1),
                   SL_IPV4_BYTE(ulDestinationIP,0));
        return ulDestinationIP;
    }
    else
    {
        return 0;
    }
}
Example #10
0
File: main.c Project: dlugaz/All
//****************************************************************************
//
//! \brief Display the IP Adderess of device
//!
//! \param[in]      none
//!
//! \return         none
//!
//
//****************************************************************************
static signed long DisplayIP()
{
    unsigned long mask, dns, gateway;
    long lRetVal = -1;
    unsigned char len, dhcpIsOn;

    if(g_ulDeviceIp == 0)
    {
        /* Device is in GO mode, Get the IP of Device */
        len = sizeof(SlNetCfgIpV4Args_t);
        dhcpIsOn = 0;
        SlNetCfgIpV4Args_t ipV4 = {0};

        // Get the IP address of device
#ifdef P2P_ROLE_TYPE_NEGOTIATE
        lRetVal = sl_NetCfgGet(SL_IPV4_AP_P2P_GO_GET_INFO,&dhcpIsOn,
                                        &len,(unsigned char *)&ipV4);
#else
        lRetVal = sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&dhcpIsOn,
                                                &len,(unsigned char *)&ipV4)
#endif
        ASSERT_ON_ERROR(lRetVal);

        g_ulDeviceIp=ipV4.ipV4;
        mask=ipV4.ipV4Mask;
        gateway=ipV4.ipV4Gateway;
        dns=ipV4.ipV4DnsServer;
    }

    UNUSED(mask);
    UNUSED(gateway);
    UNUSED(dns);

    UART_PRINT("CC3200 Device IP : IP=%d.%d.%d.%d \n\r",
                SL_IPV4_BYTE(g_ulDeviceIp,3), SL_IPV4_BYTE(g_ulDeviceIp,2),
                SL_IPV4_BYTE(g_ulDeviceIp,1), SL_IPV4_BYTE(g_ulDeviceIp,0));
    return 0;
}
Example #11
0
int
CMD_who(int argc, char **argv)
{
    UINT8 IsDHCP;
    _NetCfgIpV4Args_t ipV4;
    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP, &len,(unsigned char *)&ipV4);
    UARTprintf("  Server IP: %d.%d.%d.%d",
               SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2),
               SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0));
    UARTprintf("\n");
    UARTprintf("This node is at IP: %d.%d.%d.%d\n",
               SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2),
               SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    
    return 0;
}
Example #12
0
void sl_net_app_eh(SlNetAppEvent_t *e) {
  if (e->Event == SL_NETAPP_IPV4_IPACQUIRED_EVENT) {
    SlIpV4AcquiredAsync_t *ed = &e->EventData.ipAcquiredV4;
    asprintf(&s_wifi_sta_config.ip, "%lu.%lu.%lu.%lu", SL_IPV4_BYTE(ed->ip, 3),
             SL_IPV4_BYTE(ed->ip, 2), SL_IPV4_BYTE(ed->ip, 1),
             SL_IPV4_BYTE(ed->ip, 0));
    s_wifi_sta_config.status = MIOT_WIFI_IP_ACQUIRED;
    invoke_cb(invoke_wifi_on_change_cb, (void *) s_wifi_sta_config.status);
  } else if (e->Event == SL_NETAPP_IP_LEASED_EVENT) {
    SlIpLeasedAsync_t *ed = &e->EventData.ipLeased;
    LOG(LL_INFO,
        ("WiFi: leased %lu.%lu.%lu.%lu to %02x:%02x:%02x:%02x:%02x:%02x",
         SL_IPV4_BYTE(ed->ip_address, 3), SL_IPV4_BYTE(ed->ip_address, 2),
         SL_IPV4_BYTE(ed->ip_address, 1), SL_IPV4_BYTE(ed->ip_address, 0),
         ed->mac[0], ed->mac[1], ed->mac[2], ed->mac[3], ed->mac[4],
         ed->mac[5]));
  }
}
Example #13
0
int
CMD_ask(int argc, char **argv)
{
    UINT8 IsDHCP;
    _NetCfgIpV4Args_t ipV4;
    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    char packet[256];
    char last3[10];
    int temp;
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP, &len,(unsigned char *)&ipV4);
    temp = SL_IPV4_BYTE(ipV4.ipV4,0);
    sprintf(last3, "%d", temp);
    UARTprintf("%d", temp);
    UARTprintf("%s", last3);
    
    
    return 0;
}
Example #14
0
//****************************************************************************
//
//!    \brief Connects to the Network in AP or STA Mode - If ForceAP Jumper is
//!                                             Placed, Force it to AP mode
//!
//! \return                        0 on success else error code
//
//****************************************************************************
long ConnectToNetwork()
{
    char ucAPSSID[32];
    unsigned short len, config_opt;
    long lRetVal = -1;

    // staring simplelink
    g_uiSimplelinkRole =  sl_Start(NULL,NULL,NULL);

    // Device is not in STA mode and Force AP Jumper is not Connected 
    //- Switch to STA mode
    if(g_uiSimplelinkRole != ROLE_STA && g_uiDeviceModeConfig == ROLE_STA )
    {
        //Switch to STA Mode
        lRetVal = sl_WlanSetMode(ROLE_STA);
        ASSERT_ON_ERROR(lRetVal);
        
        lRetVal = sl_Stop(SL_STOP_TIMEOUT);
        
        g_usMCNetworkUstate = 0;
        g_uiSimplelinkRole =  sl_Start(NULL,NULL,NULL);

        UART_PRINT("started in STA mode\n\r");
    }

    //Device is not in AP mode and Force AP Jumper is Connected - 
    //Switch to AP mode
    if(g_uiSimplelinkRole != ROLE_AP && g_uiDeviceModeConfig == ROLE_AP )
    {
         //Switch to AP Mode
        lRetVal = sl_WlanSetMode(ROLE_AP);
        ASSERT_ON_ERROR(lRetVal);
        
        lRetVal = sl_Stop(SL_STOP_TIMEOUT);
        
        g_usMCNetworkUstate = 0;
        g_uiSimplelinkRole =  sl_Start(NULL,NULL,NULL);
    }

    //No Mode Change Required
    if(g_uiSimplelinkRole == ROLE_AP)
    {
       //waiting for the AP to acquire IP address from Internal DHCP Server
       while(!IS_IP_ACQUIRED(g_ulStatus))
       {

       }

       //Stop Internal HTTP Server
       lRetVal = sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
       ASSERT_ON_ERROR( lRetVal);

       //Start Internal HTTP Server
       lRetVal = sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID);
       ASSERT_ON_ERROR( lRetVal);

       char iCount=0;
       //Read the AP SSID
       memset(ucAPSSID,'\0',AP_SSID_LEN_MAX);
       len = AP_SSID_LEN_MAX;
       config_opt = WLAN_AP_OPT_SSID;
       lRetVal = sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt , &len,
                                              (unsigned char*) ucAPSSID);
        ASSERT_ON_ERROR(lRetVal);
        
       Report("\n\rDevice is in AP Mode, Please Connect to AP [%s] and"
          "type [mysimplelink.net] in the browser \n\r",ucAPSSID);
       
       //Blink LED 3 times to Indicate AP Mode
       for(iCount=0;iCount<3;iCount++)
       {
           //Turn RED LED On
           GPIO_IF_LedOn(MCU_RED_LED_GPIO);
           osi_Sleep(400);
           
           //Turn RED LED Off
           GPIO_IF_LedOff(MCU_RED_LED_GPIO);
           osi_Sleep(400);
       }

    }
    else
    {
        //Stop Internal HTTP Server
        lRetVal = sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
        ASSERT_ON_ERROR( lRetVal);

        //Start Internal HTTP Server
        lRetVal = sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID);
        ASSERT_ON_ERROR( lRetVal);
        
		/*//waiting for the device to Auto Connect
		while ( (!IS_IP_ACQUIRED(g_ulStatus))&&
			   g_ucConnectTimeout < AUTO_CONNECTION_TIMEOUT_COUNT)
		{
			//Turn RED LED On
			GPIO_IF_LedOn(MCU_RED_LED_GPIO);
			osi_Sleep(50);

			//Turn RED LED Off
			GPIO_IF_LedOff(MCU_RED_LED_GPIO);
			osi_Sleep(50);

			g_ucConnectTimeout++;
		}
		//Couldn't connect Using Auto Profile
		if(g_ucConnectTimeout == AUTO_CONNECTION_TIMEOUT_COUNT)
		{
			//Blink Red LED to Indicate Connection Error
			GPIO_IF_LedOn(MCU_RED_LED_GPIO);

			CLR_STATUS_BIT_ALL(g_ulStatus);

			Report("Use Smart Config Application to configure the device.\n\r");
			//Connect Using Smart Config
			lRetVal = SmartConfigConnect();
			ASSERT_ON_ERROR(lRetVal);

			//Waiting for the device to Auto Connect
			while(!IS_IP_ACQUIRED(g_ulStatus))
			{
				MAP_UtilsDelay(500);
			}*/
        	SlSecParams_t secParams = {0};
        	secParams.Key = (signed char *)SECURITY_KEY;
        		secParams.KeyLen = strlen(SECURITY_KEY);
        		secParams.Type = SECURITY_TYPE;
        	lRetVal = sl_WlanConnect((signed char *)SSID_NAME,
        						   strlen((const char *)SSID_NAME), 0, &secParams, 0);
        	ASSERT_ON_ERROR(lRetVal);

        	// Wait for WLAN Event
			while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
			{
				//Turn Green LED On
				GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
				osi_Sleep(50);
				//Turn Green LED Off
				GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
				osi_Sleep(50);
			}
			//Turn Green LED Off
			GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
			UART_PRINT("connected\n\r");

		}
    //Turn RED LED Off
    GPIO_IF_LedOff(MCU_RED_LED_GPIO);
    UART_PRINT("\n\rDevice is in STA Mode, Connect to the AP[%s] and type"
          "IP address [%d.%d.%d.%d] in the browser \n\r",g_ucConnectionSSID,
          SL_IPV4_BYTE(g_uiIpAddress,3),SL_IPV4_BYTE(g_uiIpAddress,2),
          SL_IPV4_BYTE(g_uiIpAddress,1),SL_IPV4_BYTE(g_uiIpAddress,0));


    return SUCCESS;
}
Example #15
0
//*****************************************************************************
//
//! Network_IF_ConnectAP  Connect to an Access Point using the specified SSID
//!
//! \param[in]  pcSsid is a string of the AP's SSID
//! \param[in]  SecurityParams is Security parameter for AP
//!
//! \return On success, zero is returned. On error, -ve value is returned
//
//*****************************************************************************
long
Network_IF_ConnectAP(char *pcSsid, SlSecParams_t SecurityParams)
{
#ifndef NOTERM  
    char acCmdStore[128];
    unsigned short usConnTimeout;
    unsigned char ucRecvdAPDetails;
#endif
    long lRetVal;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefGateway = 0;
    unsigned long ulDns = 0;

    //
    // Disconnect from the AP
    //
    Network_IF_DisconnectFromAP();
    
    //
    // This triggers the CC3200 to connect to specific AP
    //
    lRetVal = sl_WlanConnect((signed char *)pcSsid, strlen((const char *)pcSsid),
                        NULL, &SecurityParams, NULL);
    ASSERT_ON_ERROR(lRetVal);

    //
    // Wait for ~10 sec to check if connection to desire AP succeeds
    //
    while(g_usConnectIndex < 15)
    {
#ifndef SL_PLATFORM_MULTI_THREADED
        _SlNonOsMainLoopTask();
#else
              osi_Sleep(1);
#endif
        MAP_UtilsDelay(8000000);
        if(IS_CONNECTED(g_ulStatus) && IS_IP_ACQUIRED(g_ulStatus))
        {
            break;
        }
        g_usConnectIndex++;
    }

#ifndef NOTERM
    //
    // Check and loop until AP connection successful, else ask new AP SSID name
    //
    while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
    {
        //
        // Disconnect the previous attempt
        //
        Network_IF_DisconnectFromAP();

        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        UART_PRINT("Device could not connect to %s\n\r",pcSsid);

        do
        {
            ucRecvdAPDetails = 0;

            UART_PRINT("\n\r\n\rPlease enter the AP(open) SSID name # ");

            //
            // Get the AP name to connect over the UART
            //
            lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
            if(lRetVal > 0)
            {
                // remove start/end spaces if any
                lRetVal = TrimSpace(acCmdStore);

                //
                // Parse the AP name
                //
                strncpy(pcSsid, acCmdStore, lRetVal);
                if(pcSsid != NULL)
                {
                    ucRecvdAPDetails = 1;
                    pcSsid[lRetVal] = '\0';

                }
            }
        }while(ucRecvdAPDetails == 0);

        //
        // Reset Security Parameters to OPEN security type
        //
        SecurityParams.Key = (signed char *)"";
        SecurityParams.KeyLen = 0;
        SecurityParams.Type = SL_SEC_TYPE_OPEN;

        UART_PRINT("\n\rTrying to connect to AP: %s ...\n\r",pcSsid);

        //
        // Get the current timer tick and setup the timeout accordingly
        //
        usConnTimeout = g_usConnectIndex + 15;

        //
        // This triggers the CC3200 to connect to specific AP
        //
        lRetVal = sl_WlanConnect((signed char *)pcSsid,
                                  strlen((const char *)pcSsid), NULL,
                                  &SecurityParams, NULL);
        ASSERT_ON_ERROR(lRetVal);

        //
        // Wait ~10 sec to check if connection to specifed AP succeeds
        //
        while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
        {
#ifndef SL_PLATFORM_MULTI_THREADED
            _SlNonOsMainLoopTask();
#else
              osi_Sleep(1);
#endif
            MAP_UtilsDelay(8000000);
            if(g_usConnectIndex >= usConnTimeout)
            {
                break;
            }
            g_usConnectIndex++;
        }

    }
#endif
    //
    // Put message on UART
    //
    UART_PRINT("\n\rDevice has connected to %s\n\r",pcSsid);

    //
    // Get IP address
    //
    lRetVal = Network_IF_IpConfigGet(&ulIP,&ulSubMask,&ulDefGateway,&ulDns);
    ASSERT_ON_ERROR(lRetVal);

    //
    // Send the information
    //
    UART_PRINT("Device IP Address is %d.%d.%d.%d \n\r\n\r",
            SL_IPV4_BYTE(ulIP, 3),SL_IPV4_BYTE(ulIP, 2),
            SL_IPV4_BYTE(ulIP, 1),SL_IPV4_BYTE(ulIP, 0));
    return 0;
}
Example #16
0
void ControlServer(void *pvParameters) {

	char ServerBuffer[CONFIG_SERVER_BUFFER];
	char MsgBuffer[100];
	char *pMsgBuffer;

	SlSockAddrIn_t sAddr;
	SlSockAddrIn_t sLocalAddr;
	int32_t i32SockID;
	int32_t i32NewSockID;
	int32_t i32DataSize;
	int32_t i32NonBlocking = 1;
	SlSocklen_t i32AddrSize;
	int32_t retval;

	pMsgBuffer = &MsgBuffer[0];

	InitVariables();
	retval = ResetSimpleLink();
	if (retval < 0)
		while (1)
			;

	WlanConnect();

	sprintf(MsgBuffer, "Connectado a rede: %s\n\r"
			"IP: %d.%d.%d.%d\n\r"
			"Gateway: %d.%d.%d.%d\n\r", SL_IPV4_BYTE(g_sSLCon.DeviceIP, 3),
			SL_IPV4_BYTE(g_sSLCon.DeviceIP, 2),
			SL_IPV4_BYTE(g_sSLCon.DeviceIP, 1),
			SL_IPV4_BYTE(g_sSLCon.DeviceIP, 0),
			SL_IPV4_BYTE(g_sSLCon.GatewayIP, 3),
			SL_IPV4_BYTE(g_sSLCon.GatewayIP, 2),
			SL_IPV4_BYTE(g_sSLCon.GatewayIP, 1),
			SL_IPV4_BYTE(g_sSLCon.GatewayIP, 0));

	osi_MsgQWrite(&g_sUartQuee, &pMsgBuffer, OSI_NO_WAIT);

	sLocalAddr.sin_family = SL_AF_INET;
	sLocalAddr.sin_port = sl_Htons((unsigned short) g_sSLCon.PortNumber);
	sLocalAddr.sin_addr.s_addr = 0;

	i32SockID = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
	sl_Bind(i32SockID, (SlSockAddr_t *) &sLocalAddr, sizeof(SlSockAddrIn_t));
	sl_Listen(i32SockID, 0);
	sl_SetSockOpt(i32SockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &i32NonBlocking,
			sizeof(i32NonBlocking));

	while (1) {
		i32NewSockID = SL_EAGAIN;

		while (i32NewSockID < 0) {
			i32NewSockID = sl_Accept(i32SockID, (struct SlSockAddr_t *) &sAddr,
					(SlSocklen_t*) &i32AddrSize);
			if (i32NewSockID == SL_EAGAIN) {
				osi_Sleep(100);
			} else if (i32NewSockID < 0) {
				while (1) {
				}
			}
		}

		i32DataSize = sl_Recv(i32NewSockID, ServerBuffer, CONFIG_SERVER_BUFFER,
				0);

		if (strcmp(ServerBuffer, "Led On") == 0) {
			Led_Green(LED_ON);
			strcpy(ServerBuffer, "OK");
			i32DataSize = 3;
		} else if (strcmp(ServerBuffer, "Led Off") == 0) {
			Led_Green(LED_OFF);
			strcpy(ServerBuffer, "OK");
			i32DataSize = 3;
		} else if (strcmp(ServerBuffer, "Lamp On") == 0) {
			MAP_GPIOPinWrite(GPIOA0_BASE, GPIO_PIN_6, GPIO_PIN_6);
			strcpy(ServerBuffer, "OK");
			i32DataSize = 3;
		} else if (strcmp(ServerBuffer, "Lamp Off") == 0) {
			MAP_GPIOPinWrite(GPIOA0_BASE, GPIO_PIN_6, 0);
			strcpy(ServerBuffer, "OK");
			i32DataSize = 3;
		}

		sl_Send(i32NewSockID, ServerBuffer, i32DataSize, 0);
		sl_Close(i32NewSockID);
	}

}
Example #17
0
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
void main()
{
    long retVal = -1;
    unsigned long ulResetCause;
    unsigned long ulDestinationIP;

    //
    // Board Initialization
    //
    BoardInit();

    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Initialize WDT
    //
    WDT_IF_Init(NULL,80000000 * 10);

    //
    // Get the reset cause
    //
    ulResetCause = PRCMSysResetCauseGet();

    //
    // If watchdog triggered reset request hibernate
    // to clean boot the system
    //
    if( ulResetCause == PRCM_WDT_RESET )
    {
        HIBEntrePreamble();
        MAP_PRCMOCRRegisterWrite(0,1);
        MAP_PRCMHibernateWakeupSourceEnable(PRCM_HIB_SLOW_CLK_CTR);
        MAP_PRCMHibernateIntervalSet(330);
        MAP_PRCMHibernateEnter();
    }

    //
    // uDMA Initialization
    //
    UDMAInit();

    //
    // Display banner
    //
    DisplayBanner(APPLICATION_NAME);

    if( ulResetCause == PRCM_HIB_EXIT &&  (MAP_PRCMOCRRegisterRead(0) & 1) == 1 )
    {
        UART_PRINT("Reset Cause        : Watchdog Reset\n\r");
    }
    else
    {
        UART_PRINT("Reset Cause        : Power On\n\r");

        //
        // Initialize the variables.
        //
        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 desired 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();
        }
    }

    //
    // Set destination IP
    //
    ulDestinationIP = IP_ADDR;

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

    //
    // Acknowledge the watchdog so that it doesn't resets
    //
    WatchdogAck();

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

    //
    //Connecting to WLAN AP
    //
    retVal = WlanConnect();

    //
    // Acknowledge the watchdog so that it doesn't resets
    //
    WatchdogAck();

    if(retVal < 0)
    {
        UART_PRINT("Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Connected to AP    : %s \n\r",SSID_NAME);

    UART_PRINT("Device IP          : %d.%d.%d.%d\n\r\n\r",
                SL_IPV4_BYTE(g_ulIpAddr,3),
                SL_IPV4_BYTE(g_ulIpAddr,2),
                SL_IPV4_BYTE(g_ulIpAddr,1),
                SL_IPV4_BYTE(g_ulIpAddr,0));


    UART_PRINT("\nStarting UDP Client\n\n\r");

    UART_PRINT("Source IP          : %d.%d.%d.%d\n\r"
                 "Destination IP     : %d.%d.%d.%d\n\r"
                 "PORT               : %d\n\r",
                 SL_IPV4_BYTE(g_ulIpAddr,3),
                 SL_IPV4_BYTE(g_ulIpAddr,2),
                 SL_IPV4_BYTE(g_ulIpAddr,1),
                 SL_IPV4_BYTE(g_ulIpAddr,0),
                 SL_IPV4_BYTE(ulDestinationIP,3),
                 SL_IPV4_BYTE(ulDestinationIP,2),
                 SL_IPV4_BYTE(ulDestinationIP,1),
                 SL_IPV4_BYTE(ulDestinationIP,0),
                 g_uiPortNum);


    //
    // Acknowledge the watchdog so that it doesn't resets
    //
    WatchdogAck();

    //
    // Send packets
    //
    BsdUdpClient(PORT_NUM,ulDestinationIP);


    //
    // power off the network processor
    //
    sl_Stop(SL_STOP_TIMEOUT);
    while (1)
    {
        _SlNonOsMainLoopTask();
    }
}
Example #18
0
int main(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;
		SlSockAddrIn_t    Addr; 
		UINT16            AddrSize = 0; 
		INT16             SockID = 0; 
		UINT32            data; 
		long x = 0; //counter
    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;
    /* Stop WDT */
    stopWDT();
    /* Initialize the system clock of MCU */
    initClk();
		Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to generate text\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
		//added code from the powerpoint slide
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    Addr.sin_family = SL_AF_INET;
    Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
    Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
    AddrSize = sizeof(SlSockAddrIn_t);
    SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        // Print prompt for user.
        UARTprintf("\n>");
        // Peek to see if a full command is ready for processing.
        while(UARTPeek('\r') == -1)
						LED_On();
            // Approximately 1 millisecond delay.
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);

        }
        // A '\r' was detected so get the line of text from the receive buffer.
		while(Status >= 0){
      UARTprintf("\nSending a UDP packet ...\n");
		
			UARTgets(g_cInput,sizeof(g_cInput)); //this function receives the input from the Putty and places it in a string

			
			
			//DO NOT CHANGE ANYTHING ABOVE THIS COMMENT
			
			//WHAT WE NEED TO DO:
			//work with the g_cInput to get the array of letters typed into the Putty
			//then send that Array using UARTprintf
			uBuf[0] = ATYPE;   // defines this as an analog data type
			uBuf[1] = '='; 
			data = 1000;

			Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
      UARTprintf(" %s ",uBuf); //this line sends a string to the receiver
      //the above 5 lines print out a = 1000;
			//everything below this is just error cases
			if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        LED_Toggle();
        Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
        if( Status <= 0 ){
          sl_Close(SockID);
          UARTprintf("SockIDerror %d ",Status);
        }else{
          UARTprintf("ok");
        }
      }
      ROM_SysCtlDelay(ROM_SysCtlClockGet() / 100); // 10ms
			LED_Off();
		}
   }
Example #19
0
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent) {
    switch (pNetAppEvent->Event) {
        case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
        {
            UART_PRINT("[QuickStart] IP address                : %d.%d.%d.%d\r\n",
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 3),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 2),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 1),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip, 0));
            UART_PRINT("[QuickStart] Gateway                   : %d.%d.%d.%d\r\n",
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 3),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 2),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 1),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway, 0));
            UART_PRINT("[QuickStart] DNS server                : %d.%d.%d.%d\r\n",
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 3),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 2),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 1),
                    SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.dns, 0));

            SET_STATUS_BIT(g_Status, STATUS_BIT_IP_AQUIRED);
        }
            break;

        default:
            break;
    }
}
Example #20
0
int main2(void)
{
    UINT8  IsDHCP = 0;
    int32_t i32CommandStatus;
    _NetCfgIpV4Args_t ipV4;

    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    int Status = 0;

    /* Stop WDT */
    stopWDT();

    /* Initialize the system clock of MCU */
    initClk();

    Board_Init();       // initialize LaunchPad I/O and PD1 LED
    ConfigureUART();    // Initialize the UART.
    UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
    UARTprintf("This application is configured to measure analog signals from Ain7=PD0\n");
    UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
    /* Initializing the CC3100 device */
    sl_Start(0, 0, 0);

    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();

    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,
            (unsigned char *)&ipV4);

    //Print the IP
    UARTprintf("This node is at IP: %d.%d.%d.%d\n",  SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));

    //
    // Loop forever waiting  for commands from PC...
    //
    while(1)
    {
        //
        // Print prompt for user.
        //
        UARTprintf("\n>");

        //
        // Peek to see if a full command is ready for processing.
        //
        while(UARTPeek('\r') == -1)
        {
            //
            // Approximately 1 millisecond delay.
            //
            ROM_SysCtlDelay(ROM_SysCtlClockGet() / 3000);
        }

        //
        // A '\r' was detected so get the line of text from the receive buffer.
        //
        UARTgets(g_cInput,sizeof(g_cInput));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32CommandStatus = CmdLineProcess(g_cInput);

        //
        // Handle the case of bad command.
        //
        if(i32CommandStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("    Bad command. Try again.\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("    Too many arguments for command. Try again.\n");
        }
        //
        // Handle the case of too few arguments.
        //
        else if(i32CommandStatus == CMDLINE_TOO_FEW_ARGS)
        {
            UARTprintf("    Too few arguments for command. Try again.\n");
        }
        //
        // Handle the case of too few arguments.
        //
        else if(i32CommandStatus == CMDLINE_INVALID_ARG)
        {
            UARTprintf("    Invalid command argument(s). Try again.\n");
        }
    }
    
}
Example #21
0
int main(void){
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  SlSockAddrIn_t    LocalAddr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  INT16             Status = 1;  // ok
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz, ADC needs PPL active
  Board_Init();     // initialize LaunchPad I/O 
  ConfigureUART();  // Initialize the UART.
  UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
  UARTprintf("This node is configured to receive UDP packets\n");
  UARTprintf("This node should be at IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
  ST7735_InitR(INITR_REDTAB);
  ST7735_OutString("Internet of Things\n");
  ST7735_OutString("Embedded Systems\n");
  ST7735_OutString("Vol. 2, Valvano");
  ST7735_PlotClear(0,4095);  // range from 0 to 4095
  while(1){
    sl_Start(0, 0, 0); /* Initializing the CC3100 device */
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();   // connect to AP
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    while(Status > 0){
      UARTprintf("\nReceiving a UDP packet ...");

      LocalAddr.sin_family = SL_AF_INET;
      LocalAddr.sin_port = sl_Htons((UINT16)PORT_NUM);
      LocalAddr.sin_addr.s_addr = 0;
      AddrSize = sizeof(SlSockAddrIn_t);
      SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);     
      if( SockID < 0 ){
        UARTprintf("SockIDerror\n");
        Status = -1; // error
      }else{
        Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
        if( Status < 0 ){
          sl_Close(SockID); 
          UARTprintf("Sock Bind error\n");
        }else{
          Status = sl_RecvFrom(SockID, uBuf, BUF_SIZE, 0,
                  (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize );
          if( Status <= 0 ){
            sl_Close(SockID);
            UARTprintf("Receive error %d ",Status);
          }else{
            LED_Toggle();
            sl_Close(SockID);
            UARTprintf("ok %s ",uBuf);
            if((uBuf[0]==ATYPE)&&(uBuf[1]== '=')){ int i,bOk; uint32_t place;
              data = 0; bOk = 1;
              i=4;  // ignore possible negative sign
              for(place = 1000; place; place = place/10){
                if((uBuf[i]&0xF0)==0x30){ // ignore spaces
                  data += place*(uBuf[i]-0x30);
                }else{
                  if((uBuf[i]&0xF0)!= ' '){
                    bOk = 0;
                  }
                }
                i++;
              }
              if(bOk){
                ST7735_PlotLine(data);
                ST7735_PlotNextErase(); 
              }
            }
          }
        }
      }
      ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 120ms
    }
  }
}
Example #22
0
int main1(void){
  UINT8             IsDHCP = 0;
  _NetCfgIpV4Args_t ipV4;
  SlSockAddrIn_t    Addr;
  UINT16            AddrSize = 0;
  INT16             SockID = 0;
  INT16             Status = 1;  // ok
  UINT32            data;
  unsigned char     len = sizeof(_NetCfgIpV4Args_t);
  stopWDT();        // Stop WDT 
  initClk();        // PLL 50 MHz, ADC needs PPL active
  Board_Init();     // initialize LaunchPad I/O 
  ConfigureUART();  // Initialize the UART.
  UARTprintf("Section 11.4 IoT example, Volume 2 Real-time interfacing\n");
#if ADC
  ADC0_InitSWTriggerSeq3(7);  // Ain7 is on PD0
  UARTprintf("This node is configured to measure signals from Ain7=PD0\n");
#endif
#if EKG
  UARTprintf("This node is configured to generate simulated EKG data\n");
#endif
  UARTprintf("  and send UDP packets to IP: %d.%d.%d.%d  Port: %d\n\n",
      SL_IPV4_BYTE(IP_ADDR,3), SL_IPV4_BYTE(IP_ADDR,2), 
      SL_IPV4_BYTE(IP_ADDR,1), SL_IPV4_BYTE(IP_ADDR,0),PORT_NUM);
  while(1){
    sl_Start(0, 0, 0);/* Initializing the CC3100 device */
    /* Connecting to WLAN AP - Set with static parameters defined at the top
       After this call we will be connected and have IP address */
    WlanConnect();   // connect to AP
    /* Read the IP parameter */
    sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&IsDHCP,&len,(unsigned char *)&ipV4);
    UARTprintf("This node is at IP: %d.%d.%d.%d\n", SL_IPV4_BYTE(ipV4.ipV4,3), SL_IPV4_BYTE(ipV4.ipV4,2), SL_IPV4_BYTE(ipV4.ipV4,1), SL_IPV4_BYTE(ipV4.ipV4,0));
    while(Status > 0){
      Addr.sin_family = SL_AF_INET;
      Addr.sin_port = sl_Htons((UINT16)PORT_NUM);
      Addr.sin_addr.s_addr = sl_Htonl((UINT32)IP_ADDR);
      AddrSize = sizeof(SlSockAddrIn_t);
      SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
      if( SockID < 0 ){
        UARTprintf("SockIDerror ");
        Status = -1; // error
      }else{
        while(Status>0){
          UARTprintf("\nSending a UDP packet ...");
          uBuf[0] = ATYPE;   // defines this as an analog data type
          uBuf[1] = '='; 
#if ADC
          data = ADC0_InSeq3(); // 0 to 4095, Ain7 is on PD0
#endif
#if EKG
          data = EKGbuf[EKGindex];
          EKGindex = (EKGindex+1)%EKGSIZE; // 100 Hz
#endif
          Int2Str(data,(char*)&uBuf[2]); // [2] to [7] is 6 digit number
          UARTprintf(" %s ",uBuf);
          LED_Toggle();
          Status = sl_SendTo(SockID, uBuf, BUF_SIZE, 0,
                           (SlSockAddr_t *)&Addr, AddrSize);
          ROM_SysCtlDelay(ROM_SysCtlClockGet() / 25); // 80ms
          if( Status <= 0 ){
            UARTprintf("SockIDerror %d ",Status);
          }else{
           UARTprintf("ok");
          }     
        }
        sl_Close(SockID);
      }
    }
  }
}
Example #23
0
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
void main()
{
    long lRetVal = -1;

    //
    // Board Initialization
    //
    BoardInit();

    //
    // uDMA Initialization
    //
    UDMAInit();

    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

    //
    // Configuring UART
    //
    InitTerm();

    //
    // Display banner
    //
    DisplayBanner(APPLICATION_NAME);

    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 desired state at start of applicaton
    //
    // Note that all profiles and persistent settings that were done on the
    // device will be lost
    //
    lRetVal = ConfigureSimpleLinkToDefaultState();

    if(lRetVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
          UART_PRINT("Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    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
    //
    lRetVal = sl_Start(0, 0, 0);
    if (lRetVal < 0 || lRetVal != ROLE_STA)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Device started as STATION \n\r");

    UART_PRINT("Connecting to AP: %s ...\r\n",SSID_NAME);

    //
    //Connecting to WLAN AP
    //
    lRetVal = WlanConnect();
    if(lRetVal < 0)
    {
        UART_PRINT("Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Connected to AP: %s \n\r",SSID_NAME);

    UART_PRINT("Device IP: %d.%d.%d.%d\n\r\n\r",
                SL_IPV4_BYTE(g_ulIpAddr,3),
                SL_IPV4_BYTE(g_ulIpAddr,2),
                SL_IPV4_BYTE(g_ulIpAddr,1),
                SL_IPV4_BYTE(g_ulIpAddr,0));

#ifdef USER_INPUT_ENABLE
    lRetVal = UserInput();
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

#else
    lRetVal = BsdUdpClient(PORT_NUM);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }

    lRetVal = BsdUdpServer(PORT_NUM);
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }
#endif

    UART_PRINT("Exiting Application ...\n\r");

    //
    // power off the network processor
    //
    lRetVal = sl_Stop(SL_STOP_TIMEOUT);

    while (1)
    {
     _SlNonOsMainLoopTask();
    }
}
Example #24
0
//*****************************************************************************
//
//! \brief This function handles network events such as IP acquisition, IP
//!           leased, IP released etc.
//!
//! \param[in]  pNetAppEvent - Pointer to NetApp Event Info
//!
//! \return None
//!
//*****************************************************************************
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
    if(pNetAppEvent == NULL)
    {
        UART_PRINT("Null pointer\n\r");
        LOOP_FOREVER();
    }

    switch(pNetAppEvent->Event)
    {
        case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
        {
            SlIpV4AcquiredAsync_t *pEventData = NULL;

            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);

            //Ip Acquired Event Data
            pEventData = &pNetAppEvent->EventData.ipAcquiredV4;

            UART_PRINT("[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , "
                       "Gateway=%d.%d.%d.%d\n\r",
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,3),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,2),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,1),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,0),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,3),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,2),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,1),
            SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,0));

            UNUSED(pEventData);
        }
        break;

        case SL_NETAPP_IP_LEASED_EVENT:
        {
            SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_LEASED);

            //
            // Information about the IP-Leased details(like IP-Leased,lease-time,
            // mac etc) will be available in 'SlIpLeasedAsync_t' - Applications
            // can use it if required
            //
            // SlIpLeasedAsync_t *pEventData = NULL;
            // pEventData = &pNetAppEvent->EventData.ipLeased;
            //

        }
        break;

        case SL_NETAPP_IP_RELEASED_EVENT:
        {
            CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_LEASED);

            //
            // Information about the IP-Released details (like IP-address, mac
            // etc) will be available in 'SlIpReleasedAsync_t' - Applications
            // can use it if required
            //
            // SlIpReleasedAsync_t *pEventData = NULL;
            // pEventData = &pNetAppEvent->EventData.ipReleased;
            //
        }
		break;

        default:
        {
            UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r",
                       pNetAppEvent->Event);
        }
        break;
    }
}
Example #25
0
File: main.cpp Project: hangc2/wif
static void TFTPTask(void *pvParameters)
{
    SlSecParams_t secParams;
    unsigned char *pucFileBuffer = NULL;  // Data read or to be written
    unsigned long uiFileSize;

    const char *FileRead = "readFromServer.txt";  // File to be read using TFTP. Change string to filename
    const char *FileWrite = "writeToServer.txt"; // File to be written using TFTP. Change string to filename.

    long pFileHandle;			// Pointer to file handle
    SlFsFileInfo_t pFsFileInfo;
    long lRetVal = -1;
    unsigned short uiTftpErrCode;


//get wifi information
  //  get_wifi_info(ap_ssid, secPrams);

    // Configuring security parameters for the AP
    secParams.Key = (_i8*)SSID_KEY;
    secParams.KeyLen = 30;
    secParams.Type = SL_SEC_TYPE_WPA_WPA2;

    lRetVal = Network_IF_InitDriver(ROLE_STA);


    // Connecting to WLAN AP - Set with static parameters defined at the top
    // After this call we will be connected and have IP address
    lRetVal = Network_IF_ConnectAP((char*)SSID,secParams);

    UART_PRINT("Connecting to TFTP server %d.%d.%d.%d\n\r",\
                  SL_IPV4_BYTE(TFTP_IP, 3),SL_IPV4_BYTE(TFTP_IP, 2),
                  SL_IPV4_BYTE(TFTP_IP, 1),SL_IPV4_BYTE(TFTP_IP, 0));
    if(TFTP_READ)
    {
        uiFileSize = FILE_SIZE_MAX;

        pucFileBuffer = new unsigned char[uiFileSize];
        if(NULL == pucFileBuffer)
        {
            UART_PRINT("Can't Allocate Resources\r\n");
            LOOP_FOREVER();
        }

        memset(pucFileBuffer,'\0',uiFileSize);

        lRetVal = sl_TftpRecv(TFTP_IP, FileRead, (char *)pucFileBuffer,\
                                &uiFileSize, &uiTftpErrCode );
        UART_PRINT("file read is %s\n", pucFileBuffer);

        if(lRetVal < 0)
        {
            free(pucFileBuffer);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        lRetVal = sl_FsGetInfo((unsigned char *)FileRead, 0, &pFsFileInfo);

        if(lRetVal < 0 )
            lRetVal = sl_FsOpen((unsigned char *)FileRead,\
                    FS_MODE_OPEN_CREATE(FILE_SIZE_MAX,_FS_FILE_OPEN_FLAG_COMMIT|\
                      _FS_FILE_PUBLIC_WRITE), NULL,&pFileHandle);
        else
            lRetVal = sl_FsOpen((unsigned char *)FileRead,FS_MODE_OPEN_WRITE, \
                                NULL,&pFileHandle);

        if(lRetVal < 0)
        {
            free(pucFileBuffer);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        lRetVal = sl_FsWrite(pFileHandle,0, pucFileBuffer, uiFileSize);

        if(lRetVal < 0)
        {
            free(pucFileBuffer);
            lRetVal = sl_FsClose(pFileHandle,0,0,0);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        UART_PRINT("TFTP Read Successful \r\n");

        lRetVal = sl_FsClose(pFileHandle,0,0,0);

    }

    if(TFTP_WRITE)
    {
    	/* open same file which has been written with the server's file content */
        lRetVal = sl_FsOpen((unsigned char *)FileRead,FS_MODE_OPEN_READ, \
                                NULL,&pFileHandle);
        if(lRetVal < 0)
        {
            free(pucFileBuffer);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        lRetVal = sl_FsGetInfo((unsigned char *)FileRead, 0, &pFsFileInfo);
        if(lRetVal < 0)
        {
            lRetVal = sl_FsClose(pFileHandle,0,0,0);
            free(pucFileBuffer);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        uiFileSize = (&pFsFileInfo)->FileLen;

        lRetVal = sl_FsRead(pFileHandle, 0,  pucFileBuffer, uiFileSize);
        if(lRetVal < 0)
        {
            lRetVal = sl_FsClose(pFileHandle,0,0,0);
            free(pucFileBuffer);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        lRetVal = sl_FsClose(pFileHandle,0,0,0);
        /* write to server with different file name */
        lRetVal = sl_TftpSend(TFTP_IP, FileWrite,(char *) pucFileBuffer,\
                            &uiFileSize, &uiTftpErrCode  );
        if(lRetVal < 0)
        {
            free(pucFileBuffer);
            ERR_PRINT(lRetVal);
            LOOP_FOREVER();
        }

        UART_PRINT("TFTP Write Successful \r\n");
    }

    LOOP_FOREVER();
}
Example #26
0
//*****************************************************************************
//
//! UserInput
//!
//! This function
//!        1. Function for reading the user input for UDP RX/TX
//!
//! \return none
//
//*****************************************************************************
long UserInput()
{
    int iInput = 0;
    char acCmdStore[50];
    int lRetVal;
    int iRightInput = 0;
    unsigned long ulUserInputData = 0;

    UART_PRINT("Default settings: SSID Name: %s, PORT = %d, Packet Count = %d, "
                  "Destination IP: %d.%d.%d.%d\n\r",
            SSID_NAME, g_uiPortNum, g_ulPacketCount,
            SL_IPV4_BYTE(g_ulDestinationIp,3),
            SL_IPV4_BYTE(g_ulDestinationIp,2),
            SL_IPV4_BYTE(g_ulDestinationIp,1),
            SL_IPV4_BYTE(g_ulDestinationIp,0));

    do
    {
        UART_PRINT("\r\nOptions:\r\n1. Send UDP packets.\r\n2. Receive UDP "
                    "packets.\r\n3. Settings.\r\n4. Exit\r\n");
        UART_PRINT("Enter the option to use: ");
        lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
        if(lRetVal == 0)
        {
          //
          // No input. Just an enter pressed probably. Display a prompt.
          //
          UART_PRINT("\n\n\rEnter Valid Input.");
        }
        else
        {
            iInput  = (int)strtoul(acCmdStore,0,10);
            if(iInput  == 1)
            {
                UART_PRINT("Run iperf command \"iperf.exe -u -s -i 1\" and "
                            "press Enter\n\r");
                //
                // Wait to receive a character over UART
                //
                MAP_UARTCharGet(CONSOLE);
                UART_PRINT("Sending UDP packets...\n\r");

                // Before proceeding, please make sure to have a server 
                // waiting on PORT_NUM
                lRetVal = BsdUdpClient(g_uiPortNum);
                ASSERT_ON_ERROR(lRetVal);
            }
            else if(iInput  == 2)
            {
                UART_PRINT("Run iperf command \"iperf.exe -u -c %d.%d.%d.%d -i 1 "
                            "-t 100000\" and press Enter\n\r",
                          SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2),
                          SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0));
                
                //
                // Wait to receive a character over UART
                //
                MAP_UARTCharGet(CONSOLE);
                UART_PRINT("Receiving UDP packets...\n\r");
                
                // After calling this function, you can start sending data 
                // to CC3200 IP address on PORT_NUM
                lRetVal = BsdUdpServer(g_uiPortNum);
                ASSERT_ON_ERROR(lRetVal);
            }
            else if(iInput  == 3)
            {
              iRightInput = 0;
                do
                {
                    UART_PRINT("\n\rSetting Options:\n\r1. PORT\n\r2. Packet "
                               "Count\n\r3. Destination IP\n\r4. Main Menu\r\n");
                    UART_PRINT("Enter the option to use: ");
                    lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
                    if(lRetVal == 0)
                    {
                        //
                        // No input. Just an enter pressed probably. Display prompt.
                        //
                        UART_PRINT("\n\n\rEnter Valid Input.");
                    }
                    else
                    {

                        iInput  = (int)strtoul(acCmdStore,0,10);
                        //SettingInput(iInput);
                        switch(iInput)
                        {
                            case 1:
                            do
                            {
                                UART_PRINT("Enter new Port: ");
                                lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
                                if(lRetVal == 0)
                                {
                                  //
                                  // No input. Just an enter pressed probably. 
                                  // Display a prompt.
                                  //
                                  UART_PRINT("\n\rEnter Valid Input.");
                                  iRightInput = 0;
                                }
                                else
                                {
                                  ulUserInputData = (int)strtoul(acCmdStore,0,10);
                                  if(ulUserInputData <= 0 || ulUserInputData > 65535)
                                  {
                                    UART_PRINT("\n\rWrong Input");
                                    iRightInput = 0;
                                  }
                                  else
                                  {
                                    g_uiPortNum = ulUserInputData;
                                    iRightInput = 1;
                                  }
                                }

                                UART_PRINT("\r\n");
                            }while(!iRightInput);

                            iRightInput = 0;
                            break;
                        case 2:
                            do
                            {
                                UART_PRINT("Enter Packet Count: ");
                                lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
                                if(lRetVal == 0)
                                {
                                  //
                                  // No input. Just an enter pressed probably.
                                  // Display a prompt.
                                  //
                                  UART_PRINT("\n\rEnter Valid Input.");
                                  iRightInput = 0;
                                }
                                else
                                {
                                    ulUserInputData = (int)strtoul(acCmdStore,0,10);
                                  if(ulUserInputData <= 0 || ulUserInputData > 9999999)
                                  {
                                    UART_PRINT("\n\rWrong Input");
                                    iRightInput = 0;
                                  }
                                  else
                                  {
                                      g_ulPacketCount = ulUserInputData;
                                    iRightInput = 1;
                                  }
                                }

                                UART_PRINT("\r\n");
                            }while(!iRightInput);
                            iRightInput = 0;
                            break;
                        case 3:
                            do
                            {
                                UART_PRINT("Enter Destination IP: ");
                                lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
                                if(lRetVal == 0)
                                {
                                  //
                                  // No input. Just an enter pressed probably. 
                                  // Display a prompt.
                                  //
                                  UART_PRINT("\n\rEnter Valid Input.");
                                  iRightInput = 0;
                                }
                                else
                                {
                                if(IpAddressParser(acCmdStore) < 0)
                                  {
                                    UART_PRINT("\n\rWrong Input");
                                    iRightInput = 0;
                                  }
                                  else
                                  {
                                    iRightInput = 1;
                                  }
                                }

                                UART_PRINT("\r\n");
                            }while(!iRightInput);
                            iRightInput = 0;
                            break;
                        case 4:
                            iRightInput = 1;
                            break;
                            
                        default:
                            break;

                        }

                    }
                }while(!iRightInput);

            }
            else if(iInput == 4)
            {
              break;
            }
            else
            {
              UART_PRINT("\n\n\rWrong Input");
            }
        }
        UART_PRINT("\n\r");
    }while(1);

    return 0 ;

}
Example #27
0
//*****************************************************************************
//
//! Network_IF_ConnectAP  Connect to an Access Point using the specified SSID
//!
//! \param  pcSsid is a string of the AP's SSID
//!
//! \return none
//
//*****************************************************************************
int
Network_IF_ConnectAP(char *pcSsid, SlSecParams_t SecurityParams)
{
    char acCmdStore[128];
    unsigned short usConnTimeout;
    int iRetVal;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefGateway = 0;
    unsigned long ulDns = 0;
    unsigned char ucRecvdAPDetails;

    Network_IF_DisconnectFromAP();

    //
    // This triggers the CC3200 to connect to specific AP
    //
    sl_WlanConnect(pcSsid, strlen(pcSsid), NULL, &SecurityParams, NULL);

    //
    // Wait to check if connection to DIAGNOSTIC_AP succeeds
    //
    while(g_usConnectIndex < 10)
    {
        MAP_UtilsDelay(8000000);
        g_usConnectIndex++;
        if(IS_CONNECTED(g_ulStatus))
        {
            break;
        }
    }

    //
    // Check and loop until async event from network processor indicating Wlan
    // Connect success was received
    //
    while(!(IS_CONNECTED(g_ulStatus)))
    {
        //
        // Disconnect the previous attempt
        //
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        UART_PRINT("Device could not connect to %s\n\r",pcSsid);

        do
        {
            ucRecvdAPDetails = 0;

            UART_PRINT("\n\r\n\rPlease enter the AP(open) SSID name # ");

            //
            // Get the AP name to connect over the UART
            //
            iRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
            if(iRetVal > 0)
            {
                //
                // Parse the AP name
                //
                pcSsid = strtok(acCmdStore, ":");
                if(pcSsid != NULL)
                {

                    ucRecvdAPDetails = 1;

                }
            }
        } while(ucRecvdAPDetails == 0);

        UART_PRINT("\n\rTrying to connect to AP: %s ...\n\r",pcSsid);
        /*UART_PRINT("Key: %s, Len: %d, KeyID: %d, Type: %d\n\r",
                    SecurityParams.Key, SecurityParams.KeyLen
                      , SecurityParams.Type);
        */

        //
        // Get the current timer tick and setup the timeout accordingly
        //
        usConnTimeout = g_usConnectIndex + 10;

        //
        // This triggers the CC3200 to connect to specific AP
        //
        sl_WlanConnect(pcSsid, strlen(pcSsid), NULL, &SecurityParams, NULL);

        //
        // Wait to check if connection to specifed AP succeeds
        //
        while(!(IS_CONNECTED(g_ulStatus)))
        {
            if(g_usConnectIndex >= usConnTimeout)
            {
                break;
            }
            MAP_UtilsDelay(8000000);
            g_usConnectIndex++;
        }
    }

    //
    // Wait until IP is acquired
    //
    while(!(IS_IP_ACQUIRED(g_ulStatus)));

    //
    // Put message on UART
    //
    UART_PRINT("\n\rDevice has connected to %s\n\r",pcSsid);

    //
    // Get IP address
    //
    Network_IF_IpConfigGet(&ulIP,&ulSubMask,&ulDefGateway,&ulDns);

    //
    // Send the information
    //
    UART_PRINT("Device IP Address is %d.%d.%d.%d \n\r\n\r",
               SL_IPV4_BYTE(ulIP, 3),SL_IPV4_BYTE(ulIP, 2),
               SL_IPV4_BYTE(ulIP, 1),SL_IPV4_BYTE(ulIP, 0));
    return 0;
}