/** * @brief Main program. * @param None * @retval None */ int wifi_main(void) { unsigned char i; SysTick_Configuration(); // DBGU_Init(); SN8200_API_Init(921600); strcpy(domain, "www.murata-ws.com"); strcpy(uri, "/index.html"); printf("\n\rHello, Embedded World!\n\r"); printf("\n\r"); WifiOn(seqNo++); printf("\n\r"); ShowMenu(); WifiDisconn(seqNo++); WifiJoin(seqNo++); SnicInit(seqNo++); SnicIPConfig(seqNo++); /* Infinite loop */ while (1) { if(DBGU_InputReady) { ProcessUserInput(); } if(SN8200_API_HasInput()) { ProcessSN8200Input(); } if(quit_flag) break; } printf("\n\rGoodbye, Embedded World!\n\r"); }void DBGU_Init(void)
void WiFi(void) { static void (*f)(void)=NULL; static int fo=true; if(f==NULL) { DbgPrint(NULL); Dbg=_buffer_init(128); SN8200_API_Init(921600); strcpy(domain, "www.murata-ws.com"); strcpy(uri, "/index.html"); if(!__com0 || !Dbg) NVIC_SystemReset(); else { f=App_Loop; App_Loop=WiFi; SnicCleanup(seqNo++); WifiOff(seqNo++); Wait(200,App_Loop); WifiOn(seqNo++); Wait(200,App_Loop); SnicInit(seqNo++); Wait(200,App_Loop); GetStatus(seqNo++); Wait(200,App_Loop); _buffer_push(Dbg,"0\r",2); SnicGetDhcp(seqNo++); _buffer_push(Dbg,"6000\r",5); while (setTCPinfo() == CMD_ERROR) Wait(200,App_Loop); mysock = -1; tcpCreateSocket(1, srcIP, (unsigned short)srcPort, seqNo++, SNIC_TCP_CREATE_SOCKET_REQ); if (mysock != -1) { tcpCreateConnection(mysock, TEST_BUFFERSIZE, 0x5, seqNo++); } } } else { __sendFromSock(); if(fo==true) { fo=false; fo=ProcessUserInput(); } if(SN8200_API_HasInput()) ProcessSN8200Input(); f(); } }
bool ProcessUserInput(void) { char tmp[100]; if(DbgScan("%s", tmp)==1) switch(tmp[0]) { case 'q': return false; case '0': GetStatus(seqNo++); break; case '1': WifiScan(seqNo++); break; case '2': WifiDisconn(seqNo++); WifiJoin(seqNo++); SnicInit(seqNo++); SnicIPConfig(seqNo++); break; case '3': SnicInit(seqNo++); SnicGetDhcp(seqNo++); break; case '4': mysock = -1; tcpCreateSocket(0, 0xFF, 0xFF, seqNo++, SNIC_TCP_CREATE_SOCKET_REQ); if (mysock != -1) { if (getTCPinfo() == CMD_ERROR) { DbgPrint("Invalid Server\r\n"); break; } // This connection can receive data upto 0x0400=1K bytes at a time. tcpConnectToServer(mysock, destIP, (unsigned short)destPort, 0x0400, 0x5, seqNo++); } break; case '5': if (setTCPinfo() == CMD_ERROR) { DbgPrint("Invalid Server to create\r\n"); break; } mysock = -1; tcpCreateSocket(1, srcIP, (unsigned short)srcPort, seqNo++, SNIC_TCP_CREATE_SOCKET_REQ); if (mysock != -1) { // This connection can receive data upto TEST_BUFFERSIZE at a time. tcpCreateConnection(mysock, TEST_BUFFERSIZE, 0x5, seqNo++); } break; case '6': { char tempstr[2] = {0}; int8u datamode; char sockstr[8]; int32u sock; char teststr[128]; int len; DbgPrint("Enter socket number to send from: \r\n"); DbgScan("%s", sockstr); sock = strtol(sockstr, NULL, 0); DbgPrint("Content Option? (0: Default 1: User specific) \r\n"); DbgScan("%s", tempstr); datamode = atoi(tempstr); if (datamode) { DbgPrint("Enter payload to send (up to 128 bytes): \r\n"); DbgScan("%s", teststr); len = (int)strlen(teststr); sendFromSock(sock, (int8u*)teststr, len, 2, seqNo++); } else { sendFromSock(sock, TxBuf, TEST_BUFFERSIZE, 2, seqNo++); pktcnt = 0; } break; } case '7': SnicCleanup(seqNo++); WifiDisconn(seqNo++); break; case '8': ApOnOff(seqNo++); break; case '9': {//udp send int i; udpCreateSocket(0, 0, 0, seqNo++); if (mysock != -1) { if (getUDPinfo() == CMD_ERROR) { DbgPrint("Invalid Server\r\n"); break; } DbgPrint("Send %d\r\n", UDP_NUM_PKT); for (i=0; i<UDP_NUM_PKT; i++) { int si = i % TEST_BUFFERSIZE + 1; SendSNIC(TxBuf, si); DbgPrint("%d %d\r\n", i, si); } closeSocket(mysock,seqNo++); } break; } case 'a': {//udp recv int16u port = 43211; int32u ip = 0xAC1F0001; // 172.31.0.1 udpCreateSocket(1, ip, port, seqNo++); udpStartRecv(mysock, 2048, seqNo++); break; } case 'b': SnicCleanup(seqNo++); WifiOff(seqNo++); break; case 'c': WifiOn(seqNo++); break; case 'd': DbgPrint("Enter server name: %s\r\n", domain); DbgScan("%s", tmp); DbgPrint("\r\n"); if (strlen(tmp)) strcpy(domain, tmp); sendHttpReqTest(domain, 0); break; case'e': DbgPrint("Enter server name: ([CR] to accept %s)\r\n", domain); DbgScan("%s", tmp); DbgPrint("\r\n"); if (strlen(tmp)) strcpy(domain, tmp); sendHttpPostDemo(domain); break; case 'f': DbgPrint("Make sure STA is connected to SN8200 soft AP.\r\n"); strcpy(domain, "sn8200.com"); DbgPrint("Enter server name: ([CR] to accept %s)\r\n", domain); DbgScan("%s", tmp); DbgPrint("\r\n"); if (strlen(tmp)) strcpy(domain, tmp); sendHttpJsonPostDemo(domain); break; #if 1 case 'g': strcpy(domain, "192.168.10.100"); DbgPrint("Enter server name (or the peer testclient IP, peer testclient should start TCP server on port 80): ([CR] to accept %s)\r\n", domain); DbgScan("%s", tmp); DbgPrint("\r\n"); if (strlen(tmp)) strcpy(domain, tmp); sendHttpChunkReqTest(domain); break; #endif case 'h': DbgPrint("Enter server name: ([CR] to accept %s)\r\n", domain); DbgScan("%s", tmp); DbgPrint("\r\n"); if (strlen(tmp)) strcpy(domain, tmp); sendHttpReqTest(domain, 1); break; case 'i': timeout1 = 5; mysock = -1; tcpCreateSocket(0, 0xFF, 0xFF, seqNo++, SNIC_TCP_CREATE_SIMPLE_TLS_SOCKET_REQ); // use less memory in SN8200 mdelay(500); if (mysock != -1) { strcpy(Portstr, "443"); if (getTCPinfo() == CMD_ERROR) { DbgPrint("Invalid Server\r\n"); break; } tcpConnectToServer(mysock, destIP, (unsigned short)destPort,0x0000,timeout1,seqNo++); while ((sockConnected == -1) && timeout1) { mdelay(500); timeout1--; if (sockClosed == mysock) { sockClosed = -1; break; } } if (sockConnected == mysock) { sendFromSock(mysock, (int8u*)GET_REQUEST, sizeof(GET_REQUEST)-1, 2, seqNo++); sockConnected = -1; } else DbgPrint("Connect failed.\r\n"); } break; case 'j': //ssl server strcpy(Portstr, "443"); if (setTCPinfo() == CMD_ERROR) { DbgPrint("Invalid Server to create\r\n"); break; } mysock = -1; tcpCreateSocket(1, srcIP, (unsigned short)srcPort, seqNo++, SNIC_TCP_CREATE_ADV_TLS_SOCKET_REQ); if (mysock != -1) { // This connection can receive data upto TEST_BUFFERSIZE at a time. tcpCreateConnection(mysock, TEST_BUFFERSIZE, 0x5, seqNo++); } break; case 'm': ShowMenu(); break; default: break; } return true; }