From 608d6d0a5f1a3d935db83d2b1a9ddcc6b360b714 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Tue, 2 Aug 2016 15:08:07 +1000 Subject: [PATCH] DataFlash: implement a printf-like Log_Write_MessageF method --- libraries/DataFlash/DataFlash.cpp | 14 ++++++++++++++ libraries/DataFlash/DataFlash.h | 1 + 2 files changed, 15 insertions(+) diff --git a/libraries/DataFlash/DataFlash.cpp b/libraries/DataFlash/DataFlash.cpp index d4084cca7e..70040b4959 100644 --- a/libraries/DataFlash/DataFlash.cpp +++ b/libraries/DataFlash/DataFlash.cpp @@ -7,6 +7,8 @@ DataFlash_Class *DataFlash_Class::_instance; +extern const AP_HAL::HAL& hal; + const AP_Param::GroupInfo DataFlash_Class::var_info[] = { // @Param: _BACKEND_TYPE // @DisplayName: DataFlash Backend Storage type @@ -251,6 +253,18 @@ bool DataFlash_Class::logging_failed() const return backends[0]->logging_failed(); } +void DataFlash_Class::Log_Write_MessageF(const char *fmt, ...) +{ + char msg[64] {}; + + va_list ap; + va_start(ap, fmt); + hal.util->vsnprintf(msg, sizeof(msg), fmt, ap); + va_end(ap); + + Log_Write_Message(msg); +} + #define FOR_EACH_BACKEND(methodcall) \ do { \ for (uint8_t i=0; i<_next_backend; i++) { \ diff --git a/libraries/DataFlash/DataFlash.h b/libraries/DataFlash/DataFlash.h index 27cbc3a4bc..2bc7fbe1e4 100644 --- a/libraries/DataFlash/DataFlash.h +++ b/libraries/DataFlash/DataFlash.h @@ -129,6 +129,7 @@ public: bool Log_Write_MavCmd(uint16_t cmd_total, const mavlink_mission_item_t& mav_cmd); void Log_Write_Radio(const mavlink_radio_t &packet); void Log_Write_Message(const char *message); + void Log_Write_MessageF(const char *fmt, ...); void Log_Write_CameraInfo(enum LogMessages msg, const AP_AHRS &ahrs, const AP_GPS &gps, const Location ¤t_loc); void Log_Write_Camera(const AP_AHRS &ahrs, const AP_GPS &gps, const Location ¤t_loc); void Log_Write_Trigger(const AP_AHRS &ahrs, const AP_GPS &gps, const Location ¤t_loc);