diff --git a/lib/session/StreamingMsgPackEncoder.h b/lib/session/StreamingMsgPackEncoder.h index 59a7c85..b92ba0a 100644 --- a/lib/session/StreamingMsgPackEncoder.h +++ b/lib/session/StreamingMsgPackEncoder.h @@ -245,7 +245,7 @@ private: return; } - if( sentBytes_ + sizeRequired < maxBytes_ ) { + if( sentBytes_ + sizeRequired <= maxBytes_ ) { sendFunction(); sentBytes_ += sizeRequired; } else { diff --git a/readme b/readme new file mode 100644 index 0000000..9627eb8 --- /dev/null +++ b/readme @@ -0,0 +1,6 @@ + +Run tests: + pio test -v -e native + +Compile and upload: + pio run -e d1 -t upload \ No newline at end of file diff --git a/src/config.h b/src/config.h deleted file mode 100644 index 0c8d400..0000000 --- a/src/config.h +++ /dev/null @@ -1,9 +0,0 @@ - - - -// Measurement parameters -const int DELAY = 100; // interval in ms between measurements -const int SESSION_SIZE = 1024*8; // how many data points are added to the session -const byte MEASUREMENT_AVG_COUNT = 1; // averages over this many consecutive AD-converter reads -const byte TARE_AVG_COUNT = 50; // number of measurements in tare-phase (to find 0 ) -const int DIVIDER = 128; // uint32 measurements are divided by this factor, before stored in uint16_t diff --git a/src/firmware_main.cpp b/src/firmware_main.cpp index 42f8971..ba3f250 100644 --- a/src/firmware_main.cpp +++ b/src/firmware_main.cpp @@ -34,18 +34,22 @@ public: void begin() { scale.begin(CONFIG_SCALE_DOUT_PIN, CONFIG_SCALE_SCK_PIN); scale.tare( CONFIG_TARE_AVG_COUNT ); - session.init( timeClient.getEpochTime() ); } void startMeasurements() { measuring_ = true; + session.init( timeClient.getEpochTime() ); } void stopMeasurements() { measuring_ = false; } + bool isMeasuring() const { + return measuring_; + } + void iteration() { if( ! measuring_ ) { return; diff --git a/test/test_common/sessiontest.cpp b/test/test_common/sessiontest.cpp index 86f1359..bfceac3 100644 --- a/test/test_common/sessiontest.cpp +++ b/test/test_common/sessiontest.cpp @@ -4,6 +4,7 @@ #include "MockStorage.h" #include #include +#include template std::vector parseMessagePack(const uint8_t * data, uint32_t &startTime, uint32_t &startIndex) @@ -188,9 +189,28 @@ void testPartialSessionSerialization() { } } +void testPartialSessionSerializationEmptyArray() { + const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t); + typedef MeasurementSession MockSession; + + const uint32_t startTime = 194842; + const uint_t fillSize = 4937 + 81; + + std::vector data; + VectorAdaptor adaptor( &data ); + + MockSession session; + session.init(startTime); + ChunkedStreamingMsgPackEncoder encoder(&adaptor, 0, 6); + session.serialize(encoder, 0); + auto written = encoder.sentBytes(); + TEST_ASSERT(written == 6); +} + void allTests() { UNITY_BEGIN(); + RUN_TEST(testPartialSessionSerializationEmptyArray); RUN_TEST(testPartialSessionSerialization); RUN_TEST(testSessionChunkAdd); RUN_TEST(testSessionChunkGetterSetter);