diff options
author | Anton Babushkin <anton.babushkin@me.com> | 2014-03-07 11:18:31 +0400 |
---|---|---|
committer | Anton Babushkin <anton.babushkin@me.com> | 2014-03-07 11:18:31 +0400 |
commit | 80595c177a65e9ba91a35ffdee49d518df657508 (patch) | |
tree | 77d85cf420e32b0b2bfe4beea652cd07fba6fed2 /src/modules/sdlog2 | |
parent | e505f4fae5596b2b53c120a7cb2a03d2d974c83a (diff) | |
download | px4-firmware-80595c177a65e9ba91a35ffdee49d518df657508.tar.gz px4-firmware-80595c177a65e9ba91a35ffdee49d518df657508.tar.bz2 px4-firmware-80595c177a65e9ba91a35ffdee49d518df657508.zip |
sdlog2: code style fixed
Diffstat (limited to 'src/modules/sdlog2')
-rw-r--r-- | src/modules/sdlog2/logbuffer.c | 3 | ||||
-rw-r--r-- | src/modules/sdlog2/sdlog2.c | 24 | ||||
-rw-r--r-- | src/modules/sdlog2/sdlog2_messages.h | 14 |
3 files changed, 29 insertions, 12 deletions
diff --git a/src/modules/sdlog2/logbuffer.c b/src/modules/sdlog2/logbuffer.c index 6a29d7e5c..2da67d8a9 100644 --- a/src/modules/sdlog2/logbuffer.c +++ b/src/modules/sdlog2/logbuffer.c @@ -74,8 +74,9 @@ bool logbuffer_write(struct logbuffer_s *lb, void *ptr, int size) // bytes available to write int available = lb->read_ptr - lb->write_ptr - 1; - if (available < 0) + if (available < 0) { available += lb->size; + } if (size > available) { // buffer overflow diff --git a/src/modules/sdlog2/sdlog2.c b/src/modules/sdlog2/sdlog2.c index fa25d74f8..5acd2b615 100644 --- a/src/modules/sdlog2/sdlog2.c +++ b/src/modules/sdlog2/sdlog2.c @@ -222,8 +222,9 @@ static int open_log_file(void); static void sdlog2_usage(const char *reason) { - if (reason) + if (reason) { fprintf(stderr, "%s\n", reason); + } errx(1, "usage: sdlog2 {start|stop|status} [-r <log rate>] [-b <buffer size>] -e -a -t\n" "\t-r\tLog rate in Hz, 0 means unlimited rate\n" @@ -243,8 +244,9 @@ sdlog2_usage(const char *reason) */ int sdlog2_main(int argc, char *argv[]) { - if (argc < 2) + if (argc < 2) { sdlog2_usage("missing command"); + } if (!strcmp(argv[1], "start")) { @@ -403,22 +405,29 @@ static void *logwriter_thread(void *arg) int log_fd = open_log_file(); - if (log_fd < 0) + if (log_fd < 0) { return NULL; + } struct logbuffer_s *logbuf = (struct logbuffer_s *)arg; /* write log messages formats, version and parameters */ log_bytes_written += write_formats(log_fd); + log_bytes_written += write_version(log_fd); + log_bytes_written += write_parameters(log_fd); + fsync(log_fd); int poll_count = 0; void *read_ptr; + int n = 0; + bool should_wait = false; + bool is_part = false; while (true) { @@ -673,6 +682,7 @@ int sdlog2_thread_main(int argc, char *argv[]) if (r <= 0) { r = 1; } + sleep_delay = 1000000 / r; } break; @@ -745,9 +755,11 @@ int sdlog2_thread_main(int argc, char *argv[]) } struct vehicle_status_s buf_status; + struct vehicle_gps_position_s buf_gps_pos; memset(&buf_status, 0, sizeof(buf_status)); + memset(&buf_gps_pos, 0, sizeof(buf_gps_pos)); /* warning! using union here to save memory, elements should be used separately! */ @@ -892,6 +904,7 @@ int sdlog2_thread_main(int argc, char *argv[]) /* --- VEHICLE STATUS - LOG MANAGEMENT --- */ bool status_updated = copy_if_updated(ORB_ID(vehicle_status), subs.status_sub, &buf_status); + if (status_updated) { if (log_when_armed) { handle_status(&buf_status); @@ -900,6 +913,7 @@ int sdlog2_thread_main(int argc, char *argv[]) /* --- GPS POSITION - LOG MANAGEMENT --- */ bool gps_pos_updated = copy_if_updated(ORB_ID(vehicle_gps_position), subs.gps_pos_sub, &buf_gps_pos); + if (gps_pos_updated && log_name_timestamp) { gps_time = buf_gps_pos.time_gps_usec; } @@ -1068,6 +1082,7 @@ int sdlog2_thread_main(int argc, char *argv[]) if (buf.local_pos.dist_bottom_valid) { dist_bottom_present = true; } + if (dist_bottom_present) { log_msg.msg_type = LOG_DIST_MSG; log_msg.body.log_DIST.bottom = buf.local_pos.dist_bottom; @@ -1215,8 +1230,9 @@ int sdlog2_thread_main(int argc, char *argv[]) usleep(sleep_delay); } - if (logging_enabled) + if (logging_enabled) { sdlog2_stop_log(); + } pthread_mutex_destroy(&logbuffer_mutex); pthread_cond_destroy(&logbuffer_cond); diff --git a/src/modules/sdlog2/sdlog2_messages.h b/src/modules/sdlog2/sdlog2_messages.h index 16bfc355d..e27518aa0 100644 --- a/src/modules/sdlog2/sdlog2_messages.h +++ b/src/modules/sdlog2/sdlog2_messages.h @@ -267,13 +267,13 @@ struct log_DIST_s { /* --- TELE - TELEMETRY STATUS --- */ #define LOG_TELE_MSG 22 struct log_TELE_s { - uint8_t rssi; - uint8_t remote_rssi; - uint8_t noise; - uint8_t remote_noise; - uint16_t rxerrors; - uint16_t fixed; - uint8_t txbuf; + uint8_t rssi; + uint8_t remote_rssi; + uint8_t noise; + uint8_t remote_noise; + uint16_t rxerrors; + uint16_t fixed; + uint8_t txbuf; }; /********** SYSTEM MESSAGES, ID > 0x80 **********/ |