Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVSE Delegate callbacks to user application #30999

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
874d750
Fix #30665 (EVSE)
jamesharrow Nov 29, 2023
35a06a7
Fix #30665 updates to try to get further with ZAP and autogen, but st…
jamesharrow Nov 29, 2023
c3aef3a
Added ember-compatibility-functions.cpp which was missing.
jamesharrow Nov 29, 2023
a71bef8
Made all types all lowercase to resolve regen_all issues.
jamesharrow Nov 29, 2023
41acd01
Fixed lint issue (trailing whitespace).
jamesharrow Nov 29, 2023
d7636ea
Merge branch '30665-13-updates-needed-on-evse-xml-device-energy-manag…
jamesharrow Dec 4, 2023
e12cf09
Fixes #30727 - Added initial EVSE cluster and Example Energy Managame…
jamesharrow Dec 4, 2023
f27b036
Tidied up old comments.
jamesharrow Dec 4, 2023
c0651fe
Restyled by whitespace
restyled-commits Dec 4, 2023
557f7c5
Restyled by gn
restyled-commits Dec 4, 2023
6763533
Restyled by prettier-markdown
restyled-commits Dec 4, 2023
53fa295
Added copy of files to all-clusters-app linux BUILD.gn and did basic …
jamesharrow Dec 5, 2023
e47f734
Fixed lint error (Remove PRId64)
jamesharrow Dec 5, 2023
7434ae8
Fix for Documentation Build and publish checker.
jamesharrow Dec 5, 2023
d9c3550
Merge branch 'upstream-master' into 30727-add-evse-to-examplesenergy-…
jamesharrow Dec 5, 2023
b88e826
Updated all-clusters-app.zap after merge and regen_all
jamesharrow Dec 5, 2023
8b92700
Added Cluster to ESP32 CMakeLists.txt
jamesharrow Dec 5, 2023
a368a5d
Fixed ESP32 compile error caused by %d
jamesharrow Dec 5, 2023
c96744a
Added missing source files to each build variant
jamesharrow Dec 5, 2023
68479cc
Restyled by gn
restyled-commits Dec 5, 2023
919fafb
Fixed incorrect uint64_t in EnableCharging/EnableDischarging command
jamesharrow Dec 5, 2023
2cab312
Fixed more issues seen on different platforms
jamesharrow Dec 5, 2023
293cdbf
Removed unused mEndpointId
jamesharrow Dec 5, 2023
f44f52a
Add source files to shell standalone BUILD.gn, More %d fixes for dif…
jamesharrow Dec 5, 2023
43b98d4
Restyled by gn
restyled-commits Dec 5, 2023
fc54724
Removed unused mMinimumChargingCurrentLimitFromCommand
jamesharrow Dec 6, 2023
d3752ba
Removed yet more unused variables
jamesharrow Dec 6, 2023
a14846a
Fixed missing semi-colon. How did the other compilers not pick this up?
jamesharrow Dec 6, 2023
04a12f7
Capitalise function names
jamesharrow Dec 6, 2023
49acb7f
PR comment - Moved PluginServerInitCallback to sdk. Capitalised more …
jamesharrow Dec 6, 2023
a2240c5
Restyled by whitespace
restyled-commits Dec 6, 2023
ee824c0
Fixes #30805 Updated energy-evse-cluster.xml
jamesharrow Dec 6, 2023
2947b9b
Fixes #30805 zap_regen_all commit.
jamesharrow Dec 6, 2023
0015eb8
Merge branch 'project-chip:master' into 30727-add-evse-to-examplesene…
jamesharrow Dec 6, 2023
271031c
Made Fault Event allow a nullable SessionID
jamesharrow Dec 7, 2023
b886c71
Updates based on review (use kMaximumChargeCurrent instead of duplica…
jamesharrow Dec 9, 2023
adbb15e
Added RFID Event support. Removed more unnecessary chip::
jamesharrow Dec 9, 2023
a2917b6
Added Feature flags, optional commands and optional attributes.
jamesharrow Dec 10, 2023
e34b523
Made command handling conditional based on features
jamesharrow Dec 10, 2023
3b97de1
Added Feature support to all-clusters-app
jamesharrow Dec 10, 2023
da7a3fb
Restyled by clang-format
restyled-commits Dec 10, 2023
e2652ec
Fix to Darwin compile error - not checking strcmp return
jamesharrow Dec 11, 2023
a9a7e8f
Attempt to fix Darwin errors (return after else)
jamesharrow Dec 11, 2023
f719610
Merge branch 'upstream-master' into 30727-add-evse-to-examplesenergy-…
jamesharrow Dec 11, 2023
2ff5a27
Updated based on latest upstream master
jamesharrow Dec 11, 2023
11b0151
Removed unnecessary mInstance and used 'this' instead.
jamesharrow Dec 11, 2023
774790d
Merge remote-tracking branch 'upstream/master' into 30727-add-evse-to…
jamesharrow Dec 11, 2023
893c6e5
Regen_all after merge to master.
jamesharrow Dec 11, 2023
68d3ea6
Merge branch 'master' into 30727-add-evse-to-examplesenergy-managemen…
jamesharrow Dec 12, 2023
30e6e8b
Fix review comment.
jamesharrow Dec 12, 2023
98f5d2a
Merge branch 'upstream-master' into 30727-add-evse-to-examplesenergy-…
jamesharrow Dec 12, 2023
51dd8cc
Ensure Init() returns a failure if there is one. Aligned to mode-base…
jamesharrow Dec 12, 2023
48dd130
Backed out Read attr check based on features.
jamesharrow Dec 12, 2023
f5928e7
Fixed EnumerateAcceptedCommands to handle Loop::Break condition.
jamesharrow Dec 12, 2023
2fba294
Had missed StartDiagnostic as an optional command in InvokeCommand
jamesharrow Dec 12, 2023
70d9cbe
Removed extra chip:: in attr types.
jamesharrow Dec 12, 2023
2feb493
Updated HwSetVehicleID to copy the value from callee
jamesharrow Dec 13, 2023
ebe0d14
Fixed potential buffer overrun in HwSetVehicleID.
jamesharrow Dec 13, 2023
bd0461c
Merge branch 'master' into 30727-add-evse-to-examplesenergy-managemen…
jamesharrow Dec 13, 2023
90d5c0f
Fixed simple to address comments raised by Andrei in PR 30857
jamesharrow Dec 13, 2023
3f7560d
Fixed simple to address comments raised by Andrei in PR 30857
jamesharrow Dec 13, 2023
50cad61
Check Delegate is initialized before calling functions.
jamesharrow Dec 14, 2023
848fb88
Check Delegate is initialized before calling functions.
jamesharrow Dec 14, 2023
5a97d39
Added callbacks into Application code
jamesharrow Dec 14, 2023
eaa65f9
Restyled by whitespace
restyled-commits Dec 14, 2023
e00f848
Ensured that mVehicleID free's any malloc'd CharSpan in destructor
jamesharrow Dec 14, 2023
0939d3b
Sync EnergyEvseDelegateImpl.cpp from Example Energy Management
jamesharrow Dec 14, 2023
0fdf9cc
Ensured that mVehicleID free's any malloc'd CharSpan in destructor
jamesharrow Dec 14, 2023
c92a4e2
Sync EnergyEvseDelegateImpl.cpp from Example Energy Management
jamesharrow Dec 14, 2023
5bda642
Sync'd changes from example energy management app, and commits from #…
jamesharrow Dec 14, 2023
339196c
Added namespace to avoid global namespace error in header file.
jamesharrow Dec 14, 2023
ab1ae6a
Merge branch 'master' into 30727-add-evse-to-examplesenergy-managemen…
jamesharrow Dec 14, 2023
6ab439b
Re-write of ApplicationInit to handle potential errors
jamesharrow Dec 14, 2023
58cc794
Re-write of ApplicationInit to handle potential errors
jamesharrow Dec 14, 2023
67fb025
Merge branch 'upstream-master' into 30997-complete-evse-delegate-impl…
jamesharrow Dec 14, 2023
c832208
Removed unnecessary void in function decl.
jamesharrow Dec 14, 2023
34dd424
Open and saved in ZAP, then regen_all
jamesharrow Dec 15, 2023
4903b29
Merge branch 'upstream-master' into 30727-add-evse-to-examplesenergy-…
jamesharrow Dec 15, 2023
23910e2
Updated Energy-management-app.zap / .matter after change to general-d…
jamesharrow Dec 15, 2023
a375a52
Merge branch 'upstream-master' into 30997-complete-evse-delegate-impl…
jamesharrow Dec 15, 2023
2822b3e
Updated Energy-management-app.zap / .matter after change to general-d…
jamesharrow Dec 15, 2023
4793eb1
Restyled by whitespace
restyled-commits Dec 15, 2023
7385acd
Merge branch 'upstream-master' into 30727-add-evse-to-examplesenergy-…
jamesharrow Dec 15, 2023
ee510f4
Fixed types to be signed=true
jamesharrow Dec 16, 2023
be39a66
Fixed 31032 - revert removal of side="server". Also turned on Events.
jamesharrow Dec 16, 2023
49f39b5
PR comment fix - remove Localization Config and Time Format Localizat…
jamesharrow Dec 16, 2023
55eedc3
Merge branch '30727-add-evse-to-examplesenergy-management-app' into 3…
jamesharrow Dec 16, 2023
2acee39
Removed EVSE commands from ZAP to avoid emberAf linker errors since t…
jamesharrow Dec 17, 2023
a133b95
Merge branch 'master' into 30997-complete-evse-delegate-implementation
jamesharrow Dec 18, 2023
192e834
Merge branch 'upstream-master' into 30997-complete-evse-delegate-impl…
jamesharrow Dec 18, 2023
ba7e436
Regen_all to update energy-management.matter file to remove commands …
jamesharrow Dec 18, 2023
73ecb1b
Minor changes to align all-clusters and energy-management common.
jamesharrow Dec 18, 2023
3f62fea
Apply suggestions from code review
jamesharrow Dec 19, 2023
feaa006
Addressed comment and replicated into example energy management copies.
jamesharrow Dec 19, 2023
e8833d9
Added documentation to EVSE Callbacks as to which struct in the union…
jamesharrow Dec 19, 2023
4701102
Added Energy EVSE and Device Energy Management to config-data.yml und…
jamesharrow Dec 19, 2023
4c93db2
Merge branch 'master' into 30997-complete-evse-delegate-implementation
jamesharrow Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7354,6 +7354,15 @@ endpoint 1 {
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 2;

handle command GetTargetsResponse;
handle command Disable;
handle command EnableCharging;
handle command EnableDischarging;
handle command StartDiagnostics;
handle command SetTargets;
handle command GetTargets;
handle command ClearTargets;
}

server cluster WindowCovering {
Expand Down
66 changes: 66 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -11737,6 +11737,72 @@
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"commands": [
{
"name": "GetTargetsResponse",
"code": 0,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
},
{
"name": "Disable",
"code": 1,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "EnableCharging",
"code": 2,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "EnableDischarging",
"code": 3,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "StartDiagnostics",
"code": 4,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "SetTargets",
"code": 5,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "GetTargets",
"code": 6,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "ClearTargets",
"code": 7,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
}
],
"attributes": [
{
"name": "State",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

namespace chip {
namespace app {
namespace Clusters {

using namespace chip::app::Clusters::EnergyEvse;

/* This callbacks mechanism is intended to allow different delegates to
* dispatch notifications that something has changed.
*
* This is not specific to the EnergyEVSE cluster, but includes DeviceEnergyManagement
* and potential future clusters.
*/
enum EVSECallbackType
{
/*
* The State has changed (e.g. from Disabled to Charging, or vice-versa)
*/
StateChanged,
/*
* ChargeCurrent has changed
*/
ChargeCurrentChanged,
/*
* Charging Preferences have changed
*/
ChargingPreferencesChanged,
/*
* DeviceEnergyManagement has changed
*/
DeviceEnergyManagementChanged,
};

struct EVSECbInfo
{
EVSECallbackType type;

union
{
/* for type = StateChanged */
struct
{
StateEnum state;
SupplyStateEnum supplyState;
} StateChange;

/* for type = ChargeCurrentChanged */
struct
{
int64_t maximumChargeCurrent;
} ChargingCurrent;
};
};

typedef void (*EVSECallbackFunc)(const EVSECbInfo * cb, intptr_t arg);

struct EVSECallbackWrapper
{
EVSECallbackFunc handler;
intptr_t arg;
};

} // namespace Clusters
} // namespace app
} // namespace chip
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#pragma once

#include "app/clusters/energy-evse-server/energy-evse-server.h"
#include <EVSECallbacks.h>

#include <app/util/af.h>
#include <app/util/config.h>
Expand Down Expand Up @@ -68,9 +69,13 @@ class EnergyEvseDelegate : public EnergyEvse::Delegate
*/
Status StartDiagnostics() override;

/**
* @brief Called by EVSE Hardware to register a single callback handler
*/
Status HwRegisterEvseCallbackHandler(EVSECallbackFunc handler, intptr_t arg);

// -----------------------------------------------------------------
// Internal API to allow an EVSE to change its internal state etc
// TODO Status HwRegisterEvseHardwareCallback(Callback);
Status HwSetMaxHardwareCurrentLimit(int64_t currentmA);
Status HwSetCircuitCapacity(int64_t currentmA);
Status HwSetCableAssemblyLimit(int64_t currentmA);
Expand Down Expand Up @@ -150,6 +155,11 @@ class EnergyEvseDelegate : public EnergyEvse::Delegate
int64_t mActualChargingCurrentLimit = 0;
StateEnum mHwState = StateEnum::kNotPluggedIn; /* Hardware state */

/* Callback related */
EVSECallbackWrapper mCallbacks = { .handler = nullptr, .arg = 0 }; /* Wrapper to allow callbacks to be registered */
Status NotifyApplicationCurrentLimitChange(int64_t maximumChargeCurrent);
Status NotifyApplicationStateChange();

/**
* @brief Helper function to work out the charge limit based on conditions and settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Status EnergyEvseDelegate::Disable()
/* update MaximumDischargeCurrent to 0 */
SetMaximumDischargeCurrent(0);

NotifyApplicationStateChange();
// TODO: Generate events

return Status::Success;
Expand All @@ -102,31 +103,31 @@ Status EnergyEvseDelegate::EnableCharging(const DataModel::Nullable<uint32_t> &

if (maximumChargeCurrent < kMinimumChargeCurrent || maximumChargeCurrent > kMaximumChargeCurrent)
{
ChipLogError(NotSpecified, "Maximum Current outside limits");
ChipLogError(AppServer, "Maximum Current outside limits");
return Status::ConstraintError;
}

if (minimumChargeCurrent < kMinimumChargeCurrent || minimumChargeCurrent > kMaximumChargeCurrent)
{
ChipLogError(NotSpecified, "Maximum Current outside limits");
ChipLogError(AppServer, "Maximum Current outside limits");
return Status::ConstraintError;
}

if (minimumChargeCurrent > maximumChargeCurrent)
{
ChipLogError(NotSpecified, "Minium Current > Maximum Current!");
ChipLogError(AppServer, "Minium Current > Maximum Current!");
return Status::ConstraintError;
}

if (chargingEnabledUntil.IsNull())
{
/* Charging enabled indefinitely */
ChipLogError(NotSpecified, "Charging enabled indefinitely");
ChipLogError(AppServer, "Charging enabled indefinitely");
}
else
{
/* check chargingEnabledUntil is in the future */
ChipLogError(NotSpecified, "Charging enabled until: %lu", static_cast<long unsigned int>(chargingEnabledUntil.Value()));
ChipLogError(AppServer, "Charging enabled until: %lu", static_cast<long unsigned int>(chargingEnabledUntil.Value()));
// TODO
// if (checkChargingEnabled)
}
Expand Down Expand Up @@ -169,6 +170,8 @@ Status EnergyEvseDelegate::EnableCharging(const DataModel::Nullable<uint32_t> &

// TODO: Generate events

NotifyApplicationStateChange();

return this->ComputeMaxChargeCurrentLimit();
}

Expand All @@ -188,6 +191,8 @@ Status EnergyEvseDelegate::EnableDischarging(const DataModel::Nullable<uint32_t>

// TODO: Generate events

NotifyApplicationStateChange();

return Status::Success;
}

Expand All @@ -199,25 +204,42 @@ Status EnergyEvseDelegate::StartDiagnostics()
/* For EVSE manufacturers to customize */
ChipLogProgress(AppServer, "EnergyEvseDelegate::StartDiagnostics()");

/* update SupplyState */
/* update SupplyState to indicate we are now in Diagnostics mode */
SetSupplyState(SupplyStateEnum::kDisabledDiagnostics);

// TODO: Generate events

// TODO: Notify Application to implement Diagnostics

NotifyApplicationStateChange();

return Status::Success;
}

/* ---------------------------------------------------------------------------
* FUNCTIONS BELOW:
* - EVSE Hardware interface
* EVSE Hardware interface below
*/

/**
* @brief Called by EVSE Hardware to register a callback handler mechanism
*
* SetMaxHardwareCurrentLimit( currentmA )
* SetCircuitCapacity( currentmA )
* SetCableAssemblyLimit( currentmA )
* SetState( EVSEStateEnum )
* SetFault
* This is normally called at start-up.
*
* @param EVSECallbackFunct - function pointer to call
* @param intptr_t - optional context to provide back to callback handler
*/
Status EnergyEvseDelegate::HwRegisterEvseCallbackHandler(EVSECallbackFunc handler, intptr_t arg)
{
if (mCallbacks.handler != nullptr)
{
ChipLogError(AppServer, "Callback handler already initialized");
return Status::Failure;
}
mCallbacks.handler = handler;
mCallbacks.arg = arg;

return Status::Success;
}

/**
* @brief Called by EVSE Hardware to notify the delegate of the maximum
Expand Down Expand Up @@ -420,17 +442,18 @@ Status EnergyEvseDelegate::HwSetVehicleID(const CharSpan & newValue)

/**
* @brief Called to compute the safe charging current limit
*
* mActualChargingCurrentLimit is the minimum of:
* - MaxHardwareCurrentLimit (of the hardware)
* - CircuitCapacity (set by the electrician - less than the hardware)
* - CableAssemblyLimit (detected when the cable is inserted)
* - MaximumChargeCurrent (from charging command)
* - UserMaximumChargeCurrent (could dynamically change)
*
*/
Status EnergyEvseDelegate::ComputeMaxChargeCurrentLimit()
{
int64_t oldValue;
/* mActualChargingCurrentLimit is the minimum of:
* - MaxHardwareCurrentLimit (of the hardware)
* - CircuitCapacity (set by the electrician - less than the hardware)
* - CableAssemblyLimit (detected when the cable is inserted)
* - MaximumChargeCurrent (from charging command)
* - UserMaximumChargeCurrent (could dynamically change)
*/

oldValue = mActualChargingCurrentLimit;
mActualChargingCurrentLimit = mMaxHardwareCurrentLimit;
Expand All @@ -448,11 +471,42 @@ Status EnergyEvseDelegate::ComputeMaxChargeCurrentLimit()
MatterReportingAttributeChangeCallback(mEndpointId, EnergyEvse::Id, MaximumChargeCurrent::Id);

/* Call the EV Charger hardware current limit callback */
// TODO
NotifyApplicationCurrentLimitChange(mMaximumChargeCurrent);
}
return Status::Success;
}

Status EnergyEvseDelegate::NotifyApplicationCurrentLimitChange(int64_t maximumChargeCurrent)
{
EVSECbInfo cbInfo;

cbInfo.type = EVSECallbackType::ChargeCurrentChanged;
cbInfo.ChargingCurrent.maximumChargeCurrent = maximumChargeCurrent;

if (mCallbacks.handler != nullptr)
{
mCallbacks.handler(&cbInfo, mCallbacks.arg);
}

return Status::Success;
}

Status EnergyEvseDelegate::NotifyApplicationStateChange()
{
EVSECbInfo cbInfo;

cbInfo.type = EVSECallbackType::StateChanged;
cbInfo.StateChange.state = mState;
cbInfo.StateChange.supplyState = mSupplyState;

if (mCallbacks.handler != nullptr)
{
mCallbacks.handler(&cbInfo, mCallbacks.arg);
}

return Status::Success;
}

/**
* Attribute methods
*/
Expand Down
Loading