Bugfix in firmware partial sending
This commit is contained in:
parent
fb5c8361a7
commit
5577490693
|
@ -0,0 +1,7 @@
|
||||||
|
Test locally
|
||||||
|
platformio test -v -e native
|
||||||
|
|
||||||
|
|
||||||
|
Device:
|
||||||
|
platformio device monitor
|
||||||
|
platformio run -t upload
|
|
@ -52,6 +52,9 @@ public:
|
||||||
assert(startIdx == lastIdx, "Not all data was sent");
|
assert(startIdx == lastIdx, "Not all data was sent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t getStartTime() const {
|
||||||
|
return currentChunk->getStartTime();
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
void rotate() {
|
void rotate() {
|
||||||
if( otherChunkFilled() )
|
if( otherChunkFilled() )
|
||||||
|
|
|
@ -200,12 +200,19 @@ public:
|
||||||
sentBytes_ += sizeof(T) * length;
|
sentBytes_ += sizeof(T) * length;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const uint32_t elementsToSend = length - elementsToSkip;
|
sentBytes_ += sizeof(T) * elementsToSkip;
|
||||||
|
const uint32_t elementsRemaining = length - elementsToSkip;
|
||||||
|
const uint32_t maxElementsToSend = (maxBytes_ - sentBytes_) / sizeof(T);
|
||||||
|
const uint32_t elementsToSend = min(elementsRemaining, maxElementsToSend);
|
||||||
if( elementsToSend == 0 ) {
|
if( elementsToSend == 0 ) {
|
||||||
sendingFinished_ = true;
|
sendingFinished_ = true;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
encoder_.sendArrayPartialContents(data + elementsToSkip, elementsToSend);
|
encoder_.sendArrayPartialContents(data + elementsToSkip, elementsToSend);
|
||||||
|
sentBytes_ += sizeof(T) * elementsToSend;
|
||||||
|
if( elementsRemaining > elementsToSend ) {
|
||||||
|
sendingFinished_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ lib_deps =
|
||||||
AsyncTCP
|
AsyncTCP
|
||||||
NTPClient
|
NTPClient
|
||||||
|
|
||||||
;[env:native]
|
[env:native]
|
||||||
;platform = native
|
platform = native
|
||||||
;test_ignore = test_embedded
|
test_ignore = test_embedded
|
||||||
;build_flags = -g
|
build_flags = -g
|
|
@ -8,4 +8,4 @@ const int CONFIG_VALUE_DIVIDER = 128; // uint32 measurements are divid
|
||||||
const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements
|
const int CONFIG_MEASURE_DELAY = 100; // interval in ms between measurements
|
||||||
|
|
||||||
|
|
||||||
const uint32_t CONFIG_SESSION_CHUNK_SIZE = 1024*8 - 3 * sizeof(uint32_t);
|
const uint32_t CONFIG_SESSION_CHUNK_SIZE = 1024*8 - 16 * sizeof(uint32_t);
|
||||||
|
|
|
@ -113,16 +113,22 @@ void httpSetup(SessionManager<Session_T> * sessionManager)
|
||||||
auto totalSize = encoderToDetermineSize.getContentLength();
|
auto totalSize = encoderToDetermineSize.getContentLength();
|
||||||
Serial.print("Sending started of total size ");
|
Serial.print("Sending started of total size ");
|
||||||
Serial.println(totalSize);
|
Serial.println(totalSize);
|
||||||
req->send("application/x-msgpack", totalSize, [=](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
|
auto callback = [=](uint8_t *buffer, size_t maxLen, size_t index) -> size_t {
|
||||||
Serial.print("Partial send maxLen ");
|
Serial.print("Partial send maxLen ");
|
||||||
Serial.print(maxLen);
|
Serial.print(maxLen);
|
||||||
Serial.print(" index ");
|
Serial.print(" index ");
|
||||||
Serial.println("index");
|
Serial.println(index);
|
||||||
CopyWriter copyWriter(buffer);
|
CopyWriter copyWriter(buffer);
|
||||||
ChunkedStreamingMsgPackEncoder<CopyWriter> encoder(©Writer, index, index + maxLen);
|
ChunkedStreamingMsgPackEncoder<CopyWriter> encoder(©Writer, index, index + maxLen);
|
||||||
sessionManager->getSession().serialize(encoder, startIdx);
|
sessionManager->getSession().serialize(encoder, startIdx);
|
||||||
|
Serial.print("Bytes sent ");
|
||||||
|
Serial.println(encoder.sentBytes() - index);
|
||||||
return encoder.sentBytes() - index;
|
return encoder.sentBytes() - index;
|
||||||
});
|
};
|
||||||
|
AsyncWebServerResponse *response = req->beginResponse("application/x-msgpack", totalSize, callback);
|
||||||
|
auto sessionId = sessionManager->getSession().getStartTime();
|
||||||
|
response->addHeader("content-disposition", "attachment; filename=\"" + String(sessionId) + ".st\"");
|
||||||
|
req->send(response);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.onNotFound(onNotFound);
|
server.onNotFound(onNotFound);
|
||||||
|
|
|
@ -147,11 +147,11 @@ void testSession() {
|
||||||
|
|
||||||
|
|
||||||
void testPartialSessionSerialization() {
|
void testPartialSessionSerialization() {
|
||||||
const uint32_t SESSION_SIZE = 128;
|
const uint32_t SESSION_SIZE = 1024*8 - 16 * sizeof(uint32_t);
|
||||||
typedef MeasurementSession<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
|
typedef MeasurementSession<uint16_t, MockStorageReader, MockStorageWriter, SESSION_SIZE> MockSession;
|
||||||
|
|
||||||
const uint32_t startTime = 194842;
|
const uint32_t startTime = 194842;
|
||||||
const uint_t fillSize = SESSION_SIZE * 4 + 7;
|
const uint_t fillSize = 4937 + 81;
|
||||||
|
|
||||||
MockSession session;
|
MockSession session;
|
||||||
session.init(startTime);
|
session.init(startTime);
|
||||||
|
@ -167,7 +167,8 @@ void testPartialSessionSerialization() {
|
||||||
session.serialize(encoder, 0);
|
session.serialize(encoder, 0);
|
||||||
auto totalSize = encoder.getContentLength();
|
auto totalSize = encoder.getContentLength();
|
||||||
|
|
||||||
std::vector<uint32_t> splits = {16, 32, 128, 256, 512, 721, 1024, totalSize};
|
std::vector<uint32_t> splits = {953, totalSize};
|
||||||
|
//std::vector<uint32_t> splits = {totalSize};
|
||||||
uint32_t written = 0;
|
uint32_t written = 0;
|
||||||
data.clear();
|
data.clear();
|
||||||
for(auto & split : splits) {
|
for(auto & split : splits) {
|
||||||
|
@ -175,6 +176,7 @@ void testPartialSessionSerialization() {
|
||||||
session.serialize(encoder, 0);
|
session.serialize(encoder, 0);
|
||||||
written = encoder.sentBytes();
|
written = encoder.sentBytes();
|
||||||
}
|
}
|
||||||
|
TEST_ASSERT(written == totalSize);
|
||||||
|
|
||||||
uint32_t readStartTime=0;
|
uint32_t readStartTime=0;
|
||||||
uint32_t readStartIndex=0;
|
uint32_t readStartIndex=0;
|
||||||
|
@ -189,11 +191,11 @@ void testPartialSessionSerialization() {
|
||||||
void allTests()
|
void allTests()
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
|
RUN_TEST(testPartialSessionSerialization);
|
||||||
RUN_TEST(testSessionChunkAdd);
|
RUN_TEST(testSessionChunkAdd);
|
||||||
RUN_TEST(testSessionChunkGetterSetter);
|
RUN_TEST(testSessionChunkGetterSetter);
|
||||||
RUN_TEST(testSessionChunkSerialization);
|
RUN_TEST(testSessionChunkSerialization);
|
||||||
RUN_TEST(testSession);
|
RUN_TEST(testSession);
|
||||||
RUN_TEST(testPartialSessionSerialization);
|
|
||||||
UNITY_END();
|
UNITY_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue