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

Commit c9da45b

Browse files
committed
Added events to firmwareVersion etc.
1 parent f4a1878 commit c9da45b

File tree

3 files changed

+93
-42
lines changed

3 files changed

+93
-42
lines changed

software/src/dbus_tsmppt_bridge.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ DBusTsmpptBridge::DBusTsmpptBridge(Tsmppt *tsmppt, QObject *parent):
4444
produce(mTsmppt, "timeInAbsorption", "/History/Daily/0/TimeInAbsorption");
4545
produce(mTsmppt, "timeInBulk", "/History/Daily/0/TimeInBulk");
4646
produce(mTsmppt, "timeInFloat", "/History/Daily/0/TimeInFloat");
47+
produce(mTsmppt, "firmwareVersion", "/FirmwareVersion");
48+
produce(mTsmppt, "hardwareVersion", "/HardwareVersion");
49+
produce(mTsmppt, "productName", "/ProductName");
50+
produce(mTsmppt, "serialNumber", "/Serial");
51+
4752
registerService();
4853
}
4954

@@ -58,13 +63,4 @@ void DBusTsmpptBridge::onTsmpptConnected()
5863
{
5964
produce("/Connected", 1);
6065
produce("/Mode", 1);
61-
QString fwver = mTsmppt->firmwareVersion();
62-
produce("/FirmwareVersion", fwver.toInt());
63-
QString hwver = mTsmppt->hardwareVersion();
64-
produce("/HardwareVersion", hwver);
65-
produce("/ProductName", mTsmppt->productName());
66-
uint64_t serial = mTsmppt->serialNumber();
67-
produce("/Serial", QString::number(serial));
68-
QString logmsg = mTsmppt->productName() + " (serial #" + QString::number(serial) + ", controler v" + hwver + "." + fwver + ") connected";
69-
QLOG_INFO() << logmsg.toStdString().c_str();
7066
}

software/src/tsmppt.cpp

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const int CS_BULK = 5;
3535

3636
Tsmppt::Tsmppt(const QString &IPAddress, const int port, int interval, int slave, QObject *parent):
3737
QObject(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+
255285
QString 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+
265311
double Tsmppt::batteryVoltage() const
266312
{
267313
return m_v_bat;
@@ -525,22 +571,16 @@ void Tsmppt::setTimeInFloat(int v)
525571

526572
QString 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

546586
void Tsmppt::onTimeout()

software/src/tsmppt.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class Tsmppt : public QObject
2929
Q_PROPERTY(int timeInBulk READ timeInBulk WRITE setTimeInBulk NOTIFY timeInBulkChanged)
3030
Q_PROPERTY(double yieldUser READ yieldUser WRITE setYieldUser NOTIFY yieldUserChanged)
3131
Q_PROPERTY(double yieldSystem READ yieldSystem WRITE setYieldSystem NOTIFY yieldSystemChanged)
32+
Q_PROPERTY(int firmwareVersion READ firmwareVersion WRITE setFirmwareVersion NOTIFY firmwareVersionChanged)
33+
Q_PROPERTY(QString hardwareVersion READ hardwareVersion WRITE setHardwareVersion NOTIFY hardwareVersionChanged)
34+
Q_PROPERTY(QString productName READ productName WRITE setProductName NOTIFY productNameChanged)
35+
Q_PROPERTY(QString serialNumber READ serialNumber WRITE setSerialNumber NOTIFY serialNumberChanged)
3236

3337
public:
3438
Tsmppt(const QString &IPAddress, const int port = 502, int interval = 5000, int slave = 1, QObject *parent = 0);
@@ -91,10 +95,17 @@ class Tsmppt : public QObject
9195
double yieldSystem() const;
9296
void setYieldSystem(double v);
9397

94-
QString firmwareVersion() const;
98+
int firmwareVersion() const;
99+
void setFirmwareVersion(int v);
100+
95101
QString hardwareVersion() const;
96-
uint64_t serialNumber() const;
102+
void setHardwareVersion(QString v);
103+
104+
QString serialNumber() const;
105+
void setSerialNumber(QString v);
106+
97107
QString productName() const;
108+
void setProductName(QString v);
98109

99110
bool initialize();
100111

@@ -120,6 +131,10 @@ class Tsmppt : public QObject
120131
void timeInBulkChanged();
121132
void yieldUserChanged();
122133
void yieldSystemChanged();
134+
void firmwareVersionChanged();
135+
void hardwareVersionChanged();
136+
void serialNumberChanged();
137+
void productNameChanged();
123138

124139
private slots:
125140
void onTimeout();
@@ -159,10 +174,10 @@ private slots:
159174
// Static values (read once):
160175
double m_v_pu; // Voltage scaling
161176
double m_i_pu; // Current scaling
162-
QString m_fw_ver;
177+
int m_fw_ver;
163178
QString m_hw_ver;
164-
uint64_t m_serial;
165-
uint16_t m_model;
179+
QString m_serial;
180+
QString m_name;
166181
};
167182

168183
#endif // TSMPPT_H

0 commit comments

Comments
 (0)