|
@ -15,7 +15,8 @@ using namespace iflytop; |
|
|
using namespace clst; |
|
|
using namespace clst; |
|
|
using namespace std; |
|
|
using namespace std; |
|
|
|
|
|
|
|
|
static MainWindow *m_mainWindow; |
|
|
|
|
|
|
|
|
static MainWindow *m_mainWindow; |
|
|
|
|
|
static CLSTControler *m_clstc; |
|
|
#define TAG "MainWindow"
|
|
|
#define TAG "MainWindow"
|
|
|
|
|
|
|
|
|
static const char *fmt(const char *fmt, ...) { |
|
|
static const char *fmt(const char *fmt, ...) { |
|
@ -47,6 +48,25 @@ static const uint32_t str2int(QString str) { |
|
|
static QSerialPort G_SerialPort; |
|
|
static QSerialPort G_SerialPort; |
|
|
static QTDataChannel G_QTDataChannel; |
|
|
static QTDataChannel G_QTDataChannel; |
|
|
|
|
|
|
|
|
|
|
|
static const QString zaferror_to_str(zaf_error_code_t value) { |
|
|
|
|
|
if (value == kaf_ec_overtime) { |
|
|
|
|
|
return "操作超时"; |
|
|
|
|
|
} else if (value == kaf_ec_device_notopen) { |
|
|
|
|
|
return "设备未打开"; |
|
|
|
|
|
} else { |
|
|
|
|
|
return "未知错误"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define DO(action) \
|
|
|
|
|
|
{ \ |
|
|
|
|
|
zaf_error_code_t ecode = action; \ |
|
|
|
|
|
if (ecode != kaf_ec_success) { \ |
|
|
|
|
|
ui->informationBrowser->setText(zaferror_to_str(ecode)); \ |
|
|
|
|
|
return; \ |
|
|
|
|
|
} \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) { |
|
|
void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) { |
|
|
// QString text;
|
|
|
// QString text;
|
|
|
// text.append(msg);
|
|
|
// text.append(msg);
|
|
@ -117,11 +137,43 @@ void MainWindow::constructUI() { |
|
|
ui->serialPortRefreshKey->setEnabled(true); |
|
|
ui->serialPortRefreshKey->setEnabled(true); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 刷新页面 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
connect(ui->refreshPageKey, &QPushButton::clicked, this, [=](bool check) { //
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 保存配置 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { //
|
|
|
|
|
|
DO(m_clstc->storageConfigs()); |
|
|
|
|
|
ui->informationBrowser->setText("保存配置成功"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 重启设备 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { //
|
|
|
|
|
|
DO(m_clstc->reboot()); |
|
|
|
|
|
ui->informationBrowser->setText("重启设备成功"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
|
|
* 恢复出厂设置 * |
|
|
|
|
|
*******************************************************************************/ |
|
|
|
|
|
connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { //
|
|
|
|
|
|
DO(m_clstc->factoryReset()); |
|
|
|
|
|
ui->informationBrowser->setText("恢复出厂设置成功"); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { |
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { |
|
|
G_QTDataChannel.bind(&G_SerialPort); |
|
|
G_QTDataChannel.bind(&G_SerialPort); |
|
|
CLSTControler::ins()->initialize(&G_QTDataChannel); |
|
|
CLSTControler::ins()->initialize(&G_QTDataChannel); |
|
|
|
|
|
m_clstc = CLSTControler::ins(); |
|
|
|
|
|
|
|
|
ui->setupUi(this); |
|
|
ui->setupUi(this); |
|
|
m_mainWindow = this; |
|
|
m_mainWindow = this; |
|
@ -133,6 +185,27 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi |
|
|
// qInstallMessageHandler(log_output);
|
|
|
// qInstallMessageHandler(log_output);
|
|
|
connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); |
|
|
connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); |
|
|
constructUI(); |
|
|
constructUI(); |
|
|
|
|
|
|
|
|
|
|
|
m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) { |
|
|
|
|
|
QString text; |
|
|
|
|
|
if (type == kuart_raw_tx) { |
|
|
|
|
|
text.append("TX: "); |
|
|
|
|
|
for (size_t i = 0; i < len; i++) { |
|
|
|
|
|
text.append(fmt("%02X ", data[i])); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (type == kuart_raw_rx) { |
|
|
|
|
|
text.append("RX: "); |
|
|
|
|
|
for (size_t i = 0; i < len; i++) { |
|
|
|
|
|
text.append(fmt("%02X ", data[i])); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
emit doinui_signal(QFunction([this, text]() { |
|
|
|
|
|
if (ui->instructionPreview->document()->lineCount() > 20) { |
|
|
|
|
|
ui->instructionPreview->clear(); |
|
|
|
|
|
} |
|
|
|
|
|
ui->instructionPreview->append(text); |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() { delete ui; } |
|
|
MainWindow::~MainWindow() { delete ui; } |