From e1c93a9288d1e78e36bb07aeb09764902a802a08 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Mon, 4 Nov 2024 00:38:12 +0100 Subject: [PATCH 1/9] upgrade v201 compat in MicroOcpp.h --- src/MicroOcpp.cpp | 135 ++++++++++++++---- src/MicroOcpp.h | 32 ++++- .../Model/Variables/VariableService.cpp | 12 ++ .../Model/Variables/VariableService.h | 1 + src/MicroOcpp_c.cpp | 16 +-- src/MicroOcpp_c.h | 8 +- 6 files changed, 159 insertions(+), 45 deletions(-) diff --git a/src/MicroOcpp.cpp b/src/MicroOcpp.cpp index 7ca20f3a..ebef107c 100644 --- a/src/MicroOcpp.cpp +++ b/src/MicroOcpp.cpp @@ -293,6 +293,8 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden new TransactionService(*context, filesystem, MO_NUM_EVSEID))); model.setRemoteControlService(std::unique_ptr( new RemoteControlService(*context, MO_NUM_EVSEID))); + model.setResetServiceV201(std::unique_ptr( + new Ocpp201::ResetService(*context))); } else #endif { @@ -305,20 +307,24 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden connectors.emplace_back(new Connector(*context, filesystem, connectorId)); } model.setConnectors(std::move(connectors)); - } - model.setHeartbeatService(std::unique_ptr( - new HeartbeatService(*context))); #if MO_ENABLE_LOCAL_AUTH - model.setAuthorizationService(std::unique_ptr( - new AuthorizationService(*context, filesystem))); + model.setAuthorizationService(std::unique_ptr( + new AuthorizationService(*context, filesystem))); #endif //MO_ENABLE_LOCAL_AUTH #if MO_ENABLE_RESERVATION - model.setReservationService(std::unique_ptr( - new ReservationService(*context, MO_NUMCONNECTORS))); + model.setReservationService(std::unique_ptr( + new ReservationService(*context, MO_NUMCONNECTORS))); #endif + model.setResetService(std::unique_ptr( + new ResetService(*context))); + } + + model.setHeartbeatService(std::unique_ptr( + new HeartbeatService(*context))); + #if MO_ENABLE_CERT_MGMT && MO_ENABLE_CERT_STORE_MBEDTLS std::unique_ptr certStore = makeCertificateStoreMbedTLS(filesystem); if (certStore) { @@ -330,18 +336,6 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden } #endif -#if MO_ENABLE_V201 - if (version.major == 2) { - //depends on VariableService - model.setResetServiceV201(std::unique_ptr( - new Ocpp201::ResetService(*context))); - } else -#endif - { - model.setResetService(std::unique_ptr( - new ResetService(*context))); - } - #if !defined(MO_CUSTOM_UPDATER) #if MO_PLATFORM == MO_PLATFORM_ARDUINO && defined(ESP32) && MO_ENABLE_MBEDTLS model.setFirmwareService( @@ -376,6 +370,12 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden configuration_load(); +#if MO_ENABLE_V201 + if (version.major == 2) { + model.getVariableService()->load(); + } +#endif //MO_ENABLE_V201 + MO_DBG_INFO("initialized MicroOcpp v" MO_VERSION " running OCPP %i.%i.%i", version.major, version.minor, version.patch); } @@ -422,41 +422,79 @@ void mocpp_loop() { context->loop(); } -std::shared_ptr beginTransaction(const char *idTag, unsigned int connectorId) { +bool beginTransaction(const char *idTag, unsigned int connectorId) { if (!context) { MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before - return nullptr; + return false; + } + + #if MO_ENABLE_V201 + if (context->getVersion().major == 2) { + if (!idTag || strnlen(idTag, MO_IDTOKEN_LEN_MAX + 2) > MO_IDTOKEN_LEN_MAX) { + MO_DBG_ERR("idTag format violation. Expect c-style string with at most %u characters", MO_IDTOKEN_LEN_MAX); + return false; + } + TransactionService::Evse *evse = nullptr; + if (auto txService = context->getModel().getTransactionService()) { + evse = txService->getEvse(connectorId); + } + if (!evse) { + MO_DBG_ERR("could not find EVSE"); + return false; + } + return evse->beginAuthorization(idTag, true); } + #endif + if (!idTag || strnlen(idTag, IDTAG_LEN_MAX + 2) > IDTAG_LEN_MAX) { MO_DBG_ERR("idTag format violation. Expect c-style string with at most %u characters", IDTAG_LEN_MAX); - return nullptr; + return false; } auto connector = context->getModel().getConnector(connectorId); if (!connector) { MO_DBG_ERR("could not find connector"); - return nullptr; + return false; } - return connector->beginTransaction(idTag); + return connector->beginTransaction(idTag) != nullptr; } -std::shared_ptr beginTransaction_authorized(const char *idTag, const char *parentIdTag, unsigned int connectorId) { +bool beginTransaction_authorized(const char *idTag, const char *parentIdTag, unsigned int connectorId) { if (!context) { MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before - return nullptr; + return false; + } + + #if MO_ENABLE_V201 + if (context->getVersion().major == 2) { + if (!idTag || strnlen(idTag, MO_IDTOKEN_LEN_MAX + 2) > MO_IDTOKEN_LEN_MAX) { + MO_DBG_ERR("idTag format violation. Expect c-style string with at most %u characters", MO_IDTOKEN_LEN_MAX); + return false; + } + TransactionService::Evse *evse = nullptr; + if (auto txService = context->getModel().getTransactionService()) { + evse = txService->getEvse(connectorId); + } + if (!evse) { + MO_DBG_ERR("could not find EVSE"); + return false; + } + return evse->beginAuthorization(idTag, false); } + #endif + if (!idTag || strnlen(idTag, IDTAG_LEN_MAX + 2) > IDTAG_LEN_MAX || (parentIdTag && strnlen(parentIdTag, IDTAG_LEN_MAX + 2) > IDTAG_LEN_MAX)) { MO_DBG_ERR("(parent)idTag format violation. Expect c-style string with at most %u characters", IDTAG_LEN_MAX); - return nullptr; + return false; } auto connector = context->getModel().getConnector(connectorId); if (!connector) { MO_DBG_ERR("could not find connector"); - return nullptr; + return false; } - return connector->beginTransaction_authorized(idTag, parentIdTag); + return connector->beginTransaction_authorized(idTag, parentIdTag) != nullptr; } bool endTransaction(const char *idTag, const char *reason, unsigned int connectorId) { @@ -464,6 +502,25 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before return false; } + + #if MO_ENABLE_V201 + if (context->getVersion().major == 2) { + if (!idTag || strnlen(idTag, MO_IDTOKEN_LEN_MAX + 2) > MO_IDTOKEN_LEN_MAX) { + MO_DBG_ERR("idTag format violation. Expect c-style string with at most %u characters", MO_IDTOKEN_LEN_MAX); + return false; + } + TransactionService::Evse *evse = nullptr; + if (auto txService = context->getModel().getTransactionService()) { + evse = txService->getEvse(connectorId); + } + if (!evse) { + MO_DBG_ERR("could not find EVSE"); + return false; + } + return evse->endAuthorization(idTag, true); + } + #endif + bool res = false; if (isTransactionActive(connectorId) && getTransactionIdTag(connectorId)) { //end transaction now if either idTag is nullptr (i.e. force stop) or the idTag matches beginTransaction @@ -524,6 +581,25 @@ bool endTransaction_authorized(const char *idTag, const char *reason, unsigned i MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before return false; } + + #if MO_ENABLE_V201 + if (context->getVersion().major == 2) { + if (!idTag || strnlen(idTag, MO_IDTOKEN_LEN_MAX + 2) > MO_IDTOKEN_LEN_MAX) { + MO_DBG_ERR("idTag format violation. Expect c-style string with at most %u characters", MO_IDTOKEN_LEN_MAX); + return false; + } + TransactionService::Evse *evse = nullptr; + if (auto txService = context->getModel().getTransactionService()) { + evse = txService->getEvse(connectorId); + } + if (!evse) { + MO_DBG_ERR("could not find EVSE"); + return false; + } + return evse->endAuthorization(idTag, false); + } + #endif + auto connector = context->getModel().getConnector(connectorId); if (!connector) { MO_DBG_ERR("could not find connector"); @@ -1003,6 +1079,7 @@ void setOccupiedInput(std::function occupied, unsigned int connectorId) evse->setOccupiedInput(occupied); } } + return; } #endif auto connector = context->getModel().getConnector(connectorId); diff --git a/src/MicroOcpp.h b/src/MicroOcpp.h index 25896a26..78f1c3b8 100644 --- a/src/MicroOcpp.h +++ b/src/MicroOcpp.h @@ -127,6 +127,7 @@ void mocpp_loop(); /* * Transaction management. * + * OCPP 1.6 (2.0.1 see below): * Begin the transaction process and prepare it. When all conditions for the transaction are true, * eventually send a StartTransaction request to the OCPP server. * Conditions: @@ -140,18 +141,24 @@ void mocpp_loop(); * * See beginTransaction_authorized for skipping steps 1) to 3) * - * Returns the transaction object if it was possible to create the transaction process. Returns - * nullptr if either another transaction process is still active or you need to try it again later. + * Returns true if it was possible to create the transaction process. Returns + * false if either another transaction process is still active or you need to try it again later. + * + * OCPP 2.0.1: + * Authorize a transaction. Like the OCPP 1.6 behavior, this should be called when the user swipes the + * card to start charging, but the semantic is slightly different. This function begins the authorized + * phase, but a transaction may already have started due to an earlier transaction start point. */ -std::shared_ptr beginTransaction(const char *idTag, unsigned int connectorId = 1); +bool beginTransaction(const char *idTag, unsigned int connectorId = 1); /* * Begin the transaction process and skip the OCPP-side authorization. See beginTransaction(...) for a * complete description */ -std::shared_ptr beginTransaction_authorized(const char *idTag, const char *parentIdTag = nullptr, unsigned int connectorId = 1); +bool beginTransaction_authorized(const char *idTag, const char *parentIdTag = nullptr, unsigned int connectorId = 1); /* + * OCPP 1.6 (2.0.1 see below): * End the transaction process if idTag is authorized to stop the transaction. The OCPP lib sends * a StopTransaction request if the following conditions are true: * Conditions: @@ -181,6 +188,15 @@ std::shared_ptr beginTransaction_authorized(const char * * `endTransaction_authorized(nullptr, reason);` * * Returns true if there is a transaction which could eventually be ended by this action + * + * OCPP 2.0.1: + * End the user authorization. Like when running with OCPP 1.6, this should be called when the user + * swipes the card to stop charging. The difference between the 1.6/2.0.1 behavior is that in 1.6, + * endTransaction always sets the transaction inactive so that it wants to stop. In 2.0.1, this only + * revokes the user authorization which may terminate the transaction but doesn't have to if the + * transaction stop point is set to EvConnected. + * + * Note: the stop reason parameter is ignored when running with OCPP 2.0.1. It's always Local */ bool endTransaction(const char *idTag = nullptr, const char *reason = nullptr, unsigned int connectorId = 1); @@ -238,6 +254,14 @@ const char *getTransactionIdTag(unsigned int connectorId = 1); */ std::shared_ptr& getTransaction(unsigned int connectorId = 1); +#if MO_ENABLE_V201 +/* + * OCPP 2.0.1 version of getTransaction(). Note that the return transaction object is of another type + * and unlike the 1.6 version, this function does not give ownership. + */ +MicroOcpp::Ocpp201::Transaction *getTransactionV201(unsigned int evseId = 1); +#endif //MO_ENABLE_V201 + /* * Returns if the OCPP library allows the EVSE to charge at the moment. * diff --git a/src/MicroOcpp/Model/Variables/VariableService.cpp b/src/MicroOcpp/Model/Variables/VariableService.cpp index dcdc499d..9c0d6fde 100644 --- a/src/MicroOcpp/Model/Variables/VariableService.cpp +++ b/src/MicroOcpp/Model/Variables/VariableService.cpp @@ -248,6 +248,18 @@ bool VariableService::addVariable(std::unique_ptr variable) { return getContainerInternalByVariable(variable->getComponentId(), variable->getName()).add(std::move(variable)); } +bool VariableService::load() { + bool success = true; + + for (size_t i = 0; i < MO_VARIABLESTORE_BUCKETS; i++) { + if (!containersInternal[i].load()) { + success = false; + } + } + + return success; +} + bool VariableService::commit() { bool success = true; diff --git a/src/MicroOcpp/Model/Variables/VariableService.h b/src/MicroOcpp/Model/Variables/VariableService.h index d4621053..afe19099 100644 --- a/src/MicroOcpp/Model/Variables/VariableService.h +++ b/src/MicroOcpp/Model/Variables/VariableService.h @@ -77,6 +77,7 @@ class VariableService : public MemoryManaged { //Get Variable. If not existent, return nullptr Variable *getVariable(const ComponentId& component, const char *name); + bool load(); bool commit(); void addContainer(VariableContainer *container); diff --git a/src/MicroOcpp_c.cpp b/src/MicroOcpp_c.cpp index 4c5b6317..3a25939d 100644 --- a/src/MicroOcpp_c.cpp +++ b/src/MicroOcpp_c.cpp @@ -131,18 +131,18 @@ std::function adaptFn(unsigned int connectorId, PollUnl } #endif //MO_ENABLE_CONNECTOR_LOCK -void ocpp_beginTransaction(const char *idTag) { - beginTransaction(idTag); +bool ocpp_beginTransaction(const char *idTag) { + return beginTransaction(idTag); } -void ocpp_beginTransaction_m(unsigned int connectorId, const char *idTag) { - beginTransaction(idTag, connectorId); +bool ocpp_beginTransaction_m(unsigned int connectorId, const char *idTag) { + return beginTransaction(idTag, connectorId); } -void ocpp_beginTransaction_authorized(const char *idTag, const char *parentIdTag) { - beginTransaction_authorized(idTag, parentIdTag); +bool ocpp_beginTransaction_authorized(const char *idTag, const char *parentIdTag) { + return beginTransaction_authorized(idTag, parentIdTag); } -void ocpp_beginTransaction_authorized_m(unsigned int connectorId, const char *idTag, const char *parentIdTag) { - beginTransaction_authorized(idTag, parentIdTag, connectorId); +bool ocpp_beginTransaction_authorized_m(unsigned int connectorId, const char *idTag, const char *parentIdTag) { + return beginTransaction_authorized(idTag, parentIdTag, connectorId); } bool ocpp_endTransaction(const char *idTag, const char *reason) { diff --git a/src/MicroOcpp_c.h b/src/MicroOcpp_c.h index 64699337..8fbef8a7 100644 --- a/src/MicroOcpp_c.h +++ b/src/MicroOcpp_c.h @@ -78,11 +78,11 @@ void ocpp_loop(); * Charging session management */ -void ocpp_beginTransaction(const char *idTag); -void ocpp_beginTransaction_m(unsigned int connectorId, const char *idTag); //multiple connectors version +bool ocpp_beginTransaction(const char *idTag); +bool ocpp_beginTransaction_m(unsigned int connectorId, const char *idTag); //multiple connectors version -void ocpp_beginTransaction_authorized(const char *idTag, const char *parentIdTag); -void ocpp_beginTransaction_authorized_m(unsigned int connectorId, const char *idTag, const char *parentIdTag); +bool ocpp_beginTransaction_authorized(const char *idTag, const char *parentIdTag); +bool ocpp_beginTransaction_authorized_m(unsigned int connectorId, const char *idTag, const char *parentIdTag); bool ocpp_endTransaction(const char *idTag, const char *reason); //idTag, reason can be NULL bool ocpp_endTransaction_m(unsigned int connectorId, const char *idTag, const char *reason); //idTag, reason can be NULL From 9aa9b449393de1cfdf8b4775b1a812b4560479be Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:29:40 +0100 Subject: [PATCH 2/9] add definition for getTransactionV201() --- src/MicroOcpp.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/MicroOcpp.cpp b/src/MicroOcpp.cpp index ebef107c..1f92b9a4 100644 --- a/src/MicroOcpp.cpp +++ b/src/MicroOcpp.cpp @@ -712,6 +712,30 @@ std::shared_ptr& getTransaction(unsigned int connectorId) { return connector->getTransaction(); } +#if MO_ENABLE_V201 +Ocpp201::Transaction *getTransactionV201(unsigned int evseId) { + if (!context) { + MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before + return nullptr; + } + + if (context->getVersion().major != 2) { + MO_DBG_ERR("only supported in v201"); //need to call mocpp_initialize before + return nullptr; + } + + TransactionService::Evse *evse = nullptr; + if (auto txService = context->getModel().getTransactionService()) { + evse = txService->getEvse(evseId); + } + if (!evse) { + MO_DBG_ERR("could not find EVSE"); + return nullptr; + } + return evse->getTransaction(); +} +#endif //MO_ENABLE_V201 + bool ocppPermitsCharge(unsigned int connectorId) { if (!context) { MO_DBG_WARN("OCPP uninitialized"); From bcfe1babdc9266edb6e695b2b218866d5677d675 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:01:57 +0100 Subject: [PATCH 3/9] refactor TxNotification --- CHANGELOG.md | 6 ++ CMakeLists.txt | 1 - src/MicroOcpp.cpp | 6 +- src/MicroOcpp.h | 3 +- .../Model/ConnectorBase/Connector.cpp | 28 ++++----- src/MicroOcpp/Model/ConnectorBase/Connector.h | 3 +- .../Model/ConnectorBase/Notification.cpp | 48 -------------- .../Model/ConnectorBase/Notification.h | 62 ------------------- .../Model/Transactions/Transaction.h | 29 +++++++++ .../Operations/RemoteStartTransaction.cpp | 2 +- src/MicroOcpp/Operations/UnlockConnector.cpp | 2 +- src/MicroOcpp_c.cpp | 12 ++-- src/MicroOcpp_c.h | 5 +- tests/Api.cpp | 6 +- tests/Boot.cpp | 3 +- tests/ChargingSessions.cpp | 8 +-- tests/LocalAuthList.cpp | 14 ++--- tests/Metering.cpp | 3 +- tests/Reservation.cpp | 4 +- tests/benchmarks/firmware_size/main.cpp | 2 +- .../benchmarks/scripts/eval_firmware_size.py | 3 - 21 files changed, 85 insertions(+), 165 deletions(-) delete mode 100644 src/MicroOcpp/Model/ConnectorBase/Notification.cpp delete mode 100644 src/MicroOcpp/Model/ConnectorBase/Notification.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 04bf0a0c..a3b82e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Changed + +- Change `MicroOcpp::TxNotification` into C-style enum, replace `OCPP_TxNotication` + ## [1.2.0] - 2024-11-03 ### Changed diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dfebce5..de6657db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,6 @@ set(MO_SRC src/MicroOcpp/Model/Certificates/CertificateService.cpp src/MicroOcpp/Model/ConnectorBase/ConnectorsCommon.cpp src/MicroOcpp/Model/ConnectorBase/Connector.cpp - src/MicroOcpp/Model/ConnectorBase/Notification.cpp src/MicroOcpp/Model/Diagnostics/DiagnosticsService.cpp src/MicroOcpp/Model/FirmwareManagement/FirmwareService.cpp src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp diff --git a/src/MicroOcpp.cpp b/src/MicroOcpp.cpp index 1f92b9a4..3f049a16 100644 --- a/src/MicroOcpp.cpp +++ b/src/MicroOcpp.cpp @@ -543,7 +543,7 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto MO_DBG_DEBUG("Authorize rejected (%s), continue transaction", idTag_capture.c_str()); auto connector = context->getModel().getConnector(connectorId); if (connector) { - connector->updateTxNotification(TxNotification::AuthorizationRejected); + connector->updateTxNotification(TxNotification_AuthorizationRejected); } return; } @@ -558,7 +558,7 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto MO_DBG_DEBUG("Authorization timeout (%s), continue transaction", idTag_capture.c_str()); auto connector = context->getModel().getConnector(connectorId); if (connector) { - connector->updateTxNotification(TxNotification::AuthorizationTimeout); + connector->updateTxNotification(TxNotification_AuthorizationTimeout); } }); @@ -1140,7 +1140,7 @@ void setStopTxReadyInput(std::function stopTxReady, unsigned int connect connector->setStopTxReadyInput(stopTxReady); } -void setTxNotificationOutput(std::function notificationOutput, unsigned int connectorId) { +void setTxNotificationOutput(std::function notificationOutput, unsigned int connectorId) { if (!context) { MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before return; diff --git a/src/MicroOcpp.h b/src/MicroOcpp.h index 78f1c3b8..95627c8d 100644 --- a/src/MicroOcpp.h +++ b/src/MicroOcpp.h @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -332,7 +331,7 @@ void setStartTxReadyInput(std::function startTxReady, unsigned int conne void setStopTxReadyInput(std::function stopTxReady, unsigned int connectorId = 1); //Input if charger is ready for StopTransaction -void setTxNotificationOutput(std::function notificationOutput, unsigned int connectorId = 1); //called when transaction state changes (see TxNotification for possible events). Transaction can be null +void setTxNotificationOutput(std::function notificationOutput, unsigned int connectorId = 1); //called when transaction state changes (see TxNotification for possible events). Transaction can be null #if MO_ENABLE_CONNECTOR_LOCK /* diff --git a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp index edb13154..b384663d 100644 --- a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp +++ b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp @@ -311,7 +311,7 @@ void Connector::loop() { transaction->setInactive(); transaction->commit(); - updateTxNotification(TxNotification::ConnectionTimeout); + updateTxNotification(TxNotification_ConnectionTimeout); } } @@ -372,7 +372,7 @@ void Connector::loop() { transaction->commit(); - updateTxNotification(TxNotification::StartTx); + updateTxNotification(TxNotification_StartTx); //fetchFrontRequest will create the StartTransaction and pass it to the message sender return; @@ -416,7 +416,7 @@ void Connector::loop() { transaction->commit(); - updateTxNotification(TxNotification::StopTx); + updateTxNotification(TxNotification_StopTx); //fetchFrontRequest will create the StopTransaction and pass it to the message sender return; @@ -736,7 +736,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { if (parentIdTag) { //parentIdTag known MO_DBG_INFO("connector %u reserved - abort transaction", connectorId); - updateTxNotification(TxNotification::ReservationConflict); + updateTxNotification(TxNotification_ReservationConflict); return nullptr; } else { //parentIdTag unkown but local authorization failed in any case @@ -776,7 +776,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { } transaction->setAuthorized(); - updateTxNotification(TxNotification::Authorized); + updateTxNotification(TxNotification_Authorized); } transaction->commit(); @@ -798,7 +798,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { MO_DBG_DEBUG("Authorize rejected (%s), abort tx process", tx->getIdTag()); tx->setIdTagDeauthorized(); tx->commit(); - updateTxNotification(TxNotification::AuthorizationRejected); + updateTxNotification(TxNotification_AuthorizationRejected); return; } @@ -820,7 +820,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { MO_DBG_INFO("connector %u reserved - abort transaction", connectorId); tx->setInactive(); tx->commit(); - updateTxNotification(TxNotification::ReservationConflict); + updateTxNotification(TxNotification_ReservationConflict); return; } } @@ -835,7 +835,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { tx->setAuthorized(); tx->commit(); - updateTxNotification(TxNotification::Authorized); + updateTxNotification(TxNotification_Authorized); }); //capture local auth and reservation check in for timeout handler @@ -850,7 +850,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { MO_DBG_DEBUG("Abort transaction process (%s), timeout, expired local auth", tx->getIdTag()); tx->setInactive(); tx->commit(); - updateTxNotification(TxNotification::AuthorizationTimeout); + updateTxNotification(TxNotification_AuthorizationTimeout); return; } @@ -859,7 +859,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { MO_DBG_INFO("connector %u reserved (offline) - abort transaction", connectorId); tx->setInactive(); tx->commit(); - updateTxNotification(TxNotification::ReservationConflict); + updateTxNotification(TxNotification_ReservationConflict); return; } @@ -871,7 +871,7 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { tx->setAuthorized(); tx->commit(); - updateTxNotification(TxNotification::Authorized); + updateTxNotification(TxNotification_Authorized); return; } @@ -882,14 +882,14 @@ std::shared_ptr Connector::beginTransaction(const char *idTag) { } tx->setAuthorized(); tx->commit(); - updateTxNotification(TxNotification::Authorized); + updateTxNotification(TxNotification_Authorized); return; } MO_DBG_DEBUG("Abort transaction process (%s): timeout", tx->getIdTag()); tx->setInactive(); tx->commit(); - updateTxNotification(TxNotification::AuthorizationTimeout); + updateTxNotification(TxNotification_AuthorizationTimeout); return; //offline tx disabled }); context.initiateRequest(std::move(authorize)); @@ -1184,7 +1184,7 @@ std::unique_ptr Connector::fetchFrontRequest() { const char* idTagInfoStatus = response["idTagInfo"]["status"] | "_Undefined"; if (strcmp(idTagInfoStatus, "Accepted")) { - updateTxNotification(TxNotification::DeAuthorized); + updateTxNotification(TxNotification_DeAuthorized); } }); auto transactionFront_capture = transactionFront; diff --git a/src/MicroOcpp/Model/ConnectorBase/Connector.h b/src/MicroOcpp/Model/ConnectorBase/Connector.h index 824e3d3b..d8d61639 100644 --- a/src/MicroOcpp/Model/ConnectorBase/Connector.h +++ b/src/MicroOcpp/Model/ConnectorBase/Connector.h @@ -7,8 +7,8 @@ #include #include -#include #include +#include #include #include #include @@ -31,7 +31,6 @@ namespace MicroOcpp { class Context; class Model; class Operation; -class Transaction; class Connector : public RequestEmitter, public MemoryManaged { private: diff --git a/src/MicroOcpp/Model/ConnectorBase/Notification.cpp b/src/MicroOcpp/Model/ConnectorBase/Notification.cpp deleted file mode 100644 index 1ad2eb1f..00000000 --- a/src/MicroOcpp/Model/ConnectorBase/Notification.cpp +++ /dev/null @@ -1,48 +0,0 @@ -// matth-x/MicroOcpp -// Copyright Matthias Akstaller 2019 - 2024 -// MIT License - -#include - -namespace MicroOcpp { - -OCPP_TxNotification convertTxNotification(TxNotification txn) { - auto res = OCPP_TxNotification::AuthorizationRejected; - - switch (txn) { - case TxNotification::AuthorizationRejected: - res = OCPP_TxNotification::AuthorizationRejected; - break; - case TxNotification::AuthorizationTimeout: - res = OCPP_TxNotification::AuthorizationTimeout; - break; - case TxNotification::Authorized: - res = OCPP_TxNotification::Authorized; - break; - case TxNotification::ConnectionTimeout: - res = OCPP_TxNotification::ConnectionTimeout; - break; - case TxNotification::DeAuthorized: - res = OCPP_TxNotification::DeAuthorized; - break; - case TxNotification::RemoteStart: - res = OCPP_TxNotification::RemoteStart; - break; - case TxNotification::RemoteStop: - res = OCPP_TxNotification::RemoteStop; - break; - case TxNotification::ReservationConflict: - res = OCPP_TxNotification::ReservationConflict; - break; - case TxNotification::StartTx: - res = OCPP_TxNotification::StartTx; - break; - case TxNotification::StopTx: - res = OCPP_TxNotification::StopTx; - break; - } - - return res; -} - -} //end namespace MicroOcpp diff --git a/src/MicroOcpp/Model/ConnectorBase/Notification.h b/src/MicroOcpp/Model/ConnectorBase/Notification.h deleted file mode 100644 index 66b14f9c..00000000 --- a/src/MicroOcpp/Model/ConnectorBase/Notification.h +++ /dev/null @@ -1,62 +0,0 @@ -// matth-x/MicroOcpp -// Copyright Matthias Akstaller 2019 - 2024 -// MIT License - -#ifndef MO_NOTIFICATION_H -#define MO_NOTIFICATION_H - -#ifdef __cplusplus - -namespace MicroOcpp { - -enum class TxNotification { - //Authorization events - Authorized, //success - AuthorizationRejected, //IdTag not authorized - AuthorizationTimeout, //authorization failed - offline - ReservationConflict, //connector reserved for other IdTag - - ConnectionTimeout, //user took to long to plug vehicle after the authorization - DeAuthorized, //server rejected StartTx - RemoteStart, //authorized via RemoteStartTransaction - RemoteStop, //stopped via RemoteStopTransaction - - //Tx lifecycle events - StartTx, - StopTx, -}; - -} //end namespace MicroOcpp - -extern "C" { -#endif //__cplusplus - -enum OCPP_TxNotification { - //Authorization events - Authorized, //success - AuthorizationRejected, //IdTag not authorized - AuthorizationTimeout, //authorization failed - offline - ReservationConflict, //connector reserved for other IdTag - - ConnectionTimeout, //user took to long to plug vehicle after the authorization - DeAuthorized, //server rejected StartTx - RemoteStart, //authorized via RemoteStartTransaction - RemoteStop, //stopped via RemoteStopTransaction - - //Tx lifecycle events - StartTx, - StopTx, -}; - -#ifdef __cplusplus -} //end extern "C" - -namespace MicroOcpp { - -OCPP_TxNotification convertTxNotification(TxNotification txn); - -} //end namespace MicroOcpp - -#endif //__cplusplus - -#endif diff --git a/src/MicroOcpp/Model/Transactions/Transaction.h b/src/MicroOcpp/Model/Transactions/Transaction.h index c9d0d80a..858f7945 100644 --- a/src/MicroOcpp/Model/Transactions/Transaction.h +++ b/src/MicroOcpp/Model/Transactions/Transaction.h @@ -5,6 +5,35 @@ #ifndef TRANSACTION_H #define TRANSACTION_H +/* General Tx defs */ +#ifdef __cplusplus +extern "C" { +#endif //__cplusplus + +//TxNotification - event from MO to the main firmware to notify it about transaction state changes +typedef enum { + UNDEFINED, + + //Authorization events + TxNotification_Authorized, //success + TxNotification_AuthorizationRejected, //IdTag/token not authorized + TxNotification_AuthorizationTimeout, //authorization failed - offline + TxNotification_ReservationConflict, //connector/evse reserved for other IdTag + + TxNotification_ConnectionTimeout, //user took to long to plug vehicle after the authorization + TxNotification_DeAuthorized, //server rejected StartTx/TxEvent + TxNotification_RemoteStart, //authorized via RemoteStartTx/RequestStartTx + TxNotification_RemoteStop, //stopped via RemoteStopTx/RequestStopTx + + //Tx lifecycle events + TxNotification_StartTx, //entered running state (StartTx/TxEvent was initiated) + TxNotification_StopTx, //left running state (StopTx/TxEvent was initiated) +} TxNotification; + +#ifdef __cplusplus +} +#endif //__cplusplus + #ifdef __cplusplus #include diff --git a/src/MicroOcpp/Operations/RemoteStartTransaction.cpp b/src/MicroOcpp/Operations/RemoteStartTransaction.cpp index b6f83bab..77314f36 100644 --- a/src/MicroOcpp/Operations/RemoteStartTransaction.cpp +++ b/src/MicroOcpp/Operations/RemoteStartTransaction.cpp @@ -106,7 +106,7 @@ void RemoteStartTransaction::processReq(JsonObject payload) { } else { tx = selectConnector->beginTransaction_authorized(idTag); } - selectConnector->updateTxNotification(TxNotification::RemoteStart); + selectConnector->updateTxNotification(TxNotification_RemoteStart); if (tx) { if (chargingProfileId >= 0) { tx->setTxProfileId(chargingProfileId); diff --git a/src/MicroOcpp/Operations/UnlockConnector.cpp b/src/MicroOcpp/Operations/UnlockConnector.cpp index 3dfdbec9..a64b7bd4 100644 --- a/src/MicroOcpp/Operations/UnlockConnector.cpp +++ b/src/MicroOcpp/Operations/UnlockConnector.cpp @@ -38,7 +38,7 @@ void UnlockConnector::processReq(JsonObject payload) { } connector->endTransaction(nullptr, "UnlockCommand"); - connector->updateTxNotification(TxNotification::RemoteStop); + connector->updateTxNotification(TxNotification_RemoteStop); cbUnlockResult = unlockConnector(); diff --git a/src/MicroOcpp_c.cpp b/src/MicroOcpp_c.cpp index 3a25939d..14d159a8 100644 --- a/src/MicroOcpp_c.cpp +++ b/src/MicroOcpp_c.cpp @@ -308,14 +308,14 @@ void ocpp_setStopTxReadyInput_m(unsigned int connectorId, InputBool_m stopTxRead setStopTxReadyInput(adaptFn(connectorId, stopTxReady), connectorId); } -void ocpp_setTxNotificationOutput(void (*notificationOutput)(OCPP_Transaction*, enum OCPP_TxNotification)) { - setTxNotificationOutput([notificationOutput] (MicroOcpp::Transaction *tx, MicroOcpp::TxNotification notification) { - notificationOutput(reinterpret_cast(tx), convertTxNotification(notification)); +void ocpp_setTxNotificationOutput(void (*notificationOutput)(OCPP_Transaction*, TxNotification)) { + setTxNotificationOutput([notificationOutput] (MicroOcpp::Transaction *tx, TxNotification notification) { + notificationOutput(reinterpret_cast(tx), notification); }); } -void ocpp_setTxNotificationOutput_m(unsigned int connectorId, void (*notificationOutput)(unsigned int, OCPP_Transaction*, enum OCPP_TxNotification)) { - setTxNotificationOutput([notificationOutput, connectorId] (MicroOcpp::Transaction *tx, MicroOcpp::TxNotification notification) { - notificationOutput(connectorId, reinterpret_cast(tx), convertTxNotification(notification)); +void ocpp_setTxNotificationOutput_m(unsigned int connectorId, void (*notificationOutput)(unsigned int, OCPP_Transaction*, TxNotification)) { + setTxNotificationOutput([notificationOutput, connectorId] (MicroOcpp::Transaction *tx, TxNotification notification) { + notificationOutput(connectorId, reinterpret_cast(tx), notification); }, connectorId); } diff --git a/src/MicroOcpp_c.h b/src/MicroOcpp_c.h index 8fbef8a7..e0ea2c69 100644 --- a/src/MicroOcpp_c.h +++ b/src/MicroOcpp_c.h @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -156,8 +155,8 @@ void ocpp_setStartTxReadyInput_m(unsigned int connectorId, InputBool_m startTxRe void ocpp_setStopTxReadyInput(InputBool stopTxReady); void ocpp_setStopTxReadyInput_m(unsigned int connectorId, InputBool_m stopTxReady); -void ocpp_setTxNotificationOutput(void (*notificationOutput)(OCPP_Transaction*, enum OCPP_TxNotification)); -void ocpp_setTxNotificationOutput_m(unsigned int connectorId, void (*notificationOutput)(unsigned int, OCPP_Transaction*, enum OCPP_TxNotification)); +void ocpp_setTxNotificationOutput(void (*notificationOutput)(OCPP_Transaction*, TxNotification)); +void ocpp_setTxNotificationOutput_m(unsigned int connectorId, void (*notificationOutput)(unsigned int, OCPP_Transaction*, TxNotification)); #if MO_ENABLE_CONNECTOR_LOCK void ocpp_setOnUnlockConnectorInOut(PollUnlockResult onUnlockConnectorInOut); diff --git a/tests/Api.cpp b/tests/Api.cpp index d7815e10..d8227a60 100644 --- a/tests/Api.cpp +++ b/tests/Api.cpp @@ -61,7 +61,7 @@ TEST_CASE( "C++ API test" ) { setOccupiedInput([c = &checkpoints[ncheck++]] () -> bool {*c = true; return false;}); setStartTxReadyInput([c = &checkpoints[ncheck++]] () -> bool {*c = true; return true;}); setStopTxReadyInput([c = &checkpoints[ncheck++]] () -> bool {*c = true; return true;}); - setTxNotificationOutput([c = &checkpoints[ncheck++]] (MicroOcpp::Transaction*, MicroOcpp::TxNotification) {*c = true;}); + setTxNotificationOutput([c = &checkpoints[ncheck++]] (MicroOcpp::Transaction*, TxNotification) {*c = true;}); #if MO_ENABLE_CONNECTOR_LOCK setOnUnlockConnectorInOut([c = &checkpoints[ncheck++]] () -> UnlockConnectorResult {*c = true; return UnlockConnectorResult_Unlocked;}); @@ -249,8 +249,8 @@ TEST_CASE( "C API test" ) { ocpp_setStartTxReadyInput_m(2, [] (unsigned int) -> bool {checkpointsc[21] = true; return true;}); ncheckc++; ocpp_setStopTxReadyInput([] () -> bool {checkpointsc[22] = true; return true;}); ncheckc++; ocpp_setStopTxReadyInput_m(2, [] (unsigned int) -> bool {checkpointsc[23] = true; return true;}); ncheckc++; - ocpp_setTxNotificationOutput([] (OCPP_Transaction*, OCPP_TxNotification) {checkpointsc[24] = true;}); ncheckc++; - ocpp_setTxNotificationOutput_m(2, [] (unsigned int, OCPP_Transaction*, OCPP_TxNotification) {checkpointsc[25] = true;}); ncheckc++; + ocpp_setTxNotificationOutput([] (OCPP_Transaction*, TxNotification) {checkpointsc[24] = true;}); ncheckc++; + ocpp_setTxNotificationOutput_m(2, [] (unsigned int, OCPP_Transaction*, TxNotification) {checkpointsc[25] = true;}); ncheckc++; #if MO_ENABLE_CONNECTOR_LOCK ocpp_setOnUnlockConnectorInOut([] () -> UnlockConnectorResult {checkpointsc[26] = true; return UnlockConnectorResult_Unlocked;}); ncheckc++; diff --git a/tests/Boot.cpp b/tests/Boot.cpp index c759b808..a4ea610f 100644 --- a/tests/Boot.cpp +++ b/tests/Boot.cpp @@ -378,7 +378,8 @@ TEST_CASE( "Boot Behavior" ) { old_opstore.reset(); //flushes the file loop(); - auto tx = beginTransaction("mIdTag"); //tx store will also be removed + beginTransaction("mIdTag"); //tx store will also be removed + auto tx = getTransaction(); auto txNr = tx->getTxNr(); //remember this for later usage tx.reset(); //reset this smart pointer loop(); diff --git a/tests/ChargingSessions.cpp b/tests/ChargingSessions.cpp index ab3d8e6e..1ac9bdef 100644 --- a/tests/ChargingSessions.cpp +++ b/tests/ChargingSessions.cpp @@ -373,8 +373,8 @@ TEST_CASE( "Charging sessions" ) { // now, tx journal is full. Block any further charging session - auto tx = beginTransaction_authorized("mIdTag"); - REQUIRE( !tx ); + auto tx_success = beginTransaction_authorized("mIdTag"); + REQUIRE( !tx_success ); loop(); @@ -449,8 +449,8 @@ TEST_CASE( "Charging sessions" ) { // now, tx journal is full. Block any further charging session - auto tx = beginTransaction_authorized("mIdTag"); - REQUIRE( tx ); + auto tx_success = beginTransaction_authorized("mIdTag"); + REQUIRE( tx_success ); loop(); diff --git a/tests/LocalAuthList.cpp b/tests/LocalAuthList.cpp index daca34c4..855a980b 100644 --- a/tests/LocalAuthList.cpp +++ b/tests/LocalAuthList.cpp @@ -94,7 +94,7 @@ TEST_CASE( "LocalAuth" ) { //check TX notification bool checkTxAuthorized = false; setTxNotificationOutput([&checkTxAuthorized] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::Authorized) { + if (txNotification == TxNotification_Authorized) { checkTxAuthorized = true; } }); @@ -150,7 +150,7 @@ TEST_CASE( "LocalAuth" ) { //check TX notification bool checkTxAuthorized = false; setTxNotificationOutput([&checkTxAuthorized] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::Authorized) { + if (txNotification == TxNotification_Authorized) { checkTxAuthorized = true; } }); @@ -182,7 +182,7 @@ TEST_CASE( "LocalAuth" ) { //make charger offline and begin tx, but idTag doesn't match - tx should be aborted bool checkTxTimeout = false; setTxNotificationOutput([&checkTxTimeout] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::AuthorizationTimeout) { + if (txNotification == TxNotification_AuthorizationTimeout) { checkTxTimeout = true; } }); @@ -217,7 +217,7 @@ TEST_CASE( "LocalAuth" ) { //check TX notification bool checkTxAuthorized = false; setTxNotificationOutput([&checkTxAuthorized] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::Authorized) { + if (txNotification == TxNotification_Authorized) { checkTxAuthorized = true; } }); @@ -255,7 +255,7 @@ TEST_CASE( "LocalAuth" ) { //check TX notification bool checkTxAuthorized = false; setTxNotificationOutput([&checkTxAuthorized] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::Authorized) { + if (txNotification == TxNotification_Authorized) { checkTxAuthorized = true; } }); @@ -390,7 +390,7 @@ TEST_CASE( "LocalAuth" ) { //check TX notification bool checkTxAuthorized = false; setTxNotificationOutput([&checkTxAuthorized] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::Authorized) { + if (txNotification == TxNotification_Authorized) { checkTxAuthorized = true; } }); @@ -427,7 +427,7 @@ TEST_CASE( "LocalAuth" ) { //check TX notification bool checkTxRejected = false; setTxNotificationOutput([&checkTxRejected] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::AuthorizationRejected) { + if (txNotification == TxNotification_AuthorizationRejected) { checkTxRejected = true; } }); diff --git a/tests/Metering.cpp b/tests/Metering.cpp index 23e79fe5..aa555e99 100644 --- a/tests/Metering.cpp +++ b/tests/Metering.cpp @@ -585,7 +585,8 @@ TEST_CASE("Metering") { auto trackMtime = mtime; - auto tx = beginTransaction_authorized("mIdTag"); + beginTransaction_authorized("mIdTag"); + auto tx = getTransaction(); loop(); diff --git a/tests/Reservation.cpp b/tests/Reservation.cpp index b25db0e2..306b804a 100644 --- a/tests/Reservation.cpp +++ b/tests/Reservation.cpp @@ -63,7 +63,7 @@ TEST_CASE( "Reservation" ) { //transaction blocked by reservation bool checkTxRejected = false; setTxNotificationOutput([&checkTxRejected] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::ReservationConflict) { + if (txNotification == TxNotification_ReservationConflict) { checkTxRejected = true; } }); @@ -225,7 +225,7 @@ TEST_CASE( "Reservation" ) { bool checkTxRejected = false; setTxNotificationOutput([&checkTxRejected] (Transaction*, TxNotification txNotification) { - if (txNotification == TxNotification::ReservationConflict) { + if (txNotification == TxNotification_ReservationConflict) { checkTxRejected = true; } }, 2); diff --git a/tests/benchmarks/firmware_size/main.cpp b/tests/benchmarks/firmware_size/main.cpp index f1d07cd1..6e849b8d 100644 --- a/tests/benchmarks/firmware_size/main.cpp +++ b/tests/benchmarks/firmware_size/main.cpp @@ -43,7 +43,7 @@ void setup() { ocpp_setOccupiedInput([] () {return false;}); ocpp_setStartTxReadyInput([] () {return false;}); ocpp_setStopTxReadyInput([] () {return false;}); - ocpp_setTxNotificationOutput([] (OCPP_Transaction*, OCPP_TxNotification) {}); + ocpp_setTxNotificationOutput([] (OCPP_Transaction*, TxNotification) {}); #if MO_ENABLE_CONNECTOR_LOCK ocpp_setOnUnlockConnectorInOut([] () {return UnlockConnectorResult_UnlockFailed;}); diff --git a/tests/benchmarks/scripts/eval_firmware_size.py b/tests/benchmarks/scripts/eval_firmware_size.py index 5d544028..7af316e9 100755 --- a/tests/benchmarks/scripts/eval_firmware_size.py +++ b/tests/benchmarks/scripts/eval_firmware_size.py @@ -137,9 +137,6 @@ def categorize_table(df): df.at['Model/ConnectorBase/Connector.cpp', 'Module'] = MODULE_CORE df.at['Model/ConnectorBase/ConnectorsCommon.cpp', 'v16'] = TICK df.at['Model/ConnectorBase/ConnectorsCommon.cpp', 'Module'] = MODULE_CORE - if 'Model/ConnectorBase/Notification.cpp' in df.index: - df.at['Model/ConnectorBase/Notification.cpp', 'v16'] = TICK - df.at['Model/ConnectorBase/Notification.cpp', 'Module'] = MODULE_CORE df.at['Model/Diagnostics/DiagnosticsService.cpp', 'v16'] = TICK df.at['Model/Diagnostics/DiagnosticsService.cpp', 'Module'] = MODULE_FW_MNGT df.at['Model/FirmwareManagement/FirmwareService.cpp', 'v16'] = TICK From be4f09273f8fc51d5417826ce9f6631efc794a8b Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:03:01 +0100 Subject: [PATCH 4/9] v201 compat for ocpp_tx C-API --- src/MicroOcpp.cpp | 8 +- .../Model/Transactions/Transaction.cpp | 109 ++++++++++++++++++ .../Model/Transactions/Transaction.h | 15 ++- src/MicroOcpp_c.cpp | 23 +++- 4 files changed, 151 insertions(+), 4 deletions(-) diff --git a/src/MicroOcpp.cpp b/src/MicroOcpp.cpp index 3f049a16..ce541655 100644 --- a/src/MicroOcpp.cpp +++ b/src/MicroOcpp.cpp @@ -704,6 +704,12 @@ std::shared_ptr& getTransaction(unsigned int connectorId) { MO_DBG_WARN("OCPP uninitialized"); return mocpp_undefinedTx; } + #if MO_ENABLE_V201 + if (context->getVersion().major == 2) { + MO_DBG_ERR("only supported in v16"); + return mocpp_undefinedTx; + } + #endif auto connector = context->getModel().getConnector(connectorId); if (!connector) { MO_DBG_ERR("could not find connector"); @@ -720,7 +726,7 @@ Ocpp201::Transaction *getTransactionV201(unsigned int evseId) { } if (context->getVersion().major != 2) { - MO_DBG_ERR("only supported in v201"); //need to call mocpp_initialize before + MO_DBG_ERR("only supported in v201"); return nullptr; } diff --git a/src/MicroOcpp/Model/Transactions/Transaction.cpp b/src/MicroOcpp/Model/Transactions/Transaction.cpp index bd21db2e..7a48a7da 100644 --- a/src/MicroOcpp/Model/Transactions/Transaction.cpp +++ b/src/MicroOcpp/Model/Transactions/Transaction.cpp @@ -355,61 +355,170 @@ bool deserializeTransactionEventChargingState(const char *chargingStateCstr, Tra #endif //MO_ENABLE_V201 +#if MO_ENABLE_V201 +bool g_ocpp_tx_compat_v201; + +void ocpp_tx_compat_setV201(bool isV201) { + g_ocpp_tx_compat_v201 = isV201; +} +#endif + int ocpp_tx_getTransactionId(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v16"); + return -1; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getTransactionId(); } +#if MO_ENABLE_V201 +const char *ocpp_tx_getTransactionIdV201(OCPP_Transaction *tx) { + if (!g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v201"); + return nullptr; + } + return reinterpret_cast(tx)->transactionId; +} +#endif //MO_ENABLE_V201 bool ocpp_tx_isAuthorized(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + return reinterpret_cast(tx)->isAuthorized; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->isAuthorized(); } bool ocpp_tx_isIdTagDeauthorized(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + return reinterpret_cast(tx)->isDeauthorized; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->isIdTagDeauthorized(); } bool ocpp_tx_isRunning(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + auto transaction = reinterpret_cast(tx); + return transaction->started && !transaction->stopped; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->isRunning(); } bool ocpp_tx_isActive(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + return reinterpret_cast(tx)->active; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->isActive(); } bool ocpp_tx_isAborted(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + auto transaction = reinterpret_cast(tx); + return !transaction->active && !transaction->started; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->isAborted(); } bool ocpp_tx_isCompleted(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + auto transaction = reinterpret_cast(tx); + return transaction->stopped && transaction->seqNos.empty(); + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->isCompleted(); } const char *ocpp_tx_getIdTag(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + auto transaction = reinterpret_cast(tx); + return transaction->idToken.get(); + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getIdTag(); } bool ocpp_tx_getBeginTimestamp(OCPP_Transaction *tx, char *buf, size_t len) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + return reinterpret_cast(tx)->beginTimestamp.toJsonString(buf, len); + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getBeginTimestamp().toJsonString(buf, len); } int32_t ocpp_tx_getMeterStart(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v16"); + return -1; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getMeterStart(); } bool ocpp_tx_getStartTimestamp(OCPP_Transaction *tx, char *buf, size_t len) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v16"); + return -1; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getStartTimestamp().toJsonString(buf, len); } const char *ocpp_tx_getStopIdTag(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + auto transaction = reinterpret_cast(tx); + return transaction->stopIdToken ? transaction->stopIdToken->get() : ""; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getStopIdTag(); } int32_t ocpp_tx_getMeterStop(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v16"); + return -1; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getMeterStop(); } void ocpp_tx_setMeterStop(OCPP_Transaction* tx, int32_t meter) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v16"); + return; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->setMeterStop(meter); } bool ocpp_tx_getStopTimestamp(OCPP_Transaction *tx, char *buf, size_t len) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + MO_DBG_ERR("only supported in v16"); + return -1; + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getStopTimestamp().toJsonString(buf, len); } const char *ocpp_tx_getStopReason(OCPP_Transaction *tx) { + #if MO_ENABLE_V201 + if (g_ocpp_tx_compat_v201) { + auto transaction = reinterpret_cast(tx); + return serializeTransactionStoppedReason(transaction->stoppedReason); + } + #endif //MO_ENABLE_V201 return reinterpret_cast(tx)->getStopReason(); } diff --git a/src/MicroOcpp/Model/Transactions/Transaction.h b/src/MicroOcpp/Model/Transactions/Transaction.h index 858f7945..877ccc4c 100644 --- a/src/MicroOcpp/Model/Transactions/Transaction.h +++ b/src/MicroOcpp/Model/Transactions/Transaction.h @@ -5,6 +5,8 @@ #ifndef TRANSACTION_H #define TRANSACTION_H +#include + /* General Tx defs */ #ifdef __cplusplus extern "C" { @@ -215,8 +217,6 @@ class Transaction : public MemoryManaged { } // namespace MicroOcpp -#include - #if MO_ENABLE_V201 #include @@ -451,7 +451,18 @@ extern "C" { struct OCPP_Transaction; typedef struct OCPP_Transaction OCPP_Transaction; +/* + * Compat mode for transactions. This means that all following C-wrapper functions will interprete the handle as v201 transactions + */ +#if MO_ENABLE_V201 +void ocpp_tx_compat_setV201(bool isV201); //if set, all OCPP_Transaction* handles are treated as v201 transactions +#endif + int ocpp_tx_getTransactionId(OCPP_Transaction *tx); +#if MO_ENABLE_V201 +const char *ocpp_tx_getTransactionIdV201(OCPP_Transaction *tx); +#endif + bool ocpp_tx_isAuthorized(OCPP_Transaction *tx); bool ocpp_tx_isIdTagDeauthorized(OCPP_Transaction *tx); diff --git a/src/MicroOcpp_c.cpp b/src/MicroOcpp_c.cpp index 14d159a8..e3035c4a 100644 --- a/src/MicroOcpp_c.cpp +++ b/src/MicroOcpp_c.cpp @@ -6,6 +6,8 @@ #include "MicroOcpp.h" #include +#include +#include #include #include @@ -184,10 +186,29 @@ OCPP_Transaction *ocpp_getTransaction() { return ocpp_getTransaction_m(1); } OCPP_Transaction *ocpp_getTransaction_m(unsigned int connectorId) { + #if MO_ENABLE_V201 + { + if (!getOcppContext()) { + MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before + return nullptr; + } + if (getOcppContext()->getModel().getVersion().major == 2) { + ocpp_tx_compat_setV201(true); //set the ocpp_tx C-API into v201 mode globally + if (getTransactionV201(connectorId)) { + return reinterpret_cast(getTransactionV201(connectorId)); + } else { + return nullptr; + } + } else { + ocpp_tx_compat_setV201(false); //set the ocpp_tx C-API into v16 mode globally + //continue with V16 implementation + } + } + #endif //MO_ENABLE_V201 if (getTransaction(connectorId)) { return reinterpret_cast(getTransaction(connectorId).get()); } else { - return NULL; + return nullptr; } } From 91b07389c726a32e1b989986285a8b75e70164e8 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:04:33 +0100 Subject: [PATCH 5/9] port TxNotification to v201 --- src/MicroOcpp.cpp | 30 ++++++++++++ src/MicroOcpp.h | 4 ++ .../Model/Transactions/TransactionService.cpp | 48 +++++++++++++++++++ .../Model/Transactions/TransactionService.h | 5 ++ 4 files changed, 87 insertions(+) diff --git a/src/MicroOcpp.cpp b/src/MicroOcpp.cpp index ce541655..5dbd3714 100644 --- a/src/MicroOcpp.cpp +++ b/src/MicroOcpp.cpp @@ -1151,6 +1151,12 @@ void setTxNotificationOutput(std::functiongetVersion().major == 2) { + MO_DBG_ERR("only supported in v16"); + return; + } + #endif auto connector = context->getModel().getConnector(connectorId); if (!connector) { MO_DBG_ERR("could not find connector"); @@ -1159,6 +1165,30 @@ void setTxNotificationOutput(std::functionsetTxNotificationOutput(notificationOutput); } +#if MO_ENABLE_V201 +void setTxNotificationOutputV201(std::function notificationOutput, unsigned int connectorId) { + if (!context) { + MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before + return; + } + + if (context->getVersion().major != 2) { + MO_DBG_ERR("only supported in v201"); + return; + } + + TransactionService::Evse *evse = nullptr; + if (auto txService = context->getModel().getTransactionService()) { + evse = txService->getEvse(connectorId); + } + if (!evse) { + MO_DBG_ERR("could not find EVSE"); + return; + } + evse->setTxNotificationOutput(notificationOutput); +} +#endif //MO_ENABLE_V201 + #if MO_ENABLE_CONNECTOR_LOCK void setOnUnlockConnectorInOut(std::function onUnlockConnectorInOut, unsigned int connectorId) { if (!context) { diff --git a/src/MicroOcpp.h b/src/MicroOcpp.h index 95627c8d..f15c13cc 100644 --- a/src/MicroOcpp.h +++ b/src/MicroOcpp.h @@ -333,6 +333,10 @@ void setStopTxReadyInput(std::function stopTxReady, unsigned int connect void setTxNotificationOutput(std::function notificationOutput, unsigned int connectorId = 1); //called when transaction state changes (see TxNotification for possible events). Transaction can be null +#if MO_ENABLE_V201 +void setTxNotificationOutputV201(std::function notificationOutput, unsigned int connectorId = 1); +#endif //MO_ENABLE_V201 + #if MO_ENABLE_CONNECTOR_LOCK /* * Set an InputOutput (reads and sets information at the same time) for forcing to unlock the diff --git a/src/MicroOcpp/Model/Transactions/TransactionService.cpp b/src/MicroOcpp/Model/Transactions/TransactionService.cpp index be9fb72a..d0e58e1f 100644 --- a/src/MicroOcpp/Model/Transactions/TransactionService.cpp +++ b/src/MicroOcpp/Model/Transactions/TransactionService.cpp @@ -261,6 +261,8 @@ void TransactionService::Evse::loop() { MO_DBG_INFO("Session mngt: timeout"); endTransaction(Ocpp201::Transaction::StoppedReason::Timeout, TransactionEventTriggerReason::EVConnectTimeout); + + updateTxNotification(TxNotification_ConnectionTimeout); } if (transaction->active && @@ -576,6 +578,14 @@ void TransactionService::Evse::loop() { txStore.commit(txEvent.get()); } + if (txEvent) { + if (txEvent->eventType == TransactionEventData::Type::Started) { + updateTxNotification(TxNotification_StartTx); + } else if (txEvent->eventType == TransactionEventData::Type::Ended) { + updateTxNotification(TxNotification_StartTx); + } + } + //try to pass ownership to front txEvent immediatley if (txEvent && !txEventFront && transaction->txNr == txNrFront && @@ -604,6 +614,16 @@ void TransactionService::Evse::setEvseReadyInput(std::function connector this->evseReadyInput = connectorEnergized; } +void TransactionService::Evse::setTxNotificationOutput(std::function txNotificationOutput) { + this->txNotificationOutput = txNotificationOutput; +} + +void TransactionService::Evse::updateTxNotification(TxNotification event) { + if (txNotificationOutput) { + txNotificationOutput(transaction.get(), event); + } +} + bool TransactionService::Evse::beginAuthorization(IdToken idToken, bool validateIdToken) { MO_DBG_DEBUG("begin auth: %s", idToken.get()); @@ -649,6 +669,8 @@ bool TransactionService::Evse::beginAuthorization(IdToken idToken, bool validate MO_DBG_DEBUG("Authorize rejected (%s), abort tx process", tx->idToken.get()); tx->isDeauthorized = true; txStore.commit(tx); + + updateTxNotification(TxNotification_AuthorizationRejected); return; } @@ -656,6 +678,8 @@ bool TransactionService::Evse::beginAuthorization(IdToken idToken, bool validate tx->isAuthorized = true; tx->notifyIdToken = true; txStore.commit(tx); + + updateTxNotification(TxNotification_Authorized); }); authorize->setOnAbortListener([this, txId] () { auto tx = getTransaction(); @@ -667,6 +691,8 @@ bool TransactionService::Evse::beginAuthorization(IdToken idToken, bool validate MO_DBG_DEBUG("Authorize timeout (%s)", tx->idToken.get()); tx->isDeauthorized = true; txStore.commit(tx); + + updateTxNotification(TxNotification_AuthorizationTimeout); }); authorize->setTimeout(20 * 1000); context.initiateRequest(std::move(authorize)); @@ -674,6 +700,9 @@ bool TransactionService::Evse::beginAuthorization(IdToken idToken, bool validate MO_DBG_DEBUG("Authorized tx directly (%s)", transaction->idToken.get()); transaction->isAuthorized = true; transaction->notifyIdToken = true; + txStore.commit(transaction.get()); + + updateTxNotification(TxNotification_Authorized); } return true; @@ -692,10 +721,16 @@ bool TransactionService::Evse::endAuthorization(IdToken idToken, bool validateId // use same idToken like tx start transaction->isAuthorizationActive = false; transaction->notifyIdToken = true; + txStore.commit(transaction.get()); + + updateTxNotification(TxNotification_Authorized); } else if (!validateIdToken) { transaction->stopIdToken = std::unique_ptr(new IdToken(idToken, getMemoryTag())); transaction->isAuthorizationActive = false; transaction->notifyStopIdToken = true; + txStore.commit(transaction.get()); + + updateTxNotification(TxNotification_Authorized); } else { // use a different idToken for stopping the tx @@ -718,6 +753,8 @@ bool TransactionService::Evse::endAuthorization(IdToken idToken, bool validateId if (strcmp(response["idTokenInfo"]["status"] | "_Undefined", "Accepted")) { MO_DBG_DEBUG("Authorize rejected (%s), don't stop tx", idToken.get()); + + updateTxNotification(TxNotification_AuthorizationRejected); return; } @@ -735,6 +772,17 @@ bool TransactionService::Evse::endAuthorization(IdToken idToken, bool validateId tx->isAuthorizationActive = false; tx->notifyStopIdToken = true; txStore.commit(tx); + + updateTxNotification(TxNotification_Authorized); + }); + authorize->setOnTimeoutListener([this, txId] () { + auto tx = getTransaction(); + if (!tx || strcmp(tx->transactionId, txId)) { + MO_DBG_INFO("dangling Authorize -- discard"); + return; + } + + updateTxNotification(TxNotification_AuthorizationTimeout); }); authorize->setTimeout(20 * 1000); context.initiateRequest(std::move(authorize)); diff --git a/src/MicroOcpp/Model/Transactions/TransactionService.h b/src/MicroOcpp/Model/Transactions/TransactionService.h index 45a0b64a..36a0bc99 100644 --- a/src/MicroOcpp/Model/Transactions/TransactionService.h +++ b/src/MicroOcpp/Model/Transactions/TransactionService.h @@ -52,6 +52,8 @@ class TransactionService : public MemoryManaged { std::function startTxReadyInput; std::function stopTxReadyInput; + std::function txNotificationOutput; + bool beginTransaction(); bool endTransaction(Ocpp201::Transaction::StoppedReason stoppedReason, Ocpp201::TransactionEventTriggerReason stopTrigger); @@ -74,6 +76,9 @@ class TransactionService : public MemoryManaged { void setEvReadyInput(std::function evRequestsEnergy); void setEvseReadyInput(std::function connectorEnergized); + void setTxNotificationOutput(std::function txNotificationOutput); + void updateTxNotification(TxNotification event); + bool beginAuthorization(IdToken idToken, bool validateIdToken = true); // authorize by swipe RFID bool endAuthorization(IdToken idToken = IdToken(), bool validateIdToken = false); // stop authorization by swipe RFID From ad0fe21c28cf33657c1e9b1141b8bed7e66dcae0 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Tue, 5 Nov 2024 01:10:22 +0100 Subject: [PATCH 6/9] init with v201 in C-API directly --- src/MicroOcpp_c.cpp | 15 +++++++++++---- src/MicroOcpp_c.h | 6 ++++-- tests/Api.cpp | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/MicroOcpp_c.cpp b/src/MicroOcpp_c.cpp index e3035c4a..6a981582 100644 --- a/src/MicroOcpp_c.cpp +++ b/src/MicroOcpp_c.cpp @@ -5,6 +5,7 @@ #include "MicroOcpp_c.h" #include "MicroOcpp.h" +#include #include #include #include @@ -15,11 +16,14 @@ MicroOcpp::Connection *ocppSocket = nullptr; -void ocpp_initialize(OCPP_Connection *conn, const char *chargePointModel, const char *chargePointVendor, struct OCPP_FilesystemOpt fsopt, bool autoRecover) { - ocpp_initialize_full(conn, ChargerCredentials(chargePointModel, chargePointVendor), fsopt, autoRecover); +void ocpp_initialize(OCPP_Connection *conn, const char *chargePointModel, const char *chargePointVendor, struct OCPP_FilesystemOpt fsopt, bool autoRecover, bool ocpp201) { + ocpp_initialize_full(conn, ocpp201 ? + ChargerCredentials::v201(chargePointModel, chargePointVendor) : + ChargerCredentials(chargePointModel, chargePointVendor), + fsopt, autoRecover, ocpp201); } -void ocpp_initialize_full(OCPP_Connection *conn, const char *bootNotificationCredentials, struct OCPP_FilesystemOpt fsopt, bool autoRecover) { +void ocpp_initialize_full(OCPP_Connection *conn, const char *bootNotificationCredentials, struct OCPP_FilesystemOpt fsopt, bool autoRecover, bool ocpp201) { if (!conn) { MO_DBG_ERR("conn is null"); } @@ -28,7 +32,10 @@ void ocpp_initialize_full(OCPP_Connection *conn, const char *bootNotificationCre MicroOcpp::FilesystemOpt adaptFsopt = fsopt; - mocpp_initialize(*ocppSocket, bootNotificationCredentials, MicroOcpp::makeDefaultFilesystemAdapter(adaptFsopt), autoRecover, MicroOcpp::ProtocolVersion(1,6)); + mocpp_initialize(*ocppSocket, bootNotificationCredentials, MicroOcpp::makeDefaultFilesystemAdapter(adaptFsopt), autoRecover, + ocpp201 ? + MicroOcpp::ProtocolVersion(2,0,1) : + MicroOcpp::ProtocolVersion(1,6)); } void ocpp_deinitialize() { diff --git a/src/MicroOcpp_c.h b/src/MicroOcpp_c.h index e0ea2c69..43b48a88 100644 --- a/src/MicroOcpp_c.h +++ b/src/MicroOcpp_c.h @@ -60,14 +60,16 @@ void ocpp_initialize( const char *chargePointModel, //model name of this charger (e.g. "My Charger") const char *chargePointVendor, //brand name (e.g. "My Company Ltd.") struct OCPP_FilesystemOpt fsopt, //If this library should format the flash if necessary. Find further options in ConfigurationOptions.h - bool autoRecover); //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended + bool autoRecover, //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended + bool ocpp201); //true to select OCPP 2.0.1, false for OCPP 1.6 //same as above, but more fields for the BootNotification void ocpp_initialize_full( OCPP_Connection *conn, //WebSocket adapter for MicroOcpp const char *bootNotificationCredentials, //e.g. '{"chargePointModel":"Demo Charger","chargePointVendor":"My Company Ltd."}' (refer to OCPP 1.6 Specification - Edition 2 p. 60) struct OCPP_FilesystemOpt fsopt, //If this library should format the flash if necessary. Find further options in ConfigurationOptions.h - bool autoRecover); //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended + bool autoRecover, //automatically sanitize the local data store when the lib detects recurring crashes. During development, `false` is recommended + bool ocpp201); //true to select OCPP 2.0.1, false for OCPP 1.6 void ocpp_deinitialize(); diff --git a/tests/Api.cpp b/tests/Api.cpp index d8227a60..41f9f8a6 100644 --- a/tests/Api.cpp +++ b/tests/Api.cpp @@ -195,7 +195,7 @@ TEST_CASE( "C API test" ) { fsopt.formatFsOnFail = true; MicroOcpp::LoopbackConnection loopback; - ocpp_initialize(reinterpret_cast(&loopback), "test-runner1234", "vendor", fsopt, false); + ocpp_initialize(reinterpret_cast(&loopback), "test-runner1234", "vendor", fsopt, false, false); auto context = getOcppContext(); auto& model = context->getModel(); From 2046ac25a18a3596365529367cc0c316585c5a72 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Thu, 21 Nov 2024 02:49:37 +0100 Subject: [PATCH 7/9] fix build checks --- examples/ESP-IDF/main/main.c | 2 +- tests/benchmarks/scripts/eval_firmware_size.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/ESP-IDF/main/main.c b/examples/ESP-IDF/main/main.c index 97b6e5b7..b0911702 100644 --- a/examples/ESP-IDF/main/main.c +++ b/examples/ESP-IDF/main/main.c @@ -160,7 +160,7 @@ void app_main(void) EXAMPLE_MO_OCPP_BACKEND, EXAMPLE_MO_CHARGEBOXID, EXAMPLE_MO_AUTHORIZATIONKEY, "", fsopt); - ocpp_initialize(osock, "ESP-IDF charger", "Your brand name here", fsopt, false); + ocpp_initialize(osock, "ESP-IDF charger", "Your brand name here", fsopt, false, false); /* Enter infinite loop */ while (1) { diff --git a/tests/benchmarks/scripts/eval_firmware_size.py b/tests/benchmarks/scripts/eval_firmware_size.py index 7af316e9..a952f7f8 100755 --- a/tests/benchmarks/scripts/eval_firmware_size.py +++ b/tests/benchmarks/scripts/eval_firmware_size.py @@ -100,10 +100,17 @@ def categorize_table(df): df.at['Core/Time.cpp', 'v16'] = TICK df.at['Core/Time.cpp', 'v201'] = TICK df.at['Core/Time.cpp', 'Module'] = MODULE_GENERAL + df.at['Core/UuidUtils.cpp', 'v16'] = TICK + df.at['Core/UuidUtils.cpp', 'v201'] = TICK + df.at['Core/UuidUtils.cpp', 'Module'] = MODULE_GENERAL if 'Debug.cpp' in df.index: df.at['Debug.cpp', 'v16'] = TICK df.at['Debug.cpp', 'v201'] = TICK df.at['Debug.cpp', 'Module'] = MODULE_HAL + if 'Platform.cpp' in df.index: + df.at['Platform.cpp', 'v16'] = TICK + df.at['Platform.cpp', 'v201'] = TICK + df.at['Platform.cpp', 'Module'] = MODULE_HAL df.at['Model/Authorization/AuthorizationData.cpp', 'v16'] = TICK df.at['Model/Authorization/AuthorizationData.cpp', 'Module'] = MODULE_LOCALAUTH df.at['Model/Authorization/AuthorizationList.cpp', 'v16'] = TICK From ed40d8d0b65119f7f94e6f64f141c074d970fea9 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Thu, 21 Nov 2024 02:51:04 +0100 Subject: [PATCH 8/9] enable further v201 benchmarks --- tests/benchmarks/scripts/measure_heap.py | 108 +++++++++++------------ 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/tests/benchmarks/scripts/measure_heap.py b/tests/benchmarks/scripts/measure_heap.py index 8ae75ddc..0b050544 100644 --- a/tests/benchmarks/scripts/measure_heap.py +++ b/tests/benchmarks/scripts/measure_heap.py @@ -15,86 +15,86 @@ # Test case selection (commented out a few to simplify testing for now) testcase_name_list = [ 'TC_B_06_CS', - #'TC_B_07_CS', - #'TC_B_09_CS', + 'TC_B_07_CS', + 'TC_B_09_CS', 'TC_B_10_CS', - #'TC_B_11_CS', - #'TC_B_12_CS', + 'TC_B_11_CS', + 'TC_B_12_CS', 'TC_B_13_CS', - #'TC_B_32_CS', - #'TC_B_34_CS', + 'TC_B_32_CS', + 'TC_B_34_CS', 'TC_B_35_CS', - #'TC_B_36_CS', - #'TC_B_37_CS', + 'TC_B_36_CS', + 'TC_B_37_CS', 'TC_B_39_CS', - #'TC_C_02_CS', - #'TC_C_04_CS', + 'TC_C_02_CS', + 'TC_C_04_CS', 'TC_C_06_CS', - #'TC_C_07_CS', - #'TC_C_49_CS', + 'TC_C_07_CS', + 'TC_C_49_CS', 'TC_E_01_CS', - #'TC_E_02_CS', - #'TC_E_03_CS', + 'TC_E_02_CS', + 'TC_E_03_CS', 'TC_E_04_CS', - #'TC_E_05_CS', - #'TC_E_06_CS', + 'TC_E_05_CS', + 'TC_E_06_CS', 'TC_E_07_CS', - #'TC_E_09_CS', - #'TC_E_13_CS', + 'TC_E_09_CS', + 'TC_E_13_CS', 'TC_E_15_CS', - #'TC_E_17_CS', - #'TC_E_20_CS', + 'TC_E_17_CS', + 'TC_E_20_CS', 'TC_E_21_CS', - #'TC_E_24_CS', - #'TC_E_25_CS', + 'TC_E_24_CS', + 'TC_E_25_CS', 'TC_E_28_CS', - #'TC_E_29_CS', - #'TC_E_30_CS', + 'TC_E_29_CS', + 'TC_E_30_CS', 'TC_E_31_CS', - #'TC_E_32_CS', - #'TC_E_33_CS', + 'TC_E_32_CS', + 'TC_E_33_CS', 'TC_E_34_CS', - #'TC_E_35_CS', - #'TC_E_39_CS', + 'TC_E_35_CS', + 'TC_E_39_CS', 'TC_F_01_CS', - #'TC_F_02_CS', - #'TC_F_03_CS', + 'TC_F_02_CS', + 'TC_F_03_CS', 'TC_F_04_CS', - #'TC_F_05_CS', - #'TC_F_06_CS', + 'TC_F_05_CS', + 'TC_F_06_CS', 'TC_F_07_CS', - #'TC_F_08_CS', - #'TC_F_09_CS', + 'TC_F_08_CS', + 'TC_F_09_CS', 'TC_F_10_CS', - #'TC_F_11_CS', - #'TC_F_12_CS', + 'TC_F_11_CS', + 'TC_F_12_CS', 'TC_F_13_CS', - #'TC_F_14_CS', - #'TC_F_20_CS', + 'TC_F_14_CS', + 'TC_F_20_CS', 'TC_F_23_CS', - #'TC_F_24_CS', - #'TC_F_26_CS', + 'TC_F_24_CS', + 'TC_F_26_CS', 'TC_F_27_CS', - #'TC_G_01_CS', - #'TC_G_02_CS', + 'TC_G_01_CS', + 'TC_G_02_CS', 'TC_G_03_CS', - #'TC_G_04_CS', - #'TC_G_05_CS', + 'TC_G_04_CS', + 'TC_G_05_CS', 'TC_G_06_CS', - #'TC_G_07_CS', - #'TC_G_08_CS', + 'TC_G_07_CS', + 'TC_G_08_CS', 'TC_G_09_CS', - #'TC_G_10_CS', - #'TC_G_11_CS', + 'TC_G_10_CS', + 'TC_G_11_CS', 'TC_G_12_CS', - #'TC_G_13_CS', - #'TC_G_14_CS', + 'TC_G_13_CS', + 'TC_G_14_CS', 'TC_G_15_CS', - #'TC_G_16_CS', - #'TC_G_17_CS', + 'TC_G_16_CS', + 'TC_G_17_CS', 'TC_J_07_CS', - #'TC_J_08_CS', - #'TC_J_09_CS', + 'TC_J_08_CS', + 'TC_J_09_CS', 'TC_J_10_CS', ] From 97194f4b24e432ea1fbd3b48150d8f7be8b88b39 Mon Sep 17 00:00:00 2001 From: matth-x <63792403+matth-x@users.noreply.github.com> Date: Sun, 5 Jan 2025 15:36:28 +0100 Subject: [PATCH 9/9] update changelog --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd630e76..1d531b23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,14 @@ ### Changed -- Change `MicroOcpp::TxNotification` into C-style enum, replace `OCPP_TxNotication` +- Change `MicroOcpp::TxNotification` into C-style enum, replace `OCPP_TxNotication` ([#386](https://github.com/matth-x/MicroOcpp/pull/386)) - Improved UUID generation ([#383](https://github.com/matth-x/MicroOcpp/pull/383)) +- `beginTransaction()` returns bool for better v2.0.1 interop ([#386](https://github.com/matth-x/MicroOcpp/pull/386)) + +### Added + +- `getTransactionV201()` exposes v201 Tx in API ([#386](https://github.com/matth-x/MicroOcpp/pull/386)) +- v201 support in Transaction.h C-API ([#386](https://github.com/matth-x/MicroOcpp/pull/386)) ### Fixed