/** @brief Initializes oscilloscope application sub-modules and structures. * * This function initializes worker module and initializes the parameters. * * @retval -1 Failure * @retval 0 Success */ int rp_app_init(int calibration)//ERG { float p[PARAMS_NUM]; int i; if (calibration == 1) {//ERG rp_default_calib_params(&rp_main_calib_params); if(rp_read_calib_params(&rp_main_calib_params) < 0) { fprintf(stderr, "rp_read_calib_params() failed, using default" " parameters\n"); } else { rp_calib_params = &rp_main_calib_params; } } if(rp_osc_worker_init(rp_calib_params) < 0) {//ERG return -1; } for(i = 0; i < PARAMS_NUM; i++) p[i] = rp_main_params[i].value; p[TRIG_DLY_PARAM] = -100; rp_set_params(&p[0], PARAMS_NUM); return 0; }
int rp_app_init(void) { fprintf(stderr, "Loading scope (with gen+pid extensions) version %s-%s.\n", VERSION_STR, REVISION_STR); rp_default_calib_params(&rp_main_calib_params); if(rp_read_calib_params(&rp_main_calib_params) < 0) { fprintf(stderr, "rp_read_calib_params() failed, using default" " parameters\n"); } if(rp_osc_worker_init(&rp_main_params[0], PARAMS_NUM, &rp_main_calib_params) < 0) { return -1; } if(generate_init(&rp_main_calib_params) < 0) { return -1; } if(pid_init() < 0) { return -1; } rp_set_params(&rp_main_params[0], PARAMS_NUM); return 0; }
int rp_update_main_params(rp_app_params_t *params) { int i = 0; if(params == NULL) return -1; pthread_mutex_lock(&rp_main_params_mutex); while(params[i].name != NULL) { rp_main_params[i].value = params[i].value; i++; } pthread_mutex_unlock(&rp_main_params_mutex); params_init = 0; rp_set_params(&rp_main_params[0], PARAMS_NUM); return 0; }
/** @brief Initializes oscilloscope application sub-modules and structures. * * This function initializes worker module and initializes the parameters. * * @retval -1 Failure * @retval 0 Success */ int rp_app_init(void) { float p[PARAMS_NUM]; int i; if(rp_osc_worker_init() < 0) { return -1; } for(i = 0; i < PARAMS_NUM; i++) p[i] = rp_main_params[i].value; p[TRIG_DLY_PARAM] = -100; rp_set_params(&p[0], PARAMS_NUM); return 0; }
int rp_app_init(void) { fprintf(stderr, "Loading scope version %s-%s.\n", VERSION_STR, REVISION_STR); rp_default_calib_params(&rp_main_calib_params); if(rp_read_calib_params(&rp_main_calib_params) < 0) { fprintf(stderr, "rp_read_calib_params() failed, using default" " parameters\n"); } if(rp_osc_worker_init(&rp_main_params[0], PARAMS_NUM, &rp_main_calib_params) < 0) { return -1; } if(generate_init(&rp_main_calib_params) < 0) { return -1; } if(rp_main_params[GAIN_CH1].value == 0) { rp_main_ch1_max_adc_v = osc_fpga_calc_adc_max_v(rp_main_calib_params.fe_ch1_fs_g_hi, rp_main_params[PRB_ATT_CH1].value); } else { rp_main_ch1_max_adc_v = osc_fpga_calc_adc_max_v(rp_main_calib_params.fe_ch1_fs_g_lo, rp_main_params[PRB_ATT_CH1].value); } if(rp_main_params[GAIN_CH2].value == 0) { rp_main_ch2_max_adc_v = osc_fpga_calc_adc_max_v(rp_main_calib_params.fe_ch2_fs_g_hi, rp_main_params[PRB_ATT_CH2].value); } else { rp_main_ch2_max_adc_v = osc_fpga_calc_adc_max_v(rp_main_calib_params.fe_ch2_fs_g_lo, rp_main_params[PRB_ATT_CH2].value); } rp_set_params(&rp_main_params[0], PARAMS_NUM); return 0; }
int rp_app_init(void) { fprintf(stderr, "Loading power analyzer version %s-%s.\n", VERSION_STR, REVISION_STR); rp_default_calib_params(&rp_main_calib_params); if(rp_read_calib_params(&rp_main_calib_params) < 0) { fprintf(stderr, "rp_read_calib_params() failed, using default" " parameters\n"); } if(rp_pwr_worker_init(&rp_main_params[0], PARAMS_NUM, &rp_main_calib_params) < 0) { return -1; } rp_set_params(&rp_main_params[0], PARAMS_NUM); return 0; }
int main(int argc , char *argv[]) { int socket_desc , client_sock , c , read_size; struct sockaddr_in server , client; char client_message[2000]; // Allocate variables float **s; int sig_num, sig_len; int i; int ret_val; // Create signals structure s = (float **)malloc(SIGNALS_NUM * sizeof(float *)); for(i = 0; i < SIGNALS_NUM; i++) { s[i] = (float *)malloc(SIGNAL_LENGTH * sizeof(float)); } char *sString; int channel1DataReady = 0; int channel2DataReady = 0; uint32_t size = 8192; char* command; char* cmdData; int channel; int yes = 1; /* Initialization of Oscilloscope application */ if(rp_app_init() < 0) { fprintf(stderr, "rp_app_init() failed!\n"); return -1; } rp_calib_params_t rp_main_calib_params; rp_default_calib_params(&rp_main_calib_params); if(rp_read_calib_params(&rp_main_calib_params) < 0) { fprintf(stderr, "rp_read_calib_params() failed, using default" " parameters\n"); } printf("Calibration fe_ch1_fs_g_hi: %7d\n", rp_main_calib_params.fe_ch1_fs_g_hi); printf("Calibration fe_ch1_dc_offs: %7d\n", rp_main_calib_params.fe_ch1_dc_offs); printf("Calibration be_ch1_dc_offs: %7d\n", rp_main_calib_params.be_ch1_dc_offs); printf("Calibration be_ch1_fs: %7d\n", rp_main_calib_params.be_ch1_fs); printf("Calibration fe_ch2_fs_g_hi: %7d\n", rp_main_calib_params.fe_ch2_fs_g_hi); printf("Calibration fe_ch2_dc_offs: %7d\n", rp_main_calib_params.fe_ch2_dc_offs); printf("Calibration be_ch2_dc_offs: %7d\n", rp_main_calib_params.be_ch2_dc_offs); printf("Calibration be_ch2_fs: %7d\n", rp_main_calib_params.be_ch2_fs); float max_adc_v_ch1 = rp_main_calib_params.fe_ch1_fs_g_hi/(float)((uint64_t)1<<32) * 100; int dc_offset_ch1 = rp_main_calib_params.be_ch1_dc_offs; float max_adc_v_ch2 = rp_main_calib_params.fe_ch2_fs_g_hi/(float)((uint64_t)1<<32) * 100; int dc_offset_ch2 = rp_main_calib_params.be_ch2_dc_offs; /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { fprintf(stderr, "rp_set_params() failed!\n"); return -1; } while(1) { //Create socket socket_desc = socket(AF_INET , SOCK_STREAM , 0); if (socket_desc == -1) { printf("Could not create socket"); } puts("Socket created"); //Prepare the sockaddr_in structure server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons( 8888 ); if ( setsockopt(socket_desc, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 ) { perror("setsockopt"); } //Bind if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0) { //print the error message perror("bind failed. Error"); return 1; } puts("bind done"); //Listen listen(socket_desc , 3); //Accept and incoming connection puts("Waiting for incoming connections..."); c = sizeof(struct sockaddr_in); //accept connection from an incoming client client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c); if (client_sock < 0) { perror("accept failed"); return 1; } puts("Connection accepted"); //Receive a message from client while( (read_size = recv(client_sock , client_message , 2000 , 0)) > 0 ) { // Check if a new waveform is available if((ret_val = rp_get_signals(&s, &sig_num, &sig_len)) >= 0) { /* Signals acquired in s[][]: * s[0][i] - TODO * s[1][i] - Channel ADC1 raw signal * s[2][i] - Channel ADC2 raw signal */ channel1DataReady = 1; channel2DataReady = 1; } client_message[read_size] = 0; cmdData = strtok(client_message, ":"); if (cmdData != NULL) { command = cmdData; cmdData = strtok(NULL, ":"); } if (strcmp(command,"getWaveform")==0) { channel = atoi(cmdData); switch(channel){ case 0: if (channel1DataReady == 1) { channel1DataReady = 0; sString = (char *) &s[1][0]; write(client_sock , sString , 4*size); break; } else { write(client_sock , "not triggered" , 13); break; } case 1: if (channel2DataReady == 1) { channel2DataReady = 0; sString = (char *) &s[2][0]; write(client_sock , sString , 4*size); break; } else { write(client_sock , "not triggered" , 13); break; } } } else if (strcmp(command,"getWaveforms")==0) { if (channel1DataReady == 1) { channel1DataReady = 0; sString = (char *) &s[1][0]; write(client_sock , sString , 2*4*size); break; } else { write(client_sock , "not triggered" , 13); break; } } else if (strcmp(command,"setRecordlength")==0) { printf("Setting record length %7d\n", atoi(cmdData)); size = atoi(cmdData); write(client_sock , "OK" , 2); } else if (strcmp(command,"setTriggerSource")==0) { printf("Setting trigger source %s\n", cmdData); if (strcmp(cmdData,"CH1")==0) { t_params[3] = 0; } else if (strcmp(cmdData,"CH2")==0) { t_params[3] = 1; } else { t_params[3] = 2; } /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { printf("rp_set_params() failed!\n"); write(client_sock , "Error" , 2); } else { write(client_sock , "OK" , 2); } } else if (strcmp(command,"setDecimation")==0) { printf("Setting decimation factor %7d\n", atoi(cmdData)); t_params[8] = atoi(cmdData); /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { printf("rp_set_params() failed!\n"); write(client_sock , "Error" , 2); } else { write(client_sock , "OK" , 2); } } else if (strcmp(command,"setTriggerLevel")==0) { printf("Setting trigger level %f\n", atof(cmdData)); t_params[6] = atof(cmdData); /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { printf("rp_set_params() failed!\n"); write(client_sock , "Error" , 2); } else { write(client_sock , "OK" , 2); } } else if (strcmp(command,"setTriggerMode")==0) { printf("Setting trigger mode %s\n", cmdData); if (strcmp(cmdData,"AUTO")==0) { t_params[2] = 0; } else if (strcmp(cmdData,"NORMAL")==0) { t_params[2] = 1; } else // single { t_params[2] = 2; } /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { printf("rp_set_params() failed!\n"); write(client_sock , "Error" , 2); } else { write(client_sock , "OK" , 2); } } else if (strcmp(command,"setTriggerDelay")==0) { printf("Setting trigger delay %f\n", atof(cmdData)); float dly = atof(cmdData); t_params[5] = dly; t_params[0] = dly; t_params[1] = size/125+dly; // Delay is in microseconds /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { printf("rp_set_params() failed!\n"); write(client_sock , "Error" , 2); } else { write(client_sock , "OK" , 2); } } else if (strcmp(command,"setTriggerEdge")==0) { printf("Setting trigger edge %7d\n", atoi(cmdData)); t_params[4] = atoi(cmdData); /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { printf("rp_set_params() failed!\n"); write(client_sock , "Error" , 2); } else { write(client_sock , "OK" , 2); } } else if (strcmp(command,"getCalibrationMaxADC")==0) { channel = atoi(cmdData); switch(channel){ case 0: printf("Calibration max ADC %7f\n", max_adc_v_ch1); sString = (char *) &max_adc_v_ch1; write(client_sock , sString , sizeof(float)); break; case 1: printf("Calibration max ADC %7f\n", max_adc_v_ch2); sString = (char *) &max_adc_v_ch2; write(client_sock , sString , sizeof(float)); break; } } else if (strcmp(command,"getCalibrationOffset")==0) { channel = atoi(cmdData); switch(channel){ case 0: printf("Calibration offset %7d\n", dc_offset_ch1); sString = (char *) &dc_offset_ch1; write(client_sock , sString , sizeof(int)); break; case 1: printf("Calibration offset %7d\n", dc_offset_ch2); sString = (char *) &dc_offset_ch2; write(client_sock , sString , sizeof(int)); break; } } else { printf("Unknown command %s\n", command); write(client_sock, "unknown command", 15); } } if(read_size == 0) { puts("Client disconnected"); fflush(stdout); close(socket_desc); } else if(read_size == -1) { perror("recv failed"); close(socket_desc); } } if(rp_app_exit() < 0) { fprintf(stderr, "rp_app_exit() failed!\n"); return -1; } return 0; }
/** Acquire utility main */ int main(int argc, char *argv[]) { g_argv0 = argv[0]; int equal = 0; int shaping = 0; int average = 0;//ERG int calibration = 0;//ERG if ( argc < MINARGS ) { usage(); exit ( EXIT_FAILURE ); } /* Command line options */ static struct option long_options[] = { /* These options set a flag. */ {"average", no_argument, 0, 'a'},//ERG {"calibration", no_argument, 0, 'c'},//ERG {"equalization", no_argument, 0, 'e'}, {"shaping", no_argument, 0, 's'}, {"gain1", required_argument, 0, '1'}, {"gain2", required_argument, 0, '2'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; const char *optstring = "aces1:2:vh";//ERG /* getopt_long stores the option index here. */ int option_index = 0; int ch = -1; while ( (ch = getopt_long( argc, argv, optstring, long_options, &option_index )) != -1 ) { switch ( ch ) { case 'a'://ERG average = 1; break; case 'c'://ERG calibration = 1; break; case 'e': equal = 1; break; case 's': shaping = 1; break; /* Gain Channel 1 */ case '1': { int gain1; if (get_gain(&gain1, optarg) != 0) { usage(); return -1; } t_params[GAIN1_PARAM] = gain1; } break; /* Gain Channel 2 */ case '2': { int gain2; if (get_gain(&gain2, optarg) != 0) { usage(); return -1; } t_params[GAIN2_PARAM] = gain2; } break; case 'v': fprintf(stdout, "%s version %s-%s\n", g_argv0, VERSION_STR, REVISION_STR); exit( EXIT_SUCCESS ); break; case 'h': usage(); exit( EXIT_SUCCESS ); break; default: usage(); exit( EXIT_FAILURE ); } } /* Acquisition size */ uint32_t size = 0; if (optind < argc) { size = atoi(argv[optind]); if (size > SIGNAL_LENGTH) { fprintf(stderr, "Invalid SIZE: %s\n", argv[optind]); usage(); exit( EXIT_FAILURE ); } } else { fprintf(stderr, "SIZE parameter missing\n"); usage(); exit( EXIT_FAILURE ); } optind++; /* Optional decimation */ if (optind < argc) { uint32_t dec = atoi(argv[optind]); uint32_t idx; for (idx = 0; idx < DEC_MAX; idx++) { if (dec == g_dec[idx]) { break; } } if (idx != DEC_MAX) { t_params[TIME_RANGE_PARAM] = idx; } else { fprintf(stderr, "Invalid decimation DEC: %s\n", argv[optind]); usage(); return -1; } } /* Filter parameters */ t_params[EQUAL_FILT_PARAM] = equal; t_params[SHAPE_FILT_PARAM] = shaping; /* Initialization of Oscilloscope application */ if(rp_app_init(calibration) < 0) {//ERG fprintf(stderr, "rp_app_init() failed!\n"); return -1; } /* Setting of parameters in Oscilloscope main module */ if(rp_set_params((float *)&t_params, PARAMS_NUM) < 0) { fprintf(stderr, "rp_set_params() failed!\n"); return -1; } { float **s; int sig_num, sig_len; int i; int ret_val; int retries = 150000; s = (float **)malloc(SIGNALS_NUM * sizeof(float *)); for(i = 0; i < SIGNALS_NUM; i++) { s[i] = (float *)malloc(SIGNAL_LENGTH * sizeof(float)); } while(retries >= 0) { if((ret_val = rp_get_signals(&s, &sig_num, &sig_len)) >= 0) { /* Signals acquired in s[][]: * s[0][i] - TODO * s[1][i] - Channel ADC1 raw signal * s[2][i] - Channel ADC2 raw signal */ if (average == 1) { if (calibration == 0) { long long ch1_average = 0; long long ch2_average = 0; for(i = 0; i < MIN(size, sig_len); i++) { ch1_average += (int)s[1][i]; ch2_average += (int)s[2][i]; } ch1_average /= MIN(size, sig_len); ch2_average /= MIN(size, sig_len); printf("%7lld %7lld\n", ch1_average, ch2_average); } else { long double ch1_average = 0.0; long double ch2_average = 0.0; for(i = 0; i < MIN(size, sig_len); i++) { ch1_average += s[1][i]; ch2_average += s[2][i]; } ch1_average /= MIN(size, sig_len); ch2_average /= MIN(size, sig_len); printf("%.4Lf %.4Lf\n", ch1_average, ch2_average); } } else if (calibration == 0) { for(i = 0; i < MIN(size, sig_len); i++) { printf("%7d %7d\n", (int)s[1][i], (int)s[2][i]); } } else { for(i = 0; i < MIN(size, sig_len); i++) { printf("%.4f %.4f\n", s[1][i], s[2][i]); } } break; } if(retries-- == 0) { fprintf(stderr, "Signal scquisition was not triggered!\n"); break; } usleep(1000); } } if(rp_app_exit() < 0) { fprintf(stderr, "rp_app_exit() failed!\n"); return -1; } return 0; }