Example #1
0
int main(int argc, char** argv) {
  char* execute = NULL;
  int iArg, iOptIndex, tmp = -1;
  while ((iArg = getopt_long(argc, argv, "e:i:t:hH:l:", g_LongOpts, &iOptIndex)) != -1) {
    switch (iArg) {
      case 'e':
        execute = optarg;
        break;
      case 't':
        tmp = strtol(optarg, NULL, 10);
        if ((errno == ERANGE || (tmp == LONG_MAX || tmp == LONG_MIN)) || (errno != 0 && tmp == 0) || tmp < 0 || tmp > 65535) {
          fprintf(stderr, "--tcp-port requires a valid port to check.\n");
          return 1;
        }
        struct tcp_port* tcp_port = new_tcp_port();
        tcp_port->port = (unsigned short) tmp;
        break;
      case 'H':
        if (access(optarg, F_OK|X_OK)) {
          fprintf(stderr, "The file passed to --hook either doesn't exist or isn't executable.\n");
          return 1;
        }
        struct hook* hook = new_hook();
        hook->executable = optarg;
        break;
      case 'i':
        tmp = strtol(optarg, NULL, 10);
        if ((errno == ERANGE || (tmp == LONG_MAX || tmp == LONG_MIN)) || (errno != 0 && tmp == 0) || tmp < 0) {
          fprintf(stderr, "--interval requires a positive amount of seconds.\n");
          return 1;
        }
        interval = tmp;
        break;
      case 'l':
        logfile = optarg;
        break;
      default:
      case 'h':
        usage();
        return 0;
    }
  }
  if (!execute) {
    fprintf(stderr, "Missing the -e flag.\n");
    return 1;
  } else if (check_access(execute)) {
    fprintf(stderr, "%s either doesn't exist or isn't executable.\n", execute);
    return 1;
  }
  signal(SIGINT, quit);
  signal(SIGQUIT, quit);
  int restarts = 0;
  for (;; restarts++)
    start(execute);

  return 0;
}
static Hook *wa_new (int velocity, int nominal, double dt)
{
    Butterworth *butflc ;
    Hook	*hook ;
    int i;
    double omega, damp;

//    allot ( Butterworth *, butflc, 1 ) ; 
	butflc =new Butterworth();
    hook = new_hook(free) ; 
    hook->p = (void *) butflc ;

	for (i=0; i<MAX_ORDER; i++) {
		butflc->xim1[i] = 0.0;
		butflc->xim2[i] = 0.0;
		butflc->xom1[i] = 0.0;
		butflc->xom2[i] = 0.0;
	}
	if (nominal) {
		omega = 2.0*M_PI*(1.0/0.8);
		damp = 0.8;
		butflc->gain = 2800.0 * 1.e-6;
	} else {
		omega = 2.0*M_PI*(1.0/0.8);
		damp = 0.7;
		butflc->gain = 2080.0 * 1.e-6;
	}
 
	/* Get the filter stages in the s-domain. */

	butflc->ns = 2;
	butflc->is[0] = 3;
	butflc->b[0] = 2.0*damp*omega;
	butflc->c[0] = omega*omega;
	omega = 2.0*M_PI*10.0;
	damp = 0.7;
	butflc->is[1] = 1;
	butflc->b[1] = 2.0*damp*omega;
	butflc->c[1] = omega*omega;
 	if (velocity) {
		butflc->ns = 3;
		butflc->is[2] = 4;
	}

    recoef (butflc, dt, 0, 1);

    return hook ;
}
static Hook *bwt_new(double fl, int ol, double fu, int ou, double dt)
	{
    int  nsout;
    double     gn;
    Butterworth *butflc ;
    Hook	*hook ;

//    allot(Butterworth *, butflc, 1); 
	butflc=new Butterworth();
    hook = new_hook(free) ; 
    hook->p = (void *) butflc ;

    butflc->ns = 0;
    if (ol + ou > MAX_ORDER) {
	return 0;
    }
    if (fu == (double) 0. || ou == 0) {
	butflc->ns = 0;
	butflc->gain = (double) 1.;
    } else {
	butsta (ou, &nsout, butflc->is, butflc->b, butflc->c);
	l2l (fu, nsout, butflc->is, butflc->b, butflc->c, &gn);
	butflc->ns = nsout;
	butflc->gain = gn;
    }
    if (fl != (double) 0. && ol != 0) {
	butsta (ol, &nsout, &butflc->is[butflc->ns], &butflc->b[
				    butflc->ns], &butflc->c[butflc->ns]);
	l2h (fl, nsout, &butflc->is[butflc->ns], &butflc->b[butflc->ns],
	      &butflc->c[butflc->ns], &gn);
	butflc->ns += nsout;
	butflc->gain *= gn;
    }
    butflc->gain = (double) 1.;

    recoef (butflc, dt, 0, 1);

    return hook;
	}