diff --git a/sunspec/integrationpluginsunspec.cpp b/sunspec/integrationpluginsunspec.cpp index a2f4656..48eaf2c 100644 --- a/sunspec/integrationpluginsunspec.cpp +++ b/sunspec/integrationpluginsunspec.cpp @@ -610,13 +610,19 @@ void IntegrationPluginSunSpec::onSunSpecModelSearchFinished(const QHashfinish(Thing::ThingErrorNoError); + } else { + info->finish(Thing::ThingErrorHardwareFailure); + } + } } void IntegrationPluginSunSpec::onWriteRequestError(QUuid requestId, const QString &error) { - Q_UNUSED(requestId) - Q_UNUSED(error) - qCDebug(dcSunSpec()) << "Write request error" << error; + qCDebug(dcSunSpec()) << "Write request error" << requestId << error; } void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::InverterData &inverterData) @@ -646,7 +652,7 @@ void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::Inv qCDebug(dcSunSpec()) << " - Operating state" << inverterData.operatingState; 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_frequencyStateTypeIds.value(thing->thingClassId()), inverterData.lineFrequency); @@ -749,10 +755,23 @@ void IntegrationPluginSunSpec::onStorageDataReceived(const SunSpecStorage::Stora if(!thing) { 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(sunspecStorageDischargingRateStateTypeId, mandatory.maxDischargeRate); + thing->setStateValue(sunspecStorageEnableChargingStateTypeId, mandatory.chargingEnabled); + thing->setStateValue(sunspecStorageEnableDischargingStateTypeId, mandatory.dischargingEnabled); + thing->setStateValue(sunspecStorageGridChargingStateTypeId, optional.gridChargingEnabled); bool charging = false; switch (optional.chargeSatus) { @@ -785,7 +804,6 @@ void IntegrationPluginSunSpec::onStorageDataReceived(const SunSpecStorage::Stora void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData &meterData) { - Q_UNUSED(meterData) SunSpecMeter *meter = static_cast(sender()); Thing *thing = m_sunSpecMeters.key(meter); @@ -793,8 +811,6 @@ void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData return; } - thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true); - qCDebug(dcSunSpec()) << "Meter data received"; qCDebug(dcSunSpec()) << " - Total AC Current" << meterData.totalAcCurrent << "[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 imported" << meterData.totalRealEnergyImported<< "[kWH]"; - thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), meterData.frequency); - thing->setStateValue(sunspecThreePhaseMeterTotalCurrentStateTypeId, meterData.totalAcCurrent); + thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true); + thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), meterData.frequency); if (thing->thingClassId() == sunspecSinglePhaseMeterThingClassId) { thing->setStateValue(sunspecSinglePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); @@ -822,18 +838,25 @@ void IntegrationPluginSunSpec::onMeterDataReceived(const SunSpecMeter::MeterData thing->setStateValue(sunspecSinglePhaseMeterLnACVoltageStateTypeId, meterData.voltageLN); thing->setStateValue(sunspecSinglePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); thing->setStateValue(sunspecSinglePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); + } else if (thing->thingClassId() == sunspecSplitPhaseMeterThingClassId) { thing->setStateValue(sunspecSplitPhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); thing->setStateValue(sunspecSplitPhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent); thing->setStateValue(sunspecSplitPhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower); thing->setStateValue(sunspecSplitPhaseMeterLnACVoltageStateTypeId, meterData.voltageLN); + thing->setStateValue(sunspecSplitPhaseMeterPhaseANVoltageStateTypeId, meterData.phaseVoltageAN); + thing->setStateValue(sunspecSplitPhaseMeterPhaseBNVoltageStateTypeId, meterData.phaseVoltageBN); thing->setStateValue(sunspecSplitPhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); thing->setStateValue(sunspecSplitPhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); + } else if (thing->thingClassId() == sunspecThreePhaseMeterThingClassId) { thing->setStateValue(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent); thing->setStateValue(sunspecThreePhaseMeterPhaseCCurrentStateTypeId, meterData.phaseCCurrent); 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(sunspecThreePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); thing->setStateValue(sunspecThreePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); diff --git a/sunspec/sunspecinverter.cpp b/sunspec/sunspecinverter.cpp index f791415..0f1dbb8 100644 --- a/sunspec/sunspecinverter.cpp +++ b/sunspec/sunspecinverter.cpp @@ -73,10 +73,10 @@ void SunSpecInverter::getInverterModelDataBlock() 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; - quint32 value = (static_cast(register1)<<16 | register2); + quint32 value = (static_cast(register0)<<16 | register1); //qCDebug(dcSunSpec()) << "Event1" << QString::number(value, 16); event1.groundFault = ((value & (0x01 << 0)) != 0); event1.dcOverVoltage = ((value & (0x01 << 1)) != 0); diff --git a/sunspec/sunspecinverter.h b/sunspec/sunspecinverter.h index 712983b..e668ca9 100644 --- a/sunspec/sunspecinverter.h +++ b/sunspec/sunspecinverter.h @@ -168,12 +168,12 @@ public: private: 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_modelModbusStartRegister = 40000; bool m_initFinishedSuccess = false; - SunSpecEvent1 bitfieldToSunSpecEvent1(quint16 register1, quint16 register2); + SunSpecEvent1 bitfieldToSunSpecEvent1(quint16 register0, quint16 register1); void getInverterModelHeader(); private slots: diff --git a/sunspec/sunspecstorage.cpp b/sunspec/sunspecstorage.cpp index b40a098..534c6fa 100644 --- a/sunspec/sunspecstorage.cpp +++ b/sunspec/sunspecstorage.cpp @@ -127,21 +127,13 @@ void SunSpecStorage::onModelDataBlockReceived(SunSpec::ModelId modelId, uint len if (length < m_modelLength) { qCDebug(dcSunSpec()) << "SunSpecMeter: on model data block received, model length is too short" << length; - //return; + return; } qCDebug(dcSunSpec()) << "SunSpecStorage: Received" << modelId; switch (modelId) { case SunSpec::ModelIdStorage: { 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.maxChargeRate = m_connection->convertValueWithSSF(data[Model124SetpointMaximumChargingRate], data[Model124ScaleFactorPercentChargeDischargeRate]); 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.gridChargingEnabled = (data[Model124ChargeGridSet] == 1); optional.currentlyAvailableEnergy = m_connection->convertValueWithSSF(data[Model124CurrentlyAvailableEnergyPercent], data[Model124ScaleFactorAvailableEnergyPercent]); - emit storageDataReceived(mandatory, optional); } break; diff --git a/sunspec/sunspecstorage.h b/sunspec/sunspecstorage.h index 87e316c..eada11e 100644 --- a/sunspec/sunspecstorage.h +++ b/sunspec/sunspecstorage.h @@ -64,7 +64,7 @@ public: Q_ENUM(GridCharge) enum ChargingStatus { - ChargingStatusOff, + ChargingStatusOff = 1, ChargingStatusEmpty, ChargingStatusDischarging, ChargingStatusCharging,