@@ -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
117119void 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
211222void DeviceTheengsBM26::bleDescriptorRead (const QLowEnergyDescriptor &, const QByteArray &)
212223{
213- // qDebug () << "DeviceTheengsBM26::bleDescriptorRead()";
224+ qWarning () << " DeviceTheengsBM26::bleDescriptorRead()" ;
214225}
215226
216227void DeviceTheengsBM26::bleDescriptorWritten (const QLowEnergyDescriptor &, const QByteArray &)
217228{
218- // qDebug () << "DeviceTheengsBM26::bleDescriptorWritten()";
229+ qWarning () << " DeviceTheengsBM26::bleDescriptorWritten()" ;
219230}
220231
221232/* ************************************************************************** */
222233
223234void 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
229253void 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
235259void 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
320351void DeviceTheengsBM26::bleServiceError (QLowEnergyService::ServiceError e)
321352{
322- qDebug () << " DeviceTheengsBM26::bleServiceError(" << e << " )" ;
353+ qWarning () << " DeviceTheengsBM26::bleServiceError(" << e << " )" ;
323354}
324355
325356/* ************************************************************************** */
0 commit comments