コード例 #1
0
ファイル: px4io.c プロジェクト: NikiRegina/Firmware
int user_start(int argc, char *argv[])
{
	/* run C++ ctors before we go any further */
	up_cxxinitialize();

	/* reset all to zero */
	memset(&system_state, 0, sizeof(system_state));
	/* default to 50 Hz PWM outputs */
	system_state.servo_rate = 50;

	/* configure the high-resolution time/callout interface */
	hrt_init();

	/* print some startup info */
	lib_lowprintf("\nPX4IO: starting\n");

	/* default all the LEDs to off while we start */
	LED_AMBER(false);
	LED_BLUE(false);
	LED_SAFETY(false);

	/* turn on servo power */
	POWER_SERVO(true);

	/* start the safety switch handler */
	safety_init();

	/* configure the first 8 PWM outputs (i.e. all of them) */
	up_pwm_servo_init(0xff);

	/* start the flight control signal handler */
	task_create("FCon",
		    SCHED_PRIORITY_DEFAULT,
		    1024,
		    (main_t)controls_main,
		    NULL);


	struct mallinfo minfo = mallinfo();
	lib_lowprintf("free %u largest %u\n", minfo.mxordblk, minfo.fordblks);

	/* we're done here, go run the communications loop */
	comms_main();
}
コード例 #2
0
ファイル: master.c プロジェクト: indazoo/OldReprapMendel
int main(int argc, char **argv)
{
  pthread_t timer_thread;
  pthread_t comms_thread;
  pthread_attr_t pthread_custom_attr;
  char buf[1024];
  FILE *f;
  int c;

  extern byte action;
  extern byte action_value;
  extern int act_after;

  if (argc == 1) {
    action = ACT_NONE;
    exitAfter = 10;
  } else if (argc == 5) {
    act_after = atoi(argv[1]);
    action = atoi(argv[2]);
    action_value = atoi(argv[3]);
    exitAfter = atoi(argv[4]);
  } else {
    fprintf(stderr, "Usage: ./master action_after action action_val exit\n");
    exit(1);
  }

  switch(fork()) {
  case -1:
    perror("Fork failed");
    exit(1);
  case 0:
    f = popen("./slave", "r");
    while(fgets(buf, 1024, f)) {
      printf(buf);
      fflush(stdout);
    }
    pclose(f);
    exit(1);
  }

  printf("Starting master\n");
  fflush(stdout);

  alarm(10);

  address = 0;

  rfd = open("0", O_RDONLY);
  wfd = open("1", O_WRONLY | O_NONBLOCK);

  pthread_attr_init(&pthread_custom_attr);
  
  pthread_create(&timer_thread, &pthread_custom_attr, timer, NULL);
  pthread_create(&comms_thread, &pthread_custom_attr, comms, NULL);

  comms_main();

  pthread_join(timer_thread, NULL);
  pthread_join(comms_thread, NULL);
  
  return 0;
}