Skip to content

Commit 3144a79

Browse files
committed
plugins: mcumgr: Add bluetooth debug logging control checkbox
1 parent 422df29 commit 3144a79

5 files changed

Lines changed: 110 additions & 34 deletions

File tree

plugins/mcumgr/bluetooth_setup.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ void bluetooth_setup::on_list_devices_currentRowChanged(int row)
115115
ui->btn_connect->setEnabled(false);
116116
}
117117
}
118+
119+
void bluetooth_setup::on_btn_clear_clicked()
120+
{
121+
ui->edit_debug->clear();
122+
}
123+
124+
void bluetooth_setup::on_check_debug_logging_stateChanged(int)
125+
{
126+
emit debug_log_state_changed(ui->check_debug_logging->isChecked());
127+
}

plugins/mcumgr/bluetooth_setup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ private slots:
5050
void on_btn_close_clicked();
5151
void on_list_devices_itemDoubleClicked(QListWidgetItem *item);
5252
void on_list_devices_currentRowChanged(int row);
53+
void on_btn_clear_clicked();
54+
void on_check_debug_logging_stateChanged(int);
5355

5456
signals:
5557
void refresh_devices();
5658
void connect_to_device(uint16_t index);
5759
void disconnect_from_device();
5860
void bluetooth_status(bool *scanning, bool *connecting);
61+
void debug_log_state_changed(bool enabled);
5962

6063
private:
6164
Ui::bluetooth_setup *ui;

plugins/mcumgr/bluetooth_setup.ui

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>400</width>
10-
<height>267</height>
9+
<width>414</width>
10+
<height>264</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -18,7 +18,7 @@
1818
<rect>
1919
<x>10</x>
2020
<y>10</y>
21-
<width>256</width>
21+
<width>251</width>
2222
<height>192</height>
2323
</rect>
2424
</property>
@@ -29,8 +29,8 @@
2929
</property>
3030
<property name="geometry">
3131
<rect>
32-
<x>20</x>
33-
<y>220</y>
32+
<x>10</x>
33+
<y>230</y>
3434
<width>75</width>
3535
<height>24</height>
3636
</rect>
@@ -45,8 +45,8 @@
4545
</property>
4646
<property name="geometry">
4747
<rect>
48-
<x>100</x>
49-
<y>220</y>
48+
<x>90</x>
49+
<y>230</y>
5050
<width>75</width>
5151
<height>24</height>
5252
</rect>
@@ -61,8 +61,8 @@
6161
</property>
6262
<property name="geometry">
6363
<rect>
64-
<x>180</x>
65-
<y>220</y>
64+
<x>170</x>
65+
<y>230</y>
6666
<width>75</width>
6767
<height>24</height>
6868
</rect>
@@ -74,8 +74,8 @@
7474
<widget class="QPushButton" name="btn_close">
7575
<property name="geometry">
7676
<rect>
77-
<x>260</x>
78-
<y>220</y>
77+
<x>250</x>
78+
<y>230</y>
7979
<width>75</width>
8080
<height>24</height>
8181
</rect>
@@ -87,9 +87,9 @@
8787
<widget class="QPlainTextEdit" name="edit_debug">
8888
<property name="geometry">
8989
<rect>
90-
<x>280</x>
90+
<x>263</x>
9191
<y>10</y>
92-
<width>104</width>
92+
<width>141</width>
9393
<height>191</height>
9494
</rect>
9595
</property>
@@ -100,6 +100,45 @@
100100
<bool>true</bool>
101101
</property>
102102
</widget>
103+
<widget class="QPushButton" name="btn_clear">
104+
<property name="geometry">
105+
<rect>
106+
<x>330</x>
107+
<y>230</y>
108+
<width>75</width>
109+
<height>24</height>
110+
</rect>
111+
</property>
112+
<property name="text">
113+
<string>Clear</string>
114+
</property>
115+
</widget>
116+
<widget class="QLabel" name="label">
117+
<property name="geometry">
118+
<rect>
119+
<x>10</x>
120+
<y>210</y>
121+
<width>201</width>
122+
<height>17</height>
123+
</rect>
124+
</property>
125+
<property name="text">
126+
<string>[Status]</string>
127+
</property>
128+
</widget>
129+
<widget class="QCheckBox" name="check_debug_logging">
130+
<property name="geometry">
131+
<rect>
132+
<x>260</x>
133+
<y>210</y>
134+
<width>131</width>
135+
<height>23</height>
136+
</rect>
137+
</property>
138+
<property name="text">
139+
<string>Debug logging</string>
140+
</property>
141+
</widget>
103142
</widget>
104143
<resources/>
105144
<connections/>

plugins/mcumgr/smp_bluetooth.cpp

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,28 @@
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

5455
smp_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

222224
void 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

237242
void 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+
}

plugins/mcumgr/smp_bluetooth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ private slots:
7070
void form_connect_to_device(uint16_t index);
7171
void form_disconnect_from_device();
7272
void form_bluetooth_status(bool *scanning, bool *connecting);
73+
void form_debug_state_changed(bool enabled);
7374
// void connection_updated(QLowEnergyConnectionParameters parameters);
7475

7576
signals:

0 commit comments

Comments
 (0)