@@ -29,8 +29,12 @@ const int REG_EHW_VERSION = 57549;
2929const int REG_ESERIAL = 57536 ;
3030const int REG_EMODEL = 57548 ;
3131
32+ const int CS_NIGHT = 3 ;
33+ const int CS_BULK = 5 ;
34+
35+
3236Tsmppt::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+
467490void Tsmppt::setYieldUser (double v)
468491{
469492 if (yield_user == v)
0 commit comments