Skip to content

Commit a21cddd

Browse files
committed
plugins: mcumgr: Add stat mgmt functionality
1 parent db7272b commit a21cddd

6 files changed

Lines changed: 547 additions & 4 deletions

File tree

plugins/mcumgr/form.ui

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<enum>QTabWidget::West</enum>
3737
</property>
3838
<property name="currentIndex">
39-
<number>2</number>
39+
<number>3</number>
4040
</property>
4141
<widget class="QWidget" name="tab_FS">
4242
<attribute name="title">
@@ -883,7 +883,18 @@
883883
</widget>
884884
</item>
885885
<item row="1" column="1">
886-
<widget class="QTableWidget" name="table_STAT_Values"/>
886+
<widget class="QTableWidget" name="table_STAT_Values">
887+
<column>
888+
<property name="text">
889+
<string>Name</string>
890+
</property>
891+
</column>
892+
<column>
893+
<property name="text">
894+
<string>Value</string>
895+
</property>
896+
</column>
897+
</widget>
887898
</item>
888899
<item row="2" column="0" colspan="2">
889900
<layout class="QHBoxLayout" name="horizontalLayout_9">

plugins/mcumgr/mcumgr.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SOURCES += \
1919
smp_error.cpp \
2020
smp_group_os_mgmt.cpp \
2121
smp_group_shell_mgmt.cpp \
22+
smp_group_stat_mgmt.cpp \
2223
smp_message.cpp \
2324
smp_processor.cpp \
2425
smp_uart.cpp \
@@ -30,6 +31,7 @@ HEADERS += \
3031
smp_error.h \
3132
smp_group_os_mgmt.h \
3233
smp_group_shell_mgmt.h \
34+
smp_group_stat_mgmt.h \
3335
smp_message.h \
3436
smp_processor.h \
3537
smp_uart.h \

plugins/mcumgr/plugin_mcumgr.cpp

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ QStandardItemModel model_image_state;
4040
smp_group_img_mgmt *my_img;
4141
smp_group_os_mgmt *my_os;
4242
smp_group_shell_mgmt *my_shell;
43+
smp_group_stat_mgmt *my_stat;
4344
QList<image_state_t> blaharray;
4445

4546
void plugin_mcumgr::setup(QMainWindow *main_window)
@@ -566,6 +567,12 @@ void plugin_mcumgr::setup(QMainWindow *main_window)
566567
gridLayout_11->addWidget(label_16, 1, 0, 1, 1);
567568

568569
table_STAT_Values = new QTableWidget(tab_5);
570+
if (table_STAT_Values->columnCount() < 2)
571+
table_STAT_Values->setColumnCount(2);
572+
QTableWidgetItem *__qtablewidgetitem12 = new QTableWidgetItem();
573+
table_STAT_Values->setHorizontalHeaderItem(0, __qtablewidgetitem12);
574+
QTableWidgetItem *__qtablewidgetitem13 = new QTableWidgetItem();
575+
table_STAT_Values->setHorizontalHeaderItem(1, __qtablewidgetitem13);
569576
table_STAT_Values->setObjectName(QString::fromUtf8("table_STAT_Values"));
570577

571578
gridLayout_11->addWidget(table_STAT_Values, 1, 1, 1, 1);
@@ -797,7 +804,7 @@ void plugin_mcumgr::setup(QMainWindow *main_window)
797804
// retranslateUi(Form);
798805

799806
// tabWidget->setCurrentIndex(0);
800-
tabWidget_2->setCurrentIndex(2);
807+
tabWidget_2->setCurrentIndex(3);
801808
tabWidget_3->setCurrentIndex(1);
802809
selector_OS->setCurrentIndex(2);
803810
///AUTOGEN_END_INIT
@@ -876,6 +883,10 @@ void plugin_mcumgr::setup(QMainWindow *main_window)
876883
tabWidget_2->setTabText(tabWidget_2->indexOf(tab_OS), QCoreApplication::translate("Form", "OS", nullptr));
877884
label_15->setText(QCoreApplication::translate("Form", "Group:", nullptr));
878885
label_16->setText(QCoreApplication::translate("Form", "Values:", nullptr));
886+
QTableWidgetItem *___qtablewidgetitem12 = table_STAT_Values->horizontalHeaderItem(0);
887+
___qtablewidgetitem12->setText(QCoreApplication::translate("Form", "Name", nullptr));
888+
QTableWidgetItem *___qtablewidgetitem13 = table_STAT_Values->horizontalHeaderItem(1);
889+
___qtablewidgetitem13->setText(QCoreApplication::translate("Form", "Value", nullptr));
879890
radio_STAT_List->setText(QCoreApplication::translate("Form", "List Groups", nullptr));
880891
radio_STAT_Fetch->setText(QCoreApplication::translate("Form", "Fetch Stats", nullptr));
881892
lbl_STAT_Status->setText(QCoreApplication::translate("Form", "[Status]", nullptr));
@@ -944,6 +955,7 @@ connect(colview_IMG_Images, SIGNAL(updatePreviewWidget(QModelIndex)), this, SLOT
944955
my_img = new smp_group_img_mgmt(processor);
945956
my_os = new smp_group_os_mgmt(processor);
946957
my_shell = new smp_group_shell_mgmt(processor);
958+
my_stat = new smp_group_stat_mgmt(processor);
947959

948960
connect(my_img, SIGNAL(status(uint8_t,group_status,QString)), this, SLOT(status(uint8_t,group_status,QString)));
949961
connect(my_img, SIGNAL(progress(uint8_t,uint8_t)), this, SLOT(progress(uint8_t,uint8_t)));
@@ -956,10 +968,15 @@ connect(colview_IMG_Images, SIGNAL(updatePreviewWidget(QModelIndex)), this, SLOT
956968
connect(my_shell, SIGNAL(status(uint8_t,group_status,QString)), this, SLOT(status(uint8_t,group_status,QString)));
957969
connect(my_shell, SIGNAL(progress(uint8_t,uint8_t)), this, SLOT(progress(uint8_t,uint8_t)));
958970
// connect(my_shell, SIGNAL(plugin_to_hex(QByteArray*)), this, SLOT(group_to_hex(QByteArray*)));
971+
972+
connect(my_stat, SIGNAL(status(uint8_t,group_status,QString)), this, SLOT(status(uint8_t,group_status,QString)));
973+
connect(my_stat, SIGNAL(progress(uint8_t,uint8_t)), this, SLOT(progress(uint8_t,uint8_t)));
974+
// connect(my_shell, SIGNAL(plugin_to_hex(QByteArray*)), this, SLOT(group_to_hex(QByteArray*)));
959975
}
960976

961977
plugin_mcumgr::~plugin_mcumgr()
962978
{
979+
delete my_stat;
963980
delete my_shell;
964981
delete my_os;
965982
delete my_img;
@@ -1288,9 +1305,25 @@ void plugin_mcumgr::on_btn_STAT_Go_clicked()
12881305
{
12891306
if (radio_STAT_List->isChecked())
12901307
{
1308+
//Execute stat list command
1309+
emit plugin_set_status(true, false);
1310+
1311+
mode = ACTION_STAT_LIST_GROUPS;
1312+
my_stat->set_parameters((check_V2_Protocol->isChecked() ? 1 : 0), edit_MTU->value(), retries, timeout_ms, mode);
1313+
my_stat->start_list_groups(&group_list);
1314+
1315+
lbl_STAT_Status->setText("Listing...");
12911316
}
1292-
else if (radio_STAT_Fetch->isChecked())
1317+
else if (radio_STAT_Fetch->isChecked() && !combo_STAT_Group->currentText().isEmpty())
12931318
{
1319+
//Execute stat get command
1320+
emit plugin_set_status(true, false);
1321+
1322+
mode = ACTION_STAT_GROUP_DATA;
1323+
my_stat->set_parameters((check_V2_Protocol->isChecked() ? 1 : 0), edit_MTU->value(), retries, timeout_ms, mode);
1324+
my_stat->start_group_data(combo_STAT_Group->currentText(), &stat_list);
1325+
1326+
lbl_STAT_Status->setText("Fetching...");
12941327
}
12951328
}
12961329

@@ -1578,6 +1611,38 @@ void plugin_mcumgr::status(uint8_t user_data, group_status status, QString error
15781611
}
15791612
}
15801613
}
1614+
else if (sender() == my_stat)
1615+
{
1616+
qDebug() << "stat sender";
1617+
if (status == STATUS_COMPLETE)
1618+
{
1619+
qDebug() << "complete";
1620+
if (user_data == ACTION_STAT_GROUP_DATA)
1621+
{
1622+
uint8_t i = 0;
1623+
1624+
//TODO: optimise
1625+
table_STAT_Values->clearContents();
1626+
1627+
while (i < stat_list.length())
1628+
{
1629+
QTableWidgetItem *row_name = new QTableWidgetItem(stat_list[i].name);
1630+
QTableWidgetItem *row_value = new QTableWidgetItem(QString::number(stat_list[i].value));
1631+
1632+
table_STAT_Values->insertRow(table_STAT_Values->rowCount());
1633+
table_STAT_Values->setItem((table_STAT_Values->rowCount() - 1), 0, row_name);
1634+
table_STAT_Values->setItem((table_STAT_Values->rowCount() - 1), 1, row_value);
1635+
1636+
++i;
1637+
}
1638+
}
1639+
else if (user_data == ACTION_STAT_LIST_GROUPS)
1640+
{
1641+
combo_STAT_Group->clear();
1642+
combo_STAT_Group->addItems(group_list);
1643+
}
1644+
}
1645+
}
15811646

15821647
if (finished == true)
15831648
{

plugins/mcumgr/plugin_mcumgr.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "smp_group_img_mgmt.h"
4242
#include "smp_group_os_mgmt.h"
4343
#include "smp_group_shell_mgmt.h"
44+
#include "smp_group_stat_mgmt.h"
4445
#include "smp_error.h"
4546

4647
//Form includes
@@ -88,6 +89,9 @@ enum mcumgr_action_t {
8889
ACTION_OS_OS_APPLICATION_INFO,
8990

9091
ACTION_SHELL_EXECUTE,
92+
93+
ACTION_STAT_GROUP_DATA,
94+
ACTION_STAT_LIST_GROUPS,
9195
};
9296

9397
class plugin_mcumgr : public QObject, AutPlugin
@@ -302,6 +306,8 @@ private slots:
302306
QList<task_list_t> task_list;
303307
QList<memory_pool_t> memory_list;
304308
int32_t shell_rc;
309+
QStringList group_list;
310+
QList<stat_value_t> stat_list;
305311
};
306312

307313
#endif // PLUGIN_MCUMGR_H

0 commit comments

Comments
 (0)