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.

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