Single JSON buffer.

This commit is contained in:
Blaž Kristan
2021-11-03 14:52:22 +01:00
parent f66fcfbe6d
commit bd521f858e
14 changed files with 158 additions and 54 deletions

View File

@@ -43,18 +43,25 @@ void handleSerial()
}
else if (next == '{') { //JSON API
bool verboseResponse = false;
while (jsonBufferLock) delay(1);
jsonBufferLock = true;
doc.clear();
{
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
//DynamicJsonDocument doc(JSON_BUFFER_SIZE);
Serial.setTimeout(100);
DeserializationError error = deserializeJson(doc, Serial);
if (error) return;
if (error) {
jsonBufferLock = false;
return;
}
fileDoc = &doc;
verboseResponse = deserializeState(doc.as<JsonObject>());
fileDoc = nullptr;
}
//only send response if TX pin is unused for other purposes
if (verboseResponse && !pinManager.isPinAllocated(1)) {
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
//DynamicJsonDocument doc(JSON_BUFFER_SIZE);
doc.clear();
JsonObject state = doc.createNestedObject("state");
serializeState(state);
JsonObject info = doc.createNestedObject("info");
@@ -62,6 +69,7 @@ void handleSerial()
serializeJson(doc, Serial);
}
jsonBufferLock = false;
}
break;
case AdaState::Header_d: