static void *wifi_update_thread(void *priv)
{
    bool init = true;
    struct wifi_factory *wififm = (struct wifi_factory *)priv;
    //struct itemview *iv = wififm->iv;
    struct textview *tv = &wififm->tv;
    struct itemview *iv = wififm->iv;

    LOGD(TAG "%s: Start\n", __FUNCTION__);

    //update_Text_Info(NULL, wififm->info, sizeof(wififm->info));
    memset(wififm->info,0, sizeof(wififm->info));
    sprintf(wififm->info, "Status : Start\n");
    iv->redraw(iv);


    if( FM_WIFI_init(wififm->info, sizeof(wififm->info), &wififm->result) < 0) {
        LOGE("[WIFI] FM_WIFI_init failed!\n");
        sprintf(wififm->info, "Status : INIT FAILED\n");
        iv->redraw(iv);
        init = false;
    }

    while (1) {
        if(init && wififm->renew) {
            wififm->renew = false;
            memset(wififm->info,0, sizeof(wififm->info));
            sprintf(wififm->info, "Status : Scanning\n");
            iv->redraw(iv);

            if( wifi_fm_test() < 0 ) {
                LOGD("[wifi_update_thread] wifi_fm_test failed!\n");
            } else {
                int count =50;
                iv->redraw(iv);
                while(count-- >0) {
                    if (wififm->exit_thd || wififm->renew)
                        break;
                    if(wifi_update_status() < 0) {
                        if(count)
                            usleep(100000);
                        else {
                            memset(wififm->info,0, sizeof(wififm->info));
                            sprintf(wififm->info, "Status : Connection timed-out\n");
                        }
                    }
                    iv->redraw(iv);
                }
            }

        }
        if (wififm->exit_thd)
            break;
        usleep(200000);
    }

    LOGD(TAG "%s: Exit\n", __FUNCTION__);
    pthread_exit(NULL);
    return NULL;
}
Exemple #2
0
int wifi_entry(struct ftm_param *param, void *priv)
{
    char *ptr;
    int chosen;
    bool exit = false;
    struct wifi_factory *wififm = (struct wifi_factory *)priv;
    struct textview *tv;
    struct itemview *iv;
    int i = 0;
    int curStatus = -1; //disconnect

    LOGD(TAG "%s new\n", __FUNCTION__);

    memset(&wififm->info[0], 0, sizeof(wififm->info));
    memset(&wififm->info[0], '\n', 10);

    init_text(&wififm->title, param->name, COLOR_YELLOW);
    init_text(&wififm->text, &wififm->info[0], COLOR_YELLOW);

    if (!wififm->iv) {
        iv = ui_new_itemview();
        if (!iv) {
            LOGD(TAG "No memory for item view");
            return -1;
        }
        wififm->iv = iv;
    }

    iv = wififm->iv;
    iv->set_title(iv, &wififm->title);
    if(param->test_type == FTM_MANUAL_ITEM)
        iv->set_items(iv, wifi_items, 0);
    else
        iv->set_items(iv, wifi_auto_items, 0);
    iv->set_text(iv, &wififm->text);
    iv->start_menu(iv,0);

    iv->redraw(iv);
    LOGD(TAG "%s new2\n", __FUNCTION__);
    /*
        tv = &wififm->tv;
        ui_init_textview(tv, wifi_key_handler, (void*)wififm);
        tv->set(tv, "Wi-Fi", &wififm->info[0]);
        tv->set_btn(tv, "Fail", "Pass", "Back");
        tv->run(tv);
    */

    if(param->test_type == FTM_MANUAL_ITEM) //manual test
    {
        /* initialize thread condition */
        wififm->exit_thd = false;
        wififm->result = false;
        wififm->renew = true;
        pthread_create(&wififm->update_thd, NULL, wifi_update_thread, priv);

        do {
            chosen = iv->run(iv, &exit);
            switch (chosen) {
            case ITEM_RENEW:
                wififm->renew = true;
                break;

            case ITEM_PASS:
            case ITEM_FAIL:
                if (chosen == ITEM_PASS) {
                    wififm->mod->test_result = FTM_TEST_PASS;
                } else if (chosen == ITEM_FAIL) {
                    wififm->mod->test_result = FTM_TEST_FAIL;
                }

                exit = true;
                break;
            }

            if (exit) {
                wififm->exit_thd = true;
                break;
            }
        } while (1);
        pthread_join(wififm->update_thd, NULL);
    }
    else if(param->test_type == FTM_AUTO_ITEM)  //auto test
    {
        if( FM_WIFI_init(wififm->info, sizeof(wififm->info), &wififm->result) < 0) {
            LOGE("[WIFI][FTM_AUTO_ITEM] FM_WIFI_init failed!\n");
            sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_init_fail);
            iv->redraw(iv);
            return -1;
        }

        while(i++ < 3) {
            //1. disconnect the connection.
            wifi_disconnect();

            //2. connect to the AP.
            if(wifi_fm_test() < 0 ) {
                LOGD("[WIFI][FTM_AUTO_ITEM] wifi_fm_test failed!\n");
            } else {
                int count =10;
                iv->redraw(iv);
                while(count-- >0) {
                    /*                    if (wififm->exit_thd || wififm->renew)
                                        break;	 */
                    if(wifi_update_status() < 0) {
                        if(count)
                            usleep(100000);
                        else {
                            memset(wififm->info,0, sizeof(wififm->info));
                            sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_timeout);
                        }
                    } else {
                        curStatus = 1;  //connected
                        //show the message
                    }
                    iv->redraw(iv);
                }
            }

            //3. check the status
            if(curStatus == 1) {
                wififm->mod->test_result = FTM_TEST_PASS;
                LOGD(TAG "while %d connected\n", i);
                break;
            }
        }

        if(3 == i) {
            wififm->mod->test_result = FTM_TEST_FAIL;
            LOGD(TAG "while i == 3\n", i);
        }

    }
    else if (param->test_type == FTM_ASYN_ITEM)
    {
        LOGD(TAG "param->test_type == FTM_ASYN_ITEM\n");
        pthread_create(&wififm->update_thd, NULL, wifi_update_thread_test, priv);
        //if(3 == param->test_type)
        {
            //pthread_join(wififm->update_thd, NULL);
        }
    }

    if (param->test_type != FTM_ASYN_ITEM)
    {
        FM_WIFI_deinit();
    }

    return 0;
}
Exemple #3
0
static void *wifi_update_thread(void *priv)
{
    struct wifi_factory *wififm = (struct wifi_factory *)priv;
    //struct itemview *iv = wififm->iv;
    struct textview *tv = &wififm->tv;
    struct itemview *iv = wififm->iv;
    char *wifi_test_error_str[] = {uistr_info_wifi_iface_err, uistr_info_wifi_fail_scan, uistr_info_wifi_no_scan_res,
                                   uistr_info_wifi_connect_err, uistr_info_wifi_no_ap
                                  };
    int error_index = 0;

    LOGD(TAG "%s: Start\n", __FUNCTION__);

    //update_Text_Info(NULL, wififm->info, sizeof(wififm->info));
    memset(wififm->info,0, sizeof(wififm->info));
    sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_start);
    iv->redraw(iv);

    if( FM_WIFI_init(wififm->info, sizeof(wififm->info), &wififm->result) < 0) {
        LOGE("[WIFI] FM_WIFI_init failed!\n");
        sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_init_fail);
        iv->redraw(iv);
        goto init_fail;
    }

    while (!wififm->exit_thd) {
        if(wififm->renew) {
            wififm->renew = false;
            memset(wififm->info,0, sizeof(wififm->info));
            sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_scanning);
            iv->redraw(iv);

            error_index = wifi_fm_test();
            if(error_index > 0) {
                LOGD("[wifi_update_thread] %s!\n", wifi_test_error_str[error_index-1]);
                sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_error, wifi_test_error_str[error_index-1]);
                iv->redraw(iv);
            } else {
                int count =50;
                iv->redraw(iv);
                while(count-- >0) {
                    if (wififm->exit_thd || wififm->renew)
                        break;
                    if(wifi_update_status() < 0) {
                        if(count)
                            usleep(100000);
                        else {
                            memset(wififm->info,0, sizeof(wififm->info));
                            sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_timeout);
                        }
                    }
                    iv->redraw(iv);
                }
            }

        }
        usleep(200000);
    }

init_fail:
    LOGD(TAG "%s: Exit\n", __FUNCTION__);
    pthread_exit(NULL);
    return NULL;

}
Exemple #4
0
static void *wifi_update_thread_test(void *priv)
{
    struct wifi_factory *wififm = (struct wifi_factory *)priv;
    struct textview *tv;
    struct itemview *iv;
    int i = 0;
    iv = wififm->iv;
    char wifi_result[32] = {0};

    int curStatus = -1; //disconnect

    if( FM_WIFI_init(wififm->info, sizeof(wififm->info), &wififm->result) < 0) {
        LOGE("[WIFI] FM_WIFI_init failed!\n");
        sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_init_fail);
        iv->redraw(iv);
        sprintf(wifi_result, "%d:%s", wififm->mod->id, result[FTM_TEST_FAIL]);
        LOGD(TAG "WIFI result:%s", wifi_result);
        write_data_to_pc(wifi_result, strlen(wifi_result));
        return NULL;
    }

    while(i++ < 3) {
        //1. disconnect the connection.
        wifi_disconnect();

        //2. connect to the AP.
        if(wifi_fm_test() > 0) {
            LOGD("[WIFI][wifi_update_thread_test] wifi_fm_test failed!\n");
        } else {
            int count =10;
            iv->redraw(iv);
            while(count-- >0) {
                /*                    if (wififm->exit_thd || wififm->renew)
                                    break;   */
                if(wifi_update_status() < 0) {
                    if(count)
                        usleep(100000);
                    else {
                        memset(wififm->info,0, sizeof(wififm->info));
                        sprintf(wififm->info, "%s : %s\n", uistr_info_wifi_status, uistr_info_wifi_timeout);
                    }
                } else {
                    curStatus = 1;  //connected
                    //show the message
                }
                iv->redraw(iv);
            }
        }

        //3. check the status
        if(curStatus == 1) {
            wififm->mod->test_result = FTM_TEST_PASS;
            LOGD(TAG "while %d connected\n", i);
            break;
        }
    }

    if(3 == i) {
        wififm->mod->test_result = FTM_TEST_FAIL;
        LOGD(TAG "while i == 3\n", i);
    }

    FM_WIFI_deinit();
    LOGD(TAG "wififm->mod->id:%d; wififm->mod->test_result:%d", wififm->mod->id, wififm->mod->test_result);
    //if(get_is_ata())
    {
        sprintf(wifi_result, "%d:%s", wififm->mod->id, result[wififm->mod->test_result]);
        LOGD(TAG "WIFI result:%s", wifi_result);
        write_data_to_pc(wifi_result, strlen(wifi_result));
    }

    return NULL;
}