Support two phase power calculation

This commit is contained in:
Gunnar Skjold 2021-10-23 08:59:16 +02:00
parent 507ed13770
commit 26bb8a0fea
3 changed files with 24 additions and 18 deletions

View File

@ -16,15 +16,23 @@ AmsData::AmsData(uint8_t meterType, bool substituteMissing, HanReader& hanReader
extractFromKaifa(hanReader, listSize);
break;
case METER_TYPE_AIDON:
extractFromAidon(hanReader, listSize, substituteMissing);
extractFromAidon(hanReader, listSize);
break;
case METER_TYPE_KAMSTRUP:
extractFromKamstrup(hanReader, listSize, substituteMissing);
extractFromKamstrup(hanReader, listSize);
break;
case METER_TYPE_OMNIPOWER:
extractFromOmnipower(hanReader, listSize, substituteMissing);
extractFromOmnipower(hanReader, listSize);
break;
}
threePhase = l1voltage > 0 && l2voltage > 0 && l3voltage > 0;
twoPhase = (l1voltage > 0 && l2voltage > 0) || (l2voltage > 0 && l3voltage > 0) || (l3voltage > 0 && l1voltage > 0);
if(threePhase) {
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
}
}
void AmsData::extractFromKaifa(HanReader& hanReader, uint8_t listSize) {
@ -90,7 +98,7 @@ void AmsData::extractFromKaifa(HanReader& hanReader, uint8_t listSize) {
}
}
void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize) {
switch(listSize) {
case (uint8_t)Aidon::List1:
listType = 1;
@ -171,15 +179,12 @@ void AmsData::extractFromAidon(HanReader& hanReader, uint8_t listSize, bool subs
l1voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL1)) / 10;
l2voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL2)) / 10;
l3voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL3)) / 10;
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
break;
}
}
}
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize) {
switch(listSize) {
case (uint8_t)Kamstrup::List3PhaseITShort:
case (uint8_t)Kamstrup::List3PhaseShort:
@ -254,14 +259,11 @@ void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool s
l1voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL1);
l2voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL2);
l3voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL3);
if(substituteMissing) {
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
}
break;
}
}
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize) {
switch(listSize) {
case (uint8_t)Kamstrup::List3PhaseITShort:
case (uint8_t)Kamstrup::List3PhaseShort:
@ -269,7 +271,7 @@ void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool
case (uint8_t)Kamstrup::List3PhaseITLong:
case (uint8_t)Kamstrup::List3PhaseLong:
case (uint8_t)Kamstrup::List1PhaseLong:
extractFromKamstrup(hanReader, listSize, substituteMissing);
extractFromKamstrup(hanReader, listSize);
break;
case (uint8_t)Omnipower::DLMS:
meterTimestamp = hanReader.getTime( (uint8_t)Omnipower_DLMS::MeterClock, true, true);
@ -340,6 +342,7 @@ void AmsData::apply(AmsData& other) {
this->l2voltage = other.getL2Voltage();
this->l3voltage = other.getL3Voltage();
this->threePhase = other.isThreePhase();
this->twoPhase = other.isTwoPhase();
case 1:
this->activeImportPower = other.getActiveImportPower();
}

View File

@ -48,6 +48,7 @@ public:
float getReactiveExportCounter();
bool isThreePhase();
bool isTwoPhase();
private:
unsigned long lastUpdateMillis = 0;
@ -58,12 +59,12 @@ private:
uint16_t activeImportPower = 0, reactiveImportPower = 0, activeExportPower = 0, reactiveExportPower = 0;
float l1voltage = 0, l2voltage = 0, l3voltage = 0, l1current = 0, l2current = 0, l3current = 0;
float activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 0;
bool threePhase = false, counterEstimated = false;
bool threePhase = false, twoPhase = false, counterEstimated = false;
void extractFromKaifa(HanReader& hanReader, uint8_t listSize);
void extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
void extractFromAidon(HanReader& hanReader, uint8_t listSize);
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize);
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize);
};
#endif

View File

@ -117,9 +117,11 @@ void AmsWebServer::loop() {
server.handleClient();
if(maxPwr == 0 && meterState->getListType() > 1 && meterConfig->mainFuse > 0 && meterConfig->distributionSystem > 0) {
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
if(meterState->isThreePhase()) {
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
maxPwr = meterConfig->mainFuse * sqrt(3) * voltage;
} else if(meterState->isTwoPhase()) {
maxPwr = meterConfig->mainFuse * voltage;
} else {
maxPwr = meterConfig->mainFuse * 230;
}