Skip to content

Commit

Permalink
EVSE - Update FakeReadings when a MaxChargeCurrent change occurs (pro…
Browse files Browse the repository at this point in the history
…ject-chip#35346)

* Updated FakeReadings when a MaxChargeCurrent change is made so that the readings are more representative of a real EV.

* Restyled by whitespace

* Removed using namespace from header file and added chip:: back into the type defintion since build fails.

* Apply suggestions from code review

Co-authored-by: Andrei Litvin <[email protected]>

* Apply suggestions from code review

* Restyled by clang-format

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: Andrei Litvin <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent ed3403d commit 44f8837
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ class EVSEManufacturer : public DEMManufacturerDelegate
*/
static void FakeReadingsTimerExpiry(System::Layer * systemLayer, void * manufacturer);

/*
* @brief Updates the parameters used to generate fake power and energy readings
*
* @param maximumChargeCurrent Maximum Charge current in mA
*/
void UpdateEVFakeReadings(const Amperage_mA maximumChargeCurrent);

private:
EnergyEvseManager * mEvseInstance;
ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * mEPMInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <EnergyTimeUtils.h>

#include <EnergyTimeUtils.h>
#include <FakeReadings.h>
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
#include <app/clusters/electrical-energy-measurement-server/EnergyReportingTestEventTriggerHandler.h>
#include <app/clusters/electrical-energy-measurement-server/electrical-energy-measurement-server.h>
Expand Down Expand Up @@ -551,6 +552,13 @@ CHIP_ERROR EVSEManufacturer::SendPeriodicEnergyReading(EndpointId aEndpointId, i
return CHIP_NO_ERROR;
}

void EVSEManufacturer::UpdateEVFakeReadings(const Amperage_mA maximumChargeCurrent)
{
FakeReadings::GetInstance().SetCurrent(maximumChargeCurrent);
// Note we have to divide by 1000 to make ma * mv = mW
FakeReadings::GetInstance().SetPower((FakeReadings::GetInstance().GetVoltage() * maximumChargeCurrent) / 1000);
}

/**
* @brief Main Callback handler - to be implemented by Manufacturer
*
Expand All @@ -573,6 +581,7 @@ void EVSEManufacturer::ApplicationCallbackHandler(const EVSECbInfo * cb, intptr_
ChipLogProgress(AppServer, "EVSE callback - maxChargeCurrent changed to %ld",
static_cast<long>(cb->ChargingCurrent.maximumChargeCurrent));
pClass->ComputeChargingSchedule();
pClass->UpdateEVFakeReadings(cb->ChargingCurrent.maximumChargeCurrent);
break;
case EVSECallbackType::EnergyMeterReadingRequested:
ChipLogProgress(AppServer, "EVSE callback - EnergyMeterReadingRequested");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#pragma once

#include <app/util/basic-types.h>
#include <lib/core/DataModelTypes.h>
#include <system/SystemLayer.h>

Expand Down Expand Up @@ -58,6 +59,15 @@ class FakeReadings
*/
void FakeReadingsUpdate();

void SetPower(chip::Power_mW power_mW);
chip::Power_mW GetPower();

void SetVoltage(chip::Voltage_mV voltage_mV);
chip::Voltage_mV GetVoltage();

void SetCurrent(chip::Amperage_mA current_mA);
chip::Amperage_mA GetCurrent();

/**
* @brief Timer expiry callback to handle fake load
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,28 @@ void FakeReadings::FakeReadingsTimerExpiry(System::Layer * systemLayer, void * m

mn->FakeReadingsUpdate();
}

void FakeReadings::SetPower(Power_mW aPower_mW)
{
mPower_mW = aPower_mW;
}
Power_mW FakeReadings::GetPower()
{
return mPower_mW;
};
void FakeReadings::SetVoltage(Voltage_mV aVoltage_mV)
{
mVoltage_mV = aVoltage_mV;
}
Voltage_mV FakeReadings::GetVoltage()
{
return mVoltage_mV;
};
void FakeReadings::SetCurrent(Amperage_mA aCurrent_mA)
{
mCurrent_mA = aCurrent_mA;
}
Amperage_mA FakeReadings::GetCurrent()
{
return mCurrent_mA;
}

0 comments on commit 44f8837

Please sign in to comment.