mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 02:53:34 +08:00
examples fix code style
This commit is contained in:
committed by
Lorenz Meier
parent
0eaf41a048
commit
662ec3f62f
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2014-2015 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2014-2015 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -73,8 +73,10 @@ static void usage(const char *reason);
|
||||
|
||||
static void usage(const char *reason)
|
||||
{
|
||||
if (reason)
|
||||
if (reason) {
|
||||
fprintf(stderr, "%s\n", reason);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: daemon {start|stop|status} [-p <additional params>]\n\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -89,13 +91,12 @@ static void usage(const char *reason)
|
||||
*/
|
||||
int matlab_csv_serial_main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 1)
|
||||
if (argc < 1) {
|
||||
usage("missing command");
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "start"))
|
||||
{
|
||||
if (thread_running)
|
||||
{
|
||||
if (!strcmp(argv[1], "start")) {
|
||||
if (thread_running) {
|
||||
warnx("already running\n");
|
||||
/* this is not an error */
|
||||
exit(0);
|
||||
@@ -103,24 +104,23 @@ int matlab_csv_serial_main(int argc, char *argv[])
|
||||
|
||||
thread_should_exit = false;
|
||||
daemon_task = task_spawn_cmd("matlab_csv_serial",
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_MAX - 5,
|
||||
2000,
|
||||
matlab_csv_serial_thread_main,
|
||||
(argv) ? (char * const *)&argv[2] : (char * const *)NULL);
|
||||
SCHED_DEFAULT,
|
||||
SCHED_PRIORITY_MAX - 5,
|
||||
2000,
|
||||
matlab_csv_serial_thread_main,
|
||||
(argv) ? (char * const *)&argv[2] : (char * const *)NULL);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "stop"))
|
||||
{
|
||||
if (!strcmp(argv[1], "stop")) {
|
||||
thread_should_exit = true;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "status"))
|
||||
{
|
||||
if (!strcmp(argv[1], "status")) {
|
||||
if (thread_running) {
|
||||
warnx("running");
|
||||
|
||||
} else {
|
||||
warnx("stopped");
|
||||
}
|
||||
@@ -139,7 +139,7 @@ int matlab_csv_serial_thread_main(int argc, char *argv[])
|
||||
errx(1, "need a serial port name as argument");
|
||||
}
|
||||
|
||||
const char* uart_name = argv[1];
|
||||
const char *uart_name = argv[1];
|
||||
|
||||
warnx("opening port %s", uart_name);
|
||||
|
||||
@@ -197,40 +197,35 @@ int matlab_csv_serial_thread_main(int argc, char *argv[])
|
||||
|
||||
thread_running = true;
|
||||
|
||||
while (!thread_should_exit)
|
||||
{
|
||||
while (!thread_should_exit) {
|
||||
|
||||
/*This runs at the rate of the sensors */
|
||||
struct pollfd fds[] = {
|
||||
{ .fd = accel0_sub, .events = POLLIN }
|
||||
{ .fd = accel0_sub, .events = POLLIN }
|
||||
};
|
||||
|
||||
/* wait for a sensor update, check for exit condition every 500 ms */
|
||||
int ret = poll(fds, sizeof(fds) / sizeof(fds[0]), 500);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
if (ret < 0) {
|
||||
/* poll error, ignore */
|
||||
|
||||
}
|
||||
else if (ret == 0)
|
||||
{
|
||||
} else if (ret == 0) {
|
||||
/* no return value, ignore */
|
||||
warnx("no sensor data");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
} else {
|
||||
|
||||
/* accel0 update available? */
|
||||
if (fds[0].revents & POLLIN)
|
||||
{
|
||||
if (fds[0].revents & POLLIN) {
|
||||
orb_copy(ORB_ID(sensor_accel), accel0_sub, &accel0);
|
||||
orb_copy(ORB_ID(sensor_accel), accel1_sub, &accel1);
|
||||
orb_copy(ORB_ID(sensor_gyro), gyro0_sub, &gyro0);
|
||||
orb_copy(ORB_ID(sensor_gyro), gyro1_sub, &gyro1);
|
||||
|
||||
// write out on accel 0, but collect for all other sensors as they have updates
|
||||
dprintf(serial_fd, "%llu,%d,%d,%d,%d,%d,%d\n", accel0.timestamp, (int)accel0.x_raw, (int)accel0.y_raw, (int)accel0.z_raw,
|
||||
dprintf(serial_fd, "%llu,%d,%d,%d,%d,%d,%d\n", accel0.timestamp, (int)accel0.x_raw, (int)accel0.y_raw,
|
||||
(int)accel0.z_raw,
|
||||
(int)accel1.x_raw, (int)accel1.y_raw, (int)accel1.z_raw);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user