Skip to content
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

StatusNotification error severity mechanism & report resolved errors #331

Merged
merged 6 commits into from
Jul 23, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- Provide ChargePointStatus in API ([#309](https://github.com/matth-x/MicroOcpp/pull/309))
- Built-in OTA over FTP ([#313](https://github.com/matth-x/MicroOcpp/pull/313))
- Built-in Diagnostics over FTP ([#313](https://github.com/matth-x/MicroOcpp/pull/313))
- Error `severity` mechanism ([#331](https://github.com/matth-x/MicroOcpp/pull/331))
- Build flag `MO_REPORT_NOERROR` to report error recovery ([#331](https://github.com/matth-x/MicroOcpp/pull/331))

### Removed

Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ set(MO_SRC_UNIT
tests/Transactions.cpp
tests/Certificates.cpp
tests/FirmwareManagement.cpp
tests/ChargePointError.cpp
)

add_executable(mo_unit_tests
Expand Down Expand Up @@ -191,6 +192,7 @@ target_compile_definitions(mo_unit_tests PUBLIC
MO_MaxChargingProfilesInstalled=3
MO_ENABLE_CERT_MGMT=1
MO_ENABLE_CONNECTOR_LOCK=1
MO_REPORT_NOERROR=1
)

target_compile_options(mo_unit_tests PUBLIC
Expand Down
3 changes: 3 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/ChargePointErrorData.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
#ifndef MO_CHARGEPOINTERRORCODE_H
#define MO_CHARGEPOINTERRORCODE_H

#include <stdint.h>

namespace MicroOcpp {

struct ErrorData {
bool isError = false; //if any error information is set
bool isFaulted = false; //if this is a severe error and the EVSE should go into the faulted state
uint8_t severity = 1; //severity: don't send less severe errors during highly severe error condition
const char *errorCode = nullptr; //see ChargePointErrorCode (p. 76/77) for possible values
const char *info = nullptr; //Additional free format information related to the error
const char *vendorId = nullptr; //vendor-specific implementation identifier
Expand Down
57 changes: 42 additions & 15 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,29 +408,52 @@ void Connector::loop() {
freeVendTrackPlugged = connectorPluggedInput();
}

auto status = getStatus();
ErrorData errorData {nullptr};
errorData.severity = 0;
int errorDataIndex = -1;

if (model.getVersion().major == 1) {
//OCPP 1.6: use StatusNotification to send error codes

if (reportedErrorIndex >= 0) {
auto error = errorDataInputs[reportedErrorIndex].operator()();
if (error.isError) {
errorData = error;
errorDataIndex = reportedErrorIndex;
}
}

for (auto i = std::min(errorDataInputs.size(), trackErrorDataInputs.size()); i >= 1; i--) {
auto index = i - 1;
auto error = errorDataInputs[index].operator()();
if (error.isError && !trackErrorDataInputs[index]) {
ErrorData error {nullptr};
if ((int)index != errorDataIndex) {
error = errorDataInputs[index].operator()();
} else {
error = errorData;
}
if (error.isError && !trackErrorDataInputs[index] && error.severity >= errorData.severity) {
//new error
auto statusNotification = makeRequest(
new Ocpp16::StatusNotification(connectorId, status, model.getClock().now(), error));
statusNotification->setTimeout(0);
context.initiateRequest(std::move(statusNotification));

currentStatus = status;
reportedStatus = status;
trackErrorDataInputs[index] = true;
errorData = error;
errorDataIndex = index;
} else if (error.isError && error.severity > errorData.severity) {
errorData = error;
errorDataIndex = index;
} else if (!error.isError && trackErrorDataInputs[index]) {
//reset error
trackErrorDataInputs[index] = false;
}
}
}

if (errorDataIndex != reportedErrorIndex) {
if (errorDataIndex >= 0 || MO_REPORT_NOERROR) {
reportedStatus = ChargePointStatus_UNDEFINED; //trigger sending currentStatus again with code NoError
} else {
reportedErrorIndex = -1;
}
}
} //if (model.getVersion().major == 1)

auto status = getStatus();

if (status != currentStatus) {
MO_DBG_DEBUG("Status changed %s -> %s %s",
Expand All @@ -446,6 +469,10 @@ void Connector::loop() {
(minimumStatusDurationInt->getInt() <= 0 || //MinimumStatusDuration disabled
mocpp_tick_ms() - t_statusTransition >= ((unsigned long) minimumStatusDurationInt->getInt()) * 1000UL)) {
reportedStatus = currentStatus;
reportedErrorIndex = errorDataIndex;
if (errorDataIndex >= 0) {
trackErrorDataInputs[errorDataIndex] = true;
}
Timestamp reportedTimestamp = model.getClock().now();
reportedTimestamp -= (mocpp_tick_ms() - t_statusTransition) / 1000UL;

Expand All @@ -456,7 +483,7 @@ void Connector::loop() {
new Ocpp201::StatusNotification(connectorId, reportedStatus, reportedTimestamp)) :
#endif //MO_ENABLE_V201
makeRequest(
new Ocpp16::StatusNotification(connectorId, reportedStatus, reportedTimestamp, getErrorCode()));
new Ocpp16::StatusNotification(connectorId, reportedStatus, reportedTimestamp, errorData));

statusNotification->setTimeout(0);
context.initiateRequest(std::move(statusNotification));
Expand All @@ -477,8 +504,8 @@ bool Connector::isFaulted() {
}

const char *Connector::getErrorCode() {
for (auto i = errorDataInputs.size(); i >= 1; i--) {
auto error = errorDataInputs[i-1].operator()();
if (reportedErrorIndex >= 0) {
auto error = errorDataInputs[reportedErrorIndex].operator()();
if (error.isError && error.errorCode) {
return error.errorCode;
}
Expand Down
5 changes: 5 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/Connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <functional>
#include <memory>

#ifndef MO_REPORT_NOERROR
#define MO_REPORT_NOERROR 0
#endif

namespace MicroOcpp {

class Context;
Expand All @@ -41,6 +45,7 @@ class Connector {
std::function<bool()> evseReadyInput;
std::vector<std::function<ErrorData ()>> errorDataInputs;
std::vector<bool> trackErrorDataInputs;
int reportedErrorIndex = -1; //last reported error
bool isFaulted();
const char *getErrorCode();

Expand Down
Loading
Loading