Beispiel #1
0
int
fmu_main(int argc, char *argv[])
{
	PortMode new_mode = PORT_MODE_UNSET;
	const char *verb = argv[1];

	if (!strcmp(verb, "stop")) {
		fmu_stop();
		errx(0, "FMU driver stopped");
	}

	if (!strcmp(verb, "id")) {
		uint8_t id[12];
		(void)get_board_serial(id);

		errx(0, "Board serial:\n %02X%02X%02X%02X %02X%02X%02X%02X %02X%02X%02X%02X",
		     (unsigned)id[0], (unsigned)id[1], (unsigned)id[2], (unsigned)id[3], (unsigned)id[4], (unsigned)id[5],
		     (unsigned)id[6], (unsigned)id[7], (unsigned)id[8], (unsigned)id[9], (unsigned)id[10], (unsigned)id[11]);
	}


	if (fmu_start() != OK)
		errx(1, "failed to start the FMU driver");

	/*
	 * Mode switches.
	 */
	if (!strcmp(verb, "mode_gpio")) {
		new_mode = PORT_FULL_GPIO;

	} else if (!strcmp(verb, "mode_pwm")) {
		new_mode = PORT_FULL_PWM;

#if defined(CONFIG_ARCH_BOARD_PX4FMU_V2)
	} else if (!strcmp(verb, "mode_pwm4")) {
		new_mode = PORT_PWM4;
#endif
#if defined(CONFIG_ARCH_BOARD_PX4FMU_V1)

	} else if (!strcmp(verb, "mode_serial")) {
		new_mode = PORT_FULL_SERIAL;

	} else if (!strcmp(verb, "mode_gpio_serial")) {
		new_mode = PORT_GPIO_AND_SERIAL;

	} else if (!strcmp(verb, "mode_pwm_serial")) {
		new_mode = PORT_PWM_AND_SERIAL;

	} else if (!strcmp(verb, "mode_pwm_gpio")) {
		new_mode = PORT_PWM_AND_GPIO;
#endif
	}

	/* was a new mode set? */
	if (new_mode != PORT_MODE_UNSET) {

		/* yes but it's the same mode */
		if (new_mode == g_port_mode)
			return OK;

		/* switch modes */
		int ret = fmu_new_mode(new_mode);
		exit(ret == OK ? 0 : 1);
	}

	if (!strcmp(verb, "test"))
		test();

	if (!strcmp(verb, "fake"))
		fake(argc - 1, argv + 1);

	if (!strcmp(verb, "sensor_reset")) {
		if (argc > 2) {
			int reset_time = strtol(argv[2], 0, 0);
			sensor_reset(reset_time);

		} else {
			sensor_reset(0);
			warnx("resettet default time");
		}

		exit(0);
	}

	if (!strcmp(verb, "peripheral_reset")) {
		if (argc > 2) {
			int reset_time = strtol(argv[2], 0, 0);
			peripheral_reset(reset_time);

		} else {
			peripheral_reset(0);
			warnx("resettet default time");
		}

		exit(0);
	}

	if (!strcmp(verb, "i2c")) {
		if (argc > 3) {
			int bus = strtol(argv[2], 0, 0);
			int clock_hz = strtol(argv[3], 0, 0);
			int ret = fmu_new_i2c_speed(bus, clock_hz);

			if (ret) {
				errx(ret, "setting I2C clock failed");
			}

			exit(0);
		} else {
			warnx("i2c cmd args: <bus id> <clock Hz>");
		}
	}

	fprintf(stderr, "FMU: unrecognised command %s, try:\n", verb);
#if defined(CONFIG_ARCH_BOARD_PX4FMU_V1)
	fprintf(stderr, "  mode_gpio, mode_serial, mode_pwm, mode_gpio_serial, mode_pwm_serial, mode_pwm_gpio, test, fake, sensor_reset, id\n");
#elif defined(CONFIG_ARCH_BOARD_PX4FMU_V2) || defined(CONFIG_ARCH_BOARD_AEROCORE)
	fprintf(stderr, "  mode_gpio, mode_pwm, test, sensor_reset [milliseconds], i2c <bus> <hz>\n");
#endif
	exit(1);
}
int
fmu_main(int argc, char *argv[])
{
	PortMode new_mode = PORT_MODE_UNSET;
	const char *verb = argv[1];

	if (!strcmp(verb, "stop")) {
		fmu_stop();
		errx(0, "FMU driver stopped\n");
		return 0;
	}

	if (!strcmp(verb, "id")) {
		errx(0,"unsupport get board serial number\n");
		return 0;
	}


	if (fmu_start() != OK) {
		errx(1, "failed to start the FMU driver\n");
		return 0;
	}

	/*
	 * Mode switches.
	 */
	if (!strcmp(verb, "mode_gpio")) {
		errx(0,"unsupport mode_gpio\n");
		return 0;
	} else if (!strcmp(verb, "mode_pwm")) {
		new_mode = PORT_FULL_PWM;
	} else if (!strcmp(verb, "mode_pwm2")) {
		new_mode = PORT_PWM2;
	} else if (!strcmp(verb, "mode_pwm4")) {
		new_mode = PORT_PWM4;
	} else if (!strcmp(verb, "mode_pwm6")) {
		new_mode = PORT_PWM6;
	} else if (!strcmp(verb, "mode_pwm8")) {
		new_mode = PORT_PWM8;
	} else if (!strcmp(verb, "mode_serial")) {
		errx(0,"unsupport mode_serial\n");
		return 0;
	} else if (!strcmp(verb, "mode_gpio_serial")) {
		errx(0,"unsupport mode_gpio_serial\n");
		return 0;
	} else if (!strcmp(verb, "mode_pwm_serial")) {
		errx(0,"unsupport mode_pwm_serial\n");
		return 0;
	} else if (!strcmp(verb, "mode_pwm_gpio")) {
		errx(0,"unsupport mode_pwm_gpio\n");
		return 0;
	}

	/* was a new mode set? */
	if (new_mode != PORT_MODE_UNSET) {

		/* yes but it's the same mode */
		if (new_mode == g_port_mode) {
			return OK;
		}

		/* switch modes */
		return fmu_new_mode(new_mode);
	}

	if (!strcmp(verb, "test")) {
		test();
		return 0;
	}

	if (!strcmp(verb, "fake")) {
		fake(argc - 1, argv + 1);
		return 0;
	}


	if (!strcmp(verb, "sensor_reset")) {
		warnx("unsupport sensor_reset\n");
		return 0;
	}

	if (!strcmp(verb, "peripheral_reset")) {
		warnx("unsupport peripheral_reset\n");
		return 0;
	}

	if (!strcmp(verb, "i2c")) {
		warnx("unsupport fmu I2C\n");
		return 0;
	}
	fprintf(stderr, "FMU: unrecognised command %s, try:\n", verb);
	return 0;
}