66class ElectricityMeter :
public ElementWithChannelActions,
67 public ActionHandler {
71 virtual void updateChannelValues();
74 void setFwdActEnergy(
int phase,
unsigned _supla_int64_t energy);
77 void setRvrActEnergy(
int phase,
unsigned _supla_int64_t energy);
80 void setFwdReactEnergy(
int phase,
unsigned _supla_int64_t energy);
83 void setRvrReactEnergy(
int phase,
unsigned _supla_int64_t energy);
87 void setFwdBalancedEnergy(uint64_t energy);
91 void setRvrBalancedEnergy(uint64_t energy);
94 void setVoltage(
int phase,
unsigned _supla_int16_t voltage);
97 void setCurrent(
int phase,
unsigned _supla_int_t current);
100 void setFreq(
unsigned _supla_int16_t freq);
103 void setPowerActive(
int phase, int64_t power);
106 void setPowerReactive(
int phase, int64_t power);
109 void setPowerApparent(
int phase, int64_t power);
112 void setPowerFactor(
int phase, _supla_int_t powerFactor);
115 void setPhaseAngle(
int phase, _supla_int_t phaseAngle);
118 void setVoltagePhaseAngle12(
unsigned _supla_int16_t voltagePhaseAngle);
121 void setVoltagePhaseAngle13(
unsigned _supla_int16_t voltagePhaseAngle);
124 void setVoltagePhaseSequence(
bool clockwise);
127 void setCurrentPhaseSequence(
bool clockwise);
142 unsigned _supla_int64_t getFwdActEnergy(
int phase);
145 unsigned _supla_int64_t getRvrActEnergy(
int phase);
148 uint64_t getFwdBalancedActEnergy();
151 uint64_t getRvrBalancedActEnergy();
154 unsigned _supla_int64_t getFwdReactEnergy(
int phase);
157 unsigned _supla_int64_t getRvrReactEnergy(
int phase);
160 unsigned _supla_int16_t getVoltage(
int phase);
163 unsigned _supla_int_t getCurrent(
int phase);
166 unsigned _supla_int16_t getFreq();
169 int64_t getPowerActive(
int phase);
172 int64_t getPowerReactive(
int phase);
175 int64_t getPowerApparent(
int phase);
178 _supla_int_t getPowerFactor(
int phase);
181 _supla_int_t getPhaseAngle(
int phase);
184 uint16_t getVoltagePhaseAngle12()
const;
187 uint16_t getVoltagePhaseAngle13()
const;
190 bool isVoltagePhaseSequenceSet()
const;
193 bool isVoltagePhaseSequenceClockwise()
const;
196 bool isCurrentPhaseSequenceSet()
const;
199 bool isCurrentPhaseSequenceClockwise()
const;
202 static unsigned _supla_int64_t
207 static unsigned _supla_int64_t
215 static unsigned _supla_int64_t
220 static unsigned _supla_int64_t
228 static unsigned _supla_int64_t
233 static unsigned _supla_int64_t
238 static unsigned _supla_int16_t
242 static unsigned _supla_int_t
246 static unsigned _supla_int16_t
250 static int64_t getPowerActive(
254 static int64_t getPowerReactive(
258 static int64_t getPowerApparent(
262 static _supla_int_t getPowerFactor(
266 static _supla_int_t getPhaseAngle(
270 static uint16_t getVoltagePhaseAngle12(
274 static uint16_t getVoltagePhaseAngle13(
278 static bool isVoltagePhaseSequenceSet(
282 static bool isVoltagePhaseSequenceClockwise(
286 static bool isCurrentPhaseSequenceSet(
290 static bool isCurrentPhaseSequenceClockwise(
293 static bool isVoltagePhaseAngle12Used(
296 static bool isVoltagePhaseAngle13Used(
299 static bool isFwdActEnergyUsed(
302 static bool isRvrActEnergyUsed(
305 static bool isFwdReactEnergyUsed(
308 static bool isRvrReactEnergyUsed(
311 static bool isFwdBalancedActEnergyUsed(
314 static bool isRvrBalancedActEnergyUsed(
317 static bool isVoltageUsed(
320 static bool isCurrentUsed(
323 static bool isFreqUsed(
326 static bool isPowerActiveUsed(
329 static bool isPowerReactiveUsed(
332 static bool isPowerApparentUsed(
335 static bool isPowerFactorUsed(
338 static bool isPhaseAngleUsed(
341 void resetReadParameters();
342 void resetReadParametersForPhase(
int phase);
347 virtual void readValuesFromDevice();
352 bool local)
override;
353 void fillChannelConfig(
void *channelConfig,
355 uint8_t configType)
override;
369 virtual void resetStorage();
376 void handleAction(
int event,
int action)
override;
378 void setRefreshRate(
unsigned int sec);
380 void sendDataWithDelay(
int delayMs = 0);
382 Channel *getChannel()
override;
383 const Channel *getChannel()
const override;
386 void enableChannelConfig();
387 void addCtType(uint64_t ctType);
388 void addPhaseLedType(uint64_t ledType);
389 bool isCtTypeSupported(uint64_t ctType)
const;
391 int8_t getPhaseLedType()
const;
392 int32_t getLedVoltageLow()
const;
393 int32_t getLedVoltageHigh()
const;
394 int32_t getLedPowerLow()
const;
395 int32_t getLedPowerHigh()
const;
396 bool isPhaseLedTypeSupported(uint64_t ledType)
const;
400 ChannelExtended extChannel;
401 uint32_t lastChannelUpdateTime = 0;
402 uint32_t rawCurrent[MAX_PHASES] = {};
403 int64_t rawActivePower[MAX_PHASES] = {};
404 int64_t rawReactivePower[MAX_PHASES] = {};
405 int64_t rawApparentPower[MAX_PHASES] = {};
407 uint32_t lastReadTime = 0;
408 uint16_t refreshRateSec = 5;
409 bool valueChanged =
false;
410 bool currentMeasurementAvailable =
false;
411 bool powerActiveMeasurementAvailable =
false;
412 bool powerReactiveMeasurementAvailable =
false;
413 bool powerApparentMeasurementAvailable =
false;
415 uint64_t availableCtTypes = 0;
416 uint64_t availablePhaseLedTypes = 0;
417 bool channelConfigUsed =
false;
418 int8_t usedCtType = -1;
420 int8_t usedPhaseLedType = -1;
422 int32_t ledVoltageLow = 21000;
423 int32_t ledVoltageHigh = 25000;
424 int32_t ledPowerLow = -5000;
425 int32_t ledPowerHigh = 5000;