From 5bf2fb186c2598fe27ad481639f0c1ad83a2ca56 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 23 Apr 2018 14:35:29 +1000 Subject: [PATCH] DataFlash: parameterise dataflash-over-mavlink cachesize --- libraries/DataFlash/DataFlash.cpp | 7 +++++++ libraries/DataFlash/DataFlash.h | 1 + libraries/DataFlash/DataFlash_MAVLink.cpp | 2 +- libraries/DataFlash/DataFlash_MAVLink.h | 8 +++++--- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/DataFlash/DataFlash.cpp b/libraries/DataFlash/DataFlash.cpp index 7e0dedcf20..e409308e64 100644 --- a/libraries/DataFlash/DataFlash.cpp +++ b/libraries/DataFlash/DataFlash.cpp @@ -50,6 +50,13 @@ const AP_Param::GroupInfo DataFlash_Class::var_info[] = { // @User: Standard AP_GROUPINFO("_FILE_DSRMROT", 4, DataFlash_Class, _params.file_disarm_rot, 0), + // @Param: _MAV_BUFSIZE + // @DisplayName: Maximum DataFlash MAVLink Backend buffer size + // @Description: Maximum amount of memory to allocate to DataFlash-over-mavlink + // @User: Advanced + // @Units: kB + AP_GROUPINFO("_MAV_BUFSIZE", 5, DataFlash_Class, _params.mav_bufsize, 8), + AP_GROUPEND }; diff --git a/libraries/DataFlash/DataFlash.h b/libraries/DataFlash/DataFlash.h index ccd9e705af..1e84305726 100644 --- a/libraries/DataFlash/DataFlash.h +++ b/libraries/DataFlash/DataFlash.h @@ -198,6 +198,7 @@ public: AP_Int8 file_disarm_rot; AP_Int8 log_disarmed; AP_Int8 log_replay; + AP_Int8 mav_bufsize; // in kilobytes } _params; const struct LogStructure *structure(uint16_t num) const; diff --git a/libraries/DataFlash/DataFlash_MAVLink.cpp b/libraries/DataFlash/DataFlash_MAVLink.cpp index 46dfc8fcc7..a068677292 100644 --- a/libraries/DataFlash/DataFlash_MAVLink.cpp +++ b/libraries/DataFlash/DataFlash_MAVLink.cpp @@ -35,7 +35,7 @@ void DataFlash_MAVLink::Init() _blocks = nullptr; while (_blockcount >= 8) { // 8 is a *magic* number - _blocks = (struct dm_block *) calloc(_blockcount, sizeof(_blocks[0])); + _blocks = (struct dm_block *) calloc(_blockcount, sizeof(struct dm_block)); if (_blocks != nullptr) { break; } diff --git a/libraries/DataFlash/DataFlash_MAVLink.h b/libraries/DataFlash/DataFlash_MAVLink.h index f00184458e..ee8f39cae6 100644 --- a/libraries/DataFlash/DataFlash_MAVLink.h +++ b/libraries/DataFlash/DataFlash_MAVLink.h @@ -23,10 +23,12 @@ public: // constructor DataFlash_MAVLink(DataFlash_Class &front, DFMessageWriter_DFLogStart *writer) : DataFlash_Backend(front, writer), - _max_blocks_per_send_blocks(8), - _blockcount(32) // this may get reduced in Init if allocation fails + _max_blocks_per_send_blocks(8) ,_perf_packing(hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, "DM_packing")) - { } + { + _blockcount = 1024*((uint8_t)_front._params.mav_bufsize) / sizeof(struct dm_block); + // ::fprintf(stderr, "DM: Using %u blocks\n", _blockcount); + } // initialisation void Init() override;