Example #1
0
int collect_loop(struct collect_state *cs)
{
  int rr, result, i;

  for(;;){
    rr = recv(cs->c_nfd, cs->c_buffer, PACKET_LEN, 0);
#ifdef DEBUG
    fprintf(stderr, "loop: received with code %d\n", rr);
#endif
    if(rr < 0){
      switch(errno){
        case EAGAIN :
        case EINTR :
          continue; /* WARNING */
        default :
          fprintf(stderr, "collect: receive failed %s\n", strerror(errno));
          gettimeofday(&(cs->c_stop), NULL);
          return -1;
      }
    }

    if(cs->c_rxp == 0){
      gettimeofday(&(cs->c_start), NULL);
    }

    cs->c_have = rr;

    cs->c_rxp++;
    cs->c_rxtotal += rr;

    if(cs->c_verbose > 1){
      fprintf(stderr, "read: got packet of %d\n", rr);
      if(cs->c_verbose > 2){
        fprintf(stderr, "read: data");
        for(i = 0; i < cs->c_have; i++){
          fprintf(stderr, " %02x", cs->c_buffer[i]);
        }
        fprintf(stderr, "\n");
      }
    }

    result = collect_process(cs);

    if(result){
      gettimeofday(&(cs->c_stop), NULL);
      return (result > 0) ? 0 : -1;
    }
  }
}
Example #2
0
int collect_loop(struct collect_state *cs)
{
	int rr, result, i;
	int *real_raw, *imag_raw;

	gnuplot_ctrl *bsln_disp[4] = {NULL, NULL, NULL, NULL};

	real_raw = malloc(sizeof(int) * FFT_SIZE * NUM_BASELINE_PRODUCTS);
	if( real_raw == NULL){
		fprintf(stderr, "capture_baseline_data: error mallocing raw_real\n");
		return -1;
	}

	imag_raw = malloc(sizeof(int) * FFT_SIZE * NUM_BASELINE_PRODUCTS);
	if( imag_raw == NULL){
		fprintf(stderr, "capture_baseline_data: error mallocing imag_real\n");
		free(real_raw);
		return -1;
	}

	if( init_baseline_display(bsln_disp) < 0){
		fprintf(stderr,"main: error initialising baseline displays\n");
		return -1;
	}
	for(;;){
		rr = recv(cs->c_nfd, cs->c_buffer, PACKET_LEN, 0);
#ifdef DEBUG
		fprintf(stderr, "loop: received with code %d\n", rr);
#endif
		if(rr < 0){
			switch(errno){
				case EAGAIN :
				case EINTR :
					continue; /* WARNING */
				default :
					fprintf(stderr, "collect: receive failed %s\n", strerror(errno));
					gettimeofday(&(cs->c_stop), NULL);
					return -1;
			}
		}

		if(cs->c_rxp == 0){
			gettimeofday(&(cs->c_start), NULL);
		}

		cs->c_have = rr;

		cs->c_rxp++;
		cs->c_rxtotal += rr;

		if(cs->c_verbose > 1){
			fprintf(stderr, "read: got packet of %d\n", rr);
			if(cs->c_verbose > 2){
				fprintf(stderr, "read: data");
				for(i = 0; i < cs->c_have; i++){
					fprintf(stderr, " %02x", cs->c_buffer[i]);
				}
				fprintf(stderr, "\n");
			}
		}

		result = collect_process(cs, bsln_disp, real_raw, imag_raw);

		if(result){
#ifdef DEBUG
			fprintf(stderr, "CLEANUP......................CLEANUP\n");
#endif
			clean(bsln_disp);
			free(real_raw);
			free(imag_raw);
			gettimeofday(&(cs->c_stop), NULL);
			return (result > 0) ? 0 : -1;
		}
	}
}