Remaved storage register to original sunspec name

master
Boernsman 2021-02-04 13:37:31 +01:00
parent 5efce86683
commit 73958b2e59
3 changed files with 77 additions and 72 deletions

View File

@ -757,24 +757,24 @@ void IntegrationPluginSunSpec::onStorageDataReceived(const SunSpecStorage::Stora
}
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;
qCDebug(dcSunSpec()) << " - Setpoint for maximum charge" << mandatory.WChaMax << "[W]";
qCDebug(dcSunSpec()) << " - Setpoint for maximum charging rate." << mandatory.WChaGra << "[%]";
qCDebug(dcSunSpec()) << " - Setpoint for maximum discharging rate." << mandatory.WDisChaGra << "[%]";
qCDebug(dcSunSpec()) << " - Charging enabled" << mandatory.StorCtl_Mod_ChargingEnabled;
qCDebug(dcSunSpec()) << " - Discharging enabled" << mandatory.StorCtl_Mod_DischargingEnabled;
qCDebug(dcSunSpec()) << " - Storage status" << optional.ChaSt;
qCDebug(dcSunSpec()) << " - Currently available energy" << optional.ChaState << "[%]";
qCDebug(dcSunSpec()) << " - Grid charging enabled" << optional.ChaGriSet;
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);
thing->setStateValue(sunspecStorageChargingRateStateTypeId, mandatory.WChaGra);
thing->setStateValue(sunspecStorageDischargingRateStateTypeId, mandatory.WDisChaGra);
thing->setStateValue(sunspecStorageEnableChargingStateTypeId, mandatory.StorCtl_Mod_ChargingEnabled);
thing->setStateValue(sunspecStorageEnableDischargingStateTypeId, mandatory.StorCtl_Mod_DischargingEnabled);
thing->setStateValue(sunspecStorageGridChargingStateTypeId, optional.ChaGriSet);
bool charging = false;
switch (optional.chargeSatus) {
switch (optional.ChaSt) {
case SunSpecStorage::ChargingStatusOff:
thing->setStateValue(sunspecStorageStorageStatusStateTypeId, "Off");
break;
@ -797,7 +797,7 @@ void IntegrationPluginSunSpec::onStorageDataReceived(const SunSpecStorage::Stora
thing->setStateValue(sunspecStorageStorageStatusStateTypeId, "Discharging");
break;
};
double batteryLevel = optional.currentlyAvailableEnergy;
double batteryLevel = optional.ChaState;
thing->setStateValue(sunspecStorageBatteryLevelStateTypeId, batteryLevel);
thing->setStateValue(sunspecStorageBatteryCriticalStateTypeId, (batteryLevel < 5 && !charging));
}

View File

@ -85,7 +85,7 @@ QUuid SunSpecStorage::setGridCharging(bool enabled)
PV (charging from grid 0 disabled)
GRID (charging from 1 grid enabled*/
uint registerAddress = m_modelModbusStartRegister + Model124Optional::Model124ChargeGridSet;
uint registerAddress = m_modelModbusStartRegister + Model124Optional::Model124ChaGriSet;
quint16 value = enabled;
return m_connection->writeHoldingRegister(registerAddress, value);
}
@ -96,7 +96,7 @@ QUuid SunSpecStorage::setStorageControlMode(bool chargingEnabled, bool dischargi
quint16 value = ((static_cast<quint16>(chargingEnabled)) |
(static_cast<quint16>(dischargingEnabled) << 1)) ;
uint modbusRegister = m_modelModbusStartRegister + Model124::Model124ActivateStorageControlMode;
uint modbusRegister = m_modelModbusStartRegister + Model124::Model124StorCtl_Mod;
return m_connection->writeHoldingRegister(modbusRegister, value);
}
@ -105,7 +105,7 @@ QUuid SunSpecStorage::setChargingRate(int rate)
//Register Name InWRte
/* Defines the maximum charge rate (charge limit). Default is 100% */
uint modbusRegister = m_modelModbusStartRegister + Model124::Model124SetpointMaximumChargingRate;
uint modbusRegister = m_modelModbusStartRegister + Model124::Model124WChaGra;
int16_t value = rate * 100;
return m_connection->writeHoldingRegister(modbusRegister, value);
}
@ -114,7 +114,7 @@ QUuid SunSpecStorage::setDischargingRate(int charging)
{
//Register Name OutWRte
/* Defines the maximum discharge rate (discharge limit). Default is 100% */
uint modbusRegister = m_modelModbusStartRegister + Model124::Model124SetpointMaximumDischargeRate;
uint modbusRegister = m_modelModbusStartRegister + Model124::Model124WDisChaGra;
quint16 value = charging * 100;
return m_connection->writeHoldingRegister(modbusRegister, value);
}
@ -134,20 +134,26 @@ void SunSpecStorage::onModelDataBlockReceived(SunSpec::ModelId modelId, uint len
switch (modelId) {
case SunSpec::ModelIdStorage: {
StorageData mandatory;
mandatory.maxCharge = m_connection->convertValueWithSSF(data[Model124SetpointMaximumCharge], data[Model124ScaleFactorMaximumChargeDischargeRate]);
mandatory.maxChargeRate = m_connection->convertValueWithSSF(data[Model124SetpointMaximumChargingRate], data[Model124ScaleFactorPercentChargeDischargeRate]);
mandatory.chargingEnabled = data[Model124ActivateStorageControlMode]&0x01;
mandatory.dischargingEnabled = data[Model124ActivateStorageControlMode]&0x02;
mandatory.maxDischargeRate = m_connection->convertValueWithSSF(data[Model124SetpointMaximumDischargeRate], data[Model124ScaleFactorPercentChargeDischargeRate]);
mandatory.WChaMax = m_connection->convertValueWithSSF(data[Model124WChaMax], data[Model124WChaMax_SF]);
mandatory.WChaGra = m_connection->convertValueWithSSF(data[Model124WChaGra], data[Model124WChaDisChaGra_SF]);
mandatory.WDisChaGra = m_connection->convertValueWithSSF(data[Model124WDisChaGra], data[Model124WChaDisChaGra_SF]);
mandatory.StorCtl_Mod_ChargingEnabled = data[Model124StorCtl_Mod]&0x01;
mandatory.StorCtl_Mod_DischargingEnabled = data[Model124StorCtl_Mod]&0x02;
StorageDataOptional optional;
optional.chargeSatus = ChargingStatus(data[Model124ChargeStatus]);
optional.batteryVoltage = m_connection->convertValueWithSSF(data[Model124InternalBatteryVoltage], data[Model124ScaleFactorBatteryVoltage]);
optional.storageAvailable = m_connection->convertValueWithSSF(data[Model124StorageAvailableAH], data[Model124ScaleFactorMaximumChargingVA]);
optional.gridChargingEnabled = (data[Model124ChargeGridSet] == 1);
optional.currentlyAvailableEnergy = m_connection->convertValueWithSSF(data[Model124CurrentlyAvailableEnergyPercent], data[Model124ScaleFactorAvailableEnergyPercent]);
optional.VAChaMax = m_connection->convertValueWithSSF(data[Model124VAChaMax], data[Model124VAChaMax_SF]);
optional.MinRsvPct = m_connection->convertValueWithSSF(data[Model124MinRsvPct], data[Model124MinRsvPct_SF]);
optional.ChaState = m_connection->convertValueWithSSF(data[Model124ChaState], data[Model124ChaState_SF]);
optional.StorAval = m_connection->convertValueWithSSF(data[Model124StorAval], data[Model124StorAval_SF]);
optional.InBatV = m_connection->convertValueWithSSF(data[Model124InBatV], data[Model124InBatV_SF]);
optional.ChaSt = ChargingStatus(data[Model124ChaSt]);
optional.OutWRte = m_connection->convertValueWithSSF(data[Model124OutWRte], data[Model124InOutWRte_SF]);
optional.InWRte = m_connection->convertValueWithSSF(data[Model124InWRte], data[Model124InOutWRte_SF]);
optional.InOutWRte_WinTms = data[Model124InOutWRte_WinTms];
optional.InOutWRte_RvrtTms = data[Model124InOutWRte_RvrtTms];
optional.InOutWRte_RmpTms = data[Model124InOutWRte_RmpTms];
optional.ChaGriSet = GridCharge(data[Model124ChaGriSet]);
emit storageDataReceived(mandatory, optional);
} break;
case SunSpec::ModelIdBatteryBaseModel:
case SunSpec::ModelIdLithiumIonBatteryModel: {

View File

@ -75,58 +75,57 @@ public:
Q_ENUM(ChargingStatus)
enum Model124 { // Mandatory registers
Model124SetpointMaximumCharge = 0,
Model124SetpointMaximumChargingRate = 1,
Model124SetpointMaximumDischargeRate = 2,
Model124ActivateStorageControlMode = 3,
Model124ScaleFactorMaximumCharge = 16,
Model124ScaleFactorMaximumChargeDischargeRate = 17,
Model124WChaMax = 0,
Model124WChaGra = 1,
Model124WDisChaGra = 2,
Model124StorCtl_Mod = 3,
Model124WChaMax_SF = 16,
Model124WChaDisChaGra_SF = 17,
};
Q_ENUM(Model124)
enum Model124Optional { // Optional registers
Model124MaximumChargingVA = 4, // VAChaMax
Model124MinimumReserveStoragePercent = 5, // MinRsvPct
Model124CurrentlyAvailableEnergyPercent = 6, // ChaState
Model124StorageAvailableAH = 7, // StorAval
Model124InternalBatteryVoltage = 8, // InBatV
Model124ChargeStatus = 9, // ChaSt
Model124MaxDischargingRatePercent = 10, // OutWRte
Model124MaxChargingRatePercent = 11,
Model124ChargeDischargeTimeWindow = 12,
Model124ChargeDischargeTimeout = 13,
Model124RampTime = 14, // InOutWRte_RmpTms
Model124ChargeGridSet = 15, // ChGriSet
Model124ScaleFactorMaximumChargingVA = 18,
Model124ScaleFactorMinimumReservePercentage = 19,
Model124ScaleFactorAvailableEnergyPercent = 20,
Model124ScaleFactorStateCharge = 21,
Model124ScaleFactorBatteryVoltage = 22,
Model124ScaleFactorPercentChargeDischargeRate = 23
Model124VAChaMax = 4,
Model124MinRsvPct = 5,
Model124ChaState = 6,
Model124StorAval = 7,
Model124InBatV = 8,
Model124ChaSt = 9,
Model124OutWRte = 10,
Model124InWRte = 11,
Model124InOutWRte_WinTms = 12,
Model124InOutWRte_RvrtTms = 13,
Model124InOutWRte_RmpTms = 14,
Model124ChaGriSet = 15,
Model124VAChaMax_SF = 18,
Model124MinRsvPct_SF = 19,
Model124ChaState_SF = 20,
Model124StorAval_SF = 21,
Model124InBatV_SF = 22,
Model124InOutWRte_SF = 23
};
Q_ENUM(Model124Optional)
struct StorageData {
double maxCharge; // [W] Setpoint for maximum charge.
double maxChargeRate; // [%] Setpoint for maximum charging rate. Default is MaxChaRte.
double maxDischargeRate; // [%] Setpoint for maximum discharge rate. Default is MaxDisChaRte.
bool chargingEnabled;
bool dischargingEnabled;
double WChaMax; // [W] Setpoint for maximum charge.
double WChaGra; // [%] Setpoint for maximum charging rate. Default is MaxChaRte.
double WDisChaGra; // [%] Setpoint for maximum discharge rate. Default is MaxDisChaRte.
bool StorCtl_Mod_ChargingEnabled;
bool StorCtl_Mod_DischargingEnabled;
};
struct StorageDataOptional {
// [VA] Setpoint for maximum charging VA.
// [& ]Setpoint for minimum reserve for storage as a percentage of the nominal maximum storage.
double currentlyAvailableEnergy; // [%] Currently available energy as a percent of the capacity rating.
double storageAvailable; // [Ah] State of charge (ChaState) minus storage reserve (MinRsvPct) times capacity rating (AhrRtg).
double batteryVoltage; // [V] Internal battery voltage.
ChargingStatus chargeSatus; // Charge status of storage device. Enumerated value.
// [%] Percent of max discharge rate.
// [%] Percent of max charging rate.
// [s] Time window for charge/discharge rate change.
// [s] Timeout period for charge/discharge rate.
// [s] Ramp time for moving from current setpoint to new setpoint.
bool gridChargingEnabled;
double VAChaMax; // [VA] Setpoint for maximum charging VA.
double MinRsvPct; // [%]Setpoint for minimum reserve for storage as a percentage of the nominal maximum storage.
double ChaState; // [%] Currently available energy as a percent of the capacity rating.
double StorAval; // [Ah] State of charge (ChaState) minus storage reserve (MinRsvPct) times capacity rating (AhrRtg).
double InBatV; // [V] Internal battery voltage.
ChargingStatus ChaSt; // Charge status of storage device. Enumerated value.
double OutWRte; // [%] Percent of max discharge rate.
double InWRte; // [%] Percent of max charging rate.
uint InOutWRte_WinTms; // [s] Time window for charge/discharge rate change.
uint InOutWRte_RvrtTms; // [s] Timeout period for charge/discharge rate.
uint InOutWRte_RmpTms; // [s] Ramp time for moving from current setpoint to new setpoint.
GridCharge ChaGriSet; // 0 = PV, 1 = Grid
};
private: