Bugfix in firmware partial sending

This commit is contained in:
Martin Bauer 2019-09-08 20:28:27 +02:00
parent fb5c8361a7
commit 5577490693
7 changed files with 38 additions and 13 deletions

7
commands.readme Normal file
View File

@ -0,0 +1,7 @@
Test locally
platformio test -v -e native
Device:
platformio device monitor
platformio run -t upload

View File

@ -52,6 +52,9 @@ public:
assert(startIdx == lastIdx, "Not all data was sent");
}
uint32_t getStartTime() const {
return currentChunk->getStartTime();
}
private:
void rotate() {
if( otherChunkFilled() )

View File

@ -200,12 +200,19 @@ public:
sentBytes_ += sizeof(T) * length;
return;
} 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 ) {
sendingFinished_ = true;
return;
} else {
encoder_.sendArrayPartialContents(data + elementsToSkip, elementsToSend);
sentBytes_ += sizeof(T) * elementsToSend;
if( elementsRemaining > elementsToSend ) {
sendingFinished_ = true;
}
}
}
}

View File

@ -20,7 +20,7 @@ lib_deps =
AsyncTCP
NTPClient
;[env:native]
;platform = native
;test_ignore = test_embedded
;build_flags = -g
[env:native]
platform = native
test_ignore = test_embedded
build_flags = -g

View File

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

View File

@ -113,16 +113,22 @@ void httpSetup(SessionManager<Session_T> * sessionManager)
auto totalSize = encoderToDetermineSize.getContentLength();
Serial.print("Sending started of total size ");
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(maxLen);
Serial.print(" index ");
Serial.println("index");
Serial.println(index);
CopyWriter copyWriter(buffer);
ChunkedStreamingMsgPackEncoder<CopyWriter> encoder(&copyWriter, index, index + maxLen);
sessionManager->getSession().serialize(encoder, startIdx);
Serial.print("Bytes sent ");
Serial.println(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);

View File

@ -147,11 +147,11 @@ void testSession() {
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;
const uint32_t startTime = 194842;
const uint_t fillSize = SESSION_SIZE * 4 + 7;
const uint_t fillSize = 4937 + 81;
MockSession session;
session.init(startTime);
@ -167,7 +167,8 @@ void testPartialSessionSerialization() {
session.serialize(encoder, 0);
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;
data.clear();
for(auto & split : splits) {
@ -175,6 +176,7 @@ void testPartialSessionSerialization() {
session.serialize(encoder, 0);
written = encoder.sentBytes();
}
TEST_ASSERT(written == totalSize);
uint32_t readStartTime=0;
uint32_t readStartIndex=0;
@ -189,11 +191,11 @@ void testPartialSessionSerialization() {
void allTests()
{
UNITY_BEGIN();
RUN_TEST(testPartialSessionSerialization);
RUN_TEST(testSessionChunkAdd);
RUN_TEST(testSessionChunkGetterSetter);
RUN_TEST(testSessionChunkSerialization);
RUN_TEST(testSession);
RUN_TEST(testPartialSessionSerialization);
UNITY_END();
}