Esempio n. 1
0
static void write_stream_reflections(FILE *fh, RefList *list)
{
	Reflection *refl;
	RefListIterator *iter;

	fprintf(fh, "   h    k    l          I   sigma(I)       peak background"
	            "  fs/px  ss/px\n");

	for ( refl = first_refl(list, &iter);
	      refl != NULL;
	      refl = next_refl(refl, iter) )
	{

		signed int h, k, l;
		double intensity, esd_i, bg, pk;
		double fs, ss;

		get_indices(refl, &h, &k, &l);
		get_detector_pos(refl, &fs, &ss);
		intensity = get_intensity(refl);
		esd_i = get_esd_intensity(refl);
		pk = get_peak(refl);
		bg = get_mean_bg(refl);

		/* Reflections with redundancy = 0 are not written */
		if ( get_redundancy(refl) == 0 ) continue;

		fprintf(fh,
		       "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f %6.1f %6.1f\n",
		       h, k, l, intensity, esd_i, pk, bg, fs, ss);

	}
}
Esempio n. 2
0
static int write_stream_reflections_2_2(FILE *fh, RefList *list,
                                        struct image *image)
{
	Reflection *refl;
	RefListIterator *iter;

	fprintf(fh, "   h    k    l          I   sigma(I)       "
	            "peak background  fs/px  ss/px\n");

	for ( refl = first_refl(list, &iter);
	      refl != NULL;
	      refl = next_refl(refl, iter) )
	{

		signed int h, k, l;
		double intensity, esd_i, bg, pk;
		double fs, ss;

		get_indices(refl, &h, &k, &l);
		get_detector_pos(refl, &fs, &ss);
		intensity = get_intensity(refl);
		esd_i = get_esd_intensity(refl);
		pk = get_peak(refl);
		bg = get_mean_bg(refl);

		/* Reflections with redundancy = 0 are not written */
		if ( get_redundancy(refl) == 0 ) continue;

		if ( image->det != NULL ) {

			struct panel *p;
			double write_fs, write_ss;

			p = find_orig_panel(image->det, fs, ss);
			if ( p == NULL ) {
				ERROR("Panel not found\n");
				return 1;
			}

			/* Convert coordinates to match arrangement of panels in HDF5
			 * file */
			write_fs = fs - p->min_fs + p->orig_min_fs;
			write_ss = ss - p->min_ss + p->orig_min_ss;

			fprintf(fh, "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f"
			            " %6.1f %6.1f\n",
			        h, k, l, intensity, esd_i, pk, bg, write_fs,
			        write_ss);

		} else {

			fprintf(fh, "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f"
			            " %6.1f %6.1f\n",
			        h, k, l, intensity, esd_i, pk, bg, fs, ss);
		}
	}
	return 0;
}
Esempio n. 3
0
bool Pattern_peak_spike::display()
{
#undef LOG_PEAKS
#ifdef LOG_PEAKS
    const int max_dots = 64;
    char dots[max_dots + 2];
    memset(dots, ' ', sizeof(dots));
    dots[max_dots] = '|';
    dots[max_dots + 1] = '\0';
    memset(dots, '.', get_mapped_peak(max_dots));
    Serial.printf("peak %5u %s\n", get_peak(), dots);
#endif

    Colour c = make_hue(g_hue.get());

    int leds = get_mapped_peak(LED_COUNT / 2);

#define FADE_PEAK
#ifdef FADE_PEAK
    static Value held_leds(0, 0, LED_COUNT / 2);
    held_leds.set_velocity(-10, 60);
    if (leds > held_leds.get()) {
	held_leds.set(leds);
    }
    leds = held_leds.get();
#endif

    // Start drawing out from the bottom middle both up and horizontally.
    int start_x = COLUMN_COUNT / 2;
    int start_y = ROW_COUNT - 1;
    int x = start_x;
    int y = start_y;
    for (int led = 0; led < leds; ++led) {
	draw_pixel(x, y, c);
	draw_pixel(flip_x(x), y, c);
	++x;
	++y;
	if (x >= COLUMN_COUNT || y >= ROW_COUNT) {
	    --start_y;
	    if (start_y < 0) {
		start_y = 0;
		++start_x;
	    }
	    x = start_x;
	    y = start_y;
	}
    }

    return true;
}
Esempio n. 4
0
static int write_stream_reflections_2_3(FILE *fh, RefList *list,
                                        struct image *image)
{
	Reflection *refl;
	RefListIterator *iter;

	fprintf(fh, "   h    k    l          I   sigma(I)       "
	            "peak background  fs/px  ss/px panel\n");

	for ( refl = first_refl(list, &iter);
	      refl != NULL;
	      refl = next_refl(refl, iter) )
	{

		signed int h, k, l;
		double intensity, esd_i, pk, bg;
		double fs, ss;
		double write_fs, write_ss;
		struct panel *p = NULL;

		get_indices(refl, &h, &k, &l);
		get_detector_pos(refl, &fs, &ss);
		intensity = get_intensity(refl);
		esd_i = get_esd_intensity(refl);
		pk = get_peak(refl);
		bg = get_mean_bg(refl);

		/* Reflections with redundancy = 0 are not written */
		if ( get_redundancy(refl) == 0 ) continue;

		p = find_panel(image->det,fs,ss);
		if ( p == NULL ) {
			ERROR("Panel not found\n");
			return 1;
		}

		write_fs = fs-p->min_fs+p->orig_min_fs;
		write_ss = ss-p->min_ss+p->orig_min_ss;

		fprintf(fh,
                          "%4i %4i %4i %10.2f %10.2f %10.2f %10.2f "
                          "%6.1f %6.1f %s\n",
                           h, k, l, intensity, esd_i, pk, bg,
                           write_fs, write_ss, p->name);

	}
	return 0;
}
Esempio n. 5
0
double
RTcmix::right_peak(float p[], int n_args)
{
   return get_peak(p[0], p[1], 1);
}
Esempio n. 6
0
double
RTcmix::left_peak(float p[], int n_args)
{
   return get_peak(p[0], p[1], 0);
}
Esempio n. 7
0
double
RTcmix::input_peak(float p[], int n_args)
{
   return get_peak(p[0], p[1], ALL_CHANS);
}
Esempio n. 8
0
/* thread spawned for each connection */
void process_echo_request(void *p)
{
	int sd = (int)p;
	int n, i, nsamples;
	float sample_rate, center_freq;
	win_peak peak;
	jam_info info;
	time_info time;
	cplx *buf = prot_mem_malloc(sizeof(cplx) * WIN_SIZE);
	float *bhwin = prot_mem_malloc(sizeof(float) * WIN_SIZE);
	unsigned int run_time;

	blackman_harris(bhwin, WIN_SIZE);

	union Fpass{
		unsigned int i[UNION_SIZE];
		float fl[UNION_SIZE];
		char ch[RECV_BUF_SIZE];
	} fpass;

	time.trigger = 0;
	time.time = 0;
	time.index = 0;
	time.freq_vs_time = NULL;
	run_time = 0;

	while (1) {
		/* read a max of RECV_BUF_SIZE bytes from socket */
		if ((n = read(sd, fpass.ch, RECV_BUF_SIZE)) < 0) {
			xil_printf("%s: error reading from socket %d, closing socket\r\n", __FUNCTION__, sd);
#ifndef OS_IS_FREERTOS			
			close(sd);
			return;
#else
			break;
#endif
		}

		/* break if the recved message = "quit" */
		if (!strncmp(fpass.ch, "quit", 4))
			break;

		/* break if client closed connection */
		if (n <= 0)
			break;
		++run_time;
		/* Rearrange from network order */
		for (i = 0; i < UNION_SIZE; ++i)
		{
			fpass.i[i] = ntohl(fpass.i[i]);
		}

		/* Get info from header */
		nsamples = fpass.i[0];
		sample_rate = fpass.fl[1];
		center_freq = fpass.fl[2];

		if (nsamples != 64)
			continue;
		/* Limit nsamples to window size */
		if (nsamples > WIN_SIZE)
			nsamples = WIN_SIZE;

		uninter(&fpass.fl[3], buf, nsamples);


		for (i = 0; i < WIN_SIZE; ++i)
		{
			buf[i] *= bhwin[i];
		}

		/* fft and get peak */
		fft(buf, nsamples);
		peak = get_peak(buf, nsamples, sample_rate, center_freq);
		info = process_signal(peak, sample_rate, &time);

		if (info.valid)
		{
			printf("Time: %.2f Bandwidth: %.2f, Chirp Rate: %.2f\r\n", run_time / (sample_rate / 64000), info.bandwidth, info.chirprate);
			info.valid = 0;
		}



		/* handle request */
		/*if ((nwrote = write(sd, fpass.ch, n)) < 0) {
			xil_printf("%s: ERROR responding to client echo request. received = %d, written = %d\r\n",
					__FUNCTION__, n, nwrote);
			xil_printf("Closing socket %d\r\n", sd);


#ifndef OS_IS_FREERTOS
			close(sd);
			return;
#else
			break;
#endif
		}
*/

	}
	/* close connection */
	clear_led(7);
	prot_mem_free(bhwin);
	prot_mem_free(buf);
	close(sd);
#ifdef OS_IS_FREERTOS
	vTaskDelete(NULL);
#endif
}