Bugfix: sending empty session
This commit is contained in:
parent
2418fde01e
commit
d0ba98f12e
|
@ -245,7 +245,7 @@ private:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( sentBytes_ + sizeRequired < maxBytes_ ) {
|
if( sentBytes_ + sizeRequired <= maxBytes_ ) {
|
||||||
sendFunction();
|
sendFunction();
|
||||||
sentBytes_ += sizeRequired;
|
sentBytes_ += sizeRequired;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
Run tests:
|
||||||
|
pio test -v -e native
|
||||||
|
|
||||||
|
Compile and upload:
|
||||||
|
pio run -e d1 -t upload
|
|
@ -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
|
|
|
@ -34,18 +34,22 @@ public:
|
||||||
void begin() {
|
void begin() {
|
||||||
scale.begin(CONFIG_SCALE_DOUT_PIN, CONFIG_SCALE_SCK_PIN);
|
scale.begin(CONFIG_SCALE_DOUT_PIN, CONFIG_SCALE_SCK_PIN);
|
||||||
scale.tare( CONFIG_TARE_AVG_COUNT );
|
scale.tare( CONFIG_TARE_AVG_COUNT );
|
||||||
|
|
||||||
session.init( timeClient.getEpochTime() );
|
session.init( timeClient.getEpochTime() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void startMeasurements() {
|
void startMeasurements() {
|
||||||
measuring_ = true;
|
measuring_ = true;
|
||||||
|
session.init( timeClient.getEpochTime() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopMeasurements() {
|
void stopMeasurements() {
|
||||||
measuring_ = false;
|
measuring_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isMeasuring() const {
|
||||||
|
return measuring_;
|
||||||
|
}
|
||||||
|
|
||||||
void iteration() {
|
void iteration() {
|
||||||
if( ! measuring_ ) {
|
if( ! measuring_ ) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "MockStorage.h"
|
#include "MockStorage.h"
|
||||||
#include <unity.h>
|
#include <unity.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
template<typename Measurement_T>
|
template<typename Measurement_T>
|
||||||
std::vector<Measurement_T> parseMessagePack(const uint8_t * data, uint32_t &startTime, uint32_t &startIndex)
|
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()
|
void allTests()
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
RUN_TEST(testPartialSessionSerializationEmptyArray);
|
||||||
RUN_TEST(testPartialSessionSerialization);
|
RUN_TEST(testPartialSessionSerialization);
|
||||||
RUN_TEST(testSessionChunkAdd);
|
RUN_TEST(testSessionChunkAdd);
|
||||||
RUN_TEST(testSessionChunkGetterSetter);
|
RUN_TEST(testSessionChunkGetterSetter);
|
||||||
|
|
Loading…
Reference in New Issue