Skip to content

Commit

Permalink
[ESP32] Fix build failure and Add DeviceEnergyManagement clusters ini…
Browse files Browse the repository at this point in the history
…tialization
  • Loading branch information
jadhavrohit924 committed Jan 22, 2024
1 parent 039cbab commit c9ccd14
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/examples-esp32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,6 @@ jobs:

- name: Build example Lighting App (external platform)
run: scripts/examples/esp_example.sh lighting-app sdkconfig.ext_plat.defaults

- name: Build example Energy Management App
run: scripts/examples/esp_example.sh energy-management-app sdkconfig.defaults
1 change: 1 addition & 0 deletions examples/energy-management-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/time-format-localization-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/barrier-control-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/energy-evse-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/device-energy-management-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/network-commissioning"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/occupancy-sensor-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
Expand Down
48 changes: 38 additions & 10 deletions examples/energy-management-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "DeviceCallbacks.h"
#include <DeviceEnergyManagementManager.h>
#include <EVSEManufacturerImpl.h>
#include <EnergyEvseManager.h>
#include <EnergyManagementManager.h>
Expand Down Expand Up @@ -74,9 +75,11 @@ using namespace ::chip::Credentials;
using namespace ::chip::DeviceManager;
using namespace ::chip::DeviceLayer;

static EnergyEvseDelegate * gDelegate = nullptr;
static EnergyEvseManager * gInstance = nullptr;
static EnergyEvseDelegate * gEvseDelegate = nullptr;
static EnergyEvseManager * gEvseInstance = nullptr;
static EVSEManufacturer * gEvseManufacturer = nullptr;
static DeviceEnergyManagementDelegate * gDEMDelegate = nullptr;
static DeviceEnergyManagementManager * gDEMInstance = nullptr;

#if CONFIG_ENABLE_ESP_INSIGHTS_TRACE
extern const char insights_auth_key_start[] asm("_binary_insights_auth_key_txt_start");
Expand Down Expand Up @@ -116,23 +119,48 @@ chip::Credentials::DeviceAttestationCredentialsProvider * get_dac_provider(void)

} // namespace

EVSEManufacturer * EnergyEvse::GetEvseManufacturer()
{
return gEvseManufacturer;
}

void ApplicationInit()
{
if ((gDelegate == nullptr) && (gInstance == nullptr) && (gEvseManufacturer == nullptr))
if ((gDEMDelegate == nullptr) && (gDEMInstance == nullptr))
{
gDEMDelegate = new DeviceEnergyManagementDelegate();
if (gDEMDelegate != nullptr)
{
gDEMInstance = new DeviceEnergyManagementManager(
EndpointId(ENERGY_EVSE_ENDPOINT), *gDEMDelegate,
BitMask<DeviceEnergyManagement::Feature, uint32_t>(
DeviceEnergyManagement::Feature::kPowerAdjustment, DeviceEnergyManagement::Feature::kPowerForecastReporting,
DeviceEnergyManagement::Feature::kStateForecastReporting, DeviceEnergyManagement::Feature::kStartTimeAdjustment,
DeviceEnergyManagement::Feature::kPausable, DeviceEnergyManagement::Feature::kForecastAdjustment,
DeviceEnergyManagement::Feature::kConstraintBasedAdjustment));
gDEMInstance->Init(); /* Register Attribute & Command handlers */
}
}
else
{
ChipLogError(AppServer, "DEM Instance or Delegate already exist.")
}

if ((gEvseDelegate == nullptr) && (gEvseInstance == nullptr) && (gEvseManufacturer == nullptr))
{
gDelegate = new EnergyEvseDelegate();
if (gDelegate != nullptr)
gEvseDelegate = new EnergyEvseDelegate();
if (gEvseDelegate != nullptr)
{
gInstance = new EnergyEvseManager(
EndpointId(ENERGY_EVSE_ENDPOINT), *gDelegate,
gEvseInstance = new EnergyEvseManager(
EndpointId(ENERGY_EVSE_ENDPOINT), *gEvseDelegate,
BitMask<EnergyEvse::Feature, uint32_t>(EnergyEvse::Feature::kChargingPreferences,
EnergyEvse::Feature::kPlugAndCharge, EnergyEvse::Feature::kRfid,
EnergyEvse::Feature::kSoCReporting, EnergyEvse::Feature::kV2x),
BitMask<OptionalAttributes, uint32_t>(OptionalAttributes::kSupportsUserMaximumChargingCurrent,
OptionalAttributes::kSupportsRandomizationWindow,
OptionalAttributes::kSupportsApproximateEvEfficiency),
BitMask<OptionalCommands, uint32_t>(OptionalCommands::kSupportsStartDiagnostics));
gInstance->Init(); /* Register Attribute & Command handlers */
gEvseInstance->Init(); /* Register Attribute & Command handlers */
}
}
else
Expand All @@ -142,8 +170,8 @@ void ApplicationInit()

if (gEvseManufacturer == nullptr)
{
gEvseManufacturer = new EVSEManufacturer();
gEvseManufacturer->Init(gInstance);
gEvseManufacturer = new EVSEManufacturer(gEvseInstance);
gEvseManufacturer->Init();
}
else
{
Expand Down

0 comments on commit c9ccd14

Please sign in to comment.