/* ************************************************************** */ /* * Module TESTPARAM * This module contains functions for supervising test parameter * measurements, ie. temperatures, water pressure, etc. * * Zachary Wolf * 4/12/01 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "testparam.h" #include "imag.h" #include "vmag.h" #include "tmag.h" #include "xmag.h" /* ************************************************************** */ /* PRIVATE FUNCTIONS */ void testparam_message(char* msg); void testparam_error(char* msg); void testparam_log_meas(int num_test_param, char test_param_name[][TESTPARAM_MAX_NAME_LENGTH], double test_param_value[]); /* ************************************************************** */ /* PRIVATE PARAMETERS */ static char dat_file[100]; static char plt_file[100]; static char log_file[100]; /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * testparam_init * This function does the initialization for the module. * * Zachary Wolf * 4/12/01 */ void testparam_init(char dat_file_in[], char plt_file_in[], char log_file_in[]) { /* Save the module parameters */ strcpy(dat_file, dat_file_in); strcpy(plt_file, plt_file_in); strcpy(log_file, log_file_in); /* Done */ return; } /* ************************************************************** */ /* * testparam_meas * This function measures all test parameters. * * Output: * num_test_param_out, number of test parameters * test_param_name, name of each test parameter (including units) * test_param_value[0 to num_test_param - 1], test parameter values * * Zachary Wolf * 4/12/01 */ void testparam_meas(int* num_test_param_out, char test_param_name[][TESTPARAM_MAX_NAME_LENGTH], double test_param_value[]) { /* Declare variables */ int i; int num_tmag_probes; int num_xmag_dev; int num_test_param = 0; /* Measure the magnet current */ num_test_param++; strcpy(test_param_name[num_test_param - 1], "Magnet current (A)"); imag_get_current(&test_param_value[num_test_param - 1]); /* Measure the magnet voltage */ num_test_param++; strcpy(test_param_name[num_test_param - 1], "Magnet voltage (V)"); vmag_get_voltage(&test_param_value[num_test_param - 1]); /* Measure all temperatures */ tmag_get_num_probes(&num_tmag_probes); if (num_test_param + num_tmag_probes > TESTPARAM_MAX_NUM_TEST_PARAM) testparam_error("Maximum number of test parameters exceeded"); for (i = 0; i < num_tmag_probes; i++) { num_test_param++; tmag_get_probe_name(i, test_param_name[num_test_param - 1]); tmag_get_probe_temp(i, &test_param_value[num_test_param - 1]); } /* Measure all special parameters */ xmag_get_num_dev(&num_xmag_dev); if (num_test_param + num_xmag_dev > TESTPARAM_MAX_NUM_TEST_PARAM) testparam_error("Maximum number of test parameters exceeded"); for (i = 0; i < num_xmag_dev; i++) { num_test_param++; xmag_get_dev_name(i, test_param_name[num_test_param - 1]); xmag_get_dev_meas(i, &test_param_value[num_test_param - 1]); } /* Write the results to the log file */ testparam_log_meas(num_test_param, test_param_name, test_param_value); /* Fill in the number of test parameters */ *num_test_param_out = num_test_param; /* Done */ return; } /* ************************************************************** */ /* * testparam_dat_meas * This function writes the results of magnet test parameter measurements * to the data file. * * Input: * num_test_param, number of test parameters * test_param_name, name of each test parameter (including units) * test_param_value[0 to num_test_param - 1], test parameter values * * Zachary Wolf * 4/12/01 */ void testparam_dat_meas(int num_test_param, char test_param_name[][TESTPARAM_MAX_NAME_LENGTH], double test_param_value[]) { /* Declare variables */ FILE* file_ptr; static int call_num; int i; /* Open the dat file */ file_ptr = fopen(dat_file, "a"); if (file_ptr == NULL) { printf("testparam_dat_meas: Unable to open dat file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, "\n"); fprintf(file_ptr, "\n"); fprintf(file_ptr, " Test Parameter Measurements\n"); fprintf(file_ptr, "\n"); for (i = 0; i < num_test_param; i++) { fprintf(file_ptr, "P%i = %s\n", i, test_param_name[i]); } fprintf(file_ptr, "\n"); fprintf(file_ptr, " Time "); for (i = 0; i < num_test_param; i++) fprintf(file_ptr, " P%i ", i); fprintf(file_ptr, "\n"); fprintf(file_ptr, "--------"); for (i = 0; i < num_test_param; i++) fprintf(file_ptr, " -------"); fprintf(file_ptr, "\n"); } /* Write the data */ fprintf(file_ptr, "%s", TimeStr()); for (i = 0; i < num_test_param; i++) fprintf(file_ptr, " %7.2f", test_param_value[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * testparam_plt_meas * This function writes the results of magnet test parameter measurements * to the plot file. * * Input: * num_test_param, number of test parameters * test_param_name, name of each test parameter (including units) * test_param_value[0 to num_test_param - 1], test parameter values * * Zachary Wolf * 4/12/01 */ void testparam_plt_meas(int num_test_param, char test_param_name[][TESTPARAM_MAX_NAME_LENGTH], double test_param_value[]) { /* Declare variables */ FILE* file_ptr; static int call_num; int hr, min, sec; static long t_0; long t_now; int i; /* Open the plot file */ file_ptr = fopen(plt_file, "a"); if (file_ptr == NULL) { printf("testparam_plt_meas: Unable to open plt file\n"); return; } /* Increment the number of calls */ call_num++; /* Write a header on the first call */ if (call_num == 1) { fprintf(file_ptr, ";time(min), P0, P1, ...\n"); for (i = 0; i < num_test_param; i++) { fprintf(file_ptr, ";P%i = %s\n", i, test_param_name[i]); } } /* Get a time reference on the first call */ if (call_num == 1) { GetSystemTime(&hr, &min, &sec); t_0 = hr*3600 + min*60 + sec; } /* Write the data */ GetSystemTime(&hr, &min, &sec); t_now = hr*3600 + min*60 + sec; fprintf(file_ptr, "%8.2f", (t_now - t_0) / 60.); for (i = 0; i < num_test_param; i++) fprintf(file_ptr, " %7.2f", test_param_value[i]); fprintf(file_ptr, "\n"); /* Close the dat file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * testparam_exit * This function prepares the module for program exit. * * Zachary Wolf * 4/12/01 */ void testparam_exit(void) { /* Nothing needs to be done */ /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * testparam_message * This function handles messages for the module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 4/12/01 */ void testparam_message(char* message) { /* Print the message */ printf("%s\n", message); /* Done */ return; } /* ************************************************************** */ /* * testparam_error * This function handles error messages for the module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 4/12/01 */ void testparam_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nTESTPARAM ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); } /* ************************************************************** */ /* * testparam_log_meas * This function writes the results of magnet test parameter measurements * to the log file. * * Input: * num_test_param, number of test parameters * test_param_name, name of each test parameter (including units) * test_param_value[0 to num_test_param - 1], test parameter values * * Zachary Wolf * 4/12/01 */ void testparam_log_meas(int num_test_param, char test_param_name[][TESTPARAM_MAX_NAME_LENGTH], double test_param_value[]) { /* Declare variables */ FILE* file_ptr; int i; /* Open the log file */ file_ptr = fopen(log_file, "a"); if (file_ptr == NULL) { printf("testparam_log_meas: Unable to open log file\n"); return; } /* Write the measured values to the log file */ fprintf(file_ptr, "%s Magnet Test Parameter Measurements\n", TimeStr()); for (i = 0; i < num_test_param; i++) { fprintf(file_ptr, " P%i = %s, Value = %7.2f\n", i, test_param_name[i], test_param_value[i]); } /* Close the dat file */ fclose(file_ptr); /* Done */ return; }