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.

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