diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bc492b1..23b58145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/MicroOcpp/Core/Configuration.cpp b/src/MicroOcpp/Core/Configuration.cpp index 9a00fb12..cb0a8ff5 100644 --- a/src/MicroOcpp/Core/Configuration.cpp +++ b/src/MicroOcpp/Core/Configuration.cpp @@ -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 diff --git a/src/MicroOcpp/Core/Configuration.h b/src/MicroOcpp/Core/Configuration.h index f445ffce..486b9c69 100644 --- a/src/MicroOcpp/Core/Configuration.h +++ b/src/MicroOcpp/Core/Configuration.h @@ -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 diff --git a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp index db5833a5..82939863 100644 --- a/src/MicroOcpp/Model/ConnectorBase/Connector.cpp +++ b/src/MicroOcpp/Model/ConnectorBase/Connector.cpp @@ -49,7 +49,9 @@ Connector::Connector(Context& context, std::shared_ptr filesy #endif //MO_ENABLE_CONNECTOR_LOCK connectionTimeOutInt = declareConfiguration("ConnectionTimeOut", 30); + registerConfigurationValidator("ConnectionTimeOut", VALIDATE_UNSIGNED_INT); minimumStatusDurationInt = declareConfiguration("MinimumStatusDuration", 0); + registerConfigurationValidator("MinimumStatusDuration", VALIDATE_UNSIGNED_INT); stopTransactionOnInvalidIdBool = declareConfiguration("StopTransactionOnInvalidId", true); stopTransactionOnEVSideDisconnectBool = declareConfiguration("StopTransactionOnEVSideDisconnect", true); localPreAuthorizeBool = declareConfiguration("LocalPreAuthorize", false); @@ -61,6 +63,7 @@ Connector::Connector(Context& context, std::shared_ptr filesy //how long the EVSE tries the Authorize request before it enters offline mode authorizationTimeoutInt = MicroOcpp::declareConfiguration(MO_CONFIG_EXT_PREFIX "AuthorizationTimeout", 20); + registerConfigurationValidator(MO_CONFIG_EXT_PREFIX "AuthorizationTimeout", VALIDATE_UNSIGNED_INT); //FreeVend mode freeVendActiveBool = declareConfiguration(MO_CONFIG_EXT_PREFIX "FreeVendActive", false); @@ -69,7 +72,9 @@ Connector::Connector(Context& context, std::shared_ptr filesy txStartOnPowerPathClosedBool = declareConfiguration(MO_CONFIG_EXT_PREFIX "TxStartOnPowerPathClosed", false); transactionMessageAttemptsInt = declareConfiguration("TransactionMessageAttempts", 3); + registerConfigurationValidator("TransactionMessageAttempts", VALIDATE_UNSIGNED_INT); transactionMessageRetryIntervalInt = declareConfiguration("TransactionMessageRetryInterval", 60); + registerConfigurationValidator("TransactionMessageRetryInterval", VALIDATE_UNSIGNED_INT); if (!availabilityBool) { MO_DBG_ERR("Cannot declare availabilityBool"); diff --git a/src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp b/src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp index 612c5778..4ebab502 100644 --- a/src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp +++ b/src/MicroOcpp/Model/Heartbeat/HeartbeatService.cpp @@ -13,6 +13,7 @@ using namespace MicroOcpp; HeartbeatService::HeartbeatService(Context& context) : MemoryManaged("v16.Heartbeat.HeartbeatService"), context(context) { heartbeatIntervalInt = declareConfiguration("HeartbeatInterval", 86400); + registerConfigurationValidator("HeartbeatInterval", VALIDATE_UNSIGNED_INT); lastHeartbeat = mocpp_tick_ms(); //Register message handler for TriggerMessage operation diff --git a/src/MicroOcpp/Model/Metering/MeteringConnector.cpp b/src/MicroOcpp/Model/Metering/MeteringConnector.cpp index cba9870f..378232a5 100644 --- a/src/MicroOcpp/Model/Metering/MeteringConnector.cpp +++ b/src/MicroOcpp/Model/Metering/MeteringConnector.cpp @@ -28,6 +28,7 @@ MeteringConnector::MeteringConnector(Context& context, int connectorId, MeterSto auto meterValuesSampledDataString = declareConfiguration("MeterValuesSampledData", ""); declareConfiguration("MeterValuesSampledDataMaxLength", 8, CONFIGURATION_VOLATILE, true); meterValueSampleIntervalInt = declareConfiguration("MeterValueSampleInterval", 60); + registerConfigurationValidator("MeterValueSampleInterval", VALIDATE_UNSIGNED_INT); auto stopTxnSampledDataString = declareConfiguration("StopTxnSampledData", ""); declareConfiguration("StopTxnSampledDataMaxLength", 8, CONFIGURATION_VOLATILE, true); @@ -35,6 +36,7 @@ MeteringConnector::MeteringConnector(Context& context, int connectorId, MeterSto auto meterValuesAlignedDataString = declareConfiguration("MeterValuesAlignedData", ""); declareConfiguration("MeterValuesAlignedDataMaxLength", 8, CONFIGURATION_VOLATILE, true); clockAlignedDataIntervalInt = declareConfiguration("ClockAlignedDataInterval", 0); + registerConfigurationValidator("ClockAlignedDataInterval", VALIDATE_UNSIGNED_INT); auto stopTxnAlignedDataString = declareConfiguration("StopTxnAlignedData", ""); diff --git a/src/MicroOcpp/Model/Metering/MeteringService.cpp b/src/MicroOcpp/Model/Metering/MeteringService.cpp index 287f026a..73ab4deb 100644 --- a/src/MicroOcpp/Model/Metering/MeteringService.cpp +++ b/src/MicroOcpp/Model/Metering/MeteringService.cpp @@ -57,22 +57,12 @@ MeteringService::MeteringService(Context& context, int numConn, std::shared_ptr< return isValid; }; - std::function 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 diff --git a/src/MicroOcpp/Model/Reset/ResetService.cpp b/src/MicroOcpp/Model/Reset/ResetService.cpp index 8335ce42..2eef02b8 100644 --- a/src/MicroOcpp/Model/Reset/ResetService.cpp +++ b/src/MicroOcpp/Model/Reset/ResetService.cpp @@ -29,6 +29,7 @@ ResetService::ResetService(Context& context) : MemoryManaged("v16.Reset.ResetService"), context(context) { resetRetriesInt = declareConfiguration("ResetRetries", 2); + registerConfigurationValidator("ResetRetries", VALIDATE_UNSIGNED_INT); context.getOperationRegistry().registerOperation("Reset", [&context] () { return new Ocpp16::Reset(context.getModel());}); @@ -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();