Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-12-13 22:47:06 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-12-13 22:47:06 +0300
commitbdbe10598755cb4e68623bdf68bf34bf98322423 (patch)
tree984bce47450607687d67c8c940a42b4cf2a01ec4 /src/RepRap.cpp
parentc42fc40d45958489e1d84e5e88d716f98645b4e0 (diff)
JSON encoding is now done by vuprintf
Diffstat (limited to 'src/RepRap.cpp')
-rw-r--r--src/RepRap.cpp110
1 files changed, 33 insertions, 77 deletions
diff --git a/src/RepRap.cpp b/src/RepRap.cpp
index d9206e21..2dd00370 100644
--- a/src/RepRap.cpp
+++ b/src/RepRap.cpp
@@ -1296,8 +1296,7 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con
// Report message
if (sendMessage)
{
- response->cat("\"message\":");
- response->EncodeString(message, false);
+ response->catf("\"message\":\"%.s\"", message.c_str());
if (mbox.active)
{
response->cat(',');
@@ -1307,11 +1306,8 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con
// Report message box
if (mbox.active)
{
- response->cat("\"msgBox\":{\"msg\":");
- response->EncodeString(mbox.message, false);
- response->cat(",\"title\":");
- response->EncodeString(mbox.title, false);
- response->catf(",\"mode\":%d,\"seq\":%" PRIu32 ",\"timeout\":%.1f,\"controls\":%u}", mbox.mode, mbox.seq, (double)timeLeft, (unsigned int)mbox.controls.GetRaw());
+ response->catf("\"msgBox\":{\"msg\":\"%.s\",\"title\":\"%.s\",\"mode\":%d,\"seq\":%" PRIu32 ",\"timeout\":%.1f,\"controls\":%u}",
+ mbox.message.c_str(), mbox.title.c_str(), mbox.mode, mbox.seq, (double)timeLeft, (unsigned int)mbox.controls.GetRaw());
}
response->cat('}');
}
@@ -1468,11 +1464,9 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con
response->cat(',');
}
first = false;
- response->cat("{\"name\":");
- response->EncodeString(nm, false, true);
float temp;
(void)sensor->GetLatestTemperature(temp);
- response->catf(",\"temp\":%.1f}", HideNan(temp));
+ response->catf("{\"name\":\"%.s\",\"temp\":%.1f}", nm, HideNan(temp));
}
nextSensorNumber = sensor->GetSensorNumber() + 1;
}
@@ -1598,25 +1592,17 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con
response->catf(",\"volumes\":%u,\"mountedVolumes\":%u", NumSdCards, mountedCards);
#endif
- // Machine mode,
- const char *machineMode = gCodes->GetMachineModeString();
- response->cat(",\"mode\":");
- response->EncodeString(machineMode, false);
+ // Machine mode and name
+ response->catf(",\"mode\":\"%.s\",\"name\":\"%.s\"", gCodes->GetMachineModeString(), myName.c_str());
- // Machine name
- response->cat(",\"name\":");
- response->EncodeString(myName, false);
-
- /* Probe */
+ // Probe trigger threshold, trigger height, type
{
const auto zp = platform->GetZProbeOrDefault(0);
-
- // Trigger threshold, trigger height, type
response->catf(",\"probe\":{\"threshold\":%d,\"height\":%.2f,\"type\":%u}",
zp->GetAdcValue(), (double)zp->GetConfiguredTriggerHeight(), (unsigned int)zp->GetProbeType());
}
- /* Tool Mapping */
+ // Tool Mapping
{
response->cat(",\"tools\":[");
ReadLocker lock(toolListLock);
@@ -1626,12 +1612,10 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con
response->catf("{\"number\":%d,", tool->Number());
// Name
- const char *toolName = tool->GetName();
+ const char * const toolName = tool->GetName();
if (toolName[0] != 0)
{
- response->cat("\"name\":");
- response->EncodeString(toolName, false);
- response->cat(',');
+ response->catf("\"name\":\"%.s\",", toolName);
}
// Heaters
@@ -1673,9 +1657,7 @@ OutputBuffer *RepRap::GetStatusResponse(uint8_t type, ResponseSource source) con
// Filament (if any)
if (tool->GetFilament() != nullptr)
{
- const char *filamentName = tool->GetFilament()->GetName();
- response->catf(",\"filament\":");
- response->EncodeString(filamentName, false);
+ response->catf(",\"filament\":\"%.s\"", tool->GetFilament()->GetName());
}
// Offsets
@@ -1784,46 +1766,39 @@ OutputBuffer *RepRap::GetConfigResponse() noexcept
AppendIntArray(response, "currents", MaxAxesPlusExtruders, [this](size_t drive) noexcept { return (int)platform->GetMotorCurrent(drive, 906); });
// Firmware details
- response->catf(",\"firmwareElectronics\":\"%s", platform->GetElectronicsString());
+ response->catf(",\"firmwareElectronics\":\"%.s", platform->GetElectronicsString());
#ifdef DUET_NG
const char* expansionName = DuetExpansion::GetExpansionBoardName();
if (expansionName != nullptr)
{
- response->catf(" + %s", expansionName);
+ response->catf(" + %.s", expansionName);
}
const char* additionalExpansionName = DuetExpansion::GetAdditionalExpansionBoardName();
if (additionalExpansionName != nullptr)
{
- response->catf(" + %s", additionalExpansionName);
+ response->catf(" + %.s", additionalExpansionName);
}
#endif
- response->cat("\",\"firmwareName\":");
- response->EncodeString(FIRMWARE_NAME, false);
+ response->catf("\",\"firmwareName\":\"%.s\",\"firmwareVersion\":\"%.s\"", FIRMWARE_NAME, VERSION);
#ifdef BOARD_SHORT_NAME
- response->cat(",\"boardName\":");
- response->EncodeString(BOARD_SHORT_NAME, false);
+ response->catf(",\"boardName\":\"%.s\"", BOARD_SHORT_NAME);
#endif
- response->cat(",\"firmwareVersion\":");
- response->EncodeString(VERSION, false);
#if HAS_WIFI_NETWORKING
// If we have WiFi networking, send the WiFi module firmware version
# ifdef DUET_NG
if (platform->IsDuetWiFi())
- {
# endif
- response->catf(",\"dwsVersion\":\"%s\"", network->GetWiFiServerVersion());
-# ifdef DUET_NG
+ {
+ response->catf(",\"dwsVersion\":\"%.s\"", network->GetWiFiServerVersion());
}
-# endif
#endif
- response->catf(",\"firmwareDate\":\"%s\"", DATE);
+ response->catf(",\"firmwareDate\":\"%.s\"", DATE);
#if HAS_MASS_STORAGE
// System files folder
- response->catf(", \"sysdir\":");
- platform->EncodeSysDir(response);
+ response->catf(", \"sysdir\":\"%.s\"", platform->GetSysDir().Ptr());
#endif
// Motor idle parameters
@@ -1978,12 +1953,8 @@ OutputBuffer *RepRap::GetLegacyStatusResponse(uint8_t type, int seq) const noexc
if (mbox.active)
{
- response->catf(",\"msgBox.mode\":%d,\"msgBox.seq\":%" PRIu32 ",\"msgBox.timeout\":%.1f,\"msgBox.controls\":%u",
- mbox.mode, mbox.seq, (double)timeLeft, (unsigned int)mbox.controls.GetRaw());
- response->cat(",\"msgBox.msg\":");
- response->EncodeString(mbox.message, false);
- response->cat(",\"msgBox.title\":");
- response->EncodeString(mbox.title, false);
+ response->catf(",\"msgBox.mode\":%d,\"msgBox.seq\":%" PRIu32 ",\"msgBox.timeout\":%.1f,\"msgBox.controls\":%u,\"msgBox.msg\":\"%.s\",\"msgBox.title\":\"%.s\"",
+ mbox.mode, mbox.seq, (double)timeLeft, (unsigned int)mbox.controls.GetRaw(), mbox.message.c_str(), mbox.title.c_str());
}
else
{
@@ -2005,11 +1976,8 @@ OutputBuffer *RepRap::GetLegacyStatusResponse(uint8_t type, int seq) const noexc
else if (type == 3)
{
// Add the static fields
- response->catf(",\"geometry\":\"%s\",\"axes\":%u,\"totalAxes\":%u,\"axisNames\":\"%s\",\"volumes\":%u,\"numTools\":%u,\"myName\":",
- move->GetGeometryString(), numVisibleAxes, gCodes->GetTotalAxes(), gCodes->GetAxisLetters(), NumSdCards, GetNumberOfContiguousTools());
- response->EncodeString(myName, false);
- response->cat(",\"firmwareName\":");
- response->EncodeString(FIRMWARE_NAME, false);
+ response->catf(",\"geometry\":\"%s\",\"axes\":%u,\"totalAxes\":%u,\"axisNames\":\"%s\",\"volumes\":%u,\"numTools\":%u,\"myName\":\"%.s\",\"firmwareName\":\"%.s\"",
+ move->GetGeometryString(), numVisibleAxes, gCodes->GetTotalAxes(), gCodes->GetAxisLetters(), NumSdCards, GetNumberOfContiguousTools(), myName.c_str(), FIRMWARE_NAME);
}
response->cat("}\n"); // include a newline to help PanelDue resync
@@ -2029,9 +1997,7 @@ OutputBuffer *RepRap::GetFilesResponse(const char *dir, unsigned int startAt, bo
return nullptr;
}
- response->copy("{\"dir\":");
- response->EncodeString(dir, false);
- response->catf(",\"first\":%u,\"files\":[", startAt);
+ response->printf("{\"dir\":\"%.s\",\"first\":%u,\"files\":[", dir, startAt);
unsigned int err;
unsigned int nextFile = 0;
@@ -2073,7 +2039,7 @@ OutputBuffer *RepRap::GetFilesResponse(const char *dir, unsigned int startAt, bo
bytesLeft -= response->cat(',');
}
- bytesLeft -= response->EncodeString(fileInfo.fileName, false, flagsDirs && fileInfo.isDirectory);
+ bytesLeft -= response->catf((flagsDirs && fileInfo.isDirectory) ? "\"*%.s\"" : "\"%.s\"", fileInfo.fileName.c_str());
}
++filesFound;
}
@@ -2107,9 +2073,7 @@ OutputBuffer *RepRap::GetFilelistResponse(const char *dir, unsigned int startAt)
return nullptr;
}
- response->copy("{\"dir\":");
- response->EncodeString(dir, false);
- response->catf(",\"first\":%u,\"files\":[", startAt);
+ response->printf("{\"dir\":\"%.s\",\"first\":%u,\"files\":[", dir, startAt);
unsigned int err;
unsigned int nextFile = 0;
@@ -2151,10 +2115,8 @@ OutputBuffer *RepRap::GetFilelistResponse(const char *dir, unsigned int startAt)
}
// Write another file entry
- bytesLeft -= response->catf("{\"type\":\"%c\",\"name\":", fileInfo.isDirectory ? 'd' : 'f');
- bytesLeft -= response->EncodeString(fileInfo.fileName, false);
- bytesLeft -= response->catf(",\"size\":%" PRIu32, fileInfo.size);
-
+ bytesLeft -= response->catf("{\"type\":\"%c\",\"name\":\"%.s\",\"size\":%" PRIu32,
+ fileInfo.isDirectory ? 'd' : 'f', fileInfo.fileName.c_str(), fileInfo.size);
tm timeInfo;
gmtime_r(&fileInfo.lastModified, &timeInfo);
if (timeInfo.tm_year <= /*19*/80)
@@ -2267,13 +2229,10 @@ GCodeResult RepRap::GetFileInfoResponse(const char *filename, OutputBuffer *&res
if (!specificFile)
{
- response->catf(",\"printDuration\":%d,\"fileName\":", (int)printMonitor->GetPrintDuration());
- response->EncodeString(printMonitor->GetPrintingFilename(), false);
+ response->catf(",\"printDuration\":%d,\"fileName\":\"%.s\"", (int)printMonitor->GetPrintDuration(), printMonitor->GetPrintingFilename());
}
- response->cat(",\"generatedBy\":");
- response->EncodeString(info.generatedBy, false);
- response->cat("}\n");
+ response->catf(",\"generatedBy\":\"%.s\"}\n", info.generatedBy.c_str());
return GCodeResult::ok;
}
@@ -2332,7 +2291,7 @@ void RepRap::AppendStringArray(OutputBuffer *buf, const char *name, size_t numVa
{
buf->cat(',');
}
- buf->EncodeString(func(i), true);
+ buf->catf("\"%.s\"", func(i));
}
buf->cat(']');
}
@@ -2349,10 +2308,7 @@ OutputBuffer *RepRap::GetModelResponse(const char *key, const char *flags) const
if (key == nullptr) { key = ""; }
if (flags == nullptr) { flags = ""; }
- outBuf->printf("{\"key\":");
- outBuf->EncodeString(key, false);
- outBuf->catf(",\"flags\":");
- outBuf->EncodeString(flags, false);
+ outBuf->printf("{\"key\":\"%.s\",\"flags\":\"%.s\"", key, flags);
const bool wantArrayLength = (*key == '#');
if (wantArrayLength)