Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 355931a

Browse files
committed
Implemented time in bulk counter
1 parent e5a441e commit 355931a

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

software/src/dbus_tsmppt_bridge.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ DBusTsmpptBridge::DBusTsmpptBridge(Tsmppt *tsmppt, QObject *parent):
4141
produce(mTsmppt, "yieldUser", "/Yield/User", "kWh", 0);
4242
produce(mTsmppt, "yieldSystem", "/Yield/System", "kWh", 0);
4343
produce(mTsmppt, "timeInAbsorption", "/History/Daily/0/TimeInAbsorption");
44-
// TSMPPT does not give time in bulk:
45-
// produce(mTsmppt, "timeInBulk", "/History/Daily/0/TimeInBulk");
44+
produce(mTsmppt, "timeInBulk", "/History/Daily/0/TimeInBulk");
4645
produce(mTsmppt, "timeInFloat", "/History/Daily/0/TimeInFloat");
47-
48-
//registerService();
4946
}
5047

5148
DBusTsmpptBridge::~DBusTsmpptBridge()

software/src/tsmppt.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ const int REG_EHW_VERSION = 57549;
2929
const int REG_ESERIAL = 57536;
3030
const int REG_EMODEL = 57548;
3131

32+
const int CS_NIGHT = 3;
33+
const int CS_BULK = 5;
34+
35+
3236
Tsmppt::Tsmppt(const QString &IPAddress, const int port, int interval, int slave, QObject *parent):
33-
QObject(parent), mInitialized(false), mTimer(new QTimer(this)), yield_user(0), yield_system(0)
37+
QObject(parent), mInitialized(false), mTimer(new QTimer(this)), m_interval(interval), m_t_bulk(0), m_t_bulk_ms(0), yield_user(0), yield_system(0)
3438
{
3539
QLOG_DEBUG() << "Tsmppt::Tsmppt(" << IPAddress << ", " << port << ", " << interval << ", " << slave << ")";
3640
mCtx = modbus_new_tcp_pi(IPAddress.toStdString().c_str(), QString::number(port).toStdString().c_str());
@@ -49,7 +53,7 @@ QObject(parent), mInitialized(false), mTimer(new QTimer(this)), yield_user(0), y
4953
modbus_set_byte_timeout(mCtx, &to);
5054
#endif
5155
modbus_set_slave(mCtx, slave);
52-
mTimer->setInterval(interval);
56+
mTimer->setInterval(m_interval);
5357
mTimer->start();
5458
connect(mTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
5559
}
@@ -230,6 +234,11 @@ void Tsmppt::updateValues()
230234
// Charge state:
231235
setChargeState(reg[REG_CHARGE_STATE-REG_FIRST_DYN]);
232236

237+
if (m_cs == CS_BULK)
238+
m_t_bulk_ms += m_interval;
239+
else if (m_cs == CS_NIGHT)
240+
m_t_bulk_ms = 0;
241+
setTimeInBulk((int)(m_t_bulk_ms/(1000*60)));
233242
setTimeInAbsorption(reg[REG_T_ABS-REG_FIRST_DYN]/60);
234243
setTimeInFloat(reg[REG_T_FLOAT-REG_FIRST_DYN]/60);
235244
}
@@ -429,7 +438,7 @@ int Tsmppt::chargeState() const
429438
// 2 DISCONNECT 0 OFF
430439
// 3 NIGHT 0 OFF
431440
// 4 FAULT 2 FAULT
432-
// 5 MNPPT 3 BULK
441+
// 5 MPPT 3 BULK
433442
// 6 ABSORPTION 4 ABSORPTION
434443
// 7 FLOAT 5 FLOAT
435444
// 8 EQUALIZE 7 EQUALIZE
@@ -464,6 +473,20 @@ int Tsmppt::timeInFloat() const
464473
return m_t_float;
465474
}
466475

476+
477+
void Tsmppt::setTimeInBulk(int v)
478+
{
479+
if (m_t_bulk == v)
480+
return;
481+
m_t_bulk = v;
482+
emit timeInBulkChanged();
483+
}
484+
485+
int Tsmppt::timeInBulk() const
486+
{
487+
return m_t_bulk;
488+
}
489+
467490
void Tsmppt::setYieldUser(double v)
468491
{
469492
if (yield_user == v)

software/src/tsmppt.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Tsmppt : public QObject
2626
Q_PROPERTY(int chargeState READ chargeState WRITE setChargeState NOTIFY chargeStateChanged)
2727
Q_PROPERTY(int timeInAbsorption READ timeInAbsorption WRITE setTimeInAbsorption NOTIFY timeInAbsorptionChanged)
2828
Q_PROPERTY(int timeInFloat READ timeInFloat WRITE setTimeInFloat NOTIFY timeInFloatChanged)
29+
Q_PROPERTY(int timeInBulk READ timeInBulk WRITE setTimeInBulk NOTIFY timeInBulkChanged)
2930
Q_PROPERTY(double yieldUser READ yieldUser WRITE setYieldUser NOTIFY yieldUserChanged)
3031
Q_PROPERTY(double yieldSystem READ yieldSystem WRITE setYieldSystem NOTIFY yieldSystemChanged)
3132

@@ -81,6 +82,9 @@ class Tsmppt : public QObject
8182
int timeInFloat() const;
8283
void setTimeInFloat(int v);
8384

85+
int timeInBulk() const;
86+
void setTimeInBulk(int v);
87+
8488
double yieldUser() const;
8589
void setYieldUser(double v);
8690

@@ -113,6 +117,7 @@ class Tsmppt : public QObject
113117
void connectionLost();
114118
void timeInAbsorptionChanged();
115119
void timeInFloatChanged();
120+
void timeInBulkChanged();
116121
void yieldUserChanged();
117122
void yieldSystemChanged();
118123

@@ -126,6 +131,8 @@ private slots:
126131
QTimer *mTimer;
127132
modbus_t *mCtx;
128133
uint16_t *mModbusRegs;
134+
int m_interval;
135+
129136
// Dynamic values:
130137
double m_v_bat; // Battery voltage
131138
double m_v_bat_max; // Max battery voltage, daily
@@ -143,6 +150,8 @@ private slots:
143150
int m_cs; // Charge state
144151
int m_t_abs; // Time in absorption
145152
int m_t_float; // Time in float
153+
int m_t_bulk; // Time in bulk
154+
uint32_t m_t_bulk_ms; // Time in bulk (ms)
146155
double yield_user; // Watt hours, total since last reset
147156
double yield_system; // Watt hours, total
148157

0 commit comments

Comments
 (0)