Skip to content

Commit 398dd9a

Browse files
committed
TC_045_2_CS Fix Get Diagnostics - Upload Failed
1 parent 5cfcc02 commit 398dd9a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void DiagnosticsService::loop() {
5959
}
6060

6161
const auto& timestampNow = context.getModel().getClock().now();
62-
if (retries > 0 && timestampNow >= nextTry) {
62+
if (retries != -1 && timestampNow >= nextTry) {
6363

6464
if (!uploadIssued) {
6565
if (onUpload != nullptr) {
@@ -69,7 +69,7 @@ void DiagnosticsService::loop() {
6969
uploadFailure = false;
7070
} else {
7171
MO_DBG_ERR("onUpload must be set! (see setOnUpload). Will abort");
72-
retries = 0;
72+
retries = -1;
7373
uploadIssued = false;
7474
uploadFailure = true;
7575
}
@@ -80,7 +80,7 @@ void DiagnosticsService::loop() {
8080
//success!
8181
MO_DBG_DEBUG("end upload routine (by status)");
8282
uploadIssued = false;
83-
retries = 0;
83+
retries = -1;
8484
}
8585

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

111-
if (retries == 0) {
111+
if (retries == -1) {
112112
MO_DBG_DEBUG("end upload routine (no more retry)");
113113
uploadFailure = true;
114114
}
@@ -119,7 +119,7 @@ void DiagnosticsService::loop() {
119119
}
120120

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

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

192193
DiagnosticsStatus DiagnosticsService::getDiagnosticsStatus() {
193194
if (uploadFailure) {
195+
if (lastReportedStatus != DiagnosticsStatus::Uploading &&
196+
lastReportedStatus != DiagnosticsStatus::UploadFailed) {
197+
//TC_045_2_CS Ensure Uploading is reported at least once before UploadFailed
198+
return DiagnosticsStatus::Uploading;
199+
}
194200
return DiagnosticsStatus::UploadFailed;
195201
}
196202

src/MicroOcpp/Model/Diagnostics/DiagnosticsService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DiagnosticsService : public MemoryManaged {
2929
Context& context;
3030

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

7373
Ocpp16::DiagnosticsStatus getDiagnosticsStatus();
7474

0 commit comments

Comments
 (0)