@@ -35,7 +35,7 @@ const int CS_BULK = 5;
3535
3636Tsmppt::Tsmppt (const QString &IPAddress, const int port, int interval, int slave, QObject *parent):
3737QObject(parent), mInitialized(false ), mTimer(new QTimer(this )), m_interval(interval), m_cs(0 ), m_t_bulk(1 ),
38- m_t_bulk_ms(0 ), yield_user(0 ), yield_system(0 ), m_model( 1 )
38+ m_t_bulk_ms(0 ), yield_user(0 ), yield_system(0 )
3939{
4040 QLOG_DEBUG () << " Tsmppt::Tsmppt(" << IPAddress << " , " << port << " , " << interval << " , " << slave << " )" ;
4141 mCtx = modbus_new_tcp_pi (IPAddress.toStdString ().c_str (), QString::number (port).toStdString ().c_str ());
@@ -121,43 +121,65 @@ bool Tsmppt::initialize()
121121 ver += ((regs[4 ] >> 8 ) & 0x0f ) * 100 ;
122122 ver += ((regs[4 ] >> 4 ) & 0x0f ) * 10 ;
123123 ver += regs[4 ] & 0x0f ;
124- m_fw_ver = QString::number (ver);
124+ setFirmwareVersion (ver);
125125
126126 // Hardware version:
127127 if (!readInputRegisters (REG_EHW_VERSION, 1 , regs))
128128 {
129129 modbus_close (mCtx );
130130 return false ;
131131 }
132- m_hw_ver = QString::number (regs[0 ] >> 8 ) + " ." + QString::number (regs[0 ] & 0xff );
132+ setHardwareVersion ( QString::number (regs[0 ] >> 8 ) + " ." + QString::number (regs[0 ] & 0xff ) );
133133
134134 // Model
135135 if (!readInputRegisters (REG_EMODEL, 1 , regs))
136136 {
137137 modbus_close (mCtx );
138138 return false ;
139139 }
140- m_model = regs[0 ];
140+ QString name;
141+ switch (regs[0 ])
142+ {
143+ case 0 :
144+ name = " TriStar MPPT 45" ;
145+ break ;
146+
147+ case 1 :
148+ name = " TriStar MPPT 60" ;
149+ break ;
150+
151+ case 2 :
152+ name = " TriStar MPPT 30" ;
153+ break ;
154+
155+ default :
156+ name = " " ;
157+ }
158+ setProductName (name);
141159
142160 // Serial number:
143161 if (!readInputRegisters (REG_ESERIAL, 4 , regs))
144162 {
145163 modbus_close (mCtx );
146164 return false ;
147165 }
148- m_serial = (uint64_t )((regs[0 ] & 0xff ) - 0x30 ) * 10000000 ;
149- m_serial += (uint64_t )((regs[0 ] >> 8 ) - 0x30 ) * 1000000 ;
150- m_serial += (uint64_t )((regs[1 ] & 0xff ) - 0x30 ) * 100000 ;
151- m_serial += (uint64_t )((regs[1 ] >> 8 ) - 0x30 ) * 10000 ;
152- m_serial += (uint64_t )((regs[2 ] & 0xff ) - 0x30 ) * 1000 ;
153- m_serial += (uint64_t )((regs[2 ] >> 8 ) - 0x30 ) * 100 ;
154- m_serial += (uint64_t )((regs[3 ] & 0xff ) - 0x30 ) * 10 ;
155- m_serial += (uint64_t )((regs[3 ] >> 8 ) - 0x30 );
166+ uint64_t serial = (uint64_t )((regs[0 ] & 0xff ) - 0x30 ) * 10000000 ;
167+ serial += (uint64_t )((regs[0 ] >> 8 ) - 0x30 ) * 1000000 ;
168+ serial += (uint64_t )((regs[1 ] & 0xff ) - 0x30 ) * 100000 ;
169+ serial += (uint64_t )((regs[1 ] >> 8 ) - 0x30 ) * 10000 ;
170+ serial += (uint64_t )((regs[2 ] & 0xff ) - 0x30 ) * 1000 ;
171+ serial += (uint64_t )((regs[2 ] >> 8 ) - 0x30 ) * 100 ;
172+ serial += (uint64_t )((regs[3 ] & 0xff ) - 0x30 ) * 10 ;
173+ serial += (uint64_t )((regs[3 ] >> 8 ) - 0x30 );
174+ setSerialNumber (QString::number (serial));
175+
156176
157177 modbus_close (mCtx );
158178 mInitialized = true ;
159179 emit tsmpptConnected ();
160180 QLOG_DEBUG () << " Tsmppt::initialize(end)" ;
181+ QString logmsg = productName () + " (serial #" + serialNumber () + " , controler v" + hardwareVersion () + " ." + firmwareVersion () + " ) connected" ;
182+ QLOG_INFO () << logmsg.toStdString ().c_str ();
161183 return true ;
162184}
163185
@@ -247,21 +269,45 @@ void Tsmppt::updateValues()
247269 modbus_close (mCtx );
248270}
249271
250- QString Tsmppt::firmwareVersion () const
272+ int Tsmppt::firmwareVersion () const
251273{
252274 return m_fw_ver;
253275}
254276
277+ void Tsmppt::setFirmwareVersion (int v)
278+ {
279+ if (m_fw_ver == v)
280+ return ;
281+ m_fw_ver = v;
282+ emit firmwareVersionChanged ();
283+ }
284+
255285QString Tsmppt::hardwareVersion () const
256286{
257287 return m_hw_ver;
258288}
259289
260- uint64_t Tsmppt::serialNumber () const
290+ void Tsmppt::setHardwareVersion (QString v)
291+ {
292+ if (m_hw_ver == v)
293+ return ;
294+ m_hw_ver = v;
295+ emit hardwareVersionChanged ();
296+ }
297+
298+ QString Tsmppt::serialNumber () const
261299{
262300 return m_serial;
263301}
264302
303+ void Tsmppt::setSerialNumber (QString v)
304+ {
305+ if (m_serial == v)
306+ return ;
307+ m_serial = v;
308+ emit serialNumberChanged ();
309+ }
310+
265311double Tsmppt::batteryVoltage () const
266312{
267313 return m_v_bat;
@@ -525,22 +571,16 @@ void Tsmppt::setTimeInFloat(int v)
525571
526572QString Tsmppt::productName () const
527573{
528- QString name;
529- switch (m_model)
530- {
531- case 0 :
532- name = " TriStar MPPT 45" ;
533- break ;
574+ return m_name;
575+ }
534576
535- case 1 :
536- name = " TriStar MPPT 60" ;
537- break ;
538577
539- case 2 :
540- name = " TriStar MPPT 30" ;
541- break ;
542- }
543- return name;
578+ void Tsmppt::setProductName (QString v)
579+ {
580+ if (m_name == v)
581+ return ;
582+ m_name = v;
583+ emit productNameChanged ();
544584}
545585
546586void Tsmppt::onTimeout ()
0 commit comments