Exemple #1
0
LPFHPFilter::LPFHPFilter( float aLPCutoff, float aHPCutoff, int amountOfChannels )
{
    setLPF( aLPCutoff, AudioEngineProps::SAMPLE_RATE );
    setHPF( aHPCutoff, AudioEngineProps::SAMPLE_RATE );

    outSamples = new SAMPLE_TYPE[ amountOfChannels ];
    inSamples  = new SAMPLE_TYPE[ amountOfChannels ];

    for ( int i = 0; i < amountOfChannels; ++i )
    {
        outSamples[ i ] = 0.0;
        inSamples[ i ]  = 0.0;
    }
}
Exemple #2
0
/*
 * Put sensor in default sampling configuration
 * Range = +/- 2000 deg/sec
 * Sample rate divider = 9 -> sample rate = 100 Hz
 * LPF = 188 Hz bandwidth
 * Clock source = xGyro
 */
bool ITG3200::init() {
	bool status = false;
	if(test()) {
		gyroStatus = ON;
		setFullRange();
		setSampleRate(0x9);
		setLPF(ITG3200_DLPF_188);
		setClockSource(ITG3200_CLK_SEL_XGYRO);
		status = true;
	}
	else {
		Serial.println("WARNING: gyro not responding");
		status = false;
	}

	return status;
}
Exemple #3
0
/**
 * Main routine. Parse commandline args and trigger actions.
 */
int main(int argc, char **argv) {
  usb_dev_handle      *handle = NULL;
  char * usbSerialID = NULL;
  int c;

// moved this malloc() here instead of within the while(1) loop
// to prevent memory leakage problem
// as *args is not free'ed.

  char **args = malloc(MAX_COMMAND_ARGS * sizeof(char *));
  int port = 19004;
  int daemon = 0;

  // Read options
  while ( (c = getopt(argc, argv, "adhi:m:p:s:u:vx:")) != -1) {
    switch (c) {
    case 'i':
      i2cAddress = atoi(optarg);
      break;
    case 'a':
      setByValue = 1;
      break;
    case 'd':
      daemon = 1;
      break;
    case 'h':
      firmware_PTT = 1;
      break;
    case 'm':
      multiplier = atof(optarg);
      break;
    case 'p': 
      port = atoi(optarg);
      break;
    case 's':
      startupFreq = atof(optarg);
      break;
    case 'x':
      fXtall = atof(optarg);
      break;
    case 'u':
      usbSerialID = optarg;
      break;
    case 'v':
      verbose++;
      break;
    default: /* '?' */
      usage(argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  if (verbose) {
    printf("I2C Address = %X\n", i2cAddress);
    printf("fXtall = %f\n", fXtall);
    printf("multiplier = %f\n", multiplier);
    printf("startupFreq = %f\n", startupFreq);
  }

  if((argc <= optind) && (daemon == 0)){
	usage(argv[0]);
	exit(1);
  }

  usb_init();
  char attempt=0, error=0;
  do {
	attempt++;
	error=usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, VENDOR_NAME, USBDEV_SHARED_PRODUCT, PRODUCT_NAME, usbSerialID);
	if(error != 0){
	  fprintf(stderr, "Could not open USB device \"%s\" with vid=0x%x pid=0x%x, retrying\n", PRODUCT_NAME, USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT);
	  sleep(2*attempt);
	}
  } while (error && attempt < USB_MAX_RETRIES);
  if (error) {
	fprintf(stderr, "Permanent problem opening usb device. Giving up.\n");
	exit(1);
  }

  unsigned short version = readVersion(handle);
  major = (version & 0xFF00) >> 8;
  minor = (version & 0xFF);

  /* Relocate lower later */
  if (daemon) {
    printf("Starting daemon...\n");

    int socket_desc;

    socket_desc=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
    if (socket_desc==-1)
      perror("Create socket");

    struct sockaddr_in address;
    /* type of socket created in socket() */
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = INADDR_ANY;
    address.sin_port = htons(port);

    /* bind the socket to the port specified above */
    int retval;
    if (bind(socket_desc,(struct sockaddr *)&address,sizeof(address)) != 0) {
      fprintf(stderr, "Error binding to port %d\n", port);
      exit(0); 
    }

    while (1) {
      ssize_t bytes;
      char buffer[1024];
      struct sockaddr_in clnt;
      socklen_t clnt_len;
      clnt_len = sizeof(clnt);

      bytes = recvfrom (socket_desc, buffer, sizeof(buffer) - 1, 0, (struct sockaddr *)&clnt, &clnt_len);
      if (bytes > 0) {
        buffer[bytes] = 0;
        if (verbose >= 2)
          printf("Returned %d bytes from %s: %s\n", bytes, inet_ntoa(clnt.sin_addr), buffer);

        if (strncmp(buffer, "quit", 4) == 0) {
          if (verbose)
            printf("Quit command received\n");
          exit(0);
        }

        char *saveptr;
        char *token;
        int argn = 0;

        for (int i=0; i < MAX_COMMAND_ARGS;i++)
          args[i] = NULL;

        token = strtok_r(buffer, " ", &saveptr);
        while (token != NULL) {
          args[argn] = strcpy(malloc(strlen(token) + 1), token);
          argn++;          
          token = strtok_r(NULL, " ", &saveptr);
        }

        // Execute command here
        char result[100];
        do_command(handle, args, argn, result);

        // Cleanup
        for (int i=0; i < MAX_COMMAND_ARGS;i++) {
          if (args[i] != NULL)
            free(args[i]);
        }

        int retlen = strlen(result);
        if (sendto(socket_desc, result, retlen,0, (struct sockaddr *) &clnt, clnt_len) != retlen) {
          perror("Failed to send ack");
          exit(1);
        }

      } else {
      	fprintf(stderr, "recvfrom returned %d\n", bytes);
      }
    }

    close(socket_desc);
    exit(0);
  }
 
  /* Device has been opened - perform the requested operation */
  if (strcmp(argv[optind], "getregisters") == 0) {

	getRegisters(handle);

  } else if(strcmp(argv[optind], "getfreq") == 0){
	double freq; 
	if (setByValue)
		freq = readFrequencyByValue(handle);
	else
		freq = getFrequency(handle);

	if (freq != 0.00)
		printf("Frequency   : %f (x %.2f)\n", freq / multiplier, multiplier);

#ifdef HAVE_LIBNCURSES
  } else if (strcmp(argv[optind], "interactive") == 0) {
      run_interactive(handle);
#endif

  } else if (strcmp(argv[optind], "getptt") == 0){
	if (firmware_PTT) PTT = getPTT(handle);
        printf("PTT   : %d\n", PTT);

 } else if (strcmp(argv[optind], "getkeys") == 0){
	keys = getkeys(handle);
        printf("Paddles: %d\n", keys);

 } else if (strcmp(argv[optind], "gettone") == 0){
        printf("CW Tone: %d\n", CW_tone);

  } else if ((strcmp(argv[optind], "ptt") == 0) && (argc >= optind + 1)) {

	PTT = (strcmp(argv[optind+1],"on") == 0) ? 1: 0;
	setPTT(handle, PTT);
	printf("PTT set to %d\n", PTT);

  } else if (strcmp(argv[optind], "calibrate") == 0) {
	
	calibrate(handle);

  } else if ((strcmp(argv[optind], "set") == 0) && (argc >= optind + 2)) {

    if ((strcmp(argv[optind+1], "bpf_addr") == 0) && (argc >= optind + 3)) {
      // set bpf_addr index value
      setBPFAddress(handle, atoi(argv[optind+2]), atoi(argv[optind+3]));
      
    } else if ((strcmp(argv[optind+1], "bpf_point") == 0) && (argc >= optind + 3)) {
      // set bpf_point index (int) value (float)
      setBPFCrossOver(handle, atoi(argv[optind+2]), atof(argv[optind+3]));
      
    } else if ((strcmp(argv[optind+1], "bpf") == 0) && (argc >= optind + 2)) {

        setBPF(handle, (strcmp(argv[optind+2],"on") == 0) ? 1 : 0);

    } else if ((strcmp(argv[optind+1], "lpf") == 0) && (argc >= optind + 2)) {

        setLPF(handle, (strcmp(argv[optind+2],"on") == 0) ? 1 : 0);

    } else if ((strcmp(argv[optind+1], "lpf_addr") == 0) && (argc >= optind + 3)) {
      // set bpf_addr index value
      setBPFAddress(handle, atoi(argv[optind+2]), atoi(argv[optind+3]));
      displayLPFs(handle);
      
    } else if ((strcmp(argv[optind+1], "lpf_point") == 0) && (argc >= optind + 3)) {
      // set lpf_point index (int) value (float)
      setLPFCrossOver(handle, atoi(argv[optind+2]), atof(argv[optind+3]));
            
    } else if (strcmp(argv[optind+1], "freq") == 0) {

      if (setByValue)
        setFreqByValue(handle, atof(argv[optind+2]));
      else
        setFrequency(handle, atof(argv[optind+2]));
      
    } else if ((strcmp(argv[optind+1], "registers") == 0 || strcmp(argv[optind+1], "regs") == 0) && argc == optind+8) {
      unsigned char regs[6];
      int i;
      for (i = 0; i < 6; i += 1)
	regs[i] = strtol(argv[optind+2+i], NULL, 0);
      setRegisters(handle, regs);
    } else if ((strcmp(argv[optind+1], "si570_addr") == 0) && (argc >= optind + 2)) {
      
      setSi570Address(handle, atoi(argv[optind+2]));
      
    } else if (strcmp(argv[optind+1], "si570_multiplier") == 0) {
        
	int index = 0;
	int valueIndex = optind+2;
	// If there are 2 args after the variable name, one is index
	if (argc >= optind + 3) {
	  index = atoi(argv[optind+2]);
	  valueIndex++;
	}
	
        double sub, mul;
        readMultiplyLO(handle, index, &mul, &sub);
        mul = atof(argv[valueIndex]);
        setMultiplyLo(handle, index, mul, sub);
        if (verbose)
            printf("Set multiply [%d] to : %f\n", index, mul);
        
    } else if (strcmp(argv[optind+1], "xtall") == 0) {

        setXtallFrequency(handle, atof(argv[optind+2]));

    } else if (strcmp(argv[optind+1], "startup") == 0) {

	setStartupFrequency(handle, atof(argv[optind+2]));

    } else {
	usage(argv[0]);
	exit(1);
    }

  } else if (strcmp(argv[optind], "solutions") == 0) {
    solveRegisters(handle);
  } else if (strcmp(argv[optind], "status") == 0) {

	printf("USB SerialID: %s\n", serialNumberString);

	if (major >= 15) {
		readFrequencyByValue(handle);
		readStartupFreq(handle);
		readXtallFreq(handle);
		readSmoothTunePPM(handle);
		if (major >= 16 || minor >= 12) {
			readSi570Address(handle);
		}

		displayBands(handle);
		displayLPFs(handle);
		
		/*
		if (major >= 16 || ((major >= 15) && (minor >= 12))) {
		  displayBands(handle);
		} else if (minor >= 10) {
		  double sub, mul;
		  readMultiplyLO(handle, 0, &mul, &sub);
		  printf("LO Subtract : %f\n", sub);
		  printf("Multiply    : %f\n", mul);
		}
		//displayBPFFilters(handle);
		//displayLPFFilters(handle);*/
	}
  } else if (strcmp(argv[optind], "tweak") == 0) {
    tweakRegisters(handle);
  } else {
	usage(argv[0]);
	exit(1);
  }
  usb_close(handle);
  return 0;
}