/*---------------------------------------------------------------------------* * Routine: App_InitModule *---------------------------------------------------------------------------* * Description: * Setup the mode by first checking if there is a link and either * report or continue to the rest of the program. * Inputs: * void * Outputs: * void *---------------------------------------------------------------------------*/ void App_InitModule(void) { ATLIBGS_MSG_ID_E r = ATLIBGS_MSG_ID_NONE; DisplayLCD(LCD_LINE7, " Preparing"); DisplayLCD(LCD_LINE8, " Init Mod"); /* Give the unit a little time to start up */ /* (300 ms for GS1011 and 1000 ms for GS1500) */ MSTimerDelay(1000); /* Check the link */ #ifdef ATLIBGS_DEBUG_ENABLE ConsolePrintf("Checking link\r\n"); #endif /* Wait for the banner (if any) */ MSTimerDelay(500); /* Clear out the buffers */ AtLibGs_FlushRxBuffer(); /* Send command to check */ do { AtLibGs_FlushIncomingMessage(); DisplayLCD(LCD_LINE8, "Checking..."); r = AtLibGs_Check(); } while (ATLIBGS_MSG_ID_OK != r); /* Send command to DISABLE echo */ do { DisplayLCD(LCD_LINE8, "Echo Off..."); r = AtLibGs_SetEcho(ATLIBGS_DISABLE); } while (ATLIBGS_MSG_ID_OK != r); /* Done */ DisplayLCD(LCD_LINE7, ""); DisplayLCD(LCD_LINE8, ""); }
void GS_API_Init(char *port){ GS_HAL_init(port); //GS_HAL_send("\r\n", 2); // Flush buffer until we get a valid response AtLib_FlushIncomingMessage(); // Try to reset //if(AtLibGs_Reset() == HOST_APP_MSG_ID_APP_RESET) // GS_API_Printf("Reset OK"); //else // GS_API_Printf("Reset Fail"); // Turn off echo AtLibGs_SetEcho(0); // Turn on Bulk Data AtLibGs_BData(1); // Read saved network parameters //gs_api_readNetworkConfig(); AtLib_FlushIncomingMessage(); }
/*---------------------------------------------------------------------------* * Routine: WIFI_init *---------------------------------------------------------------------------* * Description: * Initial setting + DHCP and show status on the LCD. * * Inputs: * void * Outputs: * ATLIBGS_MSG_ID_E *---------------------------------------------------------------------------*/ ATLIBGS_MSG_ID_E WIFI_init(int16_t showMessage) { ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE; char wifi_mac[20]; // Check the link #ifdef HOST_APP_DEBUG_ENABLE ConsolePrintf("Checking link\r\n"); #endif AtLibGs_Init(); // Wait for the banner MSTimerDelay(500); // Send command to check do { AtLibGs_FlushIncomingMessage(); DisplayLCD(LCD_LINE8, "Checking..."); rxMsgId = AtLibGs_Check(); } while (ATLIBGS_MSG_ID_OK != rxMsgId); do { rxMsgId = AtLibGs_SetEcho(0); // disable Echo }while (ATLIBGS_MSG_ID_OK != rxMsgId); do { rxMsgId = AtLibGs_Version(); // check the GS version }while (ATLIBGS_MSG_ID_OK != rxMsgId); // Get MAC Address & Show rxMsgId = AtLibGs_GetMAC(wifi_mac); if (rxMsgId == ATLIBGS_MSG_ID_OK) AtLibGs_ParseGetMacResponse(wifi_mac); memset(&wifi_mac[12], 0, 7); if (showMessage > 0) { DisplayLCD(LCD_LINE5, "MAC ADDRESS"); DisplayLCD(LCD_LINE6, (const uint8_t *)wifi_mac); DisplayLCD(LCD_LINE2, (const uint8_t *)AppVersion); MSTimerDelay(2000); DisplayLCD(LCD_LINE2, " "); } do { AtLibGs_FlushIncomingMessage(); DisplayLCD(LCD_LINE8, "Disassociate"); rxMsgId = AtLibGs_DisAssoc(); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Enable DHCP do { DisplayLCD(LCD_LINE8, "DHCP On..."); rxMsgId = AtLibGs_DHCPSet(1); } while (ATLIBGS_MSG_ID_OK != rxMsgId); if(strlen(GNV_Setting.webprov.ssid) > 0) { if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP) { do { DisplayLCD(LCD_LINE8, " Setting WEP"); rxMsgId = AtLibGs_SetWEP1((int8_t*)GNV_Setting.webprov.password); } while (ATLIBGS_MSG_ID_OK != rxMsgId); DisplayLCD(LCD_LINE8, " WEP Set"); } else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_PER) { do { DisplayLCD(LCD_LINE8, " Setting PSK"); rxMsgId = AtLibGs_CalcNStorePSK(GNV_Setting.webprov.ssid, GNV_Setting.webprov.password); } while (ATLIBGS_MSG_ID_OK != rxMsgId); DisplayLCD(LCD_LINE8, " PSK Set"); } else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_ENT) { // Set AT+WAUTH=0 for WPA or WPA2 do { DisplayLCD(LCD_LINE8, " " ); rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Security Configuration do { DisplayLCD(LCD_LINE8, "Set Security"); rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMAUTO); } while (ATLIBGS_MSG_ID_OK != rxMsgId); } } else { #ifdef HOST_APP_SEC_WEP // Set AT+WAUTH=2 for WEP do { DisplayLCD(LCD_LINE8, " WEP AUTH " ); rxMsgId = AtLibGs_SetAuthentictionMode(2); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Set WEP do { rxMsgId = AtLibGs_SetWEP1(HOST_APP_AP_SEC_WEP); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Security Configuration do { rxMsgId = AtLibGs_SetSecurity(2); // WEP } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_SEC_PSK // Store the PSK value. This call takes might take few seconds to return do { DisplayLCD(LCD_LINE8, "Setting PSK"); rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_SEC_OPEN // Store the PSK value. This call takes might take few seconds to return do { DisplayLCD(LCD_LINE8, "No Security" ); rxMsgId = AtLibGs_SetAuthentictionMode(1); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_WPA // Set AT+WAUTH=0 for WPA or WPA2 do { DisplayLCD(LCD_LINE8, " WPA " ); rxMsgId = AtLibGs_SetAuthentictionMode(0); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Store the PSK value. This call takes might take few seconds to return do { DisplayLCD(LCD_LINE8, "Setting PSK"); rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Security Configuration do { DisplayLCD(LCD_LINE8, " WPA "); rxMsgId = AtLibGs_SetSecurity(4); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_WPA2 // Set AT+WAUTH=0 for WPA or WPA2 do { DisplayLCD(LCD_LINE8, " WPA2 " ); rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Store the PSK value. This call takes might take few seconds to return do { DisplayLCD(LCD_LINE8, "Setting PSK"); rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Security Configuration do { DisplayLCD(LCD_LINE8, " Set WPA "); rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMWPA2PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif } // Clear MAC Address and show WIFI DisplayLCD(LCD_LINE6, " WIFI "); DisplayLCD(LCD_LINE5, " "); return rxMsgId; }
ATLIBGS_MSG_ID_E WIFI_init(int16_t showMessage) { ATLIBGS_MSG_ID_E rxMsgId = ATLIBGS_MSG_ID_NONE; // Check the link #ifdef HOST_APP_DEBUG_ENABLE ConsolePrintf("Checking link\r\n"); #endif AtLibGs_Init(); // Wait for the banner MSTimerDelay(500); /* Send command to check */ do { AtLibGs_FlushIncomingMessage(); DisplayLCD(LCD_LINE4, "wl_check.. "); rxMsgId = AtLibGs_Check(); } while (ATLIBGS_MSG_ID_OK != rxMsgId); do { rxMsgId = AtLibGs_SetEcho(0); // disable Echo }while (ATLIBGS_MSG_ID_OK != rxMsgId); do { rxMsgId = AtLibGs_Version(); // check the GS version }while (ATLIBGS_MSG_ID_OK != rxMsgId); #if 0 if(strstr((const char *)MRBuffer, "2.3.")) // still debug why receive 2 extra bytes: ESC S { G_Extra2B = 2; } #endif do{ rxMsgId = AtLibGs_EnableRadio(1); // enable radio }while(rxMsgId != ATLIBGS_MSG_ID_OK); /* Get MAC Address & Show */ rxMsgId = AtLibGs_GetMAC(WiFiMAC); if (rxMsgId == ATLIBGS_MSG_ID_OK) AtLibGs_ParseGetMacResponse(WifiMAC); if (showMessage > 0) { DisplayLCD(LCD_LINE3, (const uint8_t *)WifiMAC); MSTimerDelay(2000); } do { AtLibGs_FlushIncomingMessage(); DisplayLCD(LCD_LINE4, "wl_disass.. "); rxMsgId = AtLibGs_DisAssoc(); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Enable DHCP do { DisplayLCD(LCD_LINE4, "wl_dhcpon.. "); rxMsgId = AtLibGs_DHCPSet(1); } while (ATLIBGS_MSG_ID_OK != rxMsgId); if(strlen(GNV_Setting.webprov.ssid) > 0) { if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WEP) { do { DisplayLCD(LCD_LINE4, "wl_setwep.. "); rxMsgId = AtLibGs_SetWEP1((int8_t*)GNV_Setting.webprov.password); } while (ATLIBGS_MSG_ID_OK != rxMsgId); DisplayLCD(LCD_LINE4, "wl_wepset.. "); } else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_PER) { do { DisplayLCD(LCD_LINE4, "wl_setpsk.. "); rxMsgId = AtLibGs_CalcNStorePSK(GNV_Setting.webprov.ssid, GNV_Setting.webprov.password); } while (ATLIBGS_MSG_ID_OK != rxMsgId); DisplayLCD(LCD_LINE4, "wl_pskset.. "); } else if(GNV_Setting.webprov.security == ATLIBGS_PROVSECU_WPA_ENT) { /* Set AT+WAUTH=0 for WPA or WPA2 */ do { DisplayLCD(LCD_LINE4, " " ); rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA); } while (ATLIBGS_MSG_ID_OK != rxMsgId); /* Security Configuration */ do { DisplayLCD(LCD_LINE4, "wl_setsec.. "); rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMAUTO); } while (ATLIBGS_MSG_ID_OK != rxMsgId); } } else { #ifdef HOST_APP_SEC_WEP // Set AT+WAUTH=2 for WEP do { DisplayLCD(LCD_LINE4, "wl_wepauth.." ); rxMsgId = AtLibGs_SetAuthentictionMode(2); } while (ATLIBGS_MSG_ID_OK != rxMsgId); // Set WEP do { rxMsgId = AtLibGs_SetWEP1(HOST_APP_AP_SEC_WEP); } while (ATLIBGS_MSG_ID_OK != rxMsgId); /* Security Configuration */ do { rxMsgId = AtLibGs_SetSecurity(2); // WEP } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_SEC_PSK /* Store the PSK value. This call takes might take few seconds to return */ do { DisplayLCD(LCD_LINE4, "wl_setpsk.. "); rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_SEC_OPEN /* Store the PSK value. This call takes might take few seconds to return */ do { DisplayLCD(LCD_LINE4, "wl_nosec.. " ); rxMsgId = AtLibGs_SetAuthentictionMode(1); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_WPA // Set AT+WAUTH=0 for WPA or WPA2 do { DisplayLCD(LCD_LINE4, "wl_wpa.. " ); rxMsgId = AtLibGs_SetAuthentictionMode(0); } while (ATLIBGS_MSG_ID_OK != rxMsgId); /* Store the PSK value. This call takes might take few seconds to return */ do { DisplayLCD(LCD_LINE4, "wl_setpsk.. "); rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); /* Security Configuration */ do { DisplayLCD(LCD_LINE4, "wl_wpa.. "); rxMsgId = AtLibGs_SetSecurity(4); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif #ifdef HOST_APP_WPA2 // Set AT+WAUTH=0 for WPA or WPA2 do { DisplayLCD(LCD_LINE4, "wl_wpa2.. " ); rxMsgId = AtLibGs_SetAuthentictionMode(ATLIBGS_AUTHMODE_NONE_WPA); } while (ATLIBGS_MSG_ID_OK != rxMsgId); /* Store the PSK value. This call takes might take few seconds to return */ do { DisplayLCD(LCD_LINE4, "wl_setpsk.. "); rxMsgId = AtLibGs_CalcNStorePSK(HOST_APP_AP_SSID, HOST_APP_AP_SEC_PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); /* Security Configuration */ do { DisplayLCD(LCD_LINE4, "wl_setwpa.. "); rxMsgId = AtLibGs_SetSecurity(ATLIBGS_SMWPA2PSK); } while (ATLIBGS_MSG_ID_OK != rxMsgId); #endif } return rxMsgId; }
/*--------------------------------------------------------------------------*/ T_uezError GainSpan_CmdLib_ConfigureForSPI( const T_GainSpan_CmdLib_SPISettings *aSettings) { T_uezError error; ATLIBGS_MSG_ID_E r; int i; G_GSCmdLibSettings = *aSettings; G_GSSPITemplate.iBitsPerTransfer = 8; G_GSSPITemplate.iCSPolarity = EFalse; // Falling edge G_GSSPITemplate.iClockOutPolarity = EFalse; // Falling edge G_GSSPITemplate.iClockOutPhase = EFalse; // ETrue; G_GSSPITemplate.iDataMISO = 0; G_GSSPITemplate.iDataMISO = 0; G_GSSPITemplate.iNumTransferredIn = 0; G_GSSPITemplate.iNumTransferredOut = 0; G_GSSPITemplate.iRate = aSettings->iRate / 1000; G_GSSPITemplate.iCSGPIOPort = GPIO_TO_HAL_PORT(aSettings->iSPIChipSelect); G_GSSPITemplate.iCSGPIOBit = GPIO_TO_PIN_BIT(aSettings->iSPIChipSelect); error = UEZSPIOpen(G_GSCmdLibSettings.iSPIDeviceName, &G_GSSPI); if (error) return error; // Ensure these pins are not configured elsewhere UEZGPIOLock(G_GSCmdLibSettings.iDataReadyIO); if (G_GSCmdLibSettings.iSRSTn != GPIO_NONE ){ UEZGPIOLock(G_GSCmdLibSettings.iSRSTn); UEZGPIOOutput(G_GSCmdLibSettings.iSRSTn); // WIFI_SRSTn } UEZGPIOInput(G_GSCmdLibSettings.iDataReadyIO); // WIFI IRQ if (G_GSCmdLibSettings.iProgramMode != GPIO_NONE ) { UEZGPIOLock(G_GSCmdLibSettings.iProgramMode); UEZGPIOClear(G_GSCmdLibSettings.iProgramMode); // WIFI PROGRAM OFF UEZGPIOOutput(G_GSCmdLibSettings.iProgramMode); // WIFI PROGRAM OFF } if (G_GSCmdLibSettings.iSPIMode != GPIO_NONE ) { UEZGPIOLock(G_GSCmdLibSettings.iSPIMode); UEZGPIOSet(G_GSCmdLibSettings.iSPIMode); // WIFI_MODE SPI UEZGPIOOutput(G_GSCmdLibSettings.iSPIMode); // WIFI_MODE SPI } UEZTaskDelay(1250); if (G_GSCmdLibSettings.iSRSTn != GPIO_NONE ) UEZGPIOSet(G_GSCmdLibSettings.iSRSTn); // WIFI_SRSTn UEZTaskDelay(1000); // Initialize the GainSpan SPI routines GainSpan_SPI_Start(); // Flush anything there AtLibGs_FlushIncomingMessage(); /* Send command to check 5 times for module */ for (i = 0; i < 5; i++){ AtLibGs_FlushIncomingMessage(); r = AtLibGs_Check(GAINSPAN_AT_DEFAULT_TIMEOUT); if(ATLIBGS_MSG_ID_OK == r){ break; } } if(ATLIBGS_MSG_ID_RESPONSE_TIMEOUT == r){ return UEZ_ERROR_NOT_FOUND; } /* Send command to DISABLE echo */ do { r = AtLibGs_SetEcho(ATLIBGS_DISABLE); } while (ATLIBGS_MSG_ID_OK != r); // For now, just report it is not found if (r != ATLIBGS_MSG_ID_OK) return UEZ_ERROR_NOT_FOUND; return UEZ_ERROR_NONE; }