Skip to content

Commit

Permalink
Minor OCPP 1.6 fixes (#388)
Browse files Browse the repository at this point in the history
* change misleading Reset failure debug msg

* reject negative ints in ChangeConfig
  • Loading branch information
matth-x authored Nov 24, 2024
1 parent 2d5dee9 commit 5761e0f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
### Fixed

- Timing issues for OCTT test cases ([#383](https://github.com/matth-x/MicroOcpp/pull/383))
- Misleading Reset failure dbg msg ([#388](https://github.com/matth-x/MicroOcpp/pull/388))
- Reject negative ints in ChangeConfig ([#388](https://github.com/matth-x/MicroOcpp/pull/388))

## [1.2.0] - 2024-11-03

Expand Down
9 changes: 9 additions & 0 deletions src/MicroOcpp/Core/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,13 @@ bool configuration_clean_unused() {
return configuration_save();
}

bool VALIDATE_UNSIGNED_INT(const char *value) {
for(size_t i = 0; value[i] != '\0'; i++) {
if (value[i] < '0' || value[i] > '9') {
return false;
}
}
return true;
}

} //end namespace MicroOcpp
3 changes: 3 additions & 0 deletions src/MicroOcpp/Core/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@ bool configuration_save();

bool configuration_clean_unused(); //remove configs which haven't been accessed

//default implementation for common validator
bool VALIDATE_UNSIGNED_INT(const char*);

} //end namespace MicroOcpp
#endif
5 changes: 5 additions & 0 deletions src/MicroOcpp/Model/ConnectorBase/Connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ Connector::Connector(Context& context, std::shared_ptr<FilesystemAdapter> filesy
#endif //MO_ENABLE_CONNECTOR_LOCK

connectionTimeOutInt = declareConfiguration<int>("ConnectionTimeOut", 30);
registerConfigurationValidator("ConnectionTimeOut", VALIDATE_UNSIGNED_INT);
minimumStatusDurationInt = declareConfiguration<int>("MinimumStatusDuration", 0);
registerConfigurationValidator("MinimumStatusDuration", VALIDATE_UNSIGNED_INT);
stopTransactionOnInvalidIdBool = declareConfiguration<bool>("StopTransactionOnInvalidId", true);
stopTransactionOnEVSideDisconnectBool = declareConfiguration<bool>("StopTransactionOnEVSideDisconnect", true);
localPreAuthorizeBool = declareConfiguration<bool>("LocalPreAuthorize", false);
Expand All @@ -61,6 +63,7 @@ Connector::Connector(Context& context, std::shared_ptr<FilesystemAdapter> filesy

//how long the EVSE tries the Authorize request before it enters offline mode
authorizationTimeoutInt = MicroOcpp::declareConfiguration<int>(MO_CONFIG_EXT_PREFIX "AuthorizationTimeout", 20);
registerConfigurationValidator(MO_CONFIG_EXT_PREFIX "AuthorizationTimeout", VALIDATE_UNSIGNED_INT);

//FreeVend mode
freeVendActiveBool = declareConfiguration<bool>(MO_CONFIG_EXT_PREFIX "FreeVendActive", false);
Expand All @@ -69,7 +72,9 @@ Connector::Connector(Context& context, std::shared_ptr<FilesystemAdapter> filesy
txStartOnPowerPathClosedBool = declareConfiguration<bool>(MO_CONFIG_EXT_PREFIX "TxStartOnPowerPathClosed", false);

transactionMessageAttemptsInt = declareConfiguration<int>("TransactionMessageAttempts", 3);
registerConfigurationValidator("TransactionMessageAttempts", VALIDATE_UNSIGNED_INT);
transactionMessageRetryIntervalInt = declareConfiguration<int>("TransactionMessageRetryInterval", 60);
registerConfigurationValidator("TransactionMessageRetryInterval", VALIDATE_UNSIGNED_INT);

if (!availabilityBool) {
MO_DBG_ERR("Cannot declare availabilityBool");
Expand Down
1 change: 1 addition & 0 deletions src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ using namespace MicroOcpp;

HeartbeatService::HeartbeatService(Context& context) : MemoryManaged("v16.Heartbeat.HeartbeatService"), context(context) {
heartbeatIntervalInt = declareConfiguration<int>("HeartbeatInterval", 86400);
registerConfigurationValidator("HeartbeatInterval", VALIDATE_UNSIGNED_INT);
lastHeartbeat = mocpp_tick_ms();

//Register message handler for TriggerMessage operation
Expand Down
2 changes: 2 additions & 0 deletions src/MicroOcpp/Model/Metering/MeteringConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ MeteringConnector::MeteringConnector(Context& context, int connectorId, MeterSto
auto meterValuesSampledDataString = declareConfiguration<const char*>("MeterValuesSampledData", "");
declareConfiguration<int>("MeterValuesSampledDataMaxLength", 8, CONFIGURATION_VOLATILE, true);
meterValueSampleIntervalInt = declareConfiguration<int>("MeterValueSampleInterval", 60);
registerConfigurationValidator("MeterValueSampleInterval", VALIDATE_UNSIGNED_INT);

auto stopTxnSampledDataString = declareConfiguration<const char*>("StopTxnSampledData", "");
declareConfiguration<int>("StopTxnSampledDataMaxLength", 8, CONFIGURATION_VOLATILE, true);

auto meterValuesAlignedDataString = declareConfiguration<const char*>("MeterValuesAlignedData", "");
declareConfiguration<int>("MeterValuesAlignedDataMaxLength", 8, CONFIGURATION_VOLATILE, true);
clockAlignedDataIntervalInt = declareConfiguration<int>("ClockAlignedDataInterval", 0);
registerConfigurationValidator("ClockAlignedDataInterval", VALIDATE_UNSIGNED_INT);

auto stopTxnAlignedDataString = declareConfiguration<const char*>("StopTxnAlignedData", "");

Expand Down
14 changes: 2 additions & 12 deletions src/MicroOcpp/Model/Metering/MeteringService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,12 @@ MeteringService::MeteringService(Context& context, int numConn, std::shared_ptr<
return isValid;
};

std::function<bool(const char*)> validateUnsignedIntString = [] (const char *value) {
for(size_t i = 0; value[i] != '\0'; i++)
{
if (value[i] < '0' || value[i] > '9') {
return false;
}
}
return true;
};

registerConfigurationValidator("MeterValuesSampledData", validateSelectString);
registerConfigurationValidator("StopTxnSampledData", validateSelectString);
registerConfigurationValidator("MeterValuesAlignedData", validateSelectString);
registerConfigurationValidator("StopTxnAlignedData", validateSelectString);
registerConfigurationValidator("MeterValueSampleInterval", validateUnsignedIntString);
registerConfigurationValidator("ClockAlignedDataInterval", validateUnsignedIntString);
registerConfigurationValidator("MeterValueSampleInterval", VALIDATE_UNSIGNED_INT);
registerConfigurationValidator("ClockAlignedDataInterval", VALIDATE_UNSIGNED_INT);

/*
* Register further message handlers to support echo mode: when this library
Expand Down
4 changes: 3 additions & 1 deletion src/MicroOcpp/Model/Reset/ResetService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ResetService::ResetService(Context& context)
: MemoryManaged("v16.Reset.ResetService"), context(context) {

resetRetriesInt = declareConfiguration<int>("ResetRetries", 2);
registerConfigurationValidator("ResetRetries", VALIDATE_UNSIGNED_INT);

context.getOperationRegistry().registerOperation("Reset", [&context] () {
return new Ocpp16::Reset(context.getModel());});
Expand All @@ -50,10 +51,11 @@ void ResetService::loop() {
MO_DBG_ERR("No Reset function set! Abort");
outstandingResetRetries = 0;
}
MO_DBG_ERR("Reset device failure. %s", outstandingResetRetries == 0 ? "Abort" : "Retry");

if (outstandingResetRetries <= 0) {

MO_DBG_ERR("Reset device failure. Abort");

ChargePointStatus cpStatus = ChargePointStatus_UNDEFINED;
if (context.getModel().getNumConnectors() > 0) {
cpStatus = context.getModel().getConnector(0)->getStatus();
Expand Down

0 comments on commit 5761e0f

Please sign in to comment.