Skip to content

Commit 18e06c4

Browse files
committed
fix log upload
1 parent 14051a5 commit 18e06c4

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/MicroOcpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1868,7 +1868,7 @@ MO_FilesystemAdapter *mo_getFilesystem2(MO_Context *ctx) {
18681868
}
18691869

18701870
#if MO_ENABLE_MBEDTLS
1871-
void mo_setFtpConfig(MO_Context *ctx, MO_FTPConfig ftpConfig) {
1871+
void mo_setFtpConfig2(MO_Context *ctx, MO_FTPConfig ftpConfig) {
18721872
if (!ctx) {
18731873
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
18741874
return;

src/MicroOcpp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ MO_FilesystemAdapter *mo_getFilesystem2(MO_Context *ctx);
473473
#if MO_ENABLE_MBEDTLS
474474
//Set FTP security parameters (e.g. client cert). See "FtpMbedTLS.h" for all options
475475
//To use a custom FTP client, subclass `FtpClient` (see "Ftp.h") and pass to C++ `Context` object
476-
void mo_setFtpConfig(MO_Context *ctx, MO_FTPConfig ftpConfig);
476+
void mo_setFtpConfig2(MO_Context *ctx, MO_FTPConfig ftpConfig);
477477

478478
#if MO_ENABLE_DIAGNOSTICS
479479
//Provide MO with diagnostics data for the "GetDiagnostics" operation. Should contain human-readable text which

src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ bool DiagnosticsService::requestDiagnosticsUpload(const char *location, unsigned
347347
}
348348
#endif //MO_ENABLE_V16
349349

350-
MO_GetLogStatus DiagnosticsService::getLog(MO_LogType type, int requestId, int retries, unsigned int retryInterval, const char *remoteLocation, Timestamp oldestTimestamp, Timestamp latestTimestamp, char filenameOut[MO_GETLOG_FNAME_SIZE]) {
350+
MO_GetLogStatus DiagnosticsService::getLog(MO_LogType type, int requestId, int retries, unsigned int retryInterval, const char *location, Timestamp oldestTimestamp, Timestamp latestTimestamp, char filenameOut[MO_GETLOG_FNAME_SIZE]) {
351351

352352
if (runCustomUpload || this->retries > 0) {
353353
MO_DBG_INFO("upload still running");
@@ -405,13 +405,21 @@ MO_GetLogStatus DiagnosticsService::getLog(MO_LogType type, int requestId, int r
405405

406406
MO_FREE(this->location);
407407
this->location = nullptr;
408-
size_t locationSize = strlen(location);
408+
size_t locationSize = strlen(location) + 1;
409409
this->location = static_cast<char*>(MO_MALLOC(getMemoryTag(), locationSize));
410410
if (!this->location) {
411411
MO_DBG_ERR("OOM");
412412
goto fail;
413413
}
414414

415+
{
416+
int ret = snprintf(this->location, locationSize, "%s", location);
417+
if (ret < 0 || (size_t)ret >= locationSize) {
418+
MO_DBG_ERR("snprintf: %i", ret);
419+
goto fail;
420+
}
421+
}
422+
415423
MO_FREE(this->filename);
416424
this->filename = nullptr;
417425

@@ -636,6 +644,7 @@ bool DiagnosticsService::uploadDiagnostics() {
636644
}
637645

638646
diagPreambleLen += (size_t)ret;
647+
ret = 0;
639648

640649
#if MO_ENABLE_V16
641650
if (ocppVersion == MO_OCPP_V16) {
@@ -654,8 +663,6 @@ bool DiagnosticsService::uploadDiagnostics() {
654663
auto availSvcEvse1 = availSvc ? availSvc->getEvse(1) : nullptr;
655664
auto availSvcEvse2 = availSvc ? availSvc->getEvse(2) : nullptr;
656665

657-
ret = 0;
658-
659666
if (ret >= 0 && (size_t)ret + diagPostambleLen < MO_DIAG_POSTAMBLE_SIZE) {
660667
diagPostambleLen += (size_t)ret;
661668
ret = snprintf(diagPostamble + diagPostambleLen, MO_DIAG_POSTAMBLE_SIZE - diagPostambleLen,
@@ -923,7 +930,6 @@ bool DiagnosticsService::startFtpUpload() {
923930

924931
memcpy(buf + written, fileHeading, (size_t)writeLen);
925932
written += (size_t)writeLen;
926-
filesystem->close(file);
927933
}
928934

929935
filesystem->seek(file, diagFilesBackTransferred);

src/MicroOcpp/Operations/GetLog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::unique_ptr<JsonDoc> GetLog::createConf(){
7070
auto doc = makeJsonDoc(getMemoryTag(), JSON_OBJECT_SIZE(2));
7171
JsonObject payload = doc->to<JsonObject>();
7272
payload["status"] = mo_serializeGetLogStatus(status);
73-
payload["fileName"] = (const char*)filename; //force zero-copy
73+
payload["filename"] = (const char*)filename; //force zero-copy
7474
return doc;
7575
}
7676

0 commit comments

Comments
 (0)