Ejemplo n.º 1
0
VOID AppEvtCallBack(SYS_EVT_ID event)
{
	switch (event)
	{
		case SYS_EVT_LINK_UP:
			log_info("SYS_EVT_LINK_UP\n");
       		DirectCfgFlag = 1;
			wifi_sta_connect_ap_flag = 1;
			break;
		
		case SYS_EVT_LINK_DOWN:
			log_info("SYS_EVT_LINK_DOWN\n");
			break;

		case SYS_EVT_JOIN_FAIL:
			wifi_sta_connect_ap_flag = 0;
			if (sys_status.status == SYS_STATUS_WIFI_SOFTAP) {
			   log_info("SoftAP create fail\n");
			   BSP_ChipReset();
			}

			log_info("SYS_EVT_JOIN_FAIL\n");
			break;

		case SYS_EVT_DHCP_FAIL:
			log_info("SYS_EVT_DHCP_FAIL\n");
			break;

		case SYS_EVT_SCAN_DONE:
			log_info("SYS_EVT_SCAN_DONE\n");
			break;

		case SYS_EVT_DIRECT_CFG_DONE:
			DirectCfgFlag = 1;
			log_info("SYS_EVT_DIRECT_CFG_DONE\n");
			break;

		default:
			break;
	}
}
void http_engine(unsigned int idx, char *rx, unsigned int rx_len, unsigned char *tx)
{	
    unsigned int tx_len = 0;
	static unsigned int updFlag=0;
	  
    switch (http_table[idx].status)
    {
        case HTTP_CLOSED:
            if (rx_len)
            {			    
                if(strncmpi(rx, "GET", 3) == 0)/*METHOD/part-to-resource-HTTP/Version-number*/
                {
					updFlag=0;
					log_info("GET Table form data.\n");
                    rx     += 3+1;
                    rx_len -= 3+1;
					if (strncmpi(rx, "/login.html", strlen("/login.html")) == 0)
					{
						log_info("Login system.\n");
						http_sendfile(idx, "/login.html", tx);
					} 
					else if (strncmpi(rx, "/status.html", strlen("/status.html")) == 0) 
					{
					 	log_info("Get system status html.\n");
						http_sendfile(idx, "/status.html", tx);
					}
					else if (strncmpi(rx, "/wifibase.html", strlen("/wifibase.html")) == 0) 
					{
					 	log_info("Get wifibase html.\n");
						http_sendfile(idx, "/wifibase.html", tx);
					}
					else if (strncmpi(rx, "/wifinet.html", strlen("/wifinet.html")) == 0) 
					{
					 	log_info("Get wifi network html.\n");
						http_sendfile(idx, "/wifinet.html", tx);
					}
					else if (strncmpi(rx, "/public.css", strlen("/public.css")) == 0) 
					{
					 	log_info("Get public css.\n");
						http_sendfile(idx, "/public.css", tx);
					}
					else 
					{
						log_info("Default login webserver.\n\n");
                    	http_sendfile(idx, "/login.html", tx);
					}
                }
                else if(strncmpi(rx, "POST", 4) == 0)
                {
					log_info("POST Table form data.\n");
					updFlag=0;
                    rx     += 4+1;
                    rx_len -= 4+1;
                    if (strncmpi(rx, "/reboot", 7) == 0)		/* process setupwifi form */
                    {
                        tx_len = sprintf((char*)tx, HTTP_200_HEADER);
						http_resetsys(idx, (char*)tx, tx_len);												         
                    }
				    else if (strncmpi(rx, "/factory", 8) == 0)  /* process resetwifi form */
					{
                        tx_len = sprintf((char*)tx, HTTP_200_HEADER);
						http_factory(idx, (char*)tx, tx_len);						
					}
					else if (strncmpi(rx, "/update", 7) == 0)  /* process resetwifi form */
					{	  
						updFlag=1;  
					}
				    else if (strncmpi(rx, "/wifibase", 9) == 0)  /* process resetwifi form */
					{
						http_setup_wifibase(idx, (char*)rx, rx_len, (char *)tx);
					}
				    else if (strncmpi(rx, "/setupuart", 10) == 0)  /* process resetwifi form */
					{
						http_setup_uart(idx, (char*)rx, rx_len, (char *)tx);
					}
				    else if (strncmpi(rx, "/setupnet", 9) == 0)  /* process resetwifi form */
					{
						http_setup_net(idx, (char*)rx, rx_len, (char *)tx);
					}
                    else
                    {
                        http_sendfile(idx, rx, tx);
                    }
                }
				else if(updFlag != 0)
				{					
					if(http_update(idx, (char*)rx, rx_len, (char *)tx, updFlag) == 0)
					{
						updFlag=0;
						printf("rebooting....\r\n");
						BSP_ChipReset();
					}
					else
						updFlag++;		
				}
                else
                {
                    tx_len = sprintf((char*)tx, HTTP_400_HEADER"Error 400 Bad request\r\n\r\n");
                    tcp_send(idx, tx_len);
                }
            }
            break;

        case HTTP_SEND:
            http_sendfile(idx, 0, tx);
            break;

        default:                                                      
            break;                                                          
    }                                                                         

    return;
}