Bugfix: sending empty session

This commit is contained in:
Martin Bauer 2019-09-17 20:23:34 +02:00
parent 2418fde01e
commit d0ba98f12e
5 changed files with 32 additions and 11 deletions

View File

@ -245,7 +245,7 @@ private:
return;
}
if( sentBytes_ + sizeRequired < maxBytes_ ) {
if( sentBytes_ + sizeRequired <= maxBytes_ ) {
sendFunction();
sentBytes_ += sizeRequired;
} else {

6
readme Normal file
View File

@ -0,0 +1,6 @@
Run tests:
pio test -v -e native
Compile and upload:
pio run -e d1 -t upload

View File

@ -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

View File

@ -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;

View File

@ -4,6 +4,7 @@
#include "MockStorage.h"
#include <unity.h>
#include <vector>
#include <iostream>
template<typename Measurement_T>
std::vector<Measurement_T> 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<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
const uint32_t startTime = 194842;
const uint_t fillSize = 4937 + 81;
std::vector<uint8_t> data;
VectorAdaptor adaptor( &data );
MockSession session;
session.init(startTime);
ChunkedStreamingMsgPackEncoder<VectorAdaptor> 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);