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

Commit 80a36b5

Browse files
committed
Defer logging until service is registered
1 parent 29a7588 commit 80a36b5

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

software/src/.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"python.linting.enabled": true,
3+
"python.pythonPath": "/usr/bin/python3"
4+
}

software/src/dbus_bridge.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,14 @@ void DBusBridge::registerService()
123123
QLOG_INFO() << "Registering service" << mServiceName;
124124
QDBusConnection connection = VBusItems::getConnection(mServiceName);
125125
if (connection.registerService(mServiceName))
126+
{
126127
mServiceRegistered = true;
128+
emit serviceRegistered();
129+
}
127130
else
131+
{
128132
QLOG_FATAL() << "RegisterService failed";
133+
}
129134
}
130135

131136
bool DBusBridge::toDBus(const QString &, QVariant &)

software/src/dbus_bridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class DBusBridge : public QObject
9898

9999
signals:
100100
void initialized();
101+
void serviceRegistered();
101102

102103
protected:
103104
/*!

software/src/dbus_tsmppt_bridge.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DBusTsmpptBridge::DBusTsmpptBridge(Tsmppt *tsmppt, QObject *parent):
1515
{
1616
Q_ASSERT(tsmppt != 0);
1717
connect(tsmppt, SIGNAL(tsmpptConnected()), this, SLOT(onTsmpptConnected()));
18+
connect(this, SIGNAL(serviceRegistered()), tsmppt, SLOT(startLogging()));
1819

1920
QString processName = QCoreApplication::arguments()[0];
2021
produce("/Mgmt/ProcessName", processName);
@@ -43,6 +44,7 @@ DBusTsmpptBridge::DBusTsmpptBridge(Tsmppt *tsmppt, QObject *parent):
4344
produce(mTsmppt, "timeInAbsorption", "/History/Daily/0/TimeInAbsorption");
4445
produce(mTsmppt, "timeInBulk", "/History/Daily/0/TimeInBulk");
4546
produce(mTsmppt, "timeInFloat", "/History/Daily/0/TimeInFloat");
47+
registerService();
4648
}
4749

4850
DBusTsmpptBridge::~DBusTsmpptBridge()
@@ -65,5 +67,4 @@ void DBusTsmpptBridge::onTsmpptConnected()
6567
produce("/Serial", QString::number(serial));
6668
QString logmsg = mTsmppt->productName() + " (serial #" + QString::number(serial) + ", controler v" + hwver + "." + fwver + ") connected";
6769
QLOG_INFO() << logmsg.toStdString().c_str();
68-
registerService();
6970
}

software/src/tsmppt.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const int CS_BULK = 5;
3434

3535

3636
Tsmppt::Tsmppt(const QString &IPAddress, const int port, int interval, int slave, QObject *parent):
37-
QObject(parent), mInitialized(false), mTimer(new QTimer(this)), m_interval(interval), m_cs(0), m_t_bulk(1), m_t_bulk_ms(0), yield_user(0), yield_system(0)
37+
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)
3839
{
3940
QLOG_DEBUG() << "Tsmppt::Tsmppt(" << IPAddress << ", " << port << ", " << interval << ", " << slave << ")";
4041
mCtx = modbus_new_tcp_pi(IPAddress.toStdString().c_str(), QString::number(port).toStdString().c_str());
@@ -54,7 +55,6 @@ QObject(parent), mInitialized(false), mTimer(new QTimer(this)), m_interval(inter
5455
#endif
5556
modbus_set_slave(mCtx, slave);
5657
mTimer->setInterval(m_interval);
57-
mTimer->start();
5858
connect(mTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
5959
}
6060

@@ -98,6 +98,7 @@ bool Tsmppt::initialize()
9898
}
9999

100100
uint16_t regs[6];
101+
101102
if (!readInputRegisters(REG_V_PU, 6, regs))
102103
{
103104
modbus_close(mCtx);
@@ -122,23 +123,23 @@ bool Tsmppt::initialize()
122123
ver += regs[4] & 0x0f;
123124
m_fw_ver = QString::number(ver);
124125

125-
// Read hardware version:
126+
// Hardware version:
126127
if (!readInputRegisters(REG_EHW_VERSION, 1, regs))
127128
{
128129
modbus_close(mCtx);
129130
return false;
130131
}
131132
m_hw_ver = QString::number(regs[0] >> 8) + "." + QString::number(regs[0] & 0xff);
132133

133-
// Read model
134+
// Model
134135
if (!readInputRegisters(REG_EMODEL, 1, regs))
135136
{
136137
modbus_close(mCtx);
137138
return false;
138139
}
139140
m_model = regs[0];
140141

141-
// Read serial number:
142+
// Serial number:
142143
if (!readInputRegisters(REG_ESERIAL, 4, regs))
143144
{
144145
modbus_close(mCtx);
@@ -235,7 +236,7 @@ void Tsmppt::updateValues()
235236
// Charge state:
236237
setChargeState(reg[REG_CHARGE_STATE-REG_FIRST_DYN]);
237238

238-
if (m_cs == CS_BULK)
239+
if (m_cs == CS_BULK)
239240
m_t_bulk_ms += m_interval;
240241
else if (m_cs == CS_NIGHT)
241242
m_t_bulk_ms = 0;
@@ -556,3 +557,7 @@ void Tsmppt::onTimeout()
556557
mTimer->start();
557558
}
558559

560+
void Tsmppt::startLogging()
561+
{
562+
mTimer->start();
563+
}

software/src/tsmppt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Tsmppt : public QObject
123123

124124
private slots:
125125
void onTimeout();
126+
void startLogging();
126127

127128
private:
128129
bool readInputRegisters(int addr, int nb, uint16_t *dest);

0 commit comments

Comments
 (0)