diff --git a/sunspec/integrationpluginsunspec.cpp b/sunspec/integrationpluginsunspec.cpp index a4ebf2f..a2f4656 100644 --- a/sunspec/integrationpluginsunspec.cpp +++ b/sunspec/integrationpluginsunspec.cpp @@ -65,21 +65,29 @@ void IntegrationPluginSunSpec::init() m_modbusAddressParamTypeIds.insert(sunspecSplitPhaseMeterThingClassId, sunspecSplitPhaseMeterThingModbusAddressParamTypeId); m_modbusAddressParamTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseMeterThingModbusAddressParamTypeId); - m_acPowerStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterAcPowerStateTypeId); - m_acPowerStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterAcPowerStateTypeId); - m_acPowerStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterAcPowerStateTypeId); + m_inverterCurrentPowerStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterCurrentPowerStateTypeId); + m_inverterCurrentPowerStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterCurrentPowerStateTypeId); + m_inverterCurrentPowerStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterCurrentPowerStateTypeId); - m_acEnergyStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterAcEnergyStateTypeId); - m_acEnergyStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterAcEnergyStateTypeId); - m_acEnergyStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterAcEnergyStateTypeId); + m_inverterTotalEnergyProducedStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterTotalEnergyProducedStateTypeId); + m_inverterTotalEnergyProducedStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterTotalEnergyProducedStateTypeId); + m_inverterTotalEnergyProducedStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterTotalEnergyProducedStateTypeId); - m_inverterOperatingStateTypeIds.insert(sunspecSinglePhaseMeterThingClassId, sunspecSinglePhaseInverterOperatingStateStateTypeId); - m_inverterOperatingStateTypeIds.insert(sunspecSplitPhaseMeterThingClassId, sunspecSplitPhaseInverterOperatingStateStateTypeId); - m_inverterOperatingStateTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseInverterOperatingStateStateTypeId); + m_inverterOperatingStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterOperatingStateStateTypeId); + m_inverterOperatingStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterOperatingStateStateTypeId); + m_inverterOperatingStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterOperatingStateStateTypeId); - m_inverterErrorStateTypeIds.insert(sunspecSinglePhaseMeterThingClassId, sunspecSinglePhaseInverterErrorStateTypeId); - m_inverterErrorStateTypeIds.insert(sunspecSplitPhaseMeterThingClassId, sunspecSplitPhaseInverterErrorStateTypeId); - m_inverterErrorStateTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseInverterErrorStateTypeId); + m_inverterErrorStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterErrorStateTypeId); + m_inverterErrorStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterErrorStateTypeId); + m_inverterErrorStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterErrorStateTypeId); + + m_inverterCabinetTemperatureStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterCabinetTemperatureStateTypeId); + m_inverterCabinetTemperatureStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterCabinetTemperatureStateTypeId); + m_inverterCabinetTemperatureStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterCabinetTemperatureStateTypeId); + + m_inverterAcCurrentStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterTotalCurrentStateTypeId); + m_inverterAcCurrentStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterTotalCurrentStateTypeId); + m_inverterAcCurrentStateTypeIds.insert(sunspecThreePhaseInverterThingClassId, sunspecThreePhaseInverterTotalCurrentStateTypeId); m_frequencyStateTypeIds.insert(sunspecSinglePhaseInverterThingClassId, sunspecSinglePhaseInverterFrequencyStateTypeId); m_frequencyStateTypeIds.insert(sunspecSplitPhaseInverterThingClassId, sunspecSplitPhaseInverterFrequencyStateTypeId); @@ -638,14 +646,18 @@ void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::Inv qCDebug(dcSunSpec()) << " - Operating state" << inverterData.operatingState; thing->setStateValue(m_connectedStateTypeIds.value(thing->thingClassId()), true); - thing->setStateValue(m_acPowerStateTypeIds.value(thing->thingClassId()), inverterData.acPower/1000.00); - thing->setStateValue(m_acEnergyStateTypeIds.value(thing->thingClassId()), inverterData.acEnergy/1000.00); + thing->setStateValue(m_inverterCurrentPowerStateTypeIds.value(thing->thingClassId()), inverterData.acPower/1000.00); + thing->setStateValue(m_inverterTotalEnergyProducedStateTypeIds.value(thing->thingClassId()), inverterData.acEnergy/1000.00); thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), inverterData.lineFrequency); - thing->setStateValue(sunspecThreePhaseInverterTotalCurrentStateTypeId, inverterData.acCurrent); - thing->setStateValue(sunspecThreePhaseInverterCabinetTemperatureStateTypeId, inverterData.cabinetTemperature); + thing->setStateValue(m_inverterAcCurrentStateTypeIds.value(thing->thingClassId()), inverterData.acCurrent); + thing->setStateValue(m_inverterCabinetTemperatureStateTypeIds.value(thing->thingClassId()), inverterData.cabinetTemperature); - if (thing->thingClassId() == sunspecSplitPhaseInverterThingClassId) { + if (thing->thingClassId() == sunspecSinglePhaseInverterThingClassId) { + + thing->setStateValue(sunspecSinglePhaseInverterPhaseVoltageStateTypeId, inverterData.phaseVoltageAN); + + } else if (thing->thingClassId() == sunspecSplitPhaseInverterThingClassId) { thing->setStateValue(sunspecSplitPhaseInverterPhaseANVoltageStateTypeId, inverterData.phaseVoltageAN); thing->setStateValue(sunspecSplitPhaseInverterPhaseBNVoltageStateTypeId, inverterData.phaseVoltageBN); @@ -693,39 +705,39 @@ void IntegrationPluginSunSpec::onInverterDataReceived(const SunSpecInverter::Inv //FIXME: Event1 may have multiple states at once. Only one is stated in nymea if (inverterData.event1.overTemperature) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Over temperature"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Over temperature"); } else if (inverterData.event1.underTemperature) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Under temperature"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Under temperature"); } else if (inverterData.event1.groundFault) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Ground fault"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Ground fault"); } else if (inverterData.event1.memoryLoss) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Memory loss"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Memory loss"); } else if (inverterData.event1.acOverVolt) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "AC voltage above limit"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "AC voltage above limit"); } else if (inverterData.event1.cabinetOpen) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Cabinet open"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Cabinet open"); } else if (inverterData.event1.acDisconnect) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "AC disconnect open"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "AC disconnect open"); } else if (inverterData.event1.acUnderVolt) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "AC voltage under limit"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "AC voltage under limit"); } else if (inverterData.event1.dcDicconnect) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "DC disconnect open"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "DC disconnect open"); } else if (inverterData.event1.dcOverVoltage) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "DC over voltage"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "DC over voltage"); } else if (inverterData.event1.overFrequency) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Frequency above limit"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Frequency above limit"); } else if (inverterData.event1.gridDisconnect) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Grid disconnect"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Grid disconnect"); } else if (inverterData.event1.hwTestFailure) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Hardware test failure"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Hardware test failure"); } else if (inverterData.event1.manualShutdown) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Manual shutdown"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Manual shutdown"); } else if (inverterData.event1.underFrequency) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Frequency under limit"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Frequency under limit"); } else if (inverterData.event1.blownStringFuse) { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "Blown string fuse on input"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "Blown string fuse on input"); } else { - thing->setStateValue(sunspecThreePhaseInverterErrorStateTypeId, "None"); + thing->setStateValue(m_inverterErrorStateTypeIds.value(thing->thingClassId()), "None"); } } @@ -801,13 +813,29 @@ 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(sunspecThreePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); - thing->setStateValue(sunspecThreePhaseMeterPhaseBCurrentStateTypeId, meterData.phaseBCurrent); - thing->setStateValue(sunspecThreePhaseMeterPhaseCCurrentStateTypeId, meterData.phaseCCurrent); - thing->setStateValue(sunspecThreePhaseMeterLnACVoltageStateTypeId, meterData.voltageLN); - thing->setStateValue(sunspecThreePhaseMeterTotalRealPowerEventTypeId, meterData.totalRealPower); - thing->setStateValue(sunspecThreePhaseMeterEnergyExportedStateTypeId, meterData.totalRealEnergyExported); - thing->setStateValue(sunspecThreePhaseMeterEnergyImportedStateTypeId, meterData.totalRealEnergyImported); - thing->setStateValue(m_frequencyStateTypeIds.value(thing->thingClassId()), meterData.frequency); + + if (thing->thingClassId() == sunspecSinglePhaseMeterThingClassId) { + thing->setStateValue(sunspecSinglePhaseMeterPhaseACurrentStateTypeId, meterData.phaseACurrent); + thing->setStateValue(sunspecSinglePhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower); + 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(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(sunspecThreePhaseMeterCurrentPowerEventTypeId, meterData.totalRealPower); + thing->setStateValue(sunspecThreePhaseMeterTotalEnergyProducedStateTypeId, meterData.totalRealEnergyExported); + thing->setStateValue(sunspecThreePhaseMeterTotalEnergyConsumedStateTypeId, meterData.totalRealEnergyImported); + } } diff --git a/sunspec/integrationpluginsunspec.h b/sunspec/integrationpluginsunspec.h index b860ddd..bdb8252 100644 --- a/sunspec/integrationpluginsunspec.h +++ b/sunspec/integrationpluginsunspec.h @@ -63,10 +63,13 @@ private: QHash m_connectedStateTypeIds; QHash m_frequencyStateTypeIds; - QHash m_acPowerStateTypeIds; - QHash m_acEnergyStateTypeIds; + + QHash m_inverterCurrentPowerStateTypeIds; + QHash m_inverterTotalEnergyProducedStateTypeIds; QHash m_inverterOperatingStateTypeIds; QHash m_inverterErrorStateTypeIds; + QHash m_inverterCabinetTemperatureStateTypeIds; + QHash m_inverterAcCurrentStateTypeIds; PluginTimer *m_refreshTimer = nullptr; QHash m_asyncActions; diff --git a/sunspec/integrationpluginsunspec.json b/sunspec/integrationpluginsunspec.json index b28d92d..df83b8b 100644 --- a/sunspec/integrationpluginsunspec.json +++ b/sunspec/integrationpluginsunspec.json @@ -40,7 +40,7 @@ "displayName": "SunSpec connection", "id": "f51853f3-8815-4cf3-b337-45cda1f3e6d5", "createMethods": [ "User" ], - "interfaces": ["connectable"], + "interfaces": ["gateway"], "paramTypes": [ { "id": "6be6abc4-e2b2-4687-9343-0e5164ed0ab2", @@ -105,7 +105,7 @@ "displayName": "SunSpec single phase inverter", "id": "c5d5204e-3375-4b92-8128-fab77a671fed", "createMethods": [ "Auto" ], - "interfaces": ["connectable"], + "interfaces": ["extendedsmartmeterproducer", "connectable"], "paramTypes": [ { "id": "41715d00-a947-4f43-a475-cea05790e01d", @@ -153,11 +153,11 @@ }, { "id": "f49591d6-d759-4be3-bafc-b6a7a72cf023", - "name": "acPower", + "name": "currentPower", "displayName": "AC power", "displayNameEvent": "AC power changed", "type": "double", - "unit": "KiloWatt", + "unit": "Watt", "defaultValue": 0.00 }, { @@ -171,7 +171,7 @@ }, { "id": "4c0407b3-5cd5-438d-bfa8-9a8d6695b458", - "name": "acEnergy", + "name": "totalEnergyProduced", "displayName": "AC energy", "displayNameEvent": "AC energy changed", "type": "double", @@ -239,7 +239,7 @@ "displayName": "SunSpec split phase inverter", "id": "61b38f93-d331-42bf-b1ef-d3fb16ad1230", "createMethods": [ "Auto" ], - "interfaces": ["connectable"], + "interfaces": ["extendedsmartmeterproducer", "connectable"], "paramTypes": [ { "id": "c42fb50e-210f-4b53-88eb-fa216e15f88f", @@ -314,11 +314,11 @@ }, { "id": "9235eb4b-906c-4557-8e18-bca268a367cc", - "name": "acPower", + "name": "currentPower", "displayName": "AC power", "displayNameEvent": "AC power changed", "type": "double", - "unit": "KiloWatt", + "unit": "Watt", "defaultValue": 0.00 }, { @@ -332,7 +332,7 @@ }, { "id": "fe3f8a65-121a-4ae1-b22a-ae325dc3e7e6", - "name": "acEnergy", + "name": "totalEnergyProduced", "displayName": "AC energy", "displayNameEvent": "AC energy changed", "type": "double", @@ -400,7 +400,7 @@ "displayName": "SunSpec three phase inverter", "id": "2e4122ea-96a5-415c-b5e2-7d6012265a83", "createMethods": [ "Auto" ], - "interfaces": ["connectable"], + "interfaces": ["extendedsmartmeterproducer", "connectable"], "paramTypes": [ { "id": "8d5b2b58-ce46-406d-844e-f53136afcf09", @@ -493,11 +493,11 @@ }, { "id": "14036f44-25fd-4e93-8e8c-c677b06a2c34", - "name": "acPower", + "name": "currentPower", "displayName": "AC power", "displayNameEvent": "AC power changed", "type": "double", - "unit": "KiloWatt", + "unit": "Watt", "defaultValue": 0.00 }, { @@ -511,7 +511,7 @@ }, { "id": "d493880d-eb58-4530-8010-8ea4f6d63387", - "name": "acEnergy", + "name": "totalEnergyProduced", "displayName": "AC energy", "displayNameEvent": "AC energy changed", "type": "double", @@ -579,7 +579,7 @@ "displayName": "SunSpec single phase meter", "id": "7ffa43b8-b56f-4435-8509-980e9d81dfa8", "createMethods": [ "Auto" ], - "interfaces": ["connectable"], + "interfaces": ["extendedsmartmeterconsumer", "connectable"], "paramTypes": [ { "id": "7d6fcafb-c62e-4a21-aae2-f4041c487149", @@ -646,16 +646,16 @@ }, { "id": "93cf8c6a-2620-42ed-9070-e0726d7b1dbc", - "name": "totalRealPower", + "name": "currentPower", "displayName": "Total real power", "displayNameEvent": "Total real power changed", "type": "double", - "unit": "KiloWatt", + "unit": "Watt", "defaultValue": 0.00 }, { "id": "ba275bdf-f418-4ef0-afbe-ac425c6f6783", - "name": "energyExported", + "name": "totalEnergyProduced", "displayName": "Total real energy exported", "displayNameEvent": "Total real energy exported changed", "type": "double", @@ -664,7 +664,7 @@ }, { "id": "c51dc6cb-5c05-4078-b11a-26afb2f85541", - "name": "energyImported", + "name": "totalEnergyConsumed", "displayName": "Total real energy imported", "displayNameEvent": "Total real energy imported changed", "type": "double", @@ -678,7 +678,7 @@ "displayName": "SunSpec split phase meter", "id": "b8a18e45-5ff5-4f43-915f-04ee216c809d", "createMethods": [ "Auto" ], - "interfaces": ["connectable"], + "interfaces": ["extendedsmartmeterconsumer", "connectable"], "paramTypes": [ { "id": "89aeec6d-abeb-48b5-9594-214ad5db2d03", @@ -772,16 +772,16 @@ }, { "id": "ef4bc0f8-f516-49b7-aba8-d5f987485aca", - "name": "totalRealPower", + "name": "currentPower", "displayName": "Total real power", "displayNameEvent": "Total real power changed", "type": "double", - "unit": "KiloWatt", + "unit": "Watt", "defaultValue": 0.00 }, { "id": "8a63bd73-0546-4636-8da2-23238cc06fb2", - "name": "energyExported", + "name": "totalEnergyProduced", "displayName": "Total real energy exported", "displayNameEvent": "Total real energy exported changed", "type": "double", @@ -790,7 +790,7 @@ }, { "id": "51ffb2ae-3920-40df-8290-bbf5b6e1a68f", - "name": "energyImported", + "name": "totalEnergyConsumed", "displayName": "Total real energy imported", "displayNameEvent": "Total real energy imported changed", "type": "double", @@ -804,7 +804,7 @@ "displayName": "SunSpec three phase meter", "id": "68f822f9-ff30-4275-b229-39a3674fead7", "createMethods": [ "Auto" ], - "interfaces": ["connectable"], + "interfaces": ["extendedsmartmeterconsumer", "connectable"], "paramTypes": [ { "id": "a1960821-155c-4176-86fa-974429039182", @@ -916,16 +916,16 @@ }, { "id": "c28c642f-46da-44de-ba0d-c4cbfadbf2cd", - "name": "totalRealPower", + "name": "currentPower", "displayName": "Total real power", "displayNameEvent": "Total real power changed", "type": "double", - "unit": "KiloWatt", + "unit": "Watt", "defaultValue": 0.00 }, { "id": "73ebf57f-1ad2-4d19-bfd9-9e0a514c1243", - "name": "energyExported", + "name": "totalEnergyProduced", "displayName": "Total real energy exported", "displayNameEvent": "Total real energy exported changed", "type": "double", @@ -934,7 +934,7 @@ }, { "id": "63fa4721-1b0a-458c-b66c-17c161107f0d", - "name": "energyImported", + "name": "totalEnergyConsumed", "displayName": "Total real energy imported", "displayNameEvent": "Total real energy imported changed", "type": "double", diff --git a/sunspec/sunspec.cpp b/sunspec/sunspec.cpp index 071666c..5aa4794 100644 --- a/sunspec/sunspec.cpp +++ b/sunspec/sunspec.cpp @@ -363,10 +363,9 @@ float SunSpec::convertValueWithSSF(quint32 rawValue, quint16 sunssf) float SunSpec::convertFloatValues(quint16 rawValue0, quint16 rawValue1) { - float value; - uint32_t i = qFromLittleEndian(((uint32_t)rawValue0 << 16) + rawValue1); - memcpy(&value, &i, sizeof(float)); - return value; + suns_modbus_v32_t value; + value.u = (static_cast(rawValue0) << 16) + rawValue1; + return value.f; } void SunSpec::onModbusStateChanged(QModbusDevice::State state) diff --git a/sunspec/sunspec.h b/sunspec/sunspec.h index 8021df4..971b919 100644 --- a/sunspec/sunspec.h +++ b/sunspec/sunspec.h @@ -42,6 +42,12 @@ class SunSpec : public QObject public: + typedef union { + int32_t s; + uint32_t u; + float f; + } suns_modbus_v32_t; + enum MandatoryRegistersModel1 { Manufacturer = 2, Model = 18, diff --git a/sunspec/sunspecinverter.cpp b/sunspec/sunspecinverter.cpp index 9811a98..f791415 100644 --- a/sunspec/sunspecinverter.cpp +++ b/sunspec/sunspecinverter.cpp @@ -76,23 +76,24 @@ void SunSpecInverter::getInverterModelDataBlock() SunSpecInverter::SunSpecEvent1 SunSpecInverter::bitfieldToSunSpecEvent1(quint16 register1, quint16 register2) { SunSpecEvent1 event1; - Q_UNUSED(register2); - event1.groundFault = ((register1 & (0x01 << 0)) != 0); - event1.dcOverVoltage = ((register1 & (0x01 << 1)) != 0); - event1.acDisconnect = ((register1 & (0x01 << 2)) != 0); - event1.dcDicconnect = ((register1 & (0x01 << 3)) != 0); - event1.gridDisconnect = ((register1 & (0x01 << 4)) != 0); - event1.cabinetOpen = ((register1 & (0x01 << 5)) != 0); - event1.manualShutdown = ((register1 & (0x01 << 6)) != 0); - event1.overTemperature = ((register1 & (0x01 << 7)) != 0); - event1.overFrequency = ((register1 & (0x01 << 8)) != 0); - event1.underFrequency = ((register1 & (0x01 << 9)) != 0); - event1.acOverVolt = ((register1 & (0x01 << 10)) != 0); - event1.acUnderVolt = ((register1 & (0x01 << 11)) != 0); - event1.blownStringFuse = ((register1 & (0x01 << 12)) != 0); - event1.underTemperature = ((register1 & (0x01 << 13)) != 0); - event1.memoryLoss = ((register1 & (0x01 << 14)) != 0); - event1.hwTestFailure = ((register1 & (0x01 << 15)) != 0); + quint32 value = (static_cast(register1)<<16 | register2); + //qCDebug(dcSunSpec()) << "Event1" << QString::number(value, 16); + event1.groundFault = ((value & (0x01 << 0)) != 0); + event1.dcOverVoltage = ((value & (0x01 << 1)) != 0); + event1.acDisconnect = ((value & (0x01 << 2)) != 0); + event1.dcDicconnect = ((value & (0x01 << 3)) != 0); + event1.gridDisconnect = ((value & (0x01 << 4)) != 0); + event1.cabinetOpen = ((value & (0x01 << 5)) != 0); + event1.manualShutdown = ((value & (0x01 << 6)) != 0); + event1.overTemperature = ((value & (0x01 << 7)) != 0); + event1.overFrequency = ((value & (0x01 << 8)) != 0); + event1.underFrequency = ((value & (0x01 << 9)) != 0); + event1.acOverVolt = ((value & (0x01 << 10)) != 0); + event1.acUnderVolt = ((value & (0x01 << 11)) != 0); + event1.blownStringFuse = ((value & (0x01 << 12)) != 0); + event1.underTemperature = ((value & (0x01 << 13)) != 0); + event1.memoryLoss = ((value & (0x01 << 14)) != 0); + event1.hwTestFailure = ((value & (0x01 << 15)) != 0); return event1; }