#include #include #include #include #include #include #include #include "wmg_debug.h" #include "wifi_udhcpc.h" #define WIFI_ON_OFF_TEST_CNTS 10 static void wifi_state_handle(struct Manager *w, int event_label) { wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label); switch(w->StaEvt.state) { case CONNECTING: { wmg_printf(MSG_INFO,"Connecting to the network......\n"); break; } case CONNECTED: { wmg_printf(MSG_INFO,"Connected to the AP\n"); start_udhcpc(); break; } case OBTAINING_IP: { wmg_printf(MSG_INFO,"Getting ip address......\n"); break; } case NETWORK_CONNECTED: { wmg_printf(MSG_DEBUG,"Successful network connection\n"); break; } case DISCONNECTED: { wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event)); break; } } } void print_help(){ wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n"); wmg_printf(MSG_INFO,"NAME:\n\twifi_on_off_test\n"); wmg_printf(MSG_INFO,"DESCRIPTION:\n\ttest the stability of wifi module(do wifi on and wifi off 10 times)\n"); wmg_printf(MSG_INFO,"USAGE:\n\twifi_on_off_test\n"); wmg_printf(MSG_INFO,"--------------------------------------MORE---------------------------------------\n"); wmg_printf(MSG_INFO,"The way to get help information:\n"); wmg_printf(MSG_INFO,"\twifi_on_off_test --help\n"); wmg_printf(MSG_INFO,"\twifi_on_off_test -h\n"); wmg_printf(MSG_INFO,"\twifi_on_off_test -H\n"); wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n"); } /* */ static int set_log_level(int argv, char *argc[]) { if(argv >=2 && !strncmp(argc[2],"d",1)){ char *debug = argc[2]; if(strlen(debug) >=2 && debug[2] >= '0' && debug[2] <= '5'){ wmg_set_debug_level(debug[2] - '0'); return 0; }else{ printf("Illegal level\n"); printf("Level range 0~5\n"); return -1; } } return 0; } int main(int argv, char *argc[]){ int ret = 0; int i = 0, event_label = 0; int onOffTestCnt = WIFI_ON_OFF_TEST_CNTS; const aw_wifi_interface_t *p_wifi_interface = NULL; if(argv == 3 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){ print_help(); return -1; } if(argv < 1 || argv >3){ wmg_printf(MSG_ERROR,"ERROR:No need other paras\n"); print_help(); return -1; } if(set_log_level(argv,argc)) return -1; if(NULL == argc[1]) onOffTestCnt = WIFI_ON_OFF_TEST_CNTS; else onOffTestCnt = atoi(argc[1]); event_label=rand(); wmg_printf(MSG_INFO,"on off test %d times\n",onOffTestCnt); for(i=0; i