mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-04-25 20:01:46 +00:00
Support two phase power calculation
This commit is contained in:
@@ -16,15 +16,23 @@ AmsData::AmsData(uint8_t meterType, bool substituteMissing, HanReader& hanReader
|
|||||||
extractFromKaifa(hanReader, listSize);
|
extractFromKaifa(hanReader, listSize);
|
||||||
break;
|
break;
|
||||||
case METER_TYPE_AIDON:
|
case METER_TYPE_AIDON:
|
||||||
extractFromAidon(hanReader, listSize, substituteMissing);
|
extractFromAidon(hanReader, listSize);
|
||||||
break;
|
break;
|
||||||
case METER_TYPE_KAMSTRUP:
|
case METER_TYPE_KAMSTRUP:
|
||||||
extractFromKamstrup(hanReader, listSize, substituteMissing);
|
extractFromKamstrup(hanReader, listSize);
|
||||||
break;
|
break;
|
||||||
case METER_TYPE_OMNIPOWER:
|
case METER_TYPE_OMNIPOWER:
|
||||||
extractFromOmnipower(hanReader, listSize, substituteMissing);
|
extractFromOmnipower(hanReader, listSize);
|
||||||
break;
|
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) {
|
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) {
|
switch(listSize) {
|
||||||
case (uint8_t)Aidon::List1:
|
case (uint8_t)Aidon::List1:
|
||||||
listType = 1;
|
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;
|
l1voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL1)) / 10;
|
||||||
l2voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL2)) / 10;
|
l2voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL2)) / 10;
|
||||||
l3voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL3)) / 10;
|
l3voltage = ((float) hanReader.getInt( (uint8_t)Aidon_List3PhaseIT::VoltageL3)) / 10;
|
||||||
if(substituteMissing) {
|
|
||||||
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
|
void AmsData::extractFromKamstrup(HanReader& hanReader, uint8_t listSize) {
|
||||||
switch(listSize) {
|
switch(listSize) {
|
||||||
case (uint8_t)Kamstrup::List3PhaseITShort:
|
case (uint8_t)Kamstrup::List3PhaseITShort:
|
||||||
case (uint8_t)Kamstrup::List3PhaseShort:
|
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);
|
l1voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL1);
|
||||||
l2voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL2);
|
l2voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL2);
|
||||||
l3voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL3);
|
l3voltage = hanReader.getInt( (uint8_t)Kamstrup_List3Phase::VoltageL3);
|
||||||
if(substituteMissing) {
|
|
||||||
l2current = (((activeImportPower - activeExportPower) * sqrt(3)) - (l1voltage * l1current) - (l3voltage * l3current)) / l2voltage;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool substituteMissing) {
|
void AmsData::extractFromOmnipower(HanReader& hanReader, uint8_t listSize) {
|
||||||
switch(listSize) {
|
switch(listSize) {
|
||||||
case (uint8_t)Kamstrup::List3PhaseITShort:
|
case (uint8_t)Kamstrup::List3PhaseITShort:
|
||||||
case (uint8_t)Kamstrup::List3PhaseShort:
|
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::List3PhaseITLong:
|
||||||
case (uint8_t)Kamstrup::List3PhaseLong:
|
case (uint8_t)Kamstrup::List3PhaseLong:
|
||||||
case (uint8_t)Kamstrup::List1PhaseLong:
|
case (uint8_t)Kamstrup::List1PhaseLong:
|
||||||
extractFromKamstrup(hanReader, listSize, substituteMissing);
|
extractFromKamstrup(hanReader, listSize);
|
||||||
break;
|
break;
|
||||||
case (uint8_t)Omnipower::DLMS:
|
case (uint8_t)Omnipower::DLMS:
|
||||||
meterTimestamp = hanReader.getTime( (uint8_t)Omnipower_DLMS::MeterClock, true, true);
|
meterTimestamp = hanReader.getTime( (uint8_t)Omnipower_DLMS::MeterClock, true, true);
|
||||||
@@ -340,6 +342,7 @@ void AmsData::apply(AmsData& other) {
|
|||||||
this->l2voltage = other.getL2Voltage();
|
this->l2voltage = other.getL2Voltage();
|
||||||
this->l3voltage = other.getL3Voltage();
|
this->l3voltage = other.getL3Voltage();
|
||||||
this->threePhase = other.isThreePhase();
|
this->threePhase = other.isThreePhase();
|
||||||
|
this->twoPhase = other.isTwoPhase();
|
||||||
case 1:
|
case 1:
|
||||||
this->activeImportPower = other.getActiveImportPower();
|
this->activeImportPower = other.getActiveImportPower();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public:
|
|||||||
float getReactiveExportCounter();
|
float getReactiveExportCounter();
|
||||||
|
|
||||||
bool isThreePhase();
|
bool isThreePhase();
|
||||||
|
bool isTwoPhase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long lastUpdateMillis = 0;
|
unsigned long lastUpdateMillis = 0;
|
||||||
@@ -58,12 +59,12 @@ private:
|
|||||||
uint16_t activeImportPower = 0, reactiveImportPower = 0, activeExportPower = 0, reactiveExportPower = 0;
|
uint16_t activeImportPower = 0, reactiveImportPower = 0, activeExportPower = 0, reactiveExportPower = 0;
|
||||||
float l1voltage = 0, l2voltage = 0, l3voltage = 0, l1current = 0, l2current = 0, l3current = 0;
|
float l1voltage = 0, l2voltage = 0, l3voltage = 0, l1current = 0, l2current = 0, l3current = 0;
|
||||||
float activeImportCounter = 0, reactiveImportCounter = 0, activeExportCounter = 0, reactiveExportCounter = 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 extractFromKaifa(HanReader& hanReader, uint8_t listSize);
|
||||||
void extractFromAidon(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
|
void extractFromAidon(HanReader& hanReader, uint8_t listSize);
|
||||||
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
|
void extractFromKamstrup(HanReader& hanReader, uint8_t listSize);
|
||||||
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize, bool substituteMissing);
|
void extractFromOmnipower(HanReader& hanReader, uint8_t listSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -117,9 +117,11 @@ void AmsWebServer::loop() {
|
|||||||
server.handleClient();
|
server.handleClient();
|
||||||
|
|
||||||
if(maxPwr == 0 && meterState->getListType() > 1 && meterConfig->mainFuse > 0 && meterConfig->distributionSystem > 0) {
|
if(maxPwr == 0 && meterState->getListType() > 1 && meterConfig->mainFuse > 0 && meterConfig->distributionSystem > 0) {
|
||||||
|
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
|
||||||
if(meterState->isThreePhase()) {
|
if(meterState->isThreePhase()) {
|
||||||
int voltage = meterConfig->distributionSystem == 2 ? 400 : 230;
|
|
||||||
maxPwr = meterConfig->mainFuse * sqrt(3) * voltage;
|
maxPwr = meterConfig->mainFuse * sqrt(3) * voltage;
|
||||||
|
} else if(meterState->isTwoPhase()) {
|
||||||
|
maxPwr = meterConfig->mainFuse * voltage;
|
||||||
} else {
|
} else {
|
||||||
maxPwr = meterConfig->mainFuse * 230;
|
maxPwr = meterConfig->mainFuse * 230;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user