Esempio n. 1
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(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;
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
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;
}
Esempio n. 6
0
/** Signal generator main */
int main(int argc, char *argv[])
{
    g_argv0 = argv[0];    

    if ( argc < 4 ) {

        usage();
        return -1;
    }

    /* Channel argument parsing */
    uint32_t ch = atoi(argv[1]) - 1; /* Zero based internally */
    if (ch > 1) {
        fprintf(stderr, "Invalid channel: %s\n", argv[1]);
        usage();
        return -1;
    }

    /* Signal amplitude argument parsing */
    float ampl = strtod(argv[2], NULL);
    if ( (ampl < 0.0) || (ampl > c_max_amplitude) ) {
        fprintf(stderr, "Invalid amplitude: %s\n", argv[2]);
        usage();
        return -1;
    }

    /* Signal frequency argument parsing */
    float freq = strtod(argv[3], NULL);
    if ( (freq < 0.0) || (freq > c_max_frequency ) ) {
        fprintf(stderr, "Invalid frequency: %s\n", argv[3]);
        usage();
        return -1;
    }

    /* Signal type argument parsing */
    awg_signal_t type = eSignalSine;
    if (argc > 4) {
        if ( strcmp(argv[4], "sine") == 0) {
            type = eSignalSine;
        } else if ( strcmp(argv[4], "sqr") == 0) {
            type = eSignalSquare;
        } else if ( strcmp(argv[4], "tri") == 0) {
            type = eSignalTriangle;
        } else {
            fprintf(stderr, "Invalid signal type: %s\n", argv[4]);
            usage();
            return -1;
        }
    }

    //Added by Marko
    float offsetVolts = 0.0;
    if(argc > 5){
        offsetVolts = strtod(argv[5], NULL);
        //fprintf(stderr, "Using offset: %f\n", offsetVolts);
    } 

    rp_default_calib_params(&rp_calib_params);
    gen_calib_params = &rp_calib_params;
    if(rp_read_calib_params(gen_calib_params) < 0) {
        fprintf(stderr, "rp_read_calib_params() failed, using default"
            " parameters\n");
    }
    ch1_max_dac_v = fpga_awg_calc_dac_max_v(gen_calib_params->be_ch1_fs);
    ch2_max_dac_v = fpga_awg_calc_dac_max_v(gen_calib_params->be_ch2_fs);

    awg_param_t params;
    /* Prepare data buffer (calculate from input arguments) */
    synthesize_signal(ampl,//Amplitude
                      freq,//Frequency
                      (ch == 0) ? gen_calib_params->be_ch1_dc_offs : gen_calib_params->be_ch2_dc_offs,//Calibrated Instrument DC offset
                      (ch == 0) ? gen_calib_params->be_ch1_fs : gen_calib_params->be_ch2_fs,//Calibrated Back-End full scale coefficient
                      (ch == 0) ? ch1_max_dac_v : ch2_max_dac_v,//Maximum DAC voltage
                      offsetVolts,//DC offset voltage
                      type,//Signal type/shape
                      data,//Returned synthesized AWG data vector
                      &params);//Returned AWG parameters

    /* Write the data to the FPGA and set FPGA AWG state machine */
    write_data_fpga(ch, data, &params);
}