etm-powersync-plugins-modbus/sunspec/sunspecstoragelogic.h
Patrick Schurig 4ec7aa50e8 sunspec: reconcile storage states from the registers actions write
onStorageBlockUpdated() fed chargingRate from wChaGra() and dischargingRate
from wDisChaGra(). Those are the gradients, in percent of WChaMax per
second, and read only on several inverters. The matching actions write
InWRte and OutWRte, in percent of WChaMax. The user wrote one quantity and
read back another.

Feed the two rate states from inWRte() and outWRte(), and keep the
gradients under names that cannot be mistaken for setpoints:
chargeGradient and dischargeGradient, read only.

enableDischarging was never reconciled either, while enableCharging was.
It stayed frozen on the last written value and drifted silently as soon as
the inverter changed StorCtl_Mod on its own. Reconcile both flags.

The mapping moves into SunSpecStorageLogic so it can be exercised on a
register dump without a running nymea.
2026-07-31 10:22:44 +02:00

71 lines
2.4 KiB
C++

// SPDX-License-Identifier: GPL-3.0-or-later
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright (C) 2013 - 2024, nymea GmbH
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
*
* This file is part of nymea.
*
* nymea is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* nymea is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* nymea. If not, see <https://www.gnu.org/licenses/>.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef SUNSPECSTORAGELOGIC_H
#define SUNSPECSTORAGELOGIC_H
#include <QVector>
#include <models/sunspecstoragemodel.h>
/* Decision logic of the storage (model 124) handling, kept free of the
* integration framework so it can be exercised without a running nymea.
*
* readStates() maps a storage block update onto the state values the plugin
* publishes. Having it in one place is what makes it possible to check that a
* state is fed from the very register the matching action writes to.
*/
namespace SunSpecStorageLogic {
struct StorageStates {
/* Percent of WChaMax, from InWRte / OutWRte - the very registers the
* chargingRate / dischargingRate actions write to. */
double chargingRate = 0;
double dischargingRate = 0;
/* Percent of WChaMax per second, from WChaGra / WDisChaGra. A different
* quantity from the two above, and read only on several inverters. */
double chargeGradient = 0;
double dischargeGradient = 0;
/* Both flags are reconciled from StorCtl_Mod. Reconciling only one lets the
* other drift silently as soon as the inverter changes it on its own. */
bool enableCharging = false;
bool enableDischarging = false;
bool gridCharging = false;
int batteryLevel = 0;
bool batteryCritical = false;
};
/* Value range of the InWRte / OutWRte setpoints of model 124. */
const double MinimumRatePercent = -100.0;
const double MaximumRatePercent = 100.0;
StorageStates readStates(SunSpecStorageModel *storage);
}
#endif // SUNSPECSTORAGELOGIC_H