forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEVSEManufacturerImpl.h
200 lines (177 loc) · 7.41 KB
/
EVSEManufacturerImpl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
*
* 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
#include <DeviceEnergyManagementManager.h>
#include <ElectricalPowerMeasurementDelegate.h>
#include <EnergyEvseManager.h>
#include <PowerTopologyDelegate.h>
using chip::Protocols::InteractionModel::Status;
namespace chip {
namespace app {
namespace Clusters {
namespace EnergyEvse {
/**
* The EVSEManufacturer example class
*/
class EVSEManufacturer
{
public:
EVSEManufacturer(EnergyEvseManager * aEvseInstance,
ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * aEPMInstance,
PowerTopology::PowerTopologyInstance * aPTInstance)
{
mEvseInstance = aEvseInstance;
mEPMInstance = aEPMInstance;
mPTInstance = aPTInstance;
}
EnergyEvseManager * GetEvseInstance() { return mEvseInstance; }
ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * GetEPMInstance() { return mEPMInstance; }
PowerTopology::PowerTopologyInstance * GetPTInstance() { return mPTInstance; }
EnergyEvseDelegate * GetEvseDelegate()
{
if (mEvseInstance)
{
return mEvseInstance->GetDelegate();
}
return nullptr;
}
ElectricalPowerMeasurement::ElectricalPowerMeasurementDelegate * GetEPMDelegate()
{
if (mEPMInstance)
{
return mEPMInstance->GetDelegate();
}
return nullptr;
}
PowerTopology::PowerTopologyDelegate * GetPTDelegate()
{
if (mPTInstance)
{
return mPTInstance->GetDelegate();
}
return nullptr;
}
/**
* @brief Called at start up to apply hardware settings
*/
CHIP_ERROR Init();
/**
* @brief Called at shutdown
*/
CHIP_ERROR Shutdown();
/**
* @brief Main Callback handler from delegate to user code
*/
static void ApplicationCallbackHandler(const EVSECbInfo * cb, intptr_t arg);
/**
* @brief Simple example to demonstrate how an EVSE can compute the start time
* and duration of a charging schedule
*/
CHIP_ERROR ComputeChargingSchedule();
/**
* @brief Allows a client application to initialise the Accuracy, Measurement types etc
*/
CHIP_ERROR InitializePowerMeasurementCluster();
/**
* @brief Allows a client application to initialise the PowerSource cluster
*/
CHIP_ERROR InitializePowerSourceCluster();
/**
* @brief Allows a client application to send in power readings into the system
*
* @param[in] aEndpointId - Endpoint to send to EPM Cluster
* @param[in] aActivePower_mW - ActivePower measured in milli-watts
* @param[in] aVoltage_mV - Voltage measured in milli-volts
* @param[in] aActiveCurrent_mA - ActiveCurrent measured in milli-amps
*/
CHIP_ERROR SendPowerReading(EndpointId aEndpointId, int64_t aActivePower_mW, int64_t aVoltage_mV, int64_t aCurrent_mA);
/**
* @brief Allows a client application to send cumulative energy readings into the system
*
* This is a helper function to add timestamps to the readings
*
* @param[in] aCumulativeEnergyImported -total energy imported in milli-watthours
* @param[in] aCumulativeEnergyExported -total energy exported in milli-watthours
*/
CHIP_ERROR SendCumulativeEnergyReading(EndpointId aEndpointId, int64_t aCumulativeEnergyImported,
int64_t aCumulativeEnergyExported);
/**
* @brief Allows a client application to send periodic energy readings into the system
*
* This is a helper function to add timestamps to the readings
*
* @param[in] aPeriodicEnergyImported - energy imported in milli-watthours in last period
* @param[in] aPeriodicEnergyExported - energy exported in milli-watthours in last period
*/
CHIP_ERROR SendPeriodicEnergyReading(EndpointId aEndpointId, int64_t aCumulativeEnergyImported,
int64_t aCumulativeEnergyExported);
/** Fake Meter data generation - used for testing EPM/EEM clusters */
/**
* @brief Starts a fake load/generator to periodically callback the power and energy
* clusters.
* @param[in] aEndpointId - which endpoint is the meter to be updated on
* @param[in] aPower_mW - the mean power of the load
* Positive power indicates Imported energy (e.g. a load)
* Negative power indicated Exported energy (e.g. a generator)
* @param[in] aPowerRandomness_mW This is used to define the max randomness of the
* random power values around the mean power of the load
* @param[in] aVoltage_mV - the nominal voltage measurement
* @param[in] aVoltageRandomness_mV This is used to define the max randomness of the
* random voltage values
* @param[in] aCurrent_mA - the nominal current measurement
* @param[in] aCurrentRandomness_mA This is used to define the max randomness of the
* random current values
* @param[in] aInterval_s - the callback interval in seconds
* @param[in] bReset - boolean: true will reset the energy values to 0
*/
void StartFakeReadings(EndpointId aEndpointId, int64_t aPower_mW, uint32_t aPowerRandomness_mW, int64_t aVoltage_mV,
uint32_t aVoltageRandomness_mV, int64_t aCurrent_mA, uint32_t aCurrentRandomness_mA, uint8_t aInterval_s,
bool bReset);
/**
* @brief Stops any active updates to the fake load data callbacks
*/
void StopFakeReadings();
/**
* @brief Sends fake meter data into the cluster and restarts the timer
*/
void FakeReadingsUpdate();
/**
* @brief Timer expiry callback to handle fake load
*/
static void FakeReadingsTimerExpiry(System::Layer * systemLayer, void * manufacturer);
private:
EnergyEvseManager * mEvseInstance;
ElectricalPowerMeasurement::ElectricalPowerMeasurementInstance * mEPMInstance;
PowerTopology::PowerTopologyInstance * mPTInstance;
int64_t mLastChargingEnergyMeter = 0;
int64_t mLastDischargingEnergyMeter = 0;
};
/** @brief Helper function to return the singleton EVSEManufacturer instance
*
* This is needed by the EVSEManufacturer class to support TestEventTriggers
* which are called outside of any class context. This allows the EVSEManufacturer
* class to return the relevant Delegate instance in which to invoke the test
* events on.
*
* This function is typically found in main.cpp or wherever the singleton is created.
*/
EVSEManufacturer * GetEvseManufacturer();
} // namespace EnergyEvse
} // namespace Clusters
} // namespace app
} // namespace chip