Skip to content

Fix reported defects #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 19, 2024
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

### Changed

- Replace `PollResult<bool>` with enum `UnlockConnectorResult`
- Rename master branch into main

### Added

- File index ([#270](https://github.com/matth-x/MicroOcpp/pull/270))
- Config `Cst_TxStartOnPowerPathClosed` to put back TxStartPoint
- Build flags for customizing memory limits of SmartCharging
- Operation GetInstalledCertificateIds, UC M03 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
- Operation DeleteCertificate, UC M04 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
- Operation InstallCertificate, UC M05 ([#262](https://github.com/matth-x/MicroOcpp/pull/262))
Expand All @@ -19,9 +23,15 @@

### Fixed

- Fix defect idTag check in `endTransaction`
- Make field localAuthorizationList in SendLocalList optional
- Update charging profiles when flash disabled (relates to [#260](https://github.com/matth-x/MicroOcpp/pull/260))
- Ignore UnlockConnector when handler not set
- Reject ChargingProfile if unit not supported
- Fix building with debug level warn and error
- Fix transaction freeze in offline mode ([#279](https://github.com/matth-x/MicroOcpp/pull/279))
- Fix compilation error caused by `PRId32` ([#279](https://github.com/matth-x/MicroOcpp/pull/279))
- Don't load FW-mngt. module when no handlers set

## [1.0.3] - 2024-04-06

Expand Down
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# matth-x/MicroOcpp
# Copyright Matthias Akstaller 2019 - 2023
# Copyright Matthias Akstaller 2019 - 2024
# MIT License

cmake_minimum_required(VERSION 3.15)
Expand Down Expand Up @@ -104,8 +104,6 @@ if(ESP_PLATFORM)

target_compile_options(${COMPONENT_TARGET} PUBLIC
-DMO_PLATFORM=MO_PLATFORM_ESPIDF
-DMO_CUSTOM_WS
-DMO_CUSTOM_UPDATER
-DMO_CUSTOM_RESET
)

Expand All @@ -124,8 +122,6 @@ target_include_directories(MicroOcpp PUBLIC

target_compile_definitions(MicroOcpp PUBLIC
MO_PLATFORM=MO_PLATFORM_UNIX
MO_CUSTOM_WS
MO_CUSTOM_UPDATER
MO_CUSTOM_RESET
)

Expand Down Expand Up @@ -172,8 +168,6 @@ target_compile_definitions(mo_unit_tests PUBLIC
MO_PLATFORM=MO_PLATFORM_UNIX
MO_NUMCONNECTORS=3
MO_CUSTOM_TIMER
MO_CUSTOM_WS
MO_CUSTOM_UPDATER
MO_CUSTOM_RESET
MO_DBG_LEVEL=MO_DL_DEBUG
MO_TRAFFIC_OUT
Expand All @@ -182,9 +176,13 @@ target_compile_definitions(mo_unit_tests PUBLIC
MO_SendLocalListMaxLength=4
MO_ENABLE_FILE_INDEX=1
#MO_ENABLE_MBEDTLS=1
MO_ChargeProfileMaxStackLevel=2
MO_ChargingScheduleMaxPeriods=4
MO_MaxChargingProfilesInstalled=3
)

target_compile_options(mo_unit_tests PUBLIC
-Wall
-O0
-g
--coverage
Expand Down
49 changes: 28 additions & 21 deletions src/MicroOcpp.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2023
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#include "MicroOcpp.h"
Expand Down Expand Up @@ -314,21 +314,12 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
new CertificateService(*context, std::move(certStoreUse))));
}

#if !defined(MO_CUSTOM_UPDATER) && !defined(MO_CUSTOM_WS)
#if MO_PLATFORM == MO_PLATFORM_ARDUINO && !defined(MO_CUSTOM_UPDATER)
#if defined(ESP32) || defined(ESP8266)
model.setFirmwareService(std::unique_ptr<FirmwareService>(
EspWiFi::makeFirmwareService(*context))); //instantiate FW service + ESP installation routine
#else
model.setFirmwareService(std::unique_ptr<FirmwareService>(
new FirmwareService(*context))); //only instantiate FW service
#endif

#if !defined(MO_CUSTOM_DIAGNOSTICS) && !defined(MO_CUSTOM_WS)
model.setDiagnosticsService(std::unique_ptr<DiagnosticsService>(
EspWiFi::makeDiagnosticsService(*context))); //will only return "Rejected" because client needs to implement logging
#else
model.setDiagnosticsService(std::unique_ptr<DiagnosticsService>(
new DiagnosticsService(*context)));
#endif
makeDefaultFirmwareService(*context))); //instantiate FW service + ESP installation routine
#endif //defined(ESP32) || defined(ESP8266)
#endif //MO_PLATFORM == MO_PLATFORM_ARDUINO && !defined(MO_CUSTOM_UPDATER)

#if MO_PLATFORM == MO_PLATFORM_ARDUINO && (defined(ESP32) || defined(ESP8266))
if (!model.getResetService()->getExecuteReset())
Expand Down Expand Up @@ -437,7 +428,7 @@ bool endTransaction(const char *idTag, const char *reason, unsigned int connecto
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
if (!idTag || !strcmp(idTag, getTransactionIdTag())) {
if (!idTag || !strcmp(idTag, getTransactionIdTag(connectorId))) {
res = endTransaction_authorized(idTag, reason, connectorId);
} else {
MO_DBG_INFO("endTransaction: idTag doesn't match");
Expand Down Expand Up @@ -845,7 +836,7 @@ void setTxNotificationOutput(std::function<void(MicroOcpp::Transaction*,MicroOcp
connector->setTxNotificationOutput(notificationOutput);
}

void setOnUnlockConnectorInOut(std::function<PollResult<bool>()> onUnlockConnectorInOut, unsigned int connectorId) {
void setOnUnlockConnectorInOut(std::function<UnlockConnectorResult()> onUnlockConnectorInOut, unsigned int connectorId) {
if (!context) {
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
return;
Expand Down Expand Up @@ -895,19 +886,35 @@ void setOnResetExecute(std::function<void(bool)> onResetExecute) {
}
}

#if defined(MO_CUSTOM_UPDATER) || defined(MO_CUSTOM_WS)
FirmwareService *getFirmwareService() {
if (!context) {
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
return nullptr;
}

auto& model = context->getModel();
if (!model.getFirmwareService()) {
model.setFirmwareService(std::unique_ptr<FirmwareService>(
new FirmwareService(*context)));
}

return model.getFirmwareService();
}
#endif

#if defined(MO_CUSTOM_DIAGNOSTICS) || defined(MO_CUSTOM_WS)
DiagnosticsService *getDiagnosticsService() {
if (!context) {
MO_DBG_ERR("OCPP uninitialized"); //need to call mocpp_initialize before
return nullptr;
}

auto& model = context->getModel();
if (!model.getDiagnosticsService()) {
model.setDiagnosticsService(std::unique_ptr<DiagnosticsService>(
new DiagnosticsService(*context)));
}

return model.getDiagnosticsService();
}
#endif

Context *getOcppContext() {
return context;
Expand Down
32 changes: 21 additions & 11 deletions src/MicroOcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include <MicroOcpp/Core/FilesystemAdapter.h>
#include <MicroOcpp/Core/RequestCallbacks.h>
#include <MicroOcpp/Core/Connection.h>
#include <MicroOcpp/Core/PollResult.h>
#include <MicroOcpp/Model/Metering/SampledValue.h>
#include <MicroOcpp/Model/Transactions/Transaction.h>
#include <MicroOcpp/Model/ConnectorBase/Notification.h>
#include <MicroOcpp/Model/ConnectorBase/ChargePointErrorData.h>
#include <MicroOcpp/Model/ConnectorBase/UnlockConnectorResult.h>
#include <MicroOcpp/Version.h>
#include <MicroOcpp/Model/Certificates/Certificate.h>

Expand Down Expand Up @@ -305,10 +305,12 @@ void setTxNotificationOutput(std::function<void(MicroOcpp::Transaction*,MicroOcp
/*
* Set an InputOutput (reads and sets information at the same time) for forcing to unlock the
* connector. Called as part of the OCPP operation "UnlockConnector"
* Return values: true on success, false on failure, PollResult::Await if not known yet
* Continues to call the Cb as long as it returns PollResult::Await
* Return values:
* - UnlockConnectorResult_Pending if action needs more time to complete (MO will call this cb again later or eventually timeout)
* - UnlockConnectorResult_Unlocked if successful
* - UnlockConnectorResult_UnlockFailed if not successful (e.g. lock stuck)
*/
void setOnUnlockConnectorInOut(std::function<MicroOcpp::PollResult<bool>()> onUnlockConnectorInOut, unsigned int connectorId = 1);
void setOnUnlockConnectorInOut(std::function<UnlockConnectorResult()> onUnlockConnectorInOut, unsigned int connectorId = 1);

/*
* Access further information about the internal state of the library
Expand All @@ -324,28 +326,35 @@ void setOnResetNotify(std::function<bool(bool)> onResetNotify); //call onResetNo

void setOnResetExecute(std::function<void(bool)> onResetExecute); //reset handler. This function should reboot this controller immediately. Already defined for the ESP32 on Arduino

#if defined(MO_CUSTOM_UPDATER) || defined(MO_CUSTOM_WS)
#include <MicroOcpp/Model/FirmwareManagement/FirmwareService.h>

namespace MicroOcpp {
class FirmwareService;
class DiagnosticsService;
}

/*
* You need to configure this object if FW updates are relevant for you. This project already
* brings a simple configuration for the ESP32 and ESP8266 for prototyping purposes, however
* for the productive system you will have to develop a configuration targeting the specific
* OCPP backend.
* See MicroOcpp/Model/FirmwareManagement/FirmwareService.h
* See MicroOcpp/Model/FirmwareManagement/FirmwareService.h
*
* Lazy initialization: The FW Service will be created at the first call to this function
*
* To use, add `#include <MicroOcpp/Model/FirmwareManagement/FirmwareService.h>`
*/
MicroOcpp::FirmwareService *getFirmwareService();
#endif

#if defined(MO_CUSTOM_DIAGNOSTICS) || defined(MO_CUSTOM_WS)
#include <MicroOcpp/Model/Diagnostics/DiagnosticsService.h>
/*
* This library implements the OCPP messaging side of Diagnostics, but no logging or the
* log upload to your backend.
* To integrate Diagnostics, see MicroOcpp/Model/Diagnostics/DiagnosticsService.h
*
* Lazy initialization: The Diag Service will be created at the first call to this function
*
* To use, add `#include <MicroOcpp/Model/Diagnostics/DiagnosticsService.h>`
*/
MicroOcpp::DiagnosticsService *getDiagnosticsService();
#endif

/*
* Add features and customize the behavior of the OCPP client
Expand All @@ -357,6 +366,7 @@ class Context;

//Get access to internal functions and data structures. The returned Context object allows
//you to bypass the facade functions of this header and implement custom functionality.
//To use, add `#include <MicroOcpp/Core/Context.h>`
MicroOcpp::Context *getOcppContext();

/*
Expand Down
51 changes: 0 additions & 51 deletions src/MicroOcpp/Core/PollResult.h

This file was deleted.

25 changes: 19 additions & 6 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Connector::Connector(Context& context, int connectorId)
freeVendActiveBool = declareConfiguration<bool>(MO_CONFIG_EXT_PREFIX "FreeVendActive", false);
freeVendIdTagString = declareConfiguration<const char*>(MO_CONFIG_EXT_PREFIX "FreeVendIdTag", "");

txStartOnPowerPathClosedBool = declareConfiguration<bool>(MO_CONFIG_EXT_PREFIX "TxStartOnPowerPathClosed", false);

if (!availabilityBool) {
MO_DBG_ERR("Cannot declare availabilityBool");
}
Expand Down Expand Up @@ -163,10 +165,20 @@ bool Connector::ocppPermitsCharge() {
suspendDeAuthorizedIdTag = false;
}

return transaction &&
transaction->isRunning() &&
transaction->isActive() &&
!suspendDeAuthorizedIdTag;
// check charge permission depending on TxStartPoint
if (txStartOnPowerPathClosedBool && txStartOnPowerPathClosedBool->getBool()) {
// tx starts when the power path is closed. Advertise charging before transaction
return transaction &&
transaction->isActive() &&
transaction->isAuthorized() &&
!suspendDeAuthorizedIdTag;
} else {
// tx must be started before the power path can be closed
return transaction &&
transaction->isRunning() &&
transaction->isActive() &&
!suspendDeAuthorizedIdTag;
}
}

void Connector::loop() {
Expand Down Expand Up @@ -256,6 +268,7 @@ void Connector::loop() {
if (transaction->isActive() && transaction->isAuthorized() && //tx must be authorized
(!connectorPluggedInput || connectorPluggedInput()) && //if applicable, connector must be plugged
isOperative() && //only start tx if charger is free of error conditions
(!txStartOnPowerPathClosedBool || !txStartOnPowerPathClosedBool->getBool() || !evReadyInput || evReadyInput()) && //if applicable, postpone tx start point to PowerPathClosed
(!startTxReadyInput || startTxReadyInput())) { //if defined, user Input for allowing StartTx must be true
//start Transaction

Expand Down Expand Up @@ -886,11 +899,11 @@ void Connector::addErrorDataInput(std::function<ErrorData ()> errorDataInput) {
this->trackErrorDataInputs.push_back(false);
}

void Connector::setOnUnlockConnector(std::function<PollResult<bool>()> unlockConnector) {
void Connector::setOnUnlockConnector(std::function<UnlockConnectorResult()> unlockConnector) {
this->onUnlockConnector = unlockConnector;
}

std::function<PollResult<bool>()> Connector::getOnUnlockConnector() {
std::function<UnlockConnectorResult()> Connector::getOnUnlockConnector() {
return this->onUnlockConnector;
}

Expand Down
Loading
Loading