diff --git a/libraries/AP_Logger/AP_Logger.cpp b/libraries/AP_Logger/AP_Logger.cpp index 06cfc081156..d1f0ea6b51a 100644 --- a/libraries/AP_Logger/AP_Logger.cpp +++ b/libraries/AP_Logger/AP_Logger.cpp @@ -908,6 +908,10 @@ void AP_Logger::Write_Message(const char *message) { FOR_EACH_BACKEND(Write_Message(message)); } +void AP_Logger::Write_MessageChunk(uint8_t id, const char *messagechunk, uint8_t chunk_seq) +{ + FOR_EACH_BACKEND(Write_MessageChunk(id, messagechunk, chunk_seq)); +} void AP_Logger::Write_Mode(uint8_t mode, const ModeReason reason) { diff --git a/libraries/AP_Logger/AP_Logger.h b/libraries/AP_Logger/AP_Logger.h index 10ff63d1c24..207ad645733 100644 --- a/libraries/AP_Logger/AP_Logger.h +++ b/libraries/AP_Logger/AP_Logger.h @@ -262,6 +262,16 @@ public: void Write_Power(void); void Write_Radio(const mavlink_radio_t &packet); void Write_Message(const char *message); + // support for multi-chunk messages: + uint8_t get_MSG_id() { + uint8_t ret = ++MSG_id; + if (ret > 0) { + return ret; + } + return ++MSG_id; + } + void Write_MessageChunk(uint8_t id, const char *messagechunk, uint8_t chunk_seq); + void Write_MessageF(const char *fmt, ...); void Write_Compass(); void Write_Mode(uint8_t mode, const ModeReason reason); @@ -616,6 +626,9 @@ private: void log_file_content(FileContent &file_content, const char *filename); void file_content_update(FileContent &file_content); #endif + + // support for multi-chunk messages: + uint8_t MSG_id; }; namespace AP { diff --git a/libraries/AP_Logger/AP_Logger_Backend.h b/libraries/AP_Logger/AP_Logger_Backend.h index 66bd2bafb34..a25d9815b2d 100644 --- a/libraries/AP_Logger/AP_Logger_Backend.h +++ b/libraries/AP_Logger/AP_Logger_Backend.h @@ -139,6 +139,7 @@ public: } bool Write_Message(const char *message); bool Write_MessageF(const char *fmt, ...); + bool Write_MessageChunk(uint8_t id, const char *messagechunk, uint8_t chunk_seq); bool Write_Mission_Cmd(const AP_Mission &mission, const AP_Mission::Mission_Command &cmd, LogMessages id); @@ -275,6 +276,7 @@ private: bool emit_format_for_type(LogMessages a_type); Bitmask<256> _formats_written; + uint8_t msg_id; // the ID of the next MSG message that will be logged }; #endif // HAL_LOGGING_ENABLED diff --git a/libraries/AP_Logger/LogFile.cpp b/libraries/AP_Logger/LogFile.cpp index d98921775ec..4dee365e148 100644 --- a/libraries/AP_Logger/LogFile.cpp +++ b/libraries/AP_Logger/LogFile.cpp @@ -339,13 +339,37 @@ bool AP_Logger_Backend::Write_EntireMission() // Write a text message to the log bool AP_Logger_Backend::Write_Message(const char *message) { - struct log_Message pkt{ - LOG_PACKET_HEADER_INIT(LOG_MESSAGE_MSG), + // i==0 here means we log an empty string if it is passed in: + const uint8_t id = AP::logger().get_MSG_id(); // there is a race condition on this ID; if a thread logs a message at the same time as the main thread then we can re-use this + + uint8_t chunk_seq = 0; + for (uint8_t i=0; i == 0 || i