diff options
author | Lorenz Meier <lm@inf.ethz.ch> | 2015-01-04 15:53:07 +0100 |
---|---|---|
committer | Lorenz Meier <lm@inf.ethz.ch> | 2015-01-04 15:53:07 +0100 |
commit | 7d0c89ded78161d622d40c9dd7cd7b4ac7a8c8d6 (patch) | |
tree | b928364d82bdd81891874866d4f8eb643eeff738 | |
parent | 0142002737637e80071487a632b151d47a11a2a0 (diff) | |
download | px4-firmware-7d0c89ded78161d622d40c9dd7cd7b4ac7a8c8d6.tar.gz px4-firmware-7d0c89ded78161d622d40c9dd7cd7b4ac7a8c8d6.tar.bz2 px4-firmware-7d0c89ded78161d622d40c9dd7cd7b4ac7a8c8d6.zip |
mavlink app: Abort writing to text log on microSD once SD is not writeabele any more after 5 tries. Fix to first message write.
-rw-r--r-- | src/modules/mavlink/mavlink_messages.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/modules/mavlink/mavlink_messages.cpp b/src/modules/mavlink/mavlink_messages.cpp index 89a40d032..6765100c7 100644 --- a/src/modules/mavlink/mavlink_messages.cpp +++ b/src/modules/mavlink/mavlink_messages.cpp @@ -342,6 +342,8 @@ private: MavlinkStreamStatustext(MavlinkStreamStatustext &); MavlinkStreamStatustext& operator = (const MavlinkStreamStatustext &); FILE *fp = nullptr; + unsigned write_err_count = 0; + static const unsigned write_err_threshold = 5; protected: explicit MavlinkStreamStatustext(Mavlink *mavlink) : MavlinkStream(mavlink) @@ -370,10 +372,21 @@ protected: /* write log messages in first instance to disk */ if (_mavlink->get_instance_id() == 0) { if (fp) { - fputs(msg.text, fp); - fputs("\n", fp); - fsync(fileno(fp)); - } else { + if (EOF == fputs(msg.text, fp)) { + write_err_count++; + } else { + write_err_count = 0; + } + + if (write_err_count >= write_err_threshold) { + (void)fclose(fp); + fp = nullptr; + } else { + (void)fputs("\n", fp); + (void)fsync(fileno(fp)); + } + + } else if (write_err_count < write_err_threshold) { /* string to hold the path to the log */ char log_file_name[32] = ""; char log_file_path[64] = ""; @@ -389,6 +402,10 @@ protected: strftime(log_file_name, sizeof(log_file_name), "msgs_%Y_%m_%d_%H_%M_%S.txt", &tt); snprintf(log_file_path, sizeof(log_file_path), "/fs/microsd/%s", log_file_name); fp = fopen(log_file_path, "ab"); + + /* write first message */ + fputs(msg.text, fp); + fputs("\n", fp); } } } |