You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

801 lines
38 KiB

2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #include "mainwindow.h"
  2. #include <QDateTime>
  3. #include <QMessageBox>
  4. #include <QtConcurrent>
  5. #include <QtSerialPort/QSerialPort>
  6. #include <QtSerialPort/QSerialPortInfo>
  7. #include "./ui_mainwindow.h"
  8. #include "camera_light_src_timing_controller/qt_serial_datachannel.hpp"
  9. #include "logger.hpp"
  10. using namespace iflytop;
  11. using namespace clst;
  12. using namespace std;
  13. static MainWindow *m_mainWindow;
  14. static CLSTControler *m_clstc;
  15. QTimer *timer0;
  16. QTimer *timer1;
  17. QTimer *timer2;
  18. QTimer *timer3;
  19. QTimer *checkConnectTimer0;
  20. ZQThread *m_zqthread;
  21. #define TAG "MainWindow"
  22. static const char *fmt(const char *fmt, ...) {
  23. va_list args;
  24. va_start(args, fmt);
  25. static char buf[1024] = {0};
  26. vsnprintf(buf, sizeof(buf), fmt, args);
  27. va_end(args);
  28. return buf;
  29. }
  30. static const uint32_t str2int(QString str) {
  31. // 如果0x开头,??16进制转换
  32. // 如果0b开头,??2进制转换
  33. // 否则??10进制转换
  34. // 去除掉str中_
  35. str.remove("_");
  36. if (str.startsWith("0x")) {
  37. return str.toUInt(nullptr, 16);
  38. } else if (str.startsWith("0b")) {
  39. // remove 0b
  40. str.remove(0, 2);
  41. return str.toUInt(nullptr, 2);
  42. } else {
  43. return str.toUInt(nullptr, 10);
  44. }
  45. }
  46. // static QSerialPort G_SerialPort;
  47. // static QThread G_SerialPortThread;
  48. static QTDataChannel G_QTDataChannel;
  49. static const QString zaferror_to_str(zaf_error_code_t value) {
  50. if (value == kaf_ec_overtime) {
  51. return "操作超时";
  52. } else if (value == kaf_ec_device_notopen) {
  53. return "设备未打开";
  54. } else {
  55. return "未知错误";
  56. }
  57. }
  58. #define DO(action) \
  59. { \
  60. zaf_error_code_t ecode = action; \
  61. if (ecode != kaf_ec_success) { \
  62. dumpLog("do %s fail,%s", #action, zaferror_to_str(ecode).toStdString().c_str()); \
  63. return; \
  64. } \
  65. }
  66. void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
  67. // QString text;
  68. // text.append(msg);
  69. }
  70. // void MainWindow::append_log_slot(QString text) { ui->logbrowser->append(text); }
  71. void MainWindow::doinui_slot(QFunction func) {
  72. if (func.get()) func.get()();
  73. }
  74. void MainWindow::updatePage() {
  75. {
  76. float Freq;
  77. uint32_t PluseCnt;
  78. uint32_t SeqCtrlPluseCntMax;
  79. Freq = ui->InterClk_Freq_Text->text().toFloat();
  80. PluseCnt = ui->InterClk_PluseCnt_Text->text().toUInt();
  81. SeqCtrlPluseCntMax = ui->InterClk_SeqCtrlPluseCntMax_Text->text().toUInt();
  82. DO(m_clstc->InterClk_setFreq(Freq));
  83. DO(m_clstc->InterClk_setPluseCnt(PluseCnt));
  84. DO(m_clstc->InterClk_setSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
  85. }
  86. {
  87. ExtTriggerSrcType src;
  88. SigProcessMode mode;
  89. TriggerEdge edge;
  90. uint32_t coefficient;
  91. uint32_t bias;
  92. uint32_t division;
  93. uint32_t multiplication;
  94. #define UPDATE(index) \
  95. src = ExtTriggerSrcType(ui->TriInX_SrcSelect_Val_##index->currentText().toStdString()); \
  96. coefficient = ui->TriInX_FileterCoefficient_Val_##index->text().toUInt(); \
  97. bias = ui->TriInX_FreqDetectBias_Val_##index->text().toUInt(); \
  98. mode = SigProcessMode(ui->TriInX_Mode_Val_##index->currentText().toStdString()); \
  99. edge = TriggerEdge(ui->TriInX_TriggerModeTriggerEdge_Val_##index->currentText().toStdString()); \
  100. division = ui->TriInX_TriggerModeFreqDivision_Val_##index->text().toUInt(); \
  101. multiplication = ui->TriInX_TriggerModeFreqMultiplication_Val_##index->text().toUInt(); \
  102. DO(m_clstc->TriInX_setSrcSelect(index, src)); \
  103. DO(m_clstc->TriInX_setFileterCoefficient(index, coefficient)); \
  104. DO(m_clstc->TriInX_setFreqDetectBias(index, bias)); \
  105. DO(m_clstc->TriInX_setMode(index, mode)); \
  106. DO(m_clstc->TriInX_setTriggerModeTriggerEdge(index, edge)); \
  107. DO(m_clstc->TriInX_setTriggerModeFreqDivision(index, division)); \
  108. DO(m_clstc->TriInX_setTriggerModeFreqMultiplication(index, multiplication));
  109. UPDATE(1);
  110. UPDATE(2);
  111. UPDATE(3);
  112. UPDATE(4);
  113. #undef UPDATE
  114. }
  115. {
  116. InternalSig src;
  117. uint32_t width;
  118. uint32_t offset;
  119. float duty;
  120. float freq;
  121. #define UPDATE(index) \
  122. src = InternalSig(ui->LightSrcX_TriSrc_##index->currentText().toStdString()); \
  123. width = ui->LightSrcX_TriggerModePluseWidth_##index->text().toUInt(); \
  124. offset = ui->LightSrcX_TriggerModeFirstPluseOffset_##index->text().toUInt(); \
  125. duty = ui->LightSrcX_LightIntensityDuty_##index->text().toFloat(); \
  126. freq = ui->LightSrcX_LightDriverFreq_##index->text().toFloat(); \
  127. DO(m_clstc->LightSrcX_setTriSrc(index, src)); \
  128. DO(m_clstc->LightSrcX_setTriggerModePluseWidth(index, width)); \
  129. DO(m_clstc->LightSrcX_setTriggerModeFirstPluseOffset(index, offset)); \
  130. DO(m_clstc->LightSrcX_setLightIntensityDuty(index, duty)); \
  131. DO(m_clstc->LightSrcX_setLightDriverFreq(index, freq));
  132. UPDATE(1);
  133. UPDATE(2);
  134. UPDATE(3);
  135. UPDATE(4);
  136. }
  137. {
  138. SigProcessMode mode;
  139. uint32_t offset;
  140. uint32_t bindstate1;
  141. uint32_t bindstate2;
  142. uint32_t bindstate3;
  143. uint32_t bindstate4;
  144. InternalSig sig;
  145. #define UPDATE(index) \
  146. mode = SigProcessMode(ui->ShutterX_OutputCtrlMode_##index->currentText().toStdString()); \
  147. offset = ui->ShutterX_LtEnOffset_##index->text().toUInt(); \
  148. bindstate1 = ui->ShutterX_LtEnBind_val1_##index->checkState() == Qt::CheckState::Checked; \
  149. bindstate2 = ui->ShutterX_LtEnBind_val2_##index->checkState() == Qt::CheckState::Checked; \
  150. bindstate3 = ui->ShutterX_LtEnBind_val3_##index->checkState() == Qt::CheckState::Checked; \
  151. bindstate4 = ui->ShutterX_LtEnBind_val4_##index->checkState() == Qt::CheckState::Checked; \
  152. sig = InternalSig(ui->ShutterX_InSigSelect_##index->currentText().toStdString()); \
  153. DO(m_clstc->ShutterX_setOutputCtrlMode(index, mode)); \
  154. DO(m_clstc->ShutterX_setLtEnOffset(index, offset)); \
  155. DO(m_clstc->ShutterX_setLtEnBind(index, 1, bindstate1)); \
  156. DO(m_clstc->ShutterX_setLtEnBind(index, 2, bindstate2)); \
  157. DO(m_clstc->ShutterX_setLtEnBind(index, 3, bindstate3)); \
  158. DO(m_clstc->ShutterX_setLtEnBind(index, 4, bindstate4)); \
  159. DO(m_clstc->ShutterX_setInSigSelect(index, sig));
  160. UPDATE(1);
  161. UPDATE(2);
  162. UPDATE(3);
  163. UPDATE(4);
  164. }
  165. }
  166. void MainWindow::refreshReadonlyPage0() {
  167. zaf_error_code_t ecode;
  168. if (!G_QTDataChannel.isOpen()) {
  169. return;
  170. }
  171. {
  172. float TriOutSignalFreq;
  173. DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
  174. emit doinui_signal(QFunction([this, TriOutSignalFreq]() { //
  175. ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
  176. }));
  177. }
  178. }
  179. void MainWindow::refreshReadonlyPage1() {
  180. if (!G_QTDataChannel.isOpen()) {
  181. return;
  182. }
  183. {
  184. float infreq;
  185. float outfreq;
  186. #define UPDATE(index) \
  187. DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \
  188. DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \
  189. { \
  190. emit doinui_signal(QFunction([this, infreq, outfreq]() { \
  191. ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \
  192. ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2)); \
  193. })); \
  194. }
  195. UPDATE(1);
  196. UPDATE(2);
  197. UPDATE(3);
  198. UPDATE(4);
  199. #undef UPDATE
  200. }
  201. }
  202. void MainWindow::refreshReadonlyPage2() {
  203. if (!G_QTDataChannel.isOpen()) {
  204. return;
  205. }
  206. // 刷新光源时序控制页面
  207. {
  208. float infreq;
  209. float outfreq;
  210. uint32_t state;
  211. #define UPDATE(index) \
  212. DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \
  213. DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \
  214. DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \
  215. { \
  216. emit doinui_signal(QFunction([this, infreq, outfreq, state]() { \
  217. ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \
  218. ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2)); \
  219. ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state)); \
  220. })); \
  221. }
  222. UPDATE(1);
  223. UPDATE(2);
  224. UPDATE(3);
  225. UPDATE(4);
  226. }
  227. }
  228. void MainWindow::refreshReadonlyPage3() {
  229. if (!G_QTDataChannel.isOpen()) {
  230. return;
  231. }
  232. }
  233. bool MainWindow::checkConnected() {
  234. if (!G_QTDataChannel.isOpen()) {
  235. return false;
  236. }
  237. uint32_t val;
  238. zaf_error_code_t ecode = m_clstc->reg_read(kreg_software_version, val);
  239. if (ecode != kaf_ec_success) {
  240. return false;
  241. }
  242. return true;
  243. }
  244. void MainWindow::refreshPage() {
  245. /*******************************************************************************
  246. * *
  247. *******************************************************************************/
  248. {
  249. float Freq;
  250. uint32_t PluseCnt;
  251. uint32_t SeqCtrlPluseCntMax;
  252. float TriOutSignalFreq;
  253. DO(m_clstc->InterClk_getFreq(Freq));
  254. DO(m_clstc->InterClk_getPluseCnt(PluseCnt));
  255. DO(m_clstc->InterClk_getSeqCtrlPluseCntMax(SeqCtrlPluseCntMax));
  256. DO(m_clstc->InterClk_readTriOutSignalFreq(TriOutSignalFreq));
  257. ui->InterClk_Freq_Text->setText(QString::number(Freq, 'f', 2));
  258. ui->InterClk_PluseCnt_Text->setText(QString::number(PluseCnt));
  259. ui->InterClk_SeqCtrlPluseCntMax_Text->setText(QString::number(SeqCtrlPluseCntMax));
  260. ui->InterClk_TriOutSignalFreq_Text->setText(QString::number(TriOutSignalFreq, 'f', 2));
  261. }
  262. /*******************************************************************************
  263. * *
  264. *******************************************************************************/
  265. {
  266. ExtTriggerSrcType src;
  267. SigProcessMode mode;
  268. TriggerEdge edge;
  269. uint32_t coefficient;
  270. uint32_t bias;
  271. uint32_t division;
  272. uint32_t multiplication;
  273. float infreq;
  274. float outfreq;
  275. #define UPDATE(index) \
  276. DO(m_clstc->TriInX_getSrcSelect(index, src)); \
  277. DO(m_clstc->TriInX_getFileterCoefficient(index, coefficient)); \
  278. DO(m_clstc->TriInX_getFreqDetectBias(index, bias)); \
  279. DO(m_clstc->TriInX_getMode(index, mode)); \
  280. DO(m_clstc->TriInX_getTriggerModeTriggerEdge(index, edge)); \
  281. DO(m_clstc->TriInX_getTriggerModeFreqDivision(index, division)); \
  282. DO(m_clstc->TriInX_getTriggerModeFreqMultiplication(index, multiplication)); \
  283. DO(m_clstc->TriInX_readInSignalFreq(index, infreq)); \
  284. DO(m_clstc->TriInX_readOutSignalFreq(index, outfreq)); \
  285. ui->TriInX_SrcSelect_Val_##index->setCurrentText(QString::fromStdString(src.toString())); \
  286. ui->TriInX_FileterCoefficient_Val_##index->setText(QString::number(coefficient)); \
  287. ui->TriInX_FreqDetectBias_Val_##index->setText(QString::number(bias)); \
  288. ui->TriInX_Mode_Val_##index->setCurrentText(QString::fromStdString(mode.toString())); \
  289. ui->TriInX_OutSignalFreq_Val_##index->setText(QString::number(outfreq, 'f', 2)); \
  290. ui->TriInX_InSignalFreq_Val_##index->setText(QString::number(infreq, 'f', 2)); \
  291. ui->TriInX_TriggerModeFreqDivision_Val_##index->setText(QString::number(division)); \
  292. ui->TriInX_TriggerModeFreqMultiplication_Val_##index->setText(QString::number(multiplication)); \
  293. ui->TriInX_TriggerModeTriggerEdge_Val_##index->setCurrentText(QString::fromStdString(edge.toString()));
  294. UPDATE(1);
  295. UPDATE(2);
  296. UPDATE(3);
  297. UPDATE(4);
  298. #undef UPDATE
  299. }
  300. // 刷新光源时序控制页面
  301. {
  302. InternalSig src;
  303. uint32_t width;
  304. uint32_t offset;
  305. float duty;
  306. float freq;
  307. uint32_t state;
  308. float infreq;
  309. float outfreq;
  310. #define UPDATE(index) \
  311. DO(m_clstc->LightSrcX_getTriSrc(index, src)); \
  312. DO(m_clstc->LightSrcX_getTriggerModePluseWidth(index, width)); \
  313. DO(m_clstc->LightSrcX_getTriggerModeFirstPluseOffset(index, offset)); \
  314. DO(m_clstc->LightSrcX_getLightIntensityDuty(index, duty)); \
  315. DO(m_clstc->LightSrcX_getLightDriverFreq(index, freq)); \
  316. DO(m_clstc->LightSrcX_readLightSrcErrorState(index, state)); \
  317. DO(m_clstc->LightSrcX_readInSigFreqDetect(index, infreq)); \
  318. DO(m_clstc->LightSrcX_readOutSigFreqDetect(index, outfreq)); \
  319. ui->LightSrcX_TriSrc_##index->setCurrentText(QString::fromStdString(src.toString())); \
  320. ui->LightSrcX_TriggerModePluseWidth_##index->setText(QString::number(width)); \
  321. ui->LightSrcX_TriggerModeFirstPluseOffset_##index->setText(QString::number(offset)); \
  322. ui->LightSrcX_LightIntensityDuty_##index->setText(QString::number(duty, 'f', 2)); \
  323. ui->LightSrcX_LightDriverFreq_##index->setText(QString::number(freq, 'f', 2)); \
  324. ui->LightSrcX_LightSrcErrorState_##index->setText(QString::number(state)); \
  325. ui->LightSrcX_InSigFreqDetect_##index->setText(QString::number(infreq, 'f', 2)); \
  326. ui->LightSrcX_OutSigFreqDetect_##index->setText(QString::number(outfreq, 'f', 2));
  327. UPDATE(1);
  328. UPDATE(2);
  329. UPDATE(3);
  330. UPDATE(4);
  331. }
  332. {
  333. SigProcessMode mode;
  334. uint32_t offset;
  335. uint32_t bindstate1;
  336. uint32_t bindstate2;
  337. uint32_t bindstate3;
  338. uint32_t bindstate4;
  339. InternalSig sig;
  340. #define UPDATE(index) \
  341. DO(m_clstc->ShutterX_getOutputCtrlMode(index, mode)); \
  342. DO(m_clstc->ShutterX_getLtEnOffset(index, offset)); \
  343. DO(m_clstc->ShutterX_getLtEnBind(index, 1, bindstate1)); \
  344. DO(m_clstc->ShutterX_getLtEnBind(index, 2, bindstate2)); \
  345. DO(m_clstc->ShutterX_getLtEnBind(index, 3, bindstate3)); \
  346. DO(m_clstc->ShutterX_getLtEnBind(index, 4, bindstate4)); \
  347. DO(m_clstc->ShutterX_getInSigSelect(index, sig)); \
  348. ui->ShutterX_OutputCtrlMode_##index->setCurrentText(QString::fromStdString(mode.toString())); \
  349. ui->ShutterX_LtEnOffset_##index->setText(QString::number(offset)); \
  350. ui->ShutterX_LtEnBind_val1_##index->setChecked(bindstate1 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  351. ui->ShutterX_LtEnBind_val2_##index->setChecked(bindstate2 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  352. ui->ShutterX_LtEnBind_val3_##index->setChecked(bindstate3 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  353. ui->ShutterX_LtEnBind_val4_##index->setChecked(bindstate4 != 0 ? Qt::CheckState::Checked : Qt::CheckState::Unchecked); \
  354. ui->ShutterX_InSigSelect_##index->setCurrentText(QString::fromStdString(sig.toString()));
  355. // ui->ShutterX_LtEnBind_val1_1->checkState()
  356. UPDATE(1);
  357. UPDATE(2);
  358. UPDATE(3);
  359. UPDATE(4);
  360. }
  361. }
  362. void MainWindow::constructUI() {
  363. /*******************************************************************************
  364. * serialPortCB *
  365. *******************************************************************************/
  366. const auto infos = QSerialPortInfo::availablePorts();
  367. for (const QSerialPortInfo &info : infos) {
  368. ui->serialPortCB->addItem(info.portName());
  369. }
  370. /*******************************************************************************
  371. * ?? *
  372. *******************************************************************************/
  373. ui->serialBaudrateCB->addItem("9600");
  374. ui->serialBaudrateCB->addItem("14400");
  375. ui->serialBaudrateCB->addItem("19200");
  376. ui->serialBaudrateCB->addItem("38400");
  377. ui->serialBaudrateCB->addItem("57600");
  378. ui->serialBaudrateCB->addItem("115200");
  379. ui->serialBaudrateCB->addItem("500000");
  380. ui->serialBaudrateCB->setCurrentIndex(6);
  381. /*******************************************************************************
  382. * *
  383. *******************************************************************************/
  384. connect(ui->serialPortRefreshKey, &QPushButton::clicked, this, [this](bool check) {
  385. ui->serialPortCB->clear();
  386. const auto infos = QSerialPortInfo::availablePorts();
  387. for (const QSerialPortInfo &info : infos) {
  388. ui->serialPortCB->addItem(info.portName());
  389. }
  390. });
  391. /*******************************************************************************
  392. * *
  393. *******************************************************************************/
  394. connect(ui->serialOpenKey, &QPushButton::clicked, this, [=](bool check) {
  395. // 打开串口
  396. if (ui->serialOpenKey->text() == "打开") {
  397. G_QTDataChannel.setPortName(ui->serialPortCB->currentText().toStdString());
  398. G_QTDataChannel.setBaudRate(ui->serialBaudrateCB->currentText().toInt());
  399. G_QTDataChannel.setDataBits(QSerialPort::Data8);
  400. G_QTDataChannel.setParity(QSerialPort::NoParity);
  401. G_QTDataChannel.setFlowControl(QSerialPort::NoFlowControl);
  402. G_QTDataChannel.setStopBits(QSerialPort::OneStop);
  403. if (!G_QTDataChannel.open()) {
  404. QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占??");
  405. return;
  406. }
  407. ui->serialOpenKey->setText("关闭");
  408. // 下拉菜单控件使能
  409. ui->serialBaudrateCB->setEnabled(false);
  410. ui->serialPortCB->setEnabled(false);
  411. ui->serialPortRefreshKey->setEnabled(false);
  412. } else {
  413. G_QTDataChannel.close();
  414. ui->serialOpenKey->setText("打开");
  415. ui->serialBaudrateCB->setEnabled(true);
  416. ui->serialPortCB->setEnabled(true);
  417. ui->serialPortRefreshKey->setEnabled(true);
  418. }
  419. });
  420. /*******************************************************************************
  421. * *
  422. *******************************************************************************/
  423. connect(ui->refreshPageKey, &QPushButton::clicked, this, [=](bool check) { //
  424. refreshPage();
  425. dumpLog("刷新成功");
  426. });
  427. connect(ui->UpdateCfg_Key, &QPushButton::clicked, this, [=](bool check) { //
  428. updatePage();
  429. refreshPage();
  430. dumpLog("提交成功");
  431. });
  432. /*******************************************************************************
  433. * *
  434. *******************************************************************************/
  435. connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { //
  436. DO(m_clstc->storageConfigs());
  437. dumpLog("保存配置成功");
  438. });
  439. /*******************************************************************************
  440. * *
  441. *******************************************************************************/
  442. connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { //
  443. DO(m_clstc->reboot());
  444. dumpLog("重启设备成功");
  445. });
  446. /*******************************************************************************
  447. * *
  448. *******************************************************************************/
  449. connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { //
  450. DO(m_clstc->factoryReset());
  451. dumpLog("恢复出厂设置成功");
  452. });
  453. /*******************************************************************************
  454. * ?? *
  455. *******************************************************************************/
  456. ui->RegAdd->setText("0x00000000");
  457. connect(ui->regReadKey, &QPushButton::clicked, this, [=](bool check) { //
  458. uint32_t addr = str2int(ui->RegAdd->text());
  459. uint32_t value = 0;
  460. DO(m_clstc->reg_read(addr, value, 100));
  461. ui->regReadbakVal->setText(fmt("0x%08X", value));
  462. dumpLog(fmt("读取0x%04x成功", addr));
  463. });
  464. connect(ui->regWriteKey, &QPushButton::clicked, this, [=](bool check) { //
  465. uint32_t addr = str2int(ui->RegAdd->text());
  466. uint32_t value = str2int(ui->regWriteVal->text());
  467. uint32_t readkbak = 0;
  468. DO(m_clstc->reg_write(addr, value, readkbak, 100));
  469. ui->regReadbakVal->setText(fmt("0x%04x", readkbak));
  470. dumpLog(fmt("写入0x%08x成功", addr));
  471. });
  472. connect(ui->InterClk_trigger_Key, &QPushButton::clicked, this, [=](bool check) { //
  473. DO(m_clstc->InterClk_trigger());
  474. dumpLog(fmt("触发成功"));
  475. });
  476. connect(ui->InterClk_stop_Key, &QPushButton::clicked, this, [=](bool check) { //
  477. DO(m_clstc->InterClk_stop());
  478. dumpLog(fmt("停止触发成功"));
  479. });
  480. /*******************************************************************************
  481. * *
  482. *******************************************************************************/
  483. ui->TriInX_SrcSelect_Val_1->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  484. ui->TriInX_SrcSelect_Val_1->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  485. ui->TriInX_Mode_Val_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  486. ui->TriInX_Mode_Val_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  487. ui->TriInX_TriggerModeTriggerEdge_Val_1->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  488. ui->TriInX_TriggerModeTriggerEdge_Val_1->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  489. ui->TriInX_SrcSelect_Val_2->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  490. ui->TriInX_SrcSelect_Val_2->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  491. ui->TriInX_Mode_Val_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  492. ui->TriInX_Mode_Val_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  493. ui->TriInX_TriggerModeTriggerEdge_Val_2->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  494. ui->TriInX_TriggerModeTriggerEdge_Val_2->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  495. ui->TriInX_SrcSelect_Val_3->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  496. ui->TriInX_SrcSelect_Val_3->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  497. ui->TriInX_Mode_Val_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  498. ui->TriInX_Mode_Val_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  499. ui->TriInX_TriggerModeTriggerEdge_Val_3->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  500. ui->TriInX_TriggerModeTriggerEdge_Val_3->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  501. ui->TriInX_SrcSelect_Val_4->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  502. ui->TriInX_SrcSelect_Val_4->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  503. ui->TriInX_Mode_Val_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  504. ui->TriInX_Mode_Val_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  505. ui->TriInX_TriggerModeTriggerEdge_Val_4->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  506. ui->TriInX_TriggerModeTriggerEdge_Val_4->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  507. ui->TriInX_InSignalFreq_Val_1->setDisabled(true);
  508. ui->TriInX_InSignalFreq_Val_2->setDisabled(true);
  509. ui->TriInX_InSignalFreq_Val_3->setDisabled(true);
  510. ui->TriInX_InSignalFreq_Val_4->setDisabled(true);
  511. ui->TriInX_OutSignalFreq_Val_1->setDisabled(true);
  512. ui->TriInX_OutSignalFreq_Val_2->setDisabled(true);
  513. ui->TriInX_OutSignalFreq_Val_3->setDisabled(true);
  514. ui->TriInX_OutSignalFreq_Val_4->setDisabled(true);
  515. /*******************************************************************************
  516. * *
  517. *******************************************************************************/
  518. QStringList LightSrcX_TriSrc_QStringList;
  519. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::LOGIC0).toString()));
  520. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::LOGIC1).toString()));
  521. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER).toString()));
  522. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I1).toString()));
  523. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I2).toString()));
  524. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I3).toString()));
  525. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I4).toString()));
  526. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1).toString()));
  527. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I1).toString()));
  528. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I2).toString()));
  529. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I3).toString()));
  530. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I4).toString()));
  531. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2).toString()));
  532. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I1).toString()));
  533. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I2).toString()));
  534. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I3).toString()));
  535. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I4).toString()));
  536. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3).toString()));
  537. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I1).toString()));
  538. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I2).toString()));
  539. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I3).toString()));
  540. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I4).toString()));
  541. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4).toString()));
  542. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I1).toString()));
  543. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I2).toString()));
  544. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I3).toString()));
  545. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I4).toString()));
  546. ui->LightSrcX_TriSrc_1->addItems(LightSrcX_TriSrc_QStringList);
  547. ui->LightSrcX_TriSrc_2->addItems(LightSrcX_TriSrc_QStringList);
  548. ui->LightSrcX_TriSrc_3->addItems(LightSrcX_TriSrc_QStringList);
  549. ui->LightSrcX_TriSrc_4->addItems(LightSrcX_TriSrc_QStringList);
  550. ui->LightSrcX_InSigFreqDetect_1->setDisabled(true);
  551. ui->LightSrcX_InSigFreqDetect_2->setDisabled(true);
  552. ui->LightSrcX_InSigFreqDetect_3->setDisabled(true);
  553. ui->LightSrcX_InSigFreqDetect_4->setDisabled(true);
  554. ui->LightSrcX_OutSigFreqDetect_1->setDisabled(true);
  555. ui->LightSrcX_OutSigFreqDetect_2->setDisabled(true);
  556. ui->LightSrcX_OutSigFreqDetect_3->setDisabled(true);
  557. ui->LightSrcX_OutSigFreqDetect_4->setDisabled(true);
  558. ui->LightSrcX_LightSrcErrorState_1->setDisabled(true);
  559. ui->LightSrcX_LightSrcErrorState_2->setDisabled(true);
  560. ui->LightSrcX_LightSrcErrorState_3->setDisabled(true);
  561. ui->LightSrcX_LightSrcErrorState_4->setDisabled(true);
  562. ui->LightSrcX_LightDriverFreq_1->setDisabled(true);
  563. ui->LightSrcX_LightDriverFreq_2->setDisabled(true);
  564. ui->LightSrcX_LightDriverFreq_3->setDisabled(true);
  565. ui->LightSrcX_LightDriverFreq_4->setDisabled(true);
  566. /*******************************************************************************
  567. * *
  568. *******************************************************************************/
  569. ui->ShutterX_OutputCtrlMode_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  570. ui->ShutterX_OutputCtrlMode_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  571. ui->ShutterX_OutputCtrlMode_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  572. ui->ShutterX_OutputCtrlMode_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  573. ui->ShutterX_OutputCtrlMode_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  574. ui->ShutterX_OutputCtrlMode_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  575. ui->ShutterX_OutputCtrlMode_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  576. ui->ShutterX_OutputCtrlMode_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  577. ui->ShutterX_InSigSelect_1->addItems(LightSrcX_TriSrc_QStringList);
  578. ui->ShutterX_InSigSelect_2->addItems(LightSrcX_TriSrc_QStringList);
  579. ui->ShutterX_InSigSelect_3->addItems(LightSrcX_TriSrc_QStringList);
  580. ui->ShutterX_InSigSelect_4->addItems(LightSrcX_TriSrc_QStringList);
  581. ui->InterClk_TriOutSignalFreq_Text->setDisabled(true);
  582. }
  583. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  584. // G_SerialPort.moveToThread();
  585. // QObject::connect(&G_SerialPortThread, &QThread::started, &G_SerialPort, &QSerialPort::open);
  586. G_QTDataChannel.init();
  587. CLSTControler::ins()->initialize(&G_QTDataChannel);
  588. m_clstc = CLSTControler::ins();
  589. ui->setupUi(this);
  590. m_mainWindow = this;
  591. qRegisterMetaType<int32_t>("int32_t");
  592. qRegisterMetaType<uint32_t>("uint32_t");
  593. qRegisterMetaType<float>("float");
  594. qRegisterMetaType<function<void()>>("function<void()>");
  595. qRegisterMetaType<QFunction>("QFunction");
  596. // qInstallMessageHandler(log_output);
  597. connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
  598. constructUI();
  599. // 创建定时器
  600. timer0 = new QTimer(this);
  601. timer1 = new QTimer(this);
  602. timer2 = new QTimer(this);
  603. timer3 = new QTimer(this);
  604. checkConnectTimer0 = new QTimer(this);
  605. m_zqthread = new ZQThread("", [this]() {
  606. while (true) {
  607. static bool connected = false;
  608. static bool first = true;
  609. bool connect = checkConnected();
  610. if (connected != connect || first) {
  611. first = false;
  612. connected = connect;
  613. emit doinui_signal(QFunction([this, connect]() {
  614. if (connect) {
  615. ui->DeviceConnectStateTB->setText("已连接");
  616. ui->DeviceConnectStateTB->setStyleSheet("color: green");
  617. } else {
  618. ui->DeviceConnectStateTB->setText("未连接");
  619. ui->DeviceConnectStateTB->setStyleSheet("color: red");
  620. }
  621. if (connected) {
  622. refreshPage();
  623. }
  624. }));
  625. }
  626. refreshReadonlyPage0();
  627. refreshReadonlyPage1();
  628. refreshReadonlyPage2();
  629. refreshReadonlyPage3();
  630. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  631. }
  632. });
  633. m_zqthread->start();
  634. // connect(timer0, &QTimer::timeout, this, [this]() { refreshReadonlyPage0(); });
  635. // connect(timer1, &QTimer::timeout, this, [this]() { refreshReadonlyPage1(); });
  636. // connect(timer2, &QTimer::timeout, this, [this]() { refreshReadonlyPage2(); });
  637. // connect(timer3, &QTimer::timeout, this, [this]() { refreshReadonlyPage3(); });
  638. // connect(checkConnectTimer0, &QTimer::timeout, this, [this]() { //
  639. // static bool connected = false;
  640. // bool connect = checkConnected();
  641. // if (connect) {
  642. // ui->DeviceConnectStateTB->setText("已连接");
  643. // ui->DeviceConnectStateTB->setStyleSheet("color: green");
  644. // } else {
  645. // ui->DeviceConnectStateTB->setText("未连接");
  646. // ui->DeviceConnectStateTB->setStyleSheet("color: red");
  647. // }
  648. // if (connected != connect) {
  649. // connected = connect;
  650. // if (connected) {
  651. // refreshPage();
  652. // }
  653. // }
  654. // });
  655. // timer0->setInterval(1100); // 每隔一秒触发一次
  656. // timer1->setInterval(1200); // 每隔一秒触发一次
  657. // timer2->setInterval(900); // 每隔一秒触发一次
  658. // timer3->setInterval(1000); // 每隔一秒触发一次
  659. // checkConnectTimer0->setInterval(100);
  660. // timer0->start();
  661. // timer1->start();
  662. // timer2->start();
  663. // timer3->start();
  664. // checkConnectTimer0->start();
  665. // m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) {
  666. // QString text;
  667. // if (type == kuart_raw_tx) {
  668. // text.append("TX: ");
  669. // for (size_t i = 0; i < len; i++) {
  670. // text.append(fmt("%02X ", data[i]));
  671. // }
  672. // } else if (type == kuart_raw_rx) {
  673. // text.append("RX: ");
  674. // for (size_t i = 0; i < len; i++) {
  675. // text.append(fmt("%02X ", data[i]));
  676. // }
  677. // }
  678. // emit doinui_signal(QFunction([this, text]() {
  679. // if (ui->instructionPreview->document()->lineCount() > 100) {
  680. // ui->instructionPreview->document()->clear();
  681. // }
  682. // ui->instructionPreview->append(text);
  683. // }));
  684. // });
  685. }
  686. void MainWindow::dumpLog(const char *fmt, ...) {
  687. va_list args;
  688. va_start(args, fmt);
  689. char buf[1024] = {0};
  690. vsnprintf(buf, sizeof(buf), fmt, args);
  691. qDebug() << buf;
  692. va_end(args);
  693. QString text(buf);
  694. QString info;
  695. // zos_get_ticket
  696. info.append(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"));
  697. info.append(" [Info]:");
  698. info.append(text);
  699. emit doinui_signal(QFunction([this, info]() {
  700. if (ui->instructionPreview->document()->lineCount() > 100) {
  701. ui->instructionPreview->document()->clear();
  702. }
  703. ui->instructionPreview->append(info);
  704. }));
  705. }
  706. MainWindow::~MainWindow() { delete ui; }