Skip to content

Commit

Permalink
Avoid repeated initialization
Browse files Browse the repository at this point in the history
Fixes: #375
  • Loading branch information
jmlich committed Dec 28, 2024
1 parent 0665a8d commit f1bfa9d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
10 changes: 8 additions & 2 deletions daemon/src/devices/huamidevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ void HuamiDevice::serviceEvent(char event)

void HuamiDevice::onPropertiesChanged(QString interface, QVariantMap map, QStringList list)
{
qDebug() << Q_FUNC_INFO << interface << map << list;
qDebug() << Q_FUNC_INFO << interface << map << list << m_connectionState;


if (interface == "org.bluez.Device1") {
m_reconnectTimer->start();
Expand All @@ -393,7 +394,12 @@ void HuamiDevice::onPropertiesChanged(QString interface, QVariantMap map, QStrin
}
}
if (deviceProperty("ServicesResolved").toBool() ) {
initialise();
int elapsed = init_dt.secsTo(QDateTime::currentDateTime());
qDebug() << "initialise() elapsed: " << elapsed << "starting: " << (elapsed >60);
if (elapsed > 60) {
init_dt = QDateTime::currentDateTime();
initialise();
}
}
}
}
2 changes: 2 additions & 0 deletions daemon/src/devices/huamidevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class HuamiDevice : public AbstractDevice
QString m_softwareRevision;
int m_buttonPresses = 0;
QTimer *m_keyPressTimer = nullptr;

QDateTime init_dt = QDateTime::fromTime_t(0);
};

#endif // BIPDEVICE_H
8 changes: 4 additions & 4 deletions daemon/src/devices/neodevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

NeoDevice::NeoDevice(const QString &pairedName, QObject *parent) : HuamiDevice(pairedName, parent)
{
qDebug() << "Creating Neo Device";
qDebug() << "Creating Neo Device" << pairedName;
}

QString NeoDevice::deviceType() const
Expand Down Expand Up @@ -107,16 +107,16 @@ void NeoDevice::parseServices()
QDBusInterface adapterIntro("org.bluez", devicePath(), "org.freedesktop.DBus.Introspectable", QDBusConnection::systemBus(), nullptr);
QDBusReply<QString> xml = adapterIntro.call("Introspect");

qDebug() << "Resolved services...";
// qDebug() << "Resolved services...";

qDebug().noquote() << xml.value();
// qDebug().noquote() << xml.value();

QDomDocument doc;
doc.setContent(xml.value());

QDomNodeList nodes = doc.elementsByTagName("node");

qDebug() << nodes.count() << "nodes";
// qDebug() << nodes.count() << "nodes";

for (int x = 0; x < nodes.count(); x++)
{
Expand Down
9 changes: 5 additions & 4 deletions daemon/src/services/miband2service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void MiBand2Service::initialise(bool firstTime)

void MiBand2Service::characteristicChanged(const QString &characteristic, const QByteArray &value)
{
qDebug() << Q_FUNC_INFO << "Changed:" << characteristic << value;
qDebug() << Q_FUNC_INFO << "Changed:" << characteristic << value.toHex();

if (value[0] == RESPONSE && value[1] == AUTH_SEND_KEY && ((value[2] & SUCCESS) == SUCCESS || value[2] == 0x06) ) {
qDebug() << "Received initial auth success, requesting random auth number";
Expand Down Expand Up @@ -67,14 +67,15 @@ QByteArray MiBand2Service::getSecretKey()
}

QByteArray MiBand2Service::requestAuthNumber() {
qDebug() << Q_FUNC_INFO << "Crypt Byte:" << m_cryptByte;
qDebug() << Q_FUNC_INFO << "Crypt Byte:" << QString::number(m_cryptByte, 16); // 0x80
if (m_cryptByte == 0x00) {
return UCHAR_TO_BYTEARRAY(AUTH_REQUEST_RANDOM_AUTH_NUMBER) + UCHAR_TO_BYTEARRAY(m_authByte);
} else {
uint8_t req = (m_cryptByte | AUTH_REQUEST_RANDOM_AUTH_NUMBER);
uint8_t suffix[3] = {0x02,0x01, 0x00};
uint8_t req = (m_cryptByte | AUTH_REQUEST_RANDOM_AUTH_NUMBER); // 0x80 | 0x02 = 0x82
uint8_t suffix[3] = {0x02, 0x01, 0x00};
//uint8_t suffix[1] = {0x02};

// 82 08 02 01 00
return UCHAR_TO_BYTEARRAY(req) + UCHAR_TO_BYTEARRAY(m_authByte) + UCHARARR_TO_BYTEARRAY(suffix);
}
}

0 comments on commit f1bfa9d

Please sign in to comment.