diff --git a/firmware/.vscode/extensions.json b/firmware/.vscode/extensions.json index 0f0d740..080e70d 100644 --- a/firmware/.vscode/extensions.json +++ b/firmware/.vscode/extensions.json @@ -1,7 +1,10 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ] -} +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ], + "unwantedRecommendations": [ + "ms-vscode.cpptools-extension-pack" + ] +} diff --git a/firmware/lib/logging/Logger.cpp b/firmware/lib/logging/Logger.cpp index a8f8be3..84026b2 100644 --- a/firmware/lib/logging/Logger.cpp +++ b/firmware/lib/logging/Logger.cpp @@ -3,7 +3,7 @@ constexpr size_t LOG_SIZE = 1024 * 1024 * 2; -static Logger *theLogger = nullptr; +static Logger * theLogger = nullptr; Logger *Logger::getInstance() { diff --git a/firmware/lib/logging/Logger.h b/firmware/lib/logging/Logger.h index b17a8ad..dc57ce7 100644 --- a/firmware/lib/logging/Logger.h +++ b/firmware/lib/logging/Logger.h @@ -10,6 +10,7 @@ #include #include #include +#include #endif #define LOG_INFO(...) \ @@ -48,14 +49,17 @@ public: currentSize_ += sizeof(time); const auto spaceLeft = totalSize_ - currentSize_; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-security" auto charsWritten = snprintf(&data_[currentSize_], spaceLeft, formatStr, std::forward(args)...); +#pragma GCC diagnostic pop + //Serial.println(&data_[currentSize_]); - - if (charsWritten < spaceLeft) + if(charsWritten > 0) { - currentSize_ += charsWritten; + currentSize_ += charsWritten + 1; // + 1 for trailing zero return true; } else @@ -89,6 +93,9 @@ public: current_position_ += sizeof(TimeT) + strlen(message()) + 1; } + bool operator==(const iterator & o) const { return current_position_ == o.current_position_; } + bool operator!=(const iterator & o) const { return current_position_ != o.current_position_; } + private: const char * current_position_; }; diff --git a/firmware/platformio.ini b/firmware/platformio.ini index 3659787..3b95b30 100644 --- a/firmware/platformio.ini +++ b/firmware/platformio.ini @@ -40,5 +40,6 @@ board_build.embed_txtfiles = [env:native] platform = native test_ignore = test_embedded -build_flags = -g -DPLATFORM_NATIVE -build_src_filter = +<*> - \ No newline at end of file +build_flags = -g -DPLATFORM_NATIVE -std=c++17 -O0 +build_src_filter = +<*> - - - +lib_compat_mode = off \ No newline at end of file diff --git a/firmware/src/native_main.cpp b/firmware/src/native_main.cpp index 00fd3c1..a60a8d2 100644 --- a/firmware/src/native_main.cpp +++ b/firmware/src/native_main.cpp @@ -1,5 +1,23 @@ #include "Logger.h" +#include +#include +#include int main() -{} \ No newline at end of file +{ + Logger::getInstance()->init(); + auto logger = Logger::getInstance(); + using namespace std::chrono_literals; + + LOG_INFO("Message1"); + LOG_INFO("Message %d", 5); + std::this_thread::sleep_for(2000ms); + LOG_INFO("Message %s", "3"); + + for(auto it = logger->begin(); it != logger->end(); ++it) + { + std::cout << it.time_millis() << ": " << it.message() << std::endl; + } + return 0; +} \ No newline at end of file diff --git a/firmware/test/test_common/sessiontest.cpp b/firmware/test/test_common/sessiontest.cpp index 6ea066e..81eb67c 100644 --- a/firmware/test/test_common/sessiontest.cpp +++ b/firmware/test/test_common/sessiontest.cpp @@ -1,6 +1,6 @@ #include "Dtypes.h" #include "MockSerial.h" -#include "MeasurementSession.h" +#include "SimpleMeasurementSession.h" #include "MockStorage.h" #include #include @@ -120,8 +120,8 @@ void testSessionChunkSerialization() void testSession() { - const uint32_t SESSION_SIZE = 128; - typedef MeasurementSession MockSession; + const uint32_t SESSION_SIZE = 1024; + using MockSession = SimpleMeasurementSession; const uint32_t startTime = 194842; const uint_t fillSize = SESSION_SIZE * 4 + 7; @@ -149,7 +149,7 @@ void testSession() { void testPartialSessionSerialization() { const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t); - typedef MeasurementSession MockSession; + using MockSession = SimpleMeasurementSession; const uint32_t startTime = 194842; const uint_t fillSize = 4937 + 81; @@ -191,7 +191,7 @@ void testPartialSessionSerialization() { void testPartialSessionSerializationEmptyArray() { const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t); - typedef MeasurementSession MockSession; + using MockSession = SimpleMeasurementSession; const uint32_t startTime = 194842; const uint_t fillSize = 4937 + 81;