Skip to content

Commit d2b2cee

Browse files
committed
fix test cases
1 parent d155bf0 commit d2b2cee

File tree

9 files changed

+376
-375
lines changed

9 files changed

+376
-375
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ set(MO_SRC_UNIT
145145
#tests/Configuration.cpp
146146
#tests/Reservation.cpp
147147
#tests/Reset.cpp
148-
#tests/LocalAuthList.cpp
148+
tests/LocalAuthList.cpp
149149
#tests/Variables.cpp
150150
#tests/Transactions.cpp
151-
#tests/Certificates.cpp
151+
tests/Certificates.cpp
152152
#tests/FirmwareManagement.cpp
153153
#tests/ChargePointError.cpp
154154
#tests/Boot.cpp
@@ -196,6 +196,7 @@ target_compile_definitions(mo_unit_tests PUBLIC
196196
MO_MaxChargingProfilesInstalled=3
197197
MO_ENABLE_CERT_MGMT=1
198198
MO_ENABLE_CONNECTOR_LOCK=1
199+
MO_ENABLE_DIAGNOSTICS=0
199200
MO_REPORT_NOERROR=1
200201
MO_ENABLE_V201=1
201202
MO_OVERRIDE_ALLOCATION=1

src/MicroOcpp/Core/FilesystemUtils.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ enum class StoreStatus : uint8_t {
6060
StoreStatus storeJson(MO_FilesystemAdapter *filesystem, const char *fname, const JsonDoc& doc);
6161

6262
/*
63-
* Removes files in the MO folder whose file names start with `fnamePrefix`.
63+
* Removes files in the MO folder whose file names start with `fnamePrefix`. Returns false if there
64+
* was an error deleting a file. Returns true if the files were deleted successfully, or there was
65+
* no file to delete
6466
*/
6567
bool removeByPrefix(MO_FilesystemAdapter *filesystem, const char *fnamePrefix);
6668

src/MicroOcpp/Core/MessageService.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ bool MessageService::setOnSendConf(const char *operationType, void (*onConfirmat
279279
return appendEntry(sendConfListeners, listener);
280280
}
281281

282+
void MessageService::clearRegisteredOperation(const char *operationType) {
283+
removeEntry(operationRegistry, operationType);
284+
removeEntry(operationRegistry2, operationType);
285+
removeEntry(receiveRequestListeners, operationType);
286+
removeEntry(sendConfListeners, operationType);
287+
}
288+
282289
std::unique_ptr<Request> MessageService::createRequest(const char *operationType) {
283290

284291
Operation *operation = nullptr;

src/MicroOcpp/Core/MessageService.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ class MessageService : public MemoryManaged {
7272
public:
7373
MessageService(Context& context);
7474

75+
// handle Requests from the OCPP Server
76+
bool registerOperation(const char *operationType, Operation* (*createOperationCb)(Context& context));
77+
bool registerOperation(const char *operationType, void (*onRequest)(const char *operationType, const char *payloadJson, void **userStatus, void *userData), int (*writeResponse)(const char *operationType, char *buf, size_t size, void *userStatus, void *userData), void (*finally)(const char *operationType, void *userStatus, void *userData) = nullptr, void *userData = nullptr);
78+
bool setOnReceiveRequest(const char *operationType, void (*onRequest)(const char *operationType, const char *payloadJson, void *userData), void *userData = nullptr);
79+
bool setOnSendConf(const char *operationType, void (*onConfirmation)(const char *operationType, const char *payloadJson, void *userData), void *userData = nullptr);
80+
7581
bool setup();
7682

7783
void loop(); //polls all reqQueues and decides which request to send (if any)
@@ -80,15 +86,14 @@ class MessageService : public MemoryManaged {
8086
bool sendRequest(std::unique_ptr<Request> request); //send an OCPP operation request to the server; adds request to default queue
8187
bool sendRequestPreBoot(std::unique_ptr<Request> request); //send an OCPP operation request to the server; adds request to preBootQueue
8288

83-
// handle Requests from the OCPP Server
84-
bool registerOperation(const char *operationType, Operation* (*createOperationCb)(Context& context));
85-
bool registerOperation(const char *operationType, void (*onRequest)(const char *operationType, const char *payloadJson, void **userStatus, void *userData), int (*writeResponse)(const char *operationType, char *buf, size_t size, void *userStatus, void *userData), void (*finally)(const char *operationType, void *userStatus, void *userData) = nullptr, void *userData = nullptr);
86-
bool setOnReceiveRequest(const char *operationType, void (*onRequest)(const char *operationType, const char *payloadJson, void *userData), void *userData = nullptr);
87-
bool setOnSendConf(const char *operationType, void (*onConfirmation)(const char *operationType, const char *payloadJson, void *userData), void *userData = nullptr);
88-
8989
// process message from server ("message" = serialized Request or Confirmation)
9090
bool receiveMessage(const char* payload, size_t length);
9191

92+
// Undo `registerOperation()`, `setOnReceiveRequest()` and `setOnSendConf()` for specific operation type.
93+
// Necessary to re-register different operation handler after `mo_setup()`. MO will clear all registered
94+
// handlers during `mo_deinitialize()` automatically.
95+
void clearRegisteredOperation(const char *operationType);
96+
9297
// Outgoing Requests are handled in separate queues.
9398
void addSendQueue(RequestQueue* sendQueue);
9499
void setPreBootSendQueue(VolatileRequestQueue *preBootQueue);

src/MicroOcpp/Model/Availability/AvailabilityService.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ void v16::AvailabilityServiceEvse::loop() {
155155
MO_DBG_ERR("OOM");
156156
return;
157157
}
158-
statusNotification->setTimeout(0);
159158
context.getMessageService().sendRequest(std::move(statusNotification));
160159
return;
161160
}
@@ -451,7 +450,6 @@ void v201::AvailabilityServiceEvse::loop() {
451450
context.getClock().now().isUnixTime()) {
452451

453452
auto statusNotification = makeRequest(context, new StatusNotification(context, evseId, status, context.getClock().now()));
454-
statusNotification->setTimeout(0);
455453
context.getMessageService().sendRequest(std::move(statusNotification));
456454
reportedStatus = status;
457455
return;

src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,6 @@ void DiagnosticsService::setFtpServerCert(const char *cert) {
10061006

10071007
} //namespace MicroOcpp
10081008

1009-
#endif //(MO_ENABLE_V16 || MO_ENABLE_V201) && MO_ENABLE_DIAGNOSTICS
1010-
10111009
#if MO_USE_DIAGNOSTICS == MO_DIAGNOSTICS_BUILTIN_MBEDTLS_ESP32
10121010

10131011
#include "esp_heap_caps.h"
@@ -1049,3 +1047,5 @@ void defaultDiagnosticsOnClose(void*) {
10491047
} //namespace MicroOcpp
10501048

10511049
#endif //MO_USE_DIAGNOSTICS
1050+
1051+
#endif //(MO_ENABLE_V16 || MO_ENABLE_V201) && MO_ENABLE_DIAGNOSTICS

src/MicroOcpp/Model/Model.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,15 @@ void v16::Model::updateSupportedStandardProfiles() {
271271
}
272272
}
273273

274+
#if MO_ENABLE_FIRMWAREMANAGEMENT && MO_ENABLE_DIAGNOSTICS
274275
if (firmwareService ||
275276
getDiagnosticsService()) {
276277
if (!strstr(supportedFeatureProfilesString->getString(), "FirmwareManagement")) {
277278
if (!buf.empty()) buf += ',';
278279
buf += "FirmwareManagement";
279280
}
280281
}
282+
#endif //MO_ENABLE_FIRMWAREMANAGEMENT && MO_ENABLE_DIAGNOSTICS
281283

282284
#if MO_ENABLE_LOCAL_AUTH
283285
if (authorizationService) {

0 commit comments

Comments
 (0)