示例#1
0
文件: main.c 项目: Zziwei/MotionNet
//1. collect initial data in MAG_CALI_TIME seconds
//2. do calibration for initial data
//3. if calibrator is invalid, repeat step 1.
void initCalibrator(HANDLE hComm) {
    printf("\n=========================  Initialize Calibrator  =====================\n");
    PktData pktData;

    //Mag data list for initialization
    DataHeadNode *ptr = create_list_with_head();
    int len;

    while (true) {
        printf("\nCollect data in the next %d seconds!\n", MAG_CALI_TIME);

        //Before read, flush the buffer.
        purgePort(hComm);

        time_t timeBegin = time(NULL);

        while (true) {
            pktData = blockingReadOnePacket(hComm);

            if(equals(pktData, ZERO_PKT)) {
                continue;
            }
            add_to_list_head(ptr, pktData);

            if(time(NULL) - timeBegin >= MAG_CALI_TIME)
                break;
        }

        //Start prepare double array for calculate calibrator
        len = ptr->length;
        printf("Initialize data length: %d \n", len);

        double magDataX[len] ;
        double magDataY[len] ;
        double magDataZ[len] ;
        double heading[len];

        fillMagDataArray(ptr, magDataX, magDataY, magDataZ);

        //pass magData to calibrator
        calculateCalibrator(magDataX, magDataY, magDataZ, len);

        write_list_to_file("C:/Users/xing/Desktop/Raw_Initial_Data.txt", ptr);

        if(! calibrateMagData(magDataX, magDataY, magDataZ, heading, len))
            continue;

        write_mag_to_file("C:/Users/xing/Desktop/Corrected_Initial_Mag_Data.txt", magDataX, magDataY, magDataZ, heading, len);

        clear_list(ptr);

        if(isCalibratorValid(magDataX, magDataY, magDataZ, len))
            break;
    }

    //free all list data
    free_list(ptr);
    isCalibratorInitialized = true;
    printf("\n============================  Initialize Over  ========================\n");
}
示例#2
0
/* 删除指定的记录 */
void delete_information(struct Info_list * list_head)
{
    char condition[100];
    char * trimmed_condition = NULL;
    long int id;
    printf("Enter ID which you want delete. \n>>>> ");
    fgets(condition, 100, stdin);
    trimmed_condition = trimmed(condition);
    id = atol(trimmed_condition);
    
    delete_id_in_list(list_head, id);
    
    /* 保存 */
    write_list_to_file(list_head);
}
示例#3
0
void modify_information(struct Info_list * list_head)
{
    struct Info_list * list_iter = list_head->next;
    char condition[100];
    char * trimmed_condition = NULL;
    long int id;
    struct Information * info_temp = NULL;
    struct Information * info = NULL;
    char id_char[200];
    char price_char[200];
    char number_char[200];
    
    printf("Enter ID which you want modify. \n>>>> ");
    fgets(condition, 100, stdin);
    trimmed_condition = trimmed(condition);
    id = atol(trimmed_condition);
    
    while (list_iter && list_iter->node) {
        if (list_iter->node->id == id)
            break;
        list_iter = list_iter->next;
    }
    info_temp = list_iter->node;
	if (!info_temp)
		return;
    printf("\n id: %ld", info_temp->id);
    printf("\t name: %s", info_temp->name);
    printf("\t type: %s", info_temp->type);
    printf("\t price: %.2f", info_temp->price);
    printf("\t Number: %u", info_temp->number);
    printf("\n  Company: %s", info_temp->company);
    printf("  Comment: %s\n", info_temp->comment);
    
    info = info_temp;
    printf("\nNow Enter New Data of This Information.\n");
    printf("Plase Enter ID, only numeral support, for example: \"123456\"\n");
    printf(">>>> ");
    fgets(id_char, 200, stdin);
    info->id = atol(id_char);
    printf("You Typed %ld\n", info->id);
    
    printf("Plase Enter Name, for example: \"Kobe Bryant\"\n");
    printf(">>>> ");
    fgets(info->name, 200, stdin);
    trimmed(info->name);
    printf("You Typed %s\n", info->name);
    
    printf("Plase Enter Type, for example: \"A\"\n");
    printf(">>>> ");
    fgets(info->type, 200, stdin);
    trimmed(info->type);
    printf("You Typed %s\n", info->type);
    
    printf("Plase Enter Price, only numeral support, example: \"123.456\"\n");
    printf(">>>> ");
    fgets(price_char, 200, stdin);
    info->price = atof(price_char);
    printf("You Typed %f\n", info->price);
    
    printf("Plase Enter Number, only numeral support, example: \"543210\"\n");
    printf(">>>> ");
    fgets(number_char, 200, stdin);
    info->number = atoi(number_char);
    printf("You Typed %u\n", info->number);
    
    printf("Plase Enter Company, for example: \"Red Had\"\n");
    printf(">>>> ");
    fgets(info->company, 200, stdin);
    trimmed(info->company);
    printf("You Typed %s\n", info->company);
    
    printf("Plase Enter Comment, for example: \"This is Comment\"\n");
    printf(">>>> ");
    fgets(info->comment, 400, stdin);
    printf("You Typed %s\n", info->comment);
    trimmed(info->comment);

    /* 保存 */
    write_list_to_file(list_head);

}