diff --git a/libraries/AP_CANManager/AP_CANManager.cpp b/libraries/AP_CANManager/AP_CANManager.cpp index 878a67d07f..bbd078bea3 100644 --- a/libraries/AP_CANManager/AP_CANManager.cpp +++ b/libraries/AP_CANManager/AP_CANManager.cpp @@ -39,6 +39,8 @@ #include #endif +#include + #define LOG_TAG "CANMGR" #define LOG_BUFFER_SIZE 1024 @@ -373,15 +375,13 @@ void AP_CANManager::log_text(AP_CANManager::LogLevel loglevel, const char *tag, } // log retrieve method used by file sys method to report can log -uint32_t AP_CANManager::log_retrieve(char* data, uint32_t max_size) const +void AP_CANManager::log_retrieve(ExpandingString &str) const { if (_log_buf == nullptr) { gcs().send_text(MAV_SEVERITY_ERROR, "Log buffer not available"); - return 0; + return; } - uint32_t read_len = MIN(max_size, _log_pos); - memcpy(data, _log_buf, read_len); - return read_len; + str.append(_log_buf, _log_pos); } AP_CANManager& AP::can() diff --git a/libraries/AP_CANManager/AP_CANManager.h b/libraries/AP_CANManager/AP_CANManager.h index 994536d065..ad0ea040c4 100644 --- a/libraries/AP_CANManager/AP_CANManager.h +++ b/libraries/AP_CANManager/AP_CANManager.h @@ -90,7 +90,7 @@ public: // Method to log status and debug information for review while debugging void log_text(AP_CANManager::LogLevel loglevel, const char *tag, const char *fmt, ...); - uint32_t log_retrieve(char* data, uint32_t max_size) const; + void log_retrieve(ExpandingString &str) const; // return driver type index i Driver_Type get_driver_type(uint8_t i) const diff --git a/libraries/AP_CANManager/AP_SLCANIface.cpp b/libraries/AP_CANManager/AP_SLCANIface.cpp index 08801fd7ce..785b7a7ff7 100644 --- a/libraries/AP_CANManager/AP_SLCANIface.cpp +++ b/libraries/AP_CANManager/AP_SLCANIface.cpp @@ -536,13 +536,12 @@ uint32_t SLCAN::CANIface::getErrorCount() const return 0; } -uint32_t SLCAN::CANIface::get_stats(char* data, uint32_t max_size) +void SLCAN::CANIface::get_stats(ExpandingString &str) { // When in passthrough mode methods is handled through can iface if (_can_iface) { - return _can_iface->get_stats(data, max_size); + _can_iface->get_stats(str); } - return 0; } bool SLCAN::CANIface::is_busoff() const diff --git a/libraries/AP_CANManager/AP_SLCANIface.h b/libraries/AP_CANManager/AP_SLCANIface.h index 4f12bb6569..d10266b49b 100644 --- a/libraries/AP_CANManager/AP_SLCANIface.h +++ b/libraries/AP_CANManager/AP_SLCANIface.h @@ -112,7 +112,7 @@ public: bool set_event_handle(AP_HAL::EventHandle* evt_handle) override; uint16_t getNumFilters() const override; uint32_t getErrorCount() const override; - uint32_t get_stats(char* data, uint32_t max_size) override; + void get_stats(ExpandingString &) override; bool is_busoff() const override; bool configureFilters(const CanFilterConfig* filter_configs, uint16_t num_configs) override; void flush_tx() override;