示例#1
0
int main(int argc, char **argv)
{
	int k, num_perseus;
	perseus_descr *descr;
	eeprom_prodid prodid;
	FILE *fout;
    int i;
	int sr = 95000;
	int nb = 6;
	int bs = 1024;
	int dbg_lvl = 3;
	int no_ta = 0;
	int test_time = 10;

	for (i=0; i < argc; ++i) {
		dbgprintf (3,"%d: %s\n", i, argv[i]);
		if (!strcmp(argv[i],"-s") && (i+1)<argc) {
		    ++i;
			if(sscanf(argv[i], "%d", &sr) == 1) ; else sr = 95000;
		}
		if (!strcmp(argv[i],"-n") && (i+1)<argc) {
		    ++i;
			if(sscanf(argv[i], "%d", &nb) == 1) ; else nb = 6;
		}
		if (!strcmp(argv[i],"-b") && (i+1)<argc) {
		    ++i;
			if(sscanf(argv[i], "%d", &bs) == 1) ; else bs = 1024;
		}
		if (!strcmp(argv[i],"-d") && (i+1)<argc) {
		    ++i;
			if(sscanf(argv[i], "%d", &dbg_lvl) == 1) ; else dbg_lvl = 3;
		}
		if (!strcmp(argv[i],"-a")) {
			no_ta = 1;
		}
		if (!strcmp(argv[i],"-t") && (i+1)<argc) {
		    ++i;
			if(sscanf(argv[i], "%d", &test_time) == 1) ; else test_time = 10;
		}
		if (!strcmp(argv[i],"-h")) {
		    print_usage ();
			exit (255);
		}

	}
	
	// Set debug info dumped to stderr to the maximum verbose level
	perseus_set_debug(dbg_lvl);
	
    printf ("Revision: %s\n", svn_revision);
	printf ("SAMPLE RATE: %d\n", sr);
	printf ("NBUF: %d BUF SIZE: %d TOTAL BUFFER LENGTH: %d\n", nb, bs, nb*bs);

	// Check how many Perseus receivers are connected to the system
	num_perseus = perseus_init();
	printf("%d Perseus receivers found\n",num_perseus);

	if (num_perseus==0) {
		printf("No Perseus receivers detected\n");
		perseus_exit();
		return 0;
	}

	// Open the first one...
	if ((descr=perseus_open(0))==NULL) {
		printf("error: %s\n", perseus_errorstr());
		return 255;
	}

	// Download the standard firmware to the unit
	printf("Downloading firmware...\n");
	if (perseus_firmware_download(descr,NULL)<0) {
		printf("firmware download error: %s", perseus_errorstr());
		return 255;
	}
	// Dump some information about the receiver (S/N and HW rev)
	if (descr->is_preserie == TRUE) 
		printf("The device is a preserie unit");
	else
		if (perseus_get_product_id(descr,&prodid)<0) 
			printf("get product id error: %s", perseus_errorstr());
		else
			printf("Receiver S/N: %05d-%02hX%02hX-%02hX%02hX-%02hX%02hX - HW Release:%hd.%hd\n",
					(uint16_t) prodid.sn, 
					(uint16_t) prodid.signature[5],
					(uint16_t) prodid.signature[4],
					(uint16_t) prodid.signature[3],
					(uint16_t) prodid.signature[2],
					(uint16_t) prodid.signature[1],
					(uint16_t) prodid.signature[0],
					(uint16_t) prodid.hwrel,
					(uint16_t) prodid.hwver);

    // Printing all sampling rates available .....
    {
        int buf[BUFSIZ];

        if (perseus_get_sampling_rates (descr, buf, sizeof(buf)/sizeof(buf[0])) < 0) {
			printf("get sampling rates error: %s\n", perseus_errorstr());
			goto main_cleanup;
        } else {
            int i = 0;
            while (buf[i]) {
                printf("#%d: sample rate: %d\n", i, buf[i]);
                i++;
            }
        }
    }

	// Configure the receiver for 2 MS/s operations
	printf("Configuring FPGA...\n");
	if (perseus_set_sampling_rate(descr, sr) < 0) {  // specify the sampling rate value in Samples/second
	//if (perseus_set_sampling_rate_n(descr, 0)<0)        // specify the sampling rate value as ordinal in the vector
		printf("fpga configuration error: %s\n", perseus_errorstr());
		goto main_cleanup;
	}



    // Printing all attenuator values available .....
    {
        int buf[BUFSIZ];

        if (perseus_get_attenuator_values (descr, buf, sizeof(buf)/sizeof(buf[0])) < 0) {
			printf("get attenuator values error: %s\n", perseus_errorstr());
        } else {
            int i = 0;
            while (buf[i] != -1) {
                printf("#%d: att val in dB: %d\n", i, buf[i]);
                i++;
            }
        }
    }

	// Cycle attenuator leds on the receiver front panel
	// just to see if they indicate what they shoud
//  perseus_set_attenuator(descr, PERSEUS_ATT_0DB);
//  sleep(1);
//  perseus_set_attenuator(descr, PERSEUS_ATT_10DB);
//  sleep(1);
//  perseus_set_attenuator(descr, PERSEUS_ATT_20DB);
//  sleep(1);
//  perseus_set_attenuator(descr, PERSEUS_ATT_30DB);
//  sleep(1);
//  perseus_set_attenuator(descr, PERSEUS_ATT_0DB);
//  sleep(1);
//
//   perseus_set_attenuator_in_db(descr, 0);
//   sleep(1);
//   perseus_set_attenuator_in_db(descr, 10);
//   sleep(1);
//   perseus_set_attenuator_in_db(descr, 20);
//   sleep(1);
//   perseus_set_attenuator_in_db(descr, 30);
//   sleep(1);
//   perseus_set_attenuator_in_db(descr, 0);
//   sleep(1);


    perseus_set_attenuator_in_db(descr, 33); // Bad value !!!

	if (no_ta == 0) {
		perseus_set_attenuator_n(descr, 0);
		sleep(1);
		perseus_set_attenuator_n(descr, 1);
		sleep(1);
		perseus_set_attenuator_n(descr, 2);
		sleep(1);
		perseus_set_attenuator_n(descr, 3);
		sleep(1);
		perseus_set_attenuator_n(descr, 0);
		sleep(1);
	}
	// Enable ADC Dither, Disable ADC Preamp
	perseus_set_adc(descr, TRUE, FALSE);

	// Do the same cycling test with the WB front panel led.
	// Enable preselection filters (WB_MODE Off)
	perseus_set_ddc_center_freq(descr, 7000000.000, 1);
	sleep(1);
	// Disable preselection filters (WB_MODE On)
	perseus_set_ddc_center_freq(descr, 7000000.000, 0);
	sleep(1);
	// Re-enable preselection filters (WB_MODE Off)
	perseus_set_ddc_center_freq(descr, 7000000.000, 1);

	// We open a file for binary output.
	// IQ samples will be saved in binary format to this file 
	fout = fopen("perseusdata","wb");
	if (!fout) {
		printf("Can't open output file\n");
		perseus_close(descr);
		perseus_exit();
		}
	
	// We start the acquisition passing our callback and its params 
	// (in this case the fout file handle we just open)	
	printf("Starting async data acquisition... \n");
	if (perseus_start_async_input(descr,nb*bs,user_data_callback,fout)<0) {
		printf("start async input error: %s\n", perseus_errorstr());
		goto main_cleanup;
		}

	fprintf(stderr, "Collecting input samples... ");

	// We wait a 10 s time interval.
	// The user data callback we supplied to perseus_start_async_input 
	// is being called meanwhile.
	for (k=0;k<test_time;k++) {
		fprintf(stderr, ".");
		sleep(1);
	}

	fprintf(stderr, "\ndone\n");
	
	// We stop the acquisition...
	printf("Stopping async data acquisition...\n");
	perseus_stop_async_input(descr);

	// We can safely close the output file handle here. Acquisition has stopped.
	fclose(fout);

main_cleanup:

	// And we can finally quit the test application

	printf("Quitting...\n");
	perseus_close(descr);
	perseus_exit();

	printf("Bye\n");

	return 1;
}
示例#2
0
DevicePerseus::DevicePerseus()
{
	m_nbDevices = perseus_init();
}