From 8f1471c137e13dca55aa5ca0f016223ce0621f01 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 17 Sep 2015 20:58:35 +1000 Subject: [PATCH] DataFlash: leave room in buffer for non-startup messages --- libraries/DataFlash/DataFlash_File.cpp | 20 ++++++++++++++++---- libraries/DataFlash/DataFlash_File.h | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libraries/DataFlash/DataFlash_File.cpp b/libraries/DataFlash/DataFlash_File.cpp index 3679d56e33..24d50a08d7 100644 --- a/libraries/DataFlash/DataFlash_File.cpp +++ b/libraries/DataFlash/DataFlash_File.cpp @@ -354,10 +354,22 @@ bool DataFlash_File::WritePrioritisedBlock(const void *pBuffer, uint16_t size, b uint16_t _head; uint16_t space = BUF_SPACE(_writebuf); - // we reserve some amount of space for critical messages: - if (!is_critical && space < critical_message_reserved_space()) { - _dropped++; - return false; + if (_writing_startup_messages && + _front._startup_messagewriter.fmt_done()) { + // the state machine has called us, and it has finished + // writing format messages out. It can always get back to us + // with more messages later, so let's leave room for other + // things: + if (space < non_messagewriter_message_reserved_space()) { + // this message isn't dropped, it will be sent again... + return false; + } + } else { + // we reserve some amount of space for critical messages: + if (!is_critical && space < critical_message_reserved_space()) { + _dropped++; + return false; + } } // if no room for entire message - drop it: diff --git a/libraries/DataFlash/DataFlash_File.h b/libraries/DataFlash/DataFlash_File.h index 74fea27dcb..4e8f49a049 100644 --- a/libraries/DataFlash/DataFlash_File.h +++ b/libraries/DataFlash/DataFlash_File.h @@ -115,6 +115,10 @@ private: // possibly make this a proportional to buffer size? return 1024; }; + uint16_t non_messagewriter_message_reserved_space() const { + // possibly make this a proportional to buffer size? + return 1024; + }; #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN // performance counters