Пример #1
0
int main(int argc, char *argv[])
{
  struct data_file *df;
  unsigned char buf[BUF_SIZE];
  int i;

  if (register_signals_us() < 0){
#ifdef DEBUG
    fprintf(stderr, "%s: logic error\n", __func__);
#endif
    return -1;
  }

  /**write output to stdout*/
  df = write_raw_data_file("-");
  if (df == NULL){
#ifdef DEBUG
    fprintf(stderr, "%s: logic error\n", __func__);
#endif
    return -1;
  }

  float phase    = 0.0; 
  float freq_rad = FREQ_HZ * 2 * M_PI / S_RATE;

  fprintf(stderr, "%s: radians: %f\n", __func__, freq_rad);

  for (i=0; i<BUF_SIZE; i++){
    phase += freq_rad;
    buf[i] = (unsigned char)((sin(phase)+1)*128);
    //fprintf(stdout,"%d ", buf[i]);
  }

  while (run){

    if (write_next_chunk_raw_data_file(df, buf, BUF_SIZE) < 0){
#ifdef DEBUG
      fprintf(stderr, "%s: failed to write\n", __func__);
#endif
      run = 0;
      break;
    }
  }

  destroy_raw_data_file(df);
#ifdef DEBUG
  fprintf(stderr, "%s:DONE\n", __func__);
#endif

  return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
  int i=1,j=1,k=0;
  char c, flag = 0, *host = NULL, *port = NULL;

  struct spead_socket *x = NULL;

  if (argc < 2)
    return usage(argv);

  while (i < argc){
    if (argv[i][0] == '-'){

      c = argv[i][j];

      switch(c){
        case '\0':
          j = 1;
          i++;
          break;
        case '-':
          j++;
          break;

        /*switches*/  
        case 'h':
          return usage(argv);

        case 'r':
          j++;
          flag = 1;
          k = 1;
          break;

        case 's':
          j++;
          flag = 0;
          break;

          /*settings*/
        
        default:
          fprintf(stderr, "%s: unknown option -%c\n", argv[0], c);
          return EX_USAGE;
      }

    } else {
      /*parameters*/
      switch (k){
        case 0:
          host = argv[i];
          k++;
          break;
        case 1:
          port = argv[i];
          k++;
          break;
        default:
          fprintf(stderr, "%s: extra argument %s\n", argv[0], argv[i]);
          return EX_USAGE;
      }
      i++;
      j=1;
    }
  }

  if (k < 2){
    fprintf(stderr, "%s: insufficient arguments\n", __func__);
    return EX_USAGE;
  }

  if (register_signals_us() < 0)
    return EX_SOFTWARE;

  x = create_udp_spead_socket(host, port);
  if (x == NULL){
    return EX_SOFTWARE;
  }

  switch (flag){
    
    case 0: /*sender*/
#ifdef DEBUG
      fprintf(stderr, "%s: running sender\n", __func__);
#endif

#if 0
      if (connect_spead_socket(x) < 0){
        goto cleanup;
      }
#endif 

#if 1
      if (run_sender(x) < 0){
#ifdef DEBUG
        fprintf(stderr, "%s: run sender fail\n", __func__);
#endif
      }
#endif

      break;

    case 1: /*receiver*/
#ifdef DEBUG
      fprintf(stderr, "%s: running receiver\n", __func__);
#endif

#if 0
      if (bind_spead_socket(x) < 0){
        goto cleanup;
      }
#endif

#if 1
      if (run_receiver(x) < 0){
#ifdef DEBUG
        fprintf(stderr, "%s: run receiver fail\n", __func__);
#endif
      }
#endif

      break;
  }

cleanup:  
  destroy_spead_socket(x);
  
  destroy_shared_mem();
#ifdef DEBUG
  fprintf(stderr,"%s: done\n", __func__);
#endif
  return 0;
}