Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void DiagnosticsService::loop() {
}

const auto& timestampNow = context.getModel().getClock().now();
if (retries > 0 && timestampNow >= nextTry) {
if (retries >= 0 && timestampNow >= nextTry) {

if (!uploadIssued) {
if (onUpload != nullptr) {
Expand All @@ -69,7 +69,7 @@ void DiagnosticsService::loop() {
uploadFailure = false;
} else {
MO_DBG_ERR("onUpload must be set! (see setOnUpload). Will abort");
retries = 0;
retries = -1;
uploadIssued = false;
uploadFailure = true;
}
Expand All @@ -80,7 +80,7 @@ void DiagnosticsService::loop() {
//success!
MO_DBG_DEBUG("end upload routine (by status)");
uploadIssued = false;
retries = 0;
retries = -1;
}

//check if maximum time elapsed or failed
Expand All @@ -93,7 +93,7 @@ void DiagnosticsService::loop() {
//No way to find out if failed. But maximum time has elapsed. Assume success
MO_DBG_DEBUG("end upload routine (by timer)");
uploadIssued = false;
retries = 0;
retries = -1;
} else {
//either we have UploadFailed status or (NotUploaded + timeout) here
MO_DBG_WARN("Upload timeout or failed");
Expand All @@ -108,7 +108,7 @@ void DiagnosticsService::loop() {
}
retries--;

if (retries == 0) {
if (retries == -1) {
MO_DBG_DEBUG("end upload routine (no more retry)");
uploadFailure = true;
}
Expand All @@ -119,7 +119,7 @@ void DiagnosticsService::loop() {
}

//timestamps before year 2021 will be treated as "undefined"
MicroOcpp::String DiagnosticsService::requestDiagnosticsUpload(const char *location, unsigned int retries, unsigned int retryInterval, Timestamp startTime, Timestamp stopTime) {
MicroOcpp::String DiagnosticsService::requestDiagnosticsUpload(const char *location, int retries, unsigned int retryInterval, Timestamp startTime, Timestamp stopTime) {
if (onUpload == nullptr) {
return makeString(getMemoryTag());
}
Expand Down Expand Up @@ -177,6 +177,7 @@ MicroOcpp::String DiagnosticsService::requestDiagnosticsUpload(const char *locat
nextTry = context.getModel().getClock().now();
nextTry += 5; //wait for 5s before upload
uploadIssued = false;
uploadFailure = false;

#if MO_DBG_LEVEL >= MO_DL_DEBUG
{
Expand All @@ -191,6 +192,11 @@ MicroOcpp::String DiagnosticsService::requestDiagnosticsUpload(const char *locat

DiagnosticsStatus DiagnosticsService::getDiagnosticsStatus() {
if (uploadFailure) {
if (lastReportedStatus != DiagnosticsStatus::Uploading &&
lastReportedStatus != DiagnosticsStatus::UploadFailed) {
//TC_045_2_CS Ensure Uploading is reported at least once before UploadFailed
return DiagnosticsStatus::Uploading;
}
return DiagnosticsStatus::UploadFailed;
}

Expand Down
4 changes: 2 additions & 2 deletions src/MicroOcpp/Model/Diagnostics/DiagnosticsService.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DiagnosticsService : public MemoryManaged {
Context& context;

String location;
unsigned int retries = 0;
int retries = -1;
unsigned int retryInterval = 0;
Timestamp startTime;
Timestamp stopTime;
Expand Down Expand Up @@ -68,7 +68,7 @@ class DiagnosticsService : public MemoryManaged {
//timestamps before year 2021 will be treated as "undefined"
//returns empty std::string if onUpload is missing or upload cannot be scheduled for another reason
//returns fileName of diagnostics file to be uploaded if upload has been scheduled
String requestDiagnosticsUpload(const char *location, unsigned int retries = 1, unsigned int retryInterval = 0, Timestamp startTime = Timestamp(), Timestamp stopTime = Timestamp());
String requestDiagnosticsUpload(const char *location, int retries = 1, unsigned int retryInterval = 0, Timestamp startTime = Timestamp(), Timestamp stopTime = Timestamp());

Ocpp16::DiagnosticsStatus getDiagnosticsStatus();

Expand Down
Loading