//***************************************************************************** // //! 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 ; }
//**************************************************************************** // 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(); } }
//**************************************************************************** // 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(); } }