2929#include < QTimer>
3030
3131// Aim for a connection interval of between 7.5us-30us with a 4 second supervision timeout
32- const double connection_interval_min = 7.5 ;
33- const double connection_interval_max = 30 ;
34- const int connection_latency = 0 ;
35- const int connection_supervision_timeout = 4000 ;
32+ static const double connection_interval_min = 7.5 ;
33+ static const double connection_interval_max = 30 ;
34+ static const int connection_latency = 0 ;
35+ static const int connection_supervision_timeout = 4000 ;
3636
3737// Default MTU of 490 - less than 512 maximum with a bit of safety
38- const int default_mtu = 490 ;
38+ static const int default_mtu = 490 ;
3939
40- QList<QBluetoothDeviceInfo> bluetooth_device_list;
41- QList<QBluetoothUuid> services;
40+ static QList<QBluetoothDeviceInfo> bluetooth_device_list;
41+ static QList<QBluetoothUuid> services;
4242
43- QLowEnergyService *bluetooth_service_mcumgr = nullptr ;
44- QLowEnergyCharacteristic bluetooth_characteristic_transmit;
45- uint16_t mtu;
46- uint16_t mtu_max_worked;
47- QByteArray sendbuffer;
43+ static QLowEnergyService *bluetooth_service_mcumgr = nullptr ;
44+ static QLowEnergyCharacteristic bluetooth_characteristic_transmit;
45+ static uint16_t mtu;
46+ static uint16_t mtu_max_worked;
47+ static QByteArray sendbuffer;
4848
49- bluetooth_setup *bluetooth_window;
50- QTimer retry_timer;
51- QTimer discover_timer;
52- int retry_count;
49+ static bluetooth_setup *bluetooth_window;
50+ static QTimer retry_timer;
51+ static QTimer discover_timer;
52+ static int retry_count;
53+ static bool debug_logging = false ;
5354
5455smp_bluetooth::smp_bluetooth (QObject *parent)
5556{
@@ -61,6 +62,7 @@ smp_bluetooth::smp_bluetooth(QObject *parent)
6162 QObject::connect (bluetooth_window, SIGNAL (connect_to_device (uint16_t )), this , SLOT (form_connect_to_device (uint16_t )));
6263 QObject::connect (bluetooth_window, SIGNAL (disconnect_from_device ()), this , SLOT (form_disconnect_from_device ()));
6364 QObject::connect (bluetooth_window, SIGNAL (bluetooth_status (bool *,bool *)), this , SLOT (form_bluetooth_status (bool *,bool *)));
65+ QObject::connect (bluetooth_window, SIGNAL (debug_log_state_changed (bool )), this , SLOT (form_debug_state_changed (bool )));
6466
6567 discoveryAgent = new QBluetoothDeviceDiscoveryAgent ();
6668 discoveryAgent->setLowEnergyDiscoveryTimeout (8000 );
@@ -221,7 +223,10 @@ void smp_bluetooth::service_discovered(QBluetoothUuid service_uuid)
221223
222224void smp_bluetooth::mcumgr_service_characteristic_changed (QLowEnergyCharacteristic lecCharacteristic, QByteArray baData)
223225{
224- bluetooth_window->add_debug (QString (" CHANGED!!" ));
226+ if (debug_logging == true )
227+ {
228+ bluetooth_window->add_debug (QString (" CHANGED!!" ));
229+ }
225230
226231 received_data.append (&baData);
227232
@@ -236,8 +241,12 @@ void smp_bluetooth::mcumgr_service_characteristic_changed(QLowEnergyCharacterist
236241
237242void smp_bluetooth::mcumgr_service_characteristic_written (QLowEnergyCharacteristic lecCharacteristic, QByteArray baData)
238243{
239- bluetooth_window->add_debug (QString (" WRITTEN!!" ));
240- qDebug () << baData;
244+ if (debug_logging == true )
245+ {
246+ bluetooth_window->add_debug (QString (" WRITTEN!!" ));
247+ qDebug () << baData;
248+ }
249+
241250
242251 if (baData.length () > mtu_max_worked)
243252 {
@@ -253,7 +262,11 @@ void smp_bluetooth::mcumgr_service_characteristic_written(QLowEnergyCharacterist
253262 if (sendbuffer.length () > 0 )
254263 {
255264 bluetooth_service_mcumgr->writeCharacteristic (bluetooth_characteristic_transmit, sendbuffer.left (mtu));
256- bluetooth_window->add_debug (QString (" Writing " ).append (QString::number (mtu)));
265+
266+ if (debug_logging == true )
267+ {
268+ bluetooth_window->add_debug (QString (" Writing " ).append (QString::number (sendbuffer.length () > mtu ? mtu : sendbuffer.length ())));
269+ }
257270 }
258271 }
259272}
@@ -413,7 +426,12 @@ int smp_bluetooth::send(smp_message *message)
413426
414427 sendbuffer.append (*message->data ());
415428 bluetooth_service_mcumgr->writeCharacteristic (bluetooth_characteristic_transmit, sendbuffer.left (mtu));
416- bluetooth_window->add_debug (QString (" Writing " ).append (QString::number (mtu)).append (sendbuffer.left (mtu)));
429+
430+ if (debug_logging == true )
431+ {
432+ // bluetooth_window->add_debug(QString("Writing ").append(QString::number(mtu)).append(sendbuffer.left(mtu)));
433+ bluetooth_window->add_debug (QString (" Writing " ).append (QString::number (sendbuffer.length () > mtu ? mtu : sendbuffer.length ())));
434+ }
417435
418436 return 0 ;
419437}
@@ -589,3 +607,8 @@ void smp_bluetooth::form_bluetooth_status(bool *scanning, bool *connecting)
589607 *scanning = discoveryAgent->isActive ();
590608 *connecting = device_connected;
591609}
610+
611+ void smp_bluetooth::form_debug_state_changed (bool enabled)
612+ {
613+ debug_logging = enabled;
614+ }
0 commit comments