void WF_AssertionFailed(UINT8 moduleNumber, UINT16 lineNumber) { #if defined(STACK_USE_UART) char buf[8]; putrsUART("WF ASSERTION: Module Number = "); sprintf(buf, "%d ", moduleNumber); putsUART(buf); putrsUART("Line Number = "); sprintf(buf, "%d", lineNumber); putsUART(buf); #endif #if defined(USE_LCD) { char buf[] = {WIFI_ASSERT_STRING}; memset(LCDText, ' ', sizeof(LCDText)); memcpy((void *)LCDText, (void *)buf, strlen(buf)); uitoa(moduleNumber, (BYTE*)buf); memcpy((void *)&LCDText[18], (void *)buf, strlen(buf)); LCDText[23] = 'L'; LCDText[24] = ':'; uitoa(lineNumber, &LCDText[25]); LCDUpdate(); } #endif while(1); }
void printStatus(STATUS *st) { sprintf(outBuf,"\r\n\r\nDI:%u",st->heading); putsUART(outBuf); sprintf(outBuf,"\r\nLO:%u",st->location); putsUART(outBuf); sprintf(outBuf,"\r\nOC:%u",st->obzEntrCnt); putsUART(outBuf); }
BOOL iwconfigGetMacStats(void) { tWFMacStats my_WFMacStats; WF_GetMacStats(&my_WFMacStats); putsUART("MibRxMICFailureCounts = "); { char buf_t[16]; sprintf(buf_t,"%u",(unsigned int)(my_WFMacStats.MibRxMICFailureCtr)); putsUART(buf_t); } //putsUART("\r\n"); return TRUE; }
extern void WFDisplayScanMgr() { tWFScanResult bssDesc; char ssid[32]; if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) return; if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) return; if (!IS_SCAN_STATE_VALID(SCANCXT.scanState)) return; WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc); /* Display SSID */ sprintf(ssid, "%s\r\n", bssDesc.ssid); putsUART(ssid); if (++SCANCXT.displayIdx == SCANCXT.numScanResults) { SCAN_CLEAR_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; #if defined(WF_CONSOLE) WFConsoleReleaseConsoleMsg(); #endif } return; }
/*= CursorRight_N ============================================================== Purpose: Moves the cursor left N characters to the right Inputs: n -- number of characters to move the cursor to the left Note: This sequence only takes a single digit of length, so may need to do the move in steps Returns: none ============================================================================*/ void CursorRight_N(UINT8 n) { INT8 sequence_string[sizeof(cursorRightEscapeSequence) + 2]; /* null and extra digit */ // ASSERT(n <= (strlen(g_ConsoleContext.buf) + CMD_LINE_PROMPT_LENGTH)); if (n > 0u) { SET_CURSOR( GET_CURSOR() + n ); sequence_string[0] = cursorRightEscapeSequence[0]; /* ESC */ sequence_string[1] = cursorRightEscapeSequence[1]; /* '[' */ if (n < 10u) { sequence_string[2] = n + '0'; /* ascii digit */ sequence_string[3] = cursorRightEscapeSequence[3]; /* 'C' */ sequence_string[4] = '\0'; } else { sequence_string[2] = (n / 10) + '0'; /* first ascii digit */ sequence_string[3] = (n % 10) + '0'; /* second ascii digit */ sequence_string[4] = cursorRightEscapeSequence[3]; /* 'C' */ sequence_string[5] = '\0'; } putsUART( (char *) sequence_string); } }
/***************************************************************************** * FUNCTION: RawSetByte * * RETURNS: None * * PARAMS: * rawId - RAW ID * pBuffer - Buffer containing bytes to write * length - number of bytes to read * * NOTES: Writes bytes to RAW window *****************************************************************************/ void RawSetByte(UINT16 rawId, UINT8 *pBuffer, UINT16 length) { UINT8 regId; #if defined(OUTPUT_RAW_TX_RX) UINT16 i; #endif /* if previously set index past legal range and now trying to write to RAW engine */ if ( (rawId == 0) && g_rxIndexSetBeyondBuffer && (GetRawWindowState(RAW_TX_ID) == WF_RAW_DATA_MOUNTED) ) { // WF_ASSERT(FALSE); /* attempting to write past end of RAW window */ } /* write RAW data to chip */ regId = (rawId==RAW_ID_0)?RAW_0_DATA_REG:RAW_1_DATA_REG; WriteWFArray(regId, pBuffer, length); #if defined(OUTPUT_RAW_TX_RX) for (i = 0; i < length; ++i) { char buf[16]; sprintf(buf,"T: %#x\r\n", pBuffer[i]); putsUART(buf); } #endif }
void do_ping_cmd(void) { int i; if(ARGC < 2u) { putsUART("Please input destination: ping xx.xx.xx.xx count\r\n"); return; } for(i=0;i<strlen((const char*)ARGV[1]);i++) PING_Console_Host[i] = ARGV[1][i]; if(ARGC == 3u) { #if defined (STACK_USE_CERTIFICATE_DEBUG) if( strcmppgm2ram((char*)ARGV[2], "forever") == 0) { b_PingFroever = TRUE; } else #endif sscanf((const char*)ARGV[2],"%d",(int*)&Count_PingConsole); } else Count_PingConsole = 4; }
/***************************************************************************** * FUNCTION: RawGetByte * * RETURNS: error code * * PARAMS: * rawId - RAW ID * pBuffer - Buffer to read bytes into * length - number of bytes to read * * NOTES: Reads bytes from the RAW engine *****************************************************************************/ void RawGetByte(UINT16 rawId, UINT8 *pBuffer, UINT16 length) { UINT8 regId; #if defined(OUTPUT_RAW_TX_RX) char buf[8]; #endif /* if reading a data message do following check */ if (!g_WaitingForMgmtResponse) { // if RAW index previously set out of range and caller is trying to do illegal read if ((rawId == RAW_RX_ID) && g_rxIndexSetBeyondBuffer && (GetRawWindowState(RAW_RX_ID) == WF_RAW_DATA_MOUNTED)) { WF_ASSERT(FALSE); /* attempting to read past end of RAW buffer */ } } regId = (rawId == RAW_ID_0) ? RAW_0_DATA_REG : RAW_1_DATA_REG; ReadWFArray(regId, pBuffer, length); #if defined(OUTPUT_RAW_TX_RX) putrsUART("R:"); while (length-- != 0) { sprintf(buf," %02X", *pBuffer++); putsUART(buf); } putrsUART("\r\n"); #endif }
/***************************************************************************** * FUNCTION: RawSetByte * * RETURNS: None * * PARAMS: * rawId - RAW ID * pBuffer - Buffer containing bytes to write * length - number of bytes to read * * NOTES: Writes bytes to RAW window *****************************************************************************/ void RawSetByte(UINT16 rawId, UINT8 *pBuffer, UINT16 length) { UINT8 regId; #if defined(OUTPUT_RAW_TX_RX) char buf [8]; #endif /* if previously set index past legal range and now trying to write to RAW engine */ if ( (rawId == 0) && g_rxIndexSetBeyondBuffer && (GetRawWindowState(RAW_TX_ID) == WF_RAW_DATA_MOUNTED) ) { // WF_ASSERT(FALSE); /* attempting to write past end of RAW window */ } /* write RAW data to chip */ regId = (rawId == RAW_ID_0) ? RAW_0_DATA_REG : RAW_1_DATA_REG; WriteWFArray(regId, pBuffer, length); #if defined(OUTPUT_RAW_TX_RX) putrsUART("T:"); while (length-- != 0) { sprintf(buf," %02X", *pBuffer++); putsUART(buf); } putrsUART("\r\n"); #endif }
/***************************************************************************** * FUNCTION: RawGetByte * * RETURNS: error code * * PARAMS: * rawId - RAW ID * pBuffer - Buffer to read bytes into * length - number of bytes to read * * NOTES: Reads bytes from the RAW engine *****************************************************************************/ void RawGetByte(uint16_t rawId, uint8_t *pBuffer, uint16_t length) { uint8_t regId; #if defined(OUTPUT_RAW_TX_RX) uint16_t i; #endif /* if reading a data message do following check */ if (!g_WaitingForMgmtResponse) { // if RAW index previously set out of range and caller is trying to do illegal read if ( (rawId==RAW_RX_ID) && g_rxIndexSetBeyondBuffer && (GetRawWindowState(RAW_RX_ID) == WF_RAW_DATA_MOUNTED) ) { WF_ASSERT(false); /* attempting to read past end of RAW buffer */ } } regId = (rawId==RAW_ID_0) ? RAW_0_DATA_REG:RAW_1_DATA_REG; ReadWFArray(regId, pBuffer, length); #if defined(OUTPUT_RAW_TX_RX) for (i = 0; i < length; ++i) { char buf[16]; sprintf(buf,"R: %#x\r\n", pBuffer[i]); putsUART(buf); } #endif }
extern void WFDisplayScanMgr() { tWFScanResult bssDesc; char ssid[32]; char rssiChan[48]; if (SCANCXT.numScanResults == 0) return; if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) return; if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) return; if (!IS_SCAN_STATE_VALID(SCANCXT.scanState)) return; WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc); /* Display SSID */ sprintf(ssid, "%s\r\n", bssDesc.ssid); putsUART(ssid); /* Display SSID & Channel */ /* RSSI_MAX : 200, RSSI_MIN : 106 */ sprintf(rssiChan, " => RSSI: %u, Channel: %u\r\n", bssDesc.rssi, bssDesc.channel); putsUART(rssiChan); if (++SCANCXT.displayIdx == SCANCXT.numScanResults) { SCAN_CLEAR_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; #if defined(WF_CONSOLE) WFConsoleReleaseConsoleMsg(); #endif } return; }
/******************************************************* * "Soft" real-time event handler for slow rate ********************************************************/ void slow_event_handler(void) { if(slow_event_count > slow_ticks_limit) { slow_event_count = 0; if(control_flags.first_scan) { putsUART((unsigned char *)WelcomeMsg,&UART1); //putsUART((unsigned char *)WelcomeMsg,&UART2); control_flags.first_scan = 0; } // (RAM) Parameters update management if(control_flags.PAR_update_req) { update_params(); control_flags.PAR_update_req = 0; } if(direction_flags.word != direction_flags_prev) { // RESET COUNTS QEI1_Init(); QEI2_Init(); Timer1_Init(); Timer4_Init(); direction_flags_prev = direction_flags.word; } // EEPROM update management if(control_flags.EE_update_req) { control_flags.EE_update_req = 0; } update_delta_joints(); update_delta_EE();//aggiornamento delle strutture dati status_flags.homing_done = home_f.done; // SACT protocol timeout manager (see SACT_protocol.c) SACT_timeout(); SACT_SendSDP(); SACT_SendSSP(); // CONTROL MODE STATE MANAGER control_mode_manager(); } // END IF slow_event_count.. }// END slow_event_handler
static void OutputMacAddress(void) { UINT8 mac[6]; int i; char buf[4]; WF_GetMacAddress(mac); for (i = 0; i < 6; ++i) { sprintf(buf, "%02X ", mac[i]); putsUART(buf); } putrsUART("\r\n"); }
// Writes an IP address to the LCD display and the UART as available void DisplayIPValue(IP_ADDR IPVal) { // printf("%u.%u.%u.%u", IPVal.v[0], IPVal.v[1], IPVal.v[2], IPVal.v[3]); #if defined (__dsPIC33E__) || defined (__PIC24E__) static BYTE IPDigit[4]; /* Needs to be declared as static to avoid the array getting optimized by C30 v3.30 compiler for dsPIC33E/PIC24E. Otherwise the LCD displays corrupted IP address on Explorer 16. To be fixed in the future compiler release*/ #else BYTE IPDigit[4]; #endif BYTE i; #ifdef USE_LCD BYTE j; BYTE LCDPos=16; #endif for(i = 0; i < sizeof(IP_ADDR); i++) { uitoa((WORD)IPVal.v[i], IPDigit); #if defined(STACK_USE_UART) putsUART((char *) IPDigit); #endif #ifdef USE_LCD for(j = 0; j < strlen((char*)IPDigit); j++) { LCDText[LCDPos++] = IPDigit[j]; } if(i == sizeof(IP_ADDR)-1) break; LCDText[LCDPos++] = '.'; #else if(i == sizeof(IP_ADDR)-1) break; #endif #if defined(STACK_USE_UART) while(BusyUART()); WriteUART('.'); #endif } #ifdef USE_LCD if(LCDPos < 32u) LCDText[LCDPos] = 0; LCDUpdate(); #endif }
static UINT8 SetMode_idle(void) { UINT8 networkType; WF_CPGetNetworkType(iwconfigCb.cpId, &networkType); if (FALSE == iwconfigCb.isIdle ) { if (WF_CMDisconnect() != WF_SUCCESS) { putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n"); } WF_PsPollDisable(); #ifdef STACK_USE_CERTIFICATE_DEBUG DelayMs(100); #endif } return networkType; }
// Writes an IP address to the LCD display and the UART as available void DisplayIPValue(IP_ADDR IPVal) { // printf("%u.%u.%u.%u", IPVal.v[0], IPVal.v[1], IPVal.v[2], IPVal.v[3]); BYTE IPDigit[4]; BYTE i; #ifdef USE_LCD BYTE j; BYTE LCDPos=16; #endif for(i = 0; i < sizeof(IP_ADDR); i++) { uitoa((WORD)IPVal.v[i], IPDigit); #if defined(STACK_USE_UART) putsUART((char *) IPDigit); #endif #ifdef USE_LCD for(j = 0; j < strlen((char*)IPDigit); j++) { LCDText[LCDPos++] = IPDigit[j]; } if(i == sizeof(IP_ADDR)-1) break; LCDText[LCDPos++] = '.'; #else if(i == sizeof(IP_ADDR)-1) break; #endif #if defined(STACK_USE_UART) while(BusyUART()); WriteUART('.'); #endif } #ifdef USE_LCD if(LCDPos < 32u) LCDText[LCDPos] = 0; LCDUpdate(); #endif }
void WFConsolePrintHex(UINT32 val, UINT8 width) { switch (width) { case 2: sprintf( (char *) g_ConsoleContext.txBuf, "%02x", (unsigned int)val); break; case 4: sprintf( (char *) g_ConsoleContext.txBuf, "%04x", (unsigned int)val); break; case 8: sprintf( (char *) g_ConsoleContext.txBuf, "%08lx", (unsigned long)val); break; default: sprintf( (char *) g_ConsoleContext.txBuf, "%x", (unsigned int)val); } putsUART( (char*) g_ConsoleContext.txBuf); }
void reset() { int i = 0, count = 0; unsigned char buff; /*SOFTWARE RESET COMMAND*/ do{ dummy_clocks(8); Command(0X40, 0X00000000, 0X95); //CMD0 proceed(); do{ buff = response(); count++; }while((buff!=0X01) && (count<10) ); count = 0; }while(buff!=0X01); /*SOFTWARE RESET RESPONSE BIT OBTAINED (0X01)*/ putsUART("\n\rSD Card Inserted\n\r"); Delay_s(2); return; //CHECK FOR A STA_NODISK return }
void WFConsolePrintInteger(UINT32 val, char mode) { switch (mode) { case 'c': sprintf( (char *) g_ConsoleContext.txBuf, "%c", (int)val); break; case 'x': sprintf( (char *) g_ConsoleContext.txBuf, "%x", (unsigned int)val); break; case 'u': sprintf( (char *) g_ConsoleContext.txBuf, "%u", (unsigned int)val); break; case 'd': default: sprintf( (char *) g_ConsoleContext.txBuf, "%d", (int)val); } putsUART( (char*) g_ConsoleContext.txBuf); }
void interpreteData(char rcv) { float param; if(indexCommande >= 100) { indexCommande = 0; puts("\n\nBuffer Overflow!\n\n"); } if(rcv != '\n') commande[indexCommande++] = rcv; else { commande[indexCommande] = '\0'; putsUART(&(commande[1])); param = atof(&(commande[1])); interpreteCommande(commande[0], param); indexCommande = 0; } }
/*= Backspace ================================================================ Purpose: Performs a backspace operation on the command line Inputs: none Returns: none ============================================================================*/ static void Backspace(void) { UINT8 num_chars; UINT8 orig_index = GET_CURSOR(); /* if cursor is not at the left-most position */ if (GET_CURSOR() != gCmdLinePromptLength) { /* Null out tmp cmd line */ memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine)); /* get characters before the backspace */ num_chars = GET_CURSOR() - gCmdLinePromptLength - 1; strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, num_chars); /* append characters after the deleted char (if there are any) */ if ( (GET_LEN_RX_CMD_STRING() - 1) > 0u) { strcpy( (char *) &gTmpCmdLine[num_chars], (const char *) &g_ConsoleContext.rxBuf[num_chars + 1]); } EraseEntireLine(); /* leaves g_ConsoleContext.cursorIndex at 0 */ strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine); putrsUART( (ROM FAR char *) gCmdLinePrompt); putsUART( (char *) g_ConsoleContext.rxBuf); SET_CURSOR(gCmdLinePromptLength + GET_LEN_RX_CMD_STRING()); CursorHome(); /* to first character after prompt */ /* move cursor to point of backspace */ CursorRight_N(orig_index - 1 - gCmdLinePromptLength); } }
static void Delete(void) { unsigned int num_chars; unsigned int orig_index = GET_CURSOR(); /* if cursor is not at the end of the line */ if (GET_CURSOR() != GET_LEN_RX_CMD_STRING() + gCmdLinePromptLength) { /* Null out tmp cmd line */ memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine)); /* get characters before the deleted key */ num_chars = GET_CURSOR() - gCmdLinePromptLength; strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, num_chars); /* append characters after the deleted char (if there are any) */ if (strlen( (char *) g_ConsoleContext.rxBuf) - 1 > 0u) { strcpy( (char *) &gTmpCmdLine[num_chars], (const char *) &g_ConsoleContext.rxBuf[num_chars + 1]); } EraseEntireLine(); /* leaves g_ConsoleContext.cursorIndex at 0 */ putrsUART( (ROM FAR char *) gCmdLinePrompt); strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine); putsUART( (char *) g_ConsoleContext.rxBuf ); SET_CURSOR(gCmdLinePromptLength + GET_LEN_RX_CMD_STRING()); CursorHome(); /* to first character after prompt */ /* move cursor to point of delete */ CursorRight_N(orig_index - gCmdLinePromptLength); } }
void DoUARTConfig(void) { BYTE response[MAX_USER_RESPONSE_LEN]; IP_ADDR tempIPValue; IP_ADDR *destIPValue; WORD_VAL wvTemp; BOOL bQuit = FALSE; while(!bQuit) { // Display the menu putrsUART("\r\n\r\n\rMicrochip TCP/IP Config Application ("TCPIP_STACK_VERSION", " __DATE__ ")\r\n\r\n"); putrsUART("\t1: Change serial number:\t\t"); wvTemp.v[1] = AppConfig.MyMACAddr.v[4]; wvTemp.v[0] = AppConfig.MyMACAddr.v[5]; uitoa(wvTemp.Val, response); putsUART((char *)response); putrsUART("\r\n\t2: Change host name:\t\t\t"); putsUART((char *)AppConfig.NetBIOSName); putrsUART("\r\n\t3: Change static IP address:\t\t"); DisplayIPValue(AppConfig.MyIPAddr); putrsUART("\r\n\t4: Change static gateway address:\t"); DisplayIPValue(AppConfig.MyGateway); putrsUART("\r\n\t5: Change static subnet mask:\t\t"); DisplayIPValue(AppConfig.MyMask); putrsUART("\r\n\t6: Change static primary DNS server:\t"); DisplayIPValue(AppConfig.PrimaryDNSServer); putrsUART("\r\n\t7: Change static secondary DNS server:\t"); DisplayIPValue(AppConfig.SecondaryDNSServer); putrsUART("\r\n\t8: "); putrsUART((ROM char*)(AppConfig.Flags.bIsDHCPEnabled ? "Dis" : "En")); putrsUART("able DHCP & IP Gleaning:\t\tDHCP is currently "); putrsUART((ROM char*)(AppConfig.Flags.bIsDHCPEnabled ? "enabled" : "disabled")); putrsUART("\r\n\t9: Download MPFS image."); putrsUART("\r\n\t0: Save & Quit."); putrsUART("\r\nEnter a menu choice: "); // Wait for the user to press a key while(!DataRdyUART()); putrsUART((ROM char*)"\r\n"); // Execute the user selection switch(ReadUART()) { case '1': putrsUART("New setting: "); if(ReadStringUART(response, sizeof(response))) { wvTemp.Val = atoi((char*)response); AppConfig.MyMACAddr.v[4] = wvTemp.v[1]; AppConfig.MyMACAddr.v[5] = wvTemp.v[0]; } break; case '2': putrsUART("New setting: "); ReadStringUART(response, sizeof(response) > sizeof(AppConfig.NetBIOSName) ? sizeof(AppConfig.NetBIOSName) : sizeof(response)); if(response[0] != '\0') { memcpy(AppConfig.NetBIOSName, (void*)response, sizeof(AppConfig.NetBIOSName)); FormatNetBIOSName(AppConfig.NetBIOSName); } break; case '3': destIPValue = &AppConfig.MyIPAddr; goto ReadIPConfig; case '4': destIPValue = &AppConfig.MyGateway; goto ReadIPConfig; case '5': destIPValue = &AppConfig.MyMask; goto ReadIPConfig; case '6': destIPValue = &AppConfig.PrimaryDNSServer; goto ReadIPConfig; case '7': destIPValue = &AppConfig.SecondaryDNSServer; goto ReadIPConfig; ReadIPConfig: putrsUART("New setting: "); ReadStringUART(response, sizeof(response)); if(StringToIPAddress(response, &tempIPValue)) destIPValue->Val = tempIPValue.Val; else putrsUART("Invalid input.\r\n"); break; case '8': AppConfig.Flags.bIsDHCPEnabled = !AppConfig.Flags.bIsDHCPEnabled; break; case '9': #if (defined(MPFS_USE_EEPROM)|| defined(MPFS_USE_SPI_FLASH)) && defined(STACK_USE_MPFS2) DownloadMPFS(); #endif break; case '0': bQuit = TRUE; #if defined(EEPROM_CS_TRIS) || defined(SPIFLASH_CS_TRIS) SaveAppConfig(&AppConfig); putrsUART("Settings saved.\r\n"); #else putrsUART("External EEPROM/Flash not present -- settings will be lost at reset.\r\n"); #endif break; } } }
/***************************************************************************** * FUNCTION: DisplayHistoryEntry * * RETURNS: None * * PARAMS: action -- PREV_HISTORY or NEXT_HISTORY * * NOTES: In response to the user pressing up or down arrow key, display * corresponding entry in history buffer. * *****************************************************************************/ static void DisplayHistoryEntry(UINT8 action) { BOOL foundEntry = FALSE; // if nothing in history buffer if (history.seeded == FALSE) { return; } if (action == (UINT8)kWFPrevHistory) { --history.recallIndex; if (history.recallIndex < 0) { history.recallIndex = kWFNumHistoryEntries - 1; } /* search until found a history entry or searched all entries */ while (foundEntry == FALSE) { /* if found a history entry */ if (history.buf[history.recallIndex][0] != 0) { foundEntry = TRUE; } else { --history.recallIndex; if (history.recallIndex < 0) { history.recallIndex = kWFNumHistoryEntries - 1; } } } } else /* action == kWFNextHistory */ { history.recallIndex = (history.recallIndex + 1) % kWFNumHistoryEntries; /* search until found a history entry or searched all entries */ while (foundEntry == FALSE) { /* if found a history entry */ if (history.buf[history.recallIndex][0] != 0) { foundEntry = TRUE; } else { history.recallIndex = (history.recallIndex + 1) % kWFNumHistoryEntries; } } } if (foundEntry) { // erase line on screen and output command from history EraseEntireLine(); /* leaves Cursor_Index at 0 */ putrsUART( (ROM FAR char *) gCmdLinePrompt ); putsUART( (char *) history.buf[history.recallIndex]); // copy history command to console buffer (so they match) and put cursor // at end of line memset(g_ConsoleContext.rxBuf, 0x00, GET_LEN_RX_CMD_STRING() ); strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) history.buf[history.recallIndex]); SET_CURSOR(gCmdLinePromptLength + strlen( (char *) history.buf[history.recallIndex])); } }
/*= InsertCharacter ========================================================= Purpose: Inserts and echoes an printable character into the command line at the cursor location. Inputs: c -- char to insert Returns: none ============================================================================*/ static void InsertCharacter(INT8 c) { UINT8 len; UINT8 i; UINT8 orig_cursor_index = GET_CURSOR(); UINT8 count; /* throw away characters if exceeded cmd line length */ if (GET_LEN_RX_CMD_STRING() >= sizeof(g_ConsoleContext.rxBuf)-1) { return; } len = GET_LEN_RX_CMD_STRING() + gCmdLinePromptLength; /* if inserting a character at end of cmd line */ if (GET_CURSOR() == len) { g_ConsoleContext.rxBuf[GET_CURSOR() - gCmdLinePromptLength] = c; SET_CURSOR(GET_CURSOR() + 1); EchoCharacter(c); } /* inserting a character somewhere before the end of command line */ else { /* Null out tmp cmd line */ memset(gTmpCmdLine, 0x00, sizeof(gTmpCmdLine)); /* copy up to the point of insertion */ strncpy( (char *) gTmpCmdLine, (const char *) g_ConsoleContext.rxBuf, GET_CURSOR() - gCmdLinePromptLength); /* insert the new character */ gTmpCmdLine[GET_CURSOR() - gCmdLinePromptLength] = c; /* copy the chars after the new character */ strncpy( (char *) &gTmpCmdLine[GET_CURSOR() - gCmdLinePromptLength + 1], (const char *) &g_ConsoleContext.rxBuf[GET_CURSOR() - gCmdLinePromptLength], len - GET_CURSOR()); /* put the first part of new string in the cmd line buffer */ strcpy( (char *) g_ConsoleContext.rxBuf, (const char *) gTmpCmdLine); /* erase entire line, put the cursor at index 0 */ EraseEntireLine(); /* output the prompt */ putrsUART( (ROM FAR char *) gCmdLinePrompt); /* Output the updated command line */ putsUART( (char *) &g_ConsoleContext.rxBuf[0]); /* move the cursor to the next insert location */ count = (len + 1) - orig_cursor_index - 1; for (i = 0; i < count; ++i) { putrsUART( (ROM FAR char *) cursorLeftEscapeSequence); } SET_CURSOR(orig_cursor_index + 1); } }
/***************************************************************************** Function: bool ARPProcess(void) Summary: Processes an incoming ARP packet. Description: Retrieves an ARP packet from the MAC buffer and determines if it is a response to our request (in which case the ARP is resolved) or if it is a request requiring our response (in which case we transmit one.) Precondition: ARP packet is ready in the MAC buffer. Parameters: None Return Values: true - All processing of this ARP packet is complete. Do not call again until a new ARP packet is waiting in the RX buffer. false - This function must be called again. More time is needed to send an ARP response. ***************************************************************************/ bool ARPProcess(void) { ARP_PACKET packet; static NODE_INFO Target; #if defined(STACK_USE_AUTO_IP) uint8_t i; #endif static enum { SM_ARP_IDLE = 0, SM_ARP_REPLY } smARP = SM_ARP_IDLE; switch(smARP) { case SM_ARP_IDLE: // Obtain the incoming ARP packet MACGetArray((uint8_t*)&packet, sizeof(packet)); MACDiscardRx(); SwapARPPacket(&packet); // Validate the ARP packet if ( packet.HardwareType != HW_ETHERNET || packet.MACAddrLen != sizeof(MAC_ADDR) || packet.ProtocolLen != sizeof(IP_ADDR) ) { return true; } #ifdef STACK_USE_ZEROCONF_LINK_LOCAL ARPProcessRxPkt(&packet); #endif #ifdef STACK_USE_AUTO_IP if (packet.SenderIPAddr.Val == AppConfig.MyIPAddr.Val) { AutoIPConflict(0); return true; } #endif // Handle incoming ARP responses #ifdef STACK_CLIENT_MODE if(packet.Operation == ARP_OPERATION_RESP) { /* #if defined(STACK_USE_AUTO_IP) for (i = 0; i < NETWORK_INTERFACES; i++) if (AutoIPConfigIsInProgress(i)) AutoIPConflict(i); #endif*/ Cache.MACAddr = packet.SenderMACAddr; Cache.IPAddr = packet.SenderIPAddr; //putsUART("ARPProcess: SM_ARP_IDLE: ARP_OPERATION_RESP \r\n"); return true; } #endif // Handle incoming ARP requests for our MAC address if(packet.Operation == ARP_OPERATION_REQ) { if(packet.TargetIPAddr.Val != AppConfig.MyIPAddr.Val) { return true; } #ifdef STACK_USE_ZEROCONF_LINK_LOCAL /* Fix for Loop-Back suppression: * For ZCLL-Claim packets, host should not respond. * Check Sender's MAC-address with own MAC-address and * if it is matched, response will not be sent back. This * was leading to flooding of ARP-answeres */ if(!memcmp (&packet.SenderMACAddr, &AppConfig.MyMACAddr, 6)) { putsUART("Loopback answer suppressed \r\n"); return true; } #endif #if defined(STACK_USE_AUTO_IP) for (i = 0; i < NETWORK_INTERFACES; i++) if (AutoIPConfigIsInProgress(i)) { AutoIPConflict(i); return true; } #endif Target.IPAddr = packet.SenderIPAddr; Target.MACAddr = packet.SenderMACAddr; //putsUART("ARPProcess: SM_ARP_IDLE: ARP_OPERATION_REQ \r\n"); smARP = SM_ARP_REPLY; } // Do not break. If we get down here, we need to send a reply. case SM_ARP_REPLY: packet.Operation = ARP_OPERATION_RESP; #if defined(STACK_USE_AUTO_IP) if (AutoIPIsConfigured(0)) { packet.TargetMACAddr.v[0] = 0xFF; packet.TargetMACAddr.v[1] = 0xFF; packet.TargetMACAddr.v[2] = 0xFF; packet.TargetMACAddr.v[3] = 0xFF; packet.TargetMACAddr.v[4] = 0xFF; packet.TargetMACAddr.v[5] = 0xFF; } else #endif packet.TargetMACAddr = Target.MACAddr; packet.TargetIPAddr = Target.IPAddr; #ifdef STACK_USE_ZEROCONF_LINK_LOCAL packet.SenderIPAddr = AppConfig.MyIPAddr; #endif //putsUART("ARPProcess: SM_ARP_REPLY \r\n"); // Send an ARP response to a previously received request if(!ARPPut(&packet)) { return false; } // Begin listening for ARP requests again smARP = SM_ARP_IDLE; break; } return true; }
void WFDisplayScanMgr() { tWFScanResult bssDesc; char ssid[WF_MAX_SSID_LENGTH+1]; char rssiChan[48]; int i; char st[80]; if (SCANCXT.numScanResults == 0) { SCAN_CLEAR_DISPLAY(SCANCXT.scanState); return; } if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) return; if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState)) return; if (!IS_SCAN_STATE_VALID(SCANCXT.scanState)) return; WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc); sprintf(st,"%3d ",SCANCXT.displayIdx); putrsUART(st); if (bssDesc.bssType == 1) sprintf(st,"NetType: Infra."); else if (bssDesc.bssType == 2) sprintf(st,"NetType: Ad-hoc"); putrsUART(st); sprintf(st,", ESSID:"); putrsUART(st); /* Display SSID */ for(i=0;i<bssDesc.ssidLen;i++) ssid[i] = bssDesc.ssid[i]; ssid[bssDesc.ssidLen] = 0; putsUART(ssid); putrsUART("\r\n"); /* Display SSID & Channel */ #ifdef STACK_USE_CERTIFICATE_DEBUG sprintf(rssiChan, "\tRSSI: %3u, Channel: %2u", bssDesc.rssi, bssDesc.channel); putsUART(rssiChan); /* Display BSSID */ sprintf(rssiChan, ", BSSID: %02x:%02x:%02x:%02x:%02x:%02x", bssDesc.bssid[0],bssDesc.bssid[1],bssDesc.bssid[2], bssDesc.bssid[3],bssDesc.bssid[4],bssDesc.bssid[5]); putsUART(rssiChan); /* Display Security Mode */ if((bssDesc.apConfig & 0x10) == 0) // bit4==0: open (no security) { sprintf(rssiChan, ", SecMode: %s\r\n", "Open"); } else // bit4== 1: security { if ((bssDesc.apConfig & 0xc0) == 0xc0) // bit7 == 1: WPA2, bit6 == 1: WPA { sprintf(rssiChan, ", SecMode: %s\r\n", "WPA/WPA2"); } else if ((bssDesc.apConfig & 0x80) == 0x80) // bit7 == 1: WPA2 { sprintf(rssiChan, ", SecMode: %s\r\n", "WPA2"); } else if((bssDesc.apConfig & 0x40) == 0x40)//bit6==1: WPA { sprintf(rssiChan, ", SecMode: %s\r\n", "WPA"); } else // bit7==0, bit6==0, WEP { sprintf(rssiChan, ", SecMode: %s\r\n", "WEP"); } } putsUART(rssiChan); #else sprintf(rssiChan, ", RSSI: %u, Channel: %u\r\n", bssDesc.rssi, bssDesc.channel); putsUART(rssiChan); #endif #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) preScanResult[SCANCXT.displayIdx]= bssDesc; // WF_PRESCAN if (SCANCXT.displayIdx == sizeof(preScanResult) / sizeof(preScanResult[0]) - 1) { SCAN_CLEAR_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; #if defined(WF_CONSOLE) & defined(STACK_USE_UART) WFConsoleReleaseConsoleMsg(); #endif } #endif if (++SCANCXT.displayIdx == SCANCXT.numScanResults) { SCAN_CLEAR_DISPLAY(SCANCXT.scanState); SCANCXT.displayIdx = 0; #if defined(WF_CONSOLE) & defined(STACK_USE_UART) WFConsoleReleaseConsoleMsg(); #endif } return; }
DSTATUS disk_initialize (void) { DSTATUS stat; int i = 0, count1 = 0, count2 = 0; unsigned char buff; reset(); //RESET THE SD CARD delay_ms(500); dummy_clocks(8); Command(0X41, 0X00000000, 0XFF); //CMD1 proceed(); do{ buff = response(); }while(buff!=0x01); /*SOFTWARE RESET RESPONSE BIT OBTAINED (0X01)*/ Delay_s(1); proceed(); if (buff == 0x01) { //SEND CMD55 + ACMD41 delay_ms(1); count1 = 0; do{ count2 = 0; dummy_clocks(8); Command(0X77, 0X00000000, 0X95); //CMD55 buff = 0XFF; /*CHECK THE BUFFER FOR A 0X00 RESPONSE BIT*/ do{ buff = response(); count2++; }while((buff!=0X01)&&(count2<10)); delay_ms(1); count2 = 0; dummy_clocks(8); Command(0X69,0X40000000,0X95); //CMD41 buff = 0XFF; /*CHECK THE BUFFER FOR A 0X00 RESPONSE BIT*/ proceed(); do{ buff = response(); count2++; }while((buff!=0X00)&&(count2<10)); }while(buff != 0X00); count1 = 0; //Delay before sending command delay_ms(1); stat = 0X00; putsUART("\n\r"); putsUART("Card Accepted\n\r"); Delay_s(2); } else if(buff == 0x05) { stat = STA_NOINIT; putsUART("Error!!!\n\r"); Delay_s(3); } Delay_s(1); /*SETTING BLOCK LENGTH TO 512 Bytes*/ dummy_clocks(8); Command(0X50,0X00000200,0XFF); //CMD16 proceed(); do{ buff = response(); }while(buff!=0x00); /*SOFTWARE RESET RESPONSE BIT OBTAINED (0X01)*/ putsUART("\n\rSetting Block Size to 512 Bytes\n\r"); Delay_s(2); putsUART("\n\rCOMPLETING INITIALIZATION"); return stat; }
static void do_wps_get_credentials_cmd(void) { tWFWpsCred cred; int i; char buf[6]; WF_CPGetWPSCredentials(1, &cred); if (cred.ssidLen > 0) { if (cred.ssidLen > 32) { putrsUART("SSID length is greater than 32, probably bad credential data\r\n"); return; } putrsUART("SSID: "); for (i = 0; i < cred.ssidLen; ++i) { sprintf(buf, "%c", cred.ssid[i]); putsUART(buf); } putrsUART("'\r\n"); } putrsUART("Net Key:\r\n "); for (i = 0; i < sizeof(cred.netKey); ++i) { if ( ((i % 16) == 0) && ( i != 0) ) { putrsUART("\r\n "); } sprintf(buf, "%02X ", cred.netKey[i]); putsUART(buf); } putrsUART("\r\n"); putrsUART("Auth Type: "); sprintf(buf, "%d\r\n", cred.authType); putsUART(buf); putrsUART("Enc Type: "); sprintf(buf, "%d\r\n", cred.encType); putsUART(buf); putrsUART("Net ID: "); sprintf(buf, "%d\r\n", cred.netIdx); putsUART(buf); putrsUART("Key ID: "); sprintf(buf, "%d\r\n", cred.keyIdx); putsUART(buf); putrsUART("BSSID: "); for (i = 0; i < 6; ++i) { sprintf(buf, "%02X ", cred.bssid[i]); putsUART(buf); } putrsUART("\r\n"); }
DRESULT disk_readp ( BYTE* rd, /* Pointer to the destination object */ DWORD sector, /* Sector number (LBA) */ UINT offset, /* Offset in the sector */ UINT count /* Byte count (bit15:destination) */ ) { DRESULT res; unsigned char ptr=0X00,buff; unsigned long int start_add; static unsigned char arr[512]; int length,i; /*Read Sector*/ if(offset == 0){ start_add = ((sector*512)); Delay_s(1); dummy_clocks(8); Command(0X52,start_add,0X00); //CMD18 proceed(); do{ buff = response(); }while(buff!=0x00); Delay_s(1); proceed(); do{ buff = response(); }while(buff!=0xFE); length = 0; while ( length < count ) { arr[length] = response(); length++; } Delay_s(1); dummy_clocks(8); Command(0X4C,0X00000000,0X00); //CMD12 proceed(); do{ buff = response(); }while(buff!=0xFF); length = 0; while(arr[length]!='\0') { //WriteUART(arr[length]); length++; } *rd = length; return RES_OK; } else { start_add = (sector*512); length = 0; while(length<512) //CLEAR ARRAY { arr[length] = 0; length++; } Delay_s(1); dummy_clocks(8); //SPI_cmd(sd_cmd17); Command(0X51,start_add,0X00); proceed(); do{ buff = response(); }while(buff!=0x00); do{ buff = response(); }while(buff!=0xFE); length = 0; while ( length < 512 ) { while(offset--) //RUN DOWN TILL THE OFFSET VALUE { arr[length] = response(); length++; } while(count--) //RUN DOWN TILL THE COUNT VALUE { *rd = response(); arr[length] = *rd; rd++; length++; } while(length<512) //FOR THE TRAILING BYTES { arr[length] = response(); length++; } } Delay_s(1); // dummy_clocks(8); //SPI_cmd(sd_cmd12); Command(0X4C,0X00000000,0X00); //COMMAND12 MANDATORY proceed(); do{ buff = response(); }while(buff!=0xFF); length = 0; if(flag == 1){ while(arr[length]!='\0') { WriteUART(arr[length]); length++; } } else putsUART(".."); Delay_s(2); return RES_OK; } }