Skip to content

Commit 65fa4d4

Browse files
committed
Add more debug traces for debugging BM6 device
1 parent 39332c4 commit 65fa4d4

6 files changed

Lines changed: 61 additions & 28 deletions

File tree

src/devices/device_bm26.cpp

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void DeviceTheengsBM26::deviceConnected()
9393
{
9494
qDebug() << "DeviceTheengsBM26::deviceConnected(" << m_deviceAddress << ")";
9595
Device::deviceConnected();
96+
97+
m_serviceVolt_bm6_firstwrite = false;
9698
}
9799

98100
/* ************************************************************************** */
@@ -116,7 +118,7 @@ void DeviceTheengsBM26::deviceErrored(QLowEnergyController::Error error)
116118

117119
void DeviceTheengsBM26::serviceScanDone()
118120
{
119-
qDebug() << "DeviceTheengsBM26::serviceScanDone(" << m_deviceAddress << ")";
121+
qWarning() << "DeviceTheengsBM26::serviceScanDone(" << m_deviceAddress << ")";
120122

121123
if (m_serviceVolt)
122124
{
@@ -175,6 +177,8 @@ void DeviceTheengsBM26::serviceDetailsDiscovered_volt(QLowEnergyService::Service
175177
{
176178
if (m_deviceModel == "BM6")
177179
{
180+
qWarning() << "DeviceTheengsBM26::serviceDetailsDiscovered_volt(" << m_deviceAddress << ") > ServiceDiscovered";
181+
178182
// BM6 requires sending an encrypted command before making notify available
179183

180184
const uint8_t data[16] = { 0xd1, 0x55, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -192,16 +196,23 @@ void DeviceTheengsBM26::serviceDetailsDiscovered_volt(QLowEnergyService::Service
192196
m_charWrite = m_serviceVolt->characteristic(uuid_volt_char_write);
193197
m_serviceVolt->writeCharacteristic(m_charWrite, QByteArray(reinterpret_cast<const char*>(output), 16),
194198
QLowEnergyService::WriteWithResponse);
199+
m_serviceVolt_bm6_firstwrite = true;
200+
}
201+
else if (m_deviceModel == "BM2")
202+
{
203+
// Characteristic "read / notify"
204+
m_charNotif = m_serviceVolt->characteristic(uuid_volt_char_notify);
205+
m_notificationDesc = m_charNotif.clientCharacteristicConfiguration();
206+
m_serviceVolt->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
207+
208+
// Debug
209+
if (!m_charNotif.isValid()) { qWarning() << "m_charNotif invalid"; }
210+
if (!m_notificationDesc.isValid()) { qWarning() << "m_notificationDesc invalid"; }
211+
}
212+
else
213+
{
214+
qWarning() << "DeviceTheengsBM26::serviceDetailsDiscovered_volt() BatteryMonitor device model" << m_deviceModel << "is INVALID";
195215
}
196-
197-
// Characteristic "read / notify"
198-
m_charNotif = m_serviceVolt->characteristic(uuid_volt_char_notify);
199-
m_notificationDesc = m_charNotif.clientCharacteristicConfiguration();
200-
m_serviceVolt->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
201-
202-
// Debug
203-
if (!m_charNotif.isValid()) { qWarning() << "m_charNotif invalid"; }
204-
if (!m_notificationDesc.isValid()) { qWarning() << "m_notificationDesc invalid"; }
205216
}
206217
}
207218
}
@@ -210,32 +221,45 @@ void DeviceTheengsBM26::serviceDetailsDiscovered_volt(QLowEnergyService::Service
210221

211222
void DeviceTheengsBM26::bleDescriptorRead(const QLowEnergyDescriptor &, const QByteArray &)
212223
{
213-
//qDebug() << "DeviceTheengsBM26::bleDescriptorRead()";
224+
qWarning() << "DeviceTheengsBM26::bleDescriptorRead()";
214225
}
215226

216227
void DeviceTheengsBM26::bleDescriptorWritten(const QLowEnergyDescriptor &, const QByteArray &)
217228
{
218-
//qDebug() << "DeviceTheengsBM26::bleDescriptorWritten()";
229+
qWarning() << "DeviceTheengsBM26::bleDescriptorWritten()";
219230
}
220231

221232
/* ************************************************************************** */
222233

223234
void DeviceTheengsBM26::bleWriteDone(const QLowEnergyCharacteristic &c, const QByteArray &value)
224235
{
225-
qDebug() << "DeviceTheengsBM26::bleWriteDone(" << m_deviceAddress << ") on" << c.name() << " / uuid" << c.uuid() << value.size();
226-
qDebug() << "DATA: 0x" << value.toHex();
236+
qWarning() << "DeviceTheengsBM26::bleWriteDone(" << m_deviceAddress << ") on" << c.name() << " / uuid" << c.uuid() << value.size();
237+
qWarning() << "DATA: 0x" << value.toHex();
238+
239+
if (m_deviceModel == "BM6" && m_serviceVolt_bm6_firstwrite == true)
240+
{
241+
// Characteristic "read / notify"
242+
m_charNotif = m_serviceVolt->characteristic(uuid_volt_char_notify);
243+
m_notificationDesc = m_charNotif.clientCharacteristicConfiguration();
244+
m_serviceVolt->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
245+
m_serviceVolt_bm6_firstwrite = false;
246+
247+
// Debug
248+
if (!m_charNotif.isValid()) { qWarning() << "m_charNotif invalid"; }
249+
if (!m_notificationDesc.isValid()) { qWarning() << "m_notificationDesc invalid"; }
250+
}
227251
}
228252

229253
void DeviceTheengsBM26::bleReadDone(const QLowEnergyCharacteristic &c, const QByteArray &value)
230254
{
231-
qDebug() << "DeviceTheengsBM26::bleReadDone(" << m_deviceAddress << ") on" << c.name() << " / uuid" << c.uuid() << value.size();
232-
qDebug() << "DATA: 0x" << value.toHex();
255+
qWarning() << "DeviceTheengsBM26::bleReadDone(" << m_deviceAddress << ") on" << c.name() << " / uuid" << c.uuid() << value.size();
256+
qWarning() << "DATA: 0x" << value.toHex();
233257
}
234258

235259
void DeviceTheengsBM26::bleReadNotify(const QLowEnergyCharacteristic &c, const QByteArray &value)
236260
{
237-
//qDebug() << "DeviceTheengsBM26::bleReadNotify(" << m_deviceAddress << ") on" << c.name() << " / uuid" << c.uuid() << value.size();
238-
//qDebug() << "DATA: 0x" << value.toHex();
261+
qWarning() << "DeviceTheengsBM26::bleReadNotify(" << m_deviceAddress << ") on" << c.name() << " / uuid" << c.uuid() << value.size();
262+
qWarning() << "DATA: 0x" << value.toHex();
239263

240264
// Volt UUID // 16 bytes frames
241265
if (c.uuid() == uuid_volt_char_notify && value.size() == 16)
@@ -252,6 +276,8 @@ void DeviceTheengsBM26::bleReadNotify(const QLowEnergyCharacteristic &c, const Q
252276
mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, 16, iv, data, output);
253277
mbedtls_aes_free(&aes);
254278

279+
qWarning() << "DECRYPTED DATA: 0x" << QByteArray(reinterpret_cast<const char*>(output), 16).toHex(' ');
280+
255281
float volt = -99.f;
256282
float temp = -99.f;
257283
int batt = 0;
@@ -260,13 +286,13 @@ void DeviceTheengsBM26::bleReadNotify(const QLowEnergyCharacteristic &c, const Q
260286
{
261287
temp = output[4];
262288
if (output[3] == 1) temp = -temp;
263-
qDebug() << "(BM6) temp : " << temp;
289+
qWarning() << "(BM6) temp : " << temp;
264290

265291
batt = output[5];
266-
qDebug() << "(BM6) batt : " << batt;
292+
qWarning() << "(BM6) batt : " << batt;
267293

268294
volt = static_cast<int16_t>(data[8] + (data[7] << 8)) / 10.f;
269-
qDebug() << "(BM6) volt : " << volt;
295+
qWarning() << "(BM6) volt : " << volt;
270296
}
271297
else if (m_deviceModel == "BM2")
272298
{
@@ -315,11 +341,16 @@ void DeviceTheengsBM26::bleReadNotify(const QLowEnergyCharacteristic &c, const Q
315341
<< c.name() << " / uuid" << c.uuid() << value.size() << "UNABLE TO DECRYPT !!!";
316342
#endif // ENABLE_MBEDTLS
317343
}
344+
else
345+
{
346+
qWarning() << "DeviceTheengsBM26::bleReadNotify(" << m_deviceAddress << ") UNKOWN DATA on"
347+
<< c.name() << " / uuid" << c.uuid() << value.size();
348+
}
318349
}
319350

320351
void DeviceTheengsBM26::bleServiceError(QLowEnergyService::ServiceError e)
321352
{
322-
qDebug() << "DeviceTheengsBM26::bleServiceError(" << e << ")";
353+
qWarning() << "DeviceTheengsBM26::bleServiceError(" << e << ")";
323354
}
324355

325356
/* ************************************************************************** */

src/devices/device_bm26.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class DeviceTheengsBM26: public DeviceTheengsBatteryMonitors
5151
QLowEnergyCharacteristic m_charNotif;
5252
QLowEnergyDescriptor m_notificationDesc;
5353

54+
bool m_serviceVolt_bm6_firstwrite = false;
55+
5456
const uint8_t m_key_bm2[16] = { 108, 101, 97, 103, 101, 110, 100, 255, 254, 49, 56, 56, 50, 52, 54, 54, };
5557
const uint8_t m_key_bm6[16] = { 108, 101, 97, 103, 101, 110, 100, 255, 254, 48, 49, 48, 48, 48, 48, 57, };
5658

src/devices/device_sbbt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void DeviceSwitchbotBlindTilt::deviceDisconnected()
9292

9393
void DeviceSwitchbotBlindTilt::deviceErrored(QLowEnergyController::Error error)
9494
{
95-
qDebug() << "DeviceSwitchbotBlindTilt::deviceErrored(" << error << ")";
95+
qWarning() << "DeviceSwitchbotBlindTilt::deviceErrored(" << error << ")";
9696
Device::deviceErrored(error);
9797
}
9898

src/devices/device_sbcu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ void DeviceSwitchbotCurtain::bleReadNotify(const QLowEnergyCharacteristic &c, co
256256

257257
void DeviceSwitchbotCurtain::bleServiceError(QLowEnergyService::ServiceError e)
258258
{
259-
qDebug() << "DeviceSwitchbotCurtain::bleServiceError(" << e << ")";
259+
qWarning() << "DeviceSwitchbotCurtain::bleServiceError(" << e << ")";
260260
}
261261

262262
/* ************************************************************************** */

src/devices/device_sbs1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void DeviceSwitchbotSmartSwitch::deviceDisconnected()
100100

101101
void DeviceSwitchbotSmartSwitch::deviceErrored(QLowEnergyController::Error error)
102102
{
103-
qDebug() << "DeviceSwitchbotSmartSwitch::deviceErrored(" << error << ")";
103+
qWarning() << "DeviceSwitchbotSmartSwitch::deviceErrored(" << error << ")";
104104
Device::deviceErrored(error);
105105
}
106106

@@ -267,7 +267,7 @@ void DeviceSwitchbotSmartSwitch::bleReadNotify(const QLowEnergyCharacteristic &c
267267

268268
void DeviceSwitchbotSmartSwitch::bleServiceError(QLowEnergyService::ServiceError e)
269269
{
270-
qDebug() << "DeviceSwitchbotSmartSwitch::bleServiceError(" << e << ")";
270+
qWarning() << "DeviceSwitchbotSmartSwitch::bleServiceError(" << e << ")";
271271
}
272272

273273
/* ************************************************************************** */

src/devices/device_theengs_gateway.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void DeviceGateway::deviceDisconnected()
247247

248248
void DeviceGateway::deviceErrored(QLowEnergyController::Error error)
249249
{
250-
qDebug() << "DeviceGateway::deviceErrored(" << error << ")";
250+
qWarning() << "DeviceGateway::deviceErrored(" << error << ")";
251251
Device::deviceErrored(error);
252252
/*
253253
if (m_ble_action == DeviceUtils::ACTION_THEENGS_ONBOARDING ||
@@ -568,7 +568,7 @@ void DeviceGateway::bleDescriptorWritten(const QLowEnergyDescriptor &, const QBy
568568

569569
void DeviceGateway::bleServiceError(QLowEnergyService::ServiceError e)
570570
{
571-
qDebug() << "DeviceGateway::bleServiceError(" << e << ")";
571+
qWarning() << "DeviceGateway::bleServiceError(" << e << ")";
572572
}
573573

574574
/* ************************************************************************** */

0 commit comments

Comments
 (0)