tested and fixed storage model

master
Boernsman 2021-02-04 13:00:22 +01:00
parent 62dc0ab825
commit 5efce86683
5 changed files with 39 additions and 25 deletions

View File

@ -610,13 +610,19 @@ void IntegrationPluginSunSpec::onSunSpecModelSearchFinished(const QHash<SunSpec:
void IntegrationPluginSunSpec::onWriteRequestExecuted(QUuid requestId, bool success) void IntegrationPluginSunSpec::onWriteRequestExecuted(QUuid requestId, bool success)
{ {
qCDebug(dcSunSpec()) << "Write request executed" << requestId << success; qCDebug(dcSunSpec()) << "Write request executed" << requestId << success;
if (m_asyncActions.contains(requestId)) {
ThingActionInfo *info = m_asyncActions.take(requestId);
if (success) {
info->finish(Thing::ThingErrorNoError);
} else {
info->finish(Thing::ThingErrorHardwareFailure);
}
}
} }
void IntegrationPluginSunSpec::onWriteRequestError(QUuid requestId, const QString &error) void IntegrationPluginSunSpec::onWriteRequestError(QUuid requestId, const QString &error)
{ {
Q_UNUSED(requestId) qCDebug(dcSunSpec()) << "Write request error" << requestId << error;
Q_UNUSED(error)
qCDebug(dcSunSpec()) << "Write request error" << error;
} }
void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::InverterData &inverterData) void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::InverterData &inverterData)
@ -646,7 +652,7 @@ void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::Inv
qCDebug(dcSunSpec()) << " - Operating state" << inverterData.operatingState; qCDebug(dcSunSpec()) << " - Operating state" << inverterData.operatingState;
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true); thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true);
thing->setStateValue(m_inverterCurrentPowerStateTypeIds.value(thing->thingClassId()), inverterData.acPower/1000.00); thing->setStateValue(m_inverterCurrentPowerStateTypeIds.value(thing->thingClassId()), inverterData.acPower);
thing->setStateValue(m_inverterTotalEnergyProducedStateTypeIds.value(thing->thingClassId()), inverterData.acEnergy/1000.00); thing->setStateValue(m_inverterTotalEnergyProducedStateTypeIds.value(thing->thingClassId()), inverterData.acEnergy/1000.00);
thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), inverterData.lineFrequency); thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), inverterData.lineFrequency);
@ -749,10 +755,23 @@ void IntegrationPluginSunSpec::onStorageDataReceived(const SunSpecStorage::Stora
if(!thing) { if(!thing) {
return; return;
} }
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true);
qCDebug(dcSunSpec()) << "Storage data received";
qCDebug(dcSunSpec()) << " - Setpoint for maximum charge" << mandatory.maxCharge << "[W]";
qCDebug(dcSunSpec()) << " - Setpoint for maximum charging rate." << mandatory.maxChargeRate << "[%]";
qCDebug(dcSunSpec()) << " - Setpoint for maximum discharging rate." << mandatory.maxDischargeRate << "[%]";
qCDebug(dcSunSpec()) << " - Charging enabled" << mandatory.chargingEnabled;
qCDebug(dcSunSpec()) << " - Discharging enabled" << mandatory.dischargingEnabled;
qCDebug(dcSunSpec()) << " - Storage status" << optional.chargeSatus;
qCDebug(dcSunSpec()) << " - Currently available energy" << optional.currentlyAvailableEnergy << "[%]";
qCDebug(dcSunSpec()) << " - Grid charging enabled" << optional.gridChargingEnabled;
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true);
thing->setStateValue(sunspecStorageChargingRateStateTypeId, mandatory.maxChargeRate); thing->setStateValue(sunspecStorageChargingRateStateTypeId, mandatory.maxChargeRate);
thing->setStateValue(sunspecStorageDischargingRateStateTypeId, mandatory.maxDischargeRate); thing->setStateValue(sunspecStorageDischargingRateStateTypeId, mandatory.maxDischargeRate);
thing->setStateValue(sunspecStorageEnableChargingStateTypeId, mandatory.chargingEnabled);
thing->setStateValue(sunspecStorageEnableDischargingStateTypeId, mandatory.dischargingEnabled);
thing->setStateValue(sunspecStorageGridChargingStateTypeId, optional.gridChargingEnabled);
bool charging = false; bool charging = false;
switch (optional.chargeSatus) { switch (optional.chargeSatus) {
@ -785,7 +804,6 @@ void IntegrationPluginSunSpec::onStorageDataReceived(const SunSpecStorage::Stora
void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData &meterData) void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData &meterData)
{ {
Q_UNUSED(meterData)
SunSpecMeter *meter = static_cast<SunSpecMeter *>(sender()); SunSpecMeter *meter = static_cast<SunSpecMeter *>(sender());
Thing *thing = m_sunSpecMeters.key(meter); Thing *thing = m_sunSpecMeters.key(meter);
@ -793,8 +811,6 @@ void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData
return; return;
} }
thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true);
qCDebug(dcSunSpec()) << "Meter data received"; qCDebug(dcSunSpec()) << "Meter data received";
qCDebug(dcSunSpec()) << " - Total AC Current" << meterData.totalAcCurrent << "[A]"; qCDebug(dcSunSpec()) << " - Total AC Current" << meterData.totalAcCurrent << "[A]";
qCDebug(dcSunSpec()) << " - Phase A current" << meterData.phaseACurrent << "[A]"; qCDebug(dcSunSpec()) << " - Phase A current" << meterData.phaseACurrent << "[A]";
@ -813,8 +829,8 @@ void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData
qCDebug(dcSunSpec()) << " - Total real energy exported" << meterData.totalRealEnergyExported<< "[kWH]"; qCDebug(dcSunSpec()) << " - Total real energy exported" << meterData.totalRealEnergyExported<< "[kWH]";
qCDebug(dcSunSpec()) << " - Total real energy imported" << meterData.totalRealEnergyImported<< "[kWH]"; qCDebug(dcSunSpec()) << " - Total real energy imported" << meterData.totalRealEnergyImported<< "[kWH]";
thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), meterData.frequency); thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true);
thing->setStateValue(sunspecThreePhaseMeterTotalCurrentStateTypeId, meterData.totalAcCurrent); thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), meterData.frequency);
if (thing->thingClassId() == sunspecSinglePhaseMeterThingClassId) { if (thing->thingClassId() == sunspecSinglePhaseMeterThingClassId) {
thing->setStateValue(sunspecSinglePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); thing->setStateValue(sunspecSinglePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent);
@ -822,18 +838,25 @@ void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData
thing->setStateValue(sunspecSinglePhaseMeterLnACVoltageStateTypeId, meterData.voltageLN); thing->setStateValue(sunspecSinglePhaseMeterLnACVoltageStateTypeId, meterData.voltageLN);
thing->setStateValue(sunspecSinglePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); thing->setStateValue(sunspecSinglePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported);
thing->setStateValue(sunspecSinglePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); thing->setStateValue(sunspecSinglePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported);
} else if (thing->thingClassId() == sunspecSplitPhaseMeterThingClassId) { } else if (thing->thingClassId() == sunspecSplitPhaseMeterThingClassId) {
thing->setStateValue(sunspecSplitPhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); thing->setStateValue(sunspecSplitPhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent);
thing->setStateValue(sunspecSplitPhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent); thing->setStateValue(sunspecSplitPhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent);
thing->setStateValue(sunspecSplitPhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower); thing->setStateValue(sunspecSplitPhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower);
thing->setStateValue(sunspecSplitPhaseMeterLnACVoltageStateTypeId, meterData.voltageLN); thing->setStateValue(sunspecSplitPhaseMeterLnACVoltageStateTypeId, meterData.voltageLN);
thing->setStateValue(sunspecSplitPhaseMeterPhaseANVoltageStateTypeId, meterData.phaseVoltageAN);
thing->setStateValue(sunspecSplitPhaseMeterPhaseBNVoltageStateTypeId, meterData.phaseVoltageBN);
thing->setStateValue(sunspecSplitPhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); thing->setStateValue(sunspecSplitPhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported);
thing->setStateValue(sunspecSplitPhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); thing->setStateValue(sunspecSplitPhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported);
} else if (thing->thingClassId() == sunspecThreePhaseMeterThingClassId) { } else if (thing->thingClassId() == sunspecThreePhaseMeterThingClassId) {
thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent);
thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent); thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent);
thing->setStateValue(sunspecThreePhaseMeterPhaseCCurrentStateTypeId, meterData.phaseCCurrent); thing->setStateValue(sunspecThreePhaseMeterPhaseCCurrentStateTypeId, meterData.phaseCCurrent);
thing->setStateValue(sunspecThreePhaseMeterLnACVoltageStateTypeId, meterData.voltageLN); thing->setStateValue(sunspecThreePhaseMeterLnACVoltageStateTypeId, meterData.voltageLN);
thing->setStateValue(sunspecThreePhaseMeterPhaseANVoltageStateTypeId, meterData.phaseVoltageAN);
thing->setStateValue(sunspecThreePhaseMeterPhaseBNVoltageStateTypeId, meterData.phaseVoltageBN);
thing->setStateValue(sunspecThreePhaseMeterPhaseCNVoltageStateTypeId, meterData.phaseVoltageCN);
thing->setStateValue(sunspecThreePhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower); thing->setStateValue(sunspecThreePhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower);
thing->setStateValue(sunspecThreePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); thing->setStateValue(sunspecThreePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported);
thing->setStateValue(sunspecThreePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); thing->setStateValue(sunspecThreePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported);

View File

@ -73,10 +73,10 @@ void SunSpecInverter::getInverterModelDataBlock()
m_connection->readModelDataBlock(m_modelModbusStartRegister, m_modelLength); m_connection->readModelDataBlock(m_modelModbusStartRegister, m_modelLength);
} }
SunSpecInverter::SunSpecEvent1 SunSpecInverter::bitfieldToSunSpecEvent1(quint16 register1, quint16 register2) SunSpecInverter::SunSpecEvent1 SunSpecInverter::bitfieldToSunSpecEvent1(quint16 register0, quint16 register1)
{ {
SunSpecEvent1 event1; SunSpecEvent1 event1;
quint32 value = (static_cast<quint32>(register1)<<16 | register2); quint32 value = (static_cast<quint32>(register0)<<16 | register1);
//qCDebug(dcSunSpec()) << "Event1" << QString::number(value, 16); //qCDebug(dcSunSpec()) << "Event1" << QString::number(value, 16);
event1.groundFault = ((value & (0x01 << 0)) != 0); event1.groundFault = ((value & (0x01 << 0)) != 0);
event1.dcOverVoltage = ((value & (0x01 << 1)) != 0); event1.dcOverVoltage = ((value & (0x01 << 1)) != 0);

View File

@ -168,12 +168,12 @@ public:
private: private:
SunSpec *m_connection = nullptr; SunSpec *m_connection = nullptr;
SunSpec::ModelId m_id; //e.g. 103 for three phase inverter, 113 for three phase inverter with floating point representation SunSpec::ModelId m_id;
uint m_modelLength = 0; uint m_modelLength = 0;
uint m_modelModbusStartRegister = 40000; uint m_modelModbusStartRegister = 40000;
bool m_initFinishedSuccess = false; bool m_initFinishedSuccess = false;
SunSpecEvent1 bitfieldToSunSpecEvent1(quint16 register1, quint16 register2); SunSpecEvent1 bitfieldToSunSpecEvent1(quint16 register0, quint16 register1);
void getInverterModelHeader(); void getInverterModelHeader();
private slots: private slots:

View File

@ -127,21 +127,13 @@ void SunSpecStorage::onModelDataBlockReceived(SunSpec::ModelId modelId, uint len
if (length < m_modelLength) { if (length < m_modelLength) {
qCDebug(dcSunSpec()) << "SunSpecMeter: on model data block received, model length is too short" << length; qCDebug(dcSunSpec()) << "SunSpecMeter: on model data block received, model length is too short" << length;
//return; return;
} }
qCDebug(dcSunSpec()) << "SunSpecStorage: Received" << modelId; qCDebug(dcSunSpec()) << "SunSpecStorage: Received" << modelId;
switch (modelId) { switch (modelId) {
case SunSpec::ModelIdStorage: { case SunSpec::ModelIdStorage: {
StorageData mandatory; StorageData mandatory;
qCDebug(dcSunSpec()) << " - Setpoint maximum charge" << data[Model124SetpointMaximumCharge];
qCDebug(dcSunSpec()) << " - Setpoint maximum charging rate" << data[Model124SetpointMaximumChargingRate];
qCDebug(dcSunSpec()) << " - Setpoint maximum discharge rate" << data[Model124SetpointMaximumDischargeRate];
qCDebug(dcSunSpec()) << " - Active storage control mode" << data[Model124ActivateStorageControlMode];
qCDebug(dcSunSpec()) << " - ChaGriSet" << data[Model124ChargeGridSet];
qCDebug(dcSunSpec()) << " - Scale factor max charge" << data[Model124ScaleFactorMaximumCharge];
qCDebug(dcSunSpec()) << " - Scale factor max charge/discharge rate" << data[Model124ScaleFactorMaximumChargeDischargeRate];
qCDebug(dcSunSpec()) << " - Scale factor" << data[Model124ScaleFactorAvailableEnergyPercent];
mandatory.maxCharge = m_connection->convertValueWithSSF(data[Model124SetpointMaximumCharge], data[Model124ScaleFactorMaximumChargeDischargeRate]); mandatory.maxCharge = m_connection->convertValueWithSSF(data[Model124SetpointMaximumCharge], data[Model124ScaleFactorMaximumChargeDischargeRate]);
mandatory.maxChargeRate = m_connection->convertValueWithSSF(data[Model124SetpointMaximumChargingRate], data[Model124ScaleFactorPercentChargeDischargeRate]); mandatory.maxChargeRate = m_connection->convertValueWithSSF(data[Model124SetpointMaximumChargingRate], data[Model124ScaleFactorPercentChargeDischargeRate]);
mandatory.chargingEnabled = data[Model124ActivateStorageControlMode]&0x01; mandatory.chargingEnabled = data[Model124ActivateStorageControlMode]&0x01;
@ -154,7 +146,6 @@ void SunSpecStorage::onModelDataBlockReceived(SunSpec::ModelId modelId, uint len
optional.storageAvailable = m_connection->convertValueWithSSF(data[Model124StorageAvailableAH], data[Model124ScaleFactorMaximumChargingVA]); optional.storageAvailable = m_connection->convertValueWithSSF(data[Model124StorageAvailableAH], data[Model124ScaleFactorMaximumChargingVA]);
optional.gridChargingEnabled = (data[Model124ChargeGridSet] == 1); optional.gridChargingEnabled = (data[Model124ChargeGridSet] == 1);
optional.currentlyAvailableEnergy = m_connection->convertValueWithSSF(data[Model124CurrentlyAvailableEnergyPercent], data[Model124ScaleFactorAvailableEnergyPercent]); optional.currentlyAvailableEnergy = m_connection->convertValueWithSSF(data[Model124CurrentlyAvailableEnergyPercent], data[Model124ScaleFactorAvailableEnergyPercent]);
emit storageDataReceived(mandatory, optional); emit storageDataReceived(mandatory, optional);
} break; } break;

View File

@ -64,7 +64,7 @@ public:
Q_ENUM(GridCharge) Q_ENUM(GridCharge)
enum ChargingStatus { enum ChargingStatus {
ChargingStatusOff, ChargingStatusOff = 1,
ChargingStatusEmpty, ChargingStatusEmpty,
ChargingStatusDischarging, ChargingStatusDischarging,
ChargingStatusCharging, ChargingStatusCharging,