Skip to content

Commit

Permalink
Smart Charging module fixes (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
matth-x authored Feb 17, 2024
1 parent 12d4868 commit dc2cdaa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Allow `nullptr` as parameter for `mocpp_set_console_out` ([#224](https://github.com/matth-x/MicroOcpp/issues/224))
- Fix `mocpp_tick_ms()` on esp-idf roll-over after 12 hours
- Pin ArduinoJson to v6.21 ([#245](https://github.com/matth-x/MicroOcpp/issues/245))
- Fix bounds checking in SmartCharging module ([#260](https://github.com/matth-x/MicroOcpp/pull/260))

## [1.0.0] - 2023-10-22

Expand Down
5 changes: 5 additions & 0 deletions src/MicroOcpp/Model/SmartCharging/SmartChargingModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ bool MicroOcpp::loadChargingSchedule(JsonObject& json, ChargingSchedule& out) {
return false;
}

if (periodJsonArray.size() > CHARGINGSCHEDULEMAXPERIODS) {
MO_DBG_WARN("exceed ChargingScheduleMaxPeriods");
return false;
}

for (JsonObject periodJson : periodJsonArray) {
out.chargingSchedulePeriod.push_back(ChargingSchedulePeriod());
if (!loadChargingSchedulePeriod(periodJson, out.chargingSchedulePeriod.back())) {
Expand Down
4 changes: 2 additions & 2 deletions src/MicroOcpp/Model/SmartCharging/SmartChargingService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ std::unique_ptr<ChargingSchedule> SmartChargingConnector::getCompositeSchedule(i
size_t SmartChargingConnector::getChargingProfilesCount() {
size_t chargingProfilesCount = 0;
for (size_t i = 0; i < CHARGEPROFILEMAXSTACKLEVEL + 1; i++) {
if (ChargePointTxDefaultProfile[i]) {
if (TxDefaultProfile[i]) {
chargingProfilesCount++;
}
if (ChargePointMaxProfile[i]) {
if (TxProfile[i]) {
chargingProfilesCount++;
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/MicroOcpp/Operations/SetChargingProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,21 @@ void SetChargingProfile::processReq(JsonObject payload) {
errorCode = "PropertyConstraintViolation";
return;
}
if (!connector->getTransaction() || !connector->getTransaction()->isRunning()) {

auto& transaction = connector->getTransaction();
if (!transaction || !connector->getTransaction()->isRunning()) {
//no transaction running, reject profile
accepted = false;
return;
}

if (chargingProfile->getTransactionId() < 0 ||
chargingProfile->getTransactionId() != transaction->getTransactionId()) {
//transactionId undefined / mismatch
accepted = false;
return;
}

//seems good
} else if (chargingProfile->getChargingProfilePurpose() == ChargingProfilePurposeType::ChargePointMaxProfile) {
if (connectorId > 0) {
Expand Down

0 comments on commit dc2cdaa

Please sign in to comment.