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.

858 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
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. });
  450. connect(ui->UpdateCfg_Key, &QPushButton::clicked, this, [=](bool check) { //
  451. updatePage();
  452. refreshPage();
  453. dumpLog("提交成功");
  454. displayInfo(true, "提交成功");
  455. });
  456. /*******************************************************************************
  457. * *
  458. *******************************************************************************/
  459. connect(ui->storageConfigKey, &QPushButton::clicked, this, [=](bool check) { //
  460. DO(m_clstc->storageConfigs());
  461. dumpLog("保存配置成功");
  462. displayInfo(true, "保存配置成功");
  463. });
  464. /*******************************************************************************
  465. * *
  466. *******************************************************************************/
  467. connect(ui->rebootDeviceKey, &QPushButton::clicked, this, [=](bool check) { //
  468. DO(m_clstc->reboot());
  469. dumpLog("重启设备成功");
  470. displayInfo(true, "重启设备成功");
  471. });
  472. /*******************************************************************************
  473. * *
  474. *******************************************************************************/
  475. connect(ui->factoryResetKey, &QPushButton::clicked, this, [=](bool check) { //
  476. DO(m_clstc->factoryReset());
  477. dumpLog("恢复出厂设置成功");
  478. displayInfo(true, "恢复出厂设置成功");
  479. });
  480. /*******************************************************************************
  481. * ?? *
  482. *******************************************************************************/
  483. ui->RegAdd->setText("0x00000000");
  484. connect(ui->regReadKey, &QPushButton::clicked, this, [=](bool check) { //
  485. uint32_t addr = str2int(ui->RegAdd->text());
  486. uint32_t value = 0;
  487. DO(m_clstc->reg_read(addr, value, 100));
  488. ui->regReadbakVal->setText(fmt("0x%08X", value));
  489. dumpLog(fmt("读取0x%04x成功", addr));
  490. });
  491. connect(ui->regWriteKey, &QPushButton::clicked, this, [=](bool check) { //
  492. uint32_t addr = str2int(ui->RegAdd->text());
  493. uint32_t value = str2int(ui->regWriteVal->text());
  494. uint32_t readkbak = 0;
  495. DO(m_clstc->reg_write(addr, value, readkbak, 100));
  496. ui->regReadbakVal->setText(fmt("0x%04x", readkbak));
  497. dumpLog(fmt("写入0x%08x成功", addr));
  498. });
  499. connect(ui->InterClk_trigger_Key, &QPushButton::clicked, this, [=](bool check) { //
  500. DO(m_clstc->InterClk_trigger());
  501. dumpLog(fmt("触发成功"));
  502. });
  503. connect(ui->InterClk_stop_Key, &QPushButton::clicked, this, [=](bool check) { //
  504. DO(m_clstc->InterClk_stop());
  505. dumpLog(fmt("停止触发成功"));
  506. });
  507. /*******************************************************************************
  508. * *
  509. *******************************************************************************/
  510. ui->TriInX_SrcSelect_Val_1->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  511. ui->TriInX_SrcSelect_Val_1->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  512. ui->TriInX_Mode_Val_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  513. ui->TriInX_Mode_Val_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  514. ui->TriInX_TriggerModeTriggerEdge_Val_1->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  515. ui->TriInX_TriggerModeTriggerEdge_Val_1->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  516. ui->TriInX_SrcSelect_Val_2->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  517. ui->TriInX_SrcSelect_Val_2->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  518. ui->TriInX_Mode_Val_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  519. ui->TriInX_Mode_Val_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  520. ui->TriInX_TriggerModeTriggerEdge_Val_2->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  521. ui->TriInX_TriggerModeTriggerEdge_Val_2->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  522. ui->TriInX_SrcSelect_Val_3->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  523. ui->TriInX_SrcSelect_Val_3->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  524. ui->TriInX_Mode_Val_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  525. ui->TriInX_Mode_Val_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  526. ui->TriInX_TriggerModeTriggerEdge_Val_3->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  527. ui->TriInX_TriggerModeTriggerEdge_Val_3->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  528. ui->TriInX_SrcSelect_Val_4->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::DIFF_INPUT).toString()));
  529. ui->TriInX_SrcSelect_Val_4->addItem(QString::fromStdString(ExtTriggerSrcType(ExtTriggerSrcType::OPTOCOUPLER_INPUT).toString()));
  530. ui->TriInX_Mode_Val_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRIGGER_MODE).toString()));
  531. ui->TriInX_Mode_Val_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  532. ui->TriInX_TriggerModeTriggerEdge_Val_4->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::RISING).toString()));
  533. ui->TriInX_TriggerModeTriggerEdge_Val_4->addItem(QString::fromStdString(TriggerEdge(TriggerEdge::FALLING).toString()));
  534. ui->TriInX_InSignalFreq_Val_1->setDisabled(true);
  535. ui->TriInX_InSignalFreq_Val_2->setDisabled(true);
  536. ui->TriInX_InSignalFreq_Val_3->setDisabled(true);
  537. ui->TriInX_InSignalFreq_Val_4->setDisabled(true);
  538. ui->TriInX_OutSignalFreq_Val_1->setDisabled(true);
  539. ui->TriInX_OutSignalFreq_Val_2->setDisabled(true);
  540. ui->TriInX_OutSignalFreq_Val_3->setDisabled(true);
  541. ui->TriInX_OutSignalFreq_Val_4->setDisabled(true);
  542. /*******************************************************************************
  543. * *
  544. *******************************************************************************/
  545. QStringList LightSrcX_TriSrc_QStringList;
  546. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::LOGIC0).toString()));
  547. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::LOGIC1).toString()));
  548. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER).toString()));
  549. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I1).toString()));
  550. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I2).toString()));
  551. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I3).toString()));
  552. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::INTERNAL_TRIGGER_I4).toString()));
  553. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1).toString()));
  554. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I1).toString()));
  555. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I2).toString()));
  556. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I3).toString()));
  557. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_1_I4).toString()));
  558. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2).toString()));
  559. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I1).toString()));
  560. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I2).toString()));
  561. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I3).toString()));
  562. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_2_I4).toString()));
  563. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3).toString()));
  564. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I1).toString()));
  565. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I2).toString()));
  566. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I3).toString()));
  567. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_3_I4).toString()));
  568. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4).toString()));
  569. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I1).toString()));
  570. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I2).toString()));
  571. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I3).toString()));
  572. LightSrcX_TriSrc_QStringList.append(QString::fromStdString(InternalSig(InternalSig::EXT_TRIGGER_4_I4).toString()));
  573. ui->LightSrcX_TriSrc_1->addItems(LightSrcX_TriSrc_QStringList);
  574. ui->LightSrcX_TriSrc_2->addItems(LightSrcX_TriSrc_QStringList);
  575. ui->LightSrcX_TriSrc_3->addItems(LightSrcX_TriSrc_QStringList);
  576. ui->LightSrcX_TriSrc_4->addItems(LightSrcX_TriSrc_QStringList);
  577. ui->LightSrcX_InSigFreqDetect_1->setDisabled(true);
  578. ui->LightSrcX_InSigFreqDetect_2->setDisabled(true);
  579. ui->LightSrcX_InSigFreqDetect_3->setDisabled(true);
  580. ui->LightSrcX_InSigFreqDetect_4->setDisabled(true);
  581. ui->LightSrcX_OutSigFreqDetect_1->setDisabled(true);
  582. ui->LightSrcX_OutSigFreqDetect_2->setDisabled(true);
  583. ui->LightSrcX_OutSigFreqDetect_3->setDisabled(true);
  584. ui->LightSrcX_OutSigFreqDetect_4->setDisabled(true);
  585. ui->LightSrcX_LightSrcErrorState_1->setDisabled(true);
  586. ui->LightSrcX_LightSrcErrorState_2->setDisabled(true);
  587. ui->LightSrcX_LightSrcErrorState_3->setDisabled(true);
  588. ui->LightSrcX_LightSrcErrorState_4->setDisabled(true);
  589. ui->LightSrcX_LightDriverFreq_1->setDisabled(true);
  590. ui->LightSrcX_LightDriverFreq_2->setDisabled(true);
  591. ui->LightSrcX_LightDriverFreq_3->setDisabled(true);
  592. ui->LightSrcX_LightDriverFreq_4->setDisabled(true);
  593. /*******************************************************************************
  594. * *
  595. *******************************************************************************/
  596. ui->ShutterX_OutputCtrlMode_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  597. ui->ShutterX_OutputCtrlMode_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  598. ui->ShutterX_OutputCtrlMode_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  599. ui->ShutterX_OutputCtrlMode_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::TRANSPARENT_MODE).toString()));
  600. ui->ShutterX_OutputCtrlMode_1->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  601. ui->ShutterX_OutputCtrlMode_2->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  602. ui->ShutterX_OutputCtrlMode_3->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  603. ui->ShutterX_OutputCtrlMode_4->addItem(QString::fromStdString(SigProcessMode(SigProcessMode::BIND_MODE).toString()));
  604. ui->ShutterX_InSigSelect_1->addItems(LightSrcX_TriSrc_QStringList);
  605. ui->ShutterX_InSigSelect_2->addItems(LightSrcX_TriSrc_QStringList);
  606. ui->ShutterX_InSigSelect_3->addItems(LightSrcX_TriSrc_QStringList);
  607. ui->ShutterX_InSigSelect_4->addItems(LightSrcX_TriSrc_QStringList);
  608. ui->InterClk_TriOutSignalFreq_Text->setDisabled(true);
  609. }
  610. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
  611. // G_SerialPort.moveToThread();
  612. // QObject::connect(&G_SerialPortThread, &QThread::started, &G_SerialPort, &QSerialPort::open);
  613. G_QTDataChannel.init();
  614. CLSTControler::ins()->initialize(&G_QTDataChannel);
  615. m_clstc = CLSTControler::ins();
  616. ui->setupUi(this);
  617. m_mainWindow = this;
  618. qRegisterMetaType<int32_t>("int32_t");
  619. qRegisterMetaType<uint32_t>("uint32_t");
  620. qRegisterMetaType<float>("float");
  621. qRegisterMetaType<function<void()>>("function<void()>");
  622. qRegisterMetaType<QFunction>("QFunction");
  623. // qInstallMessageHandler(log_output);
  624. connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction)));
  625. constructUI();
  626. // 创建定时器
  627. timer0 = new QTimer(this);
  628. timer1 = new QTimer(this);
  629. timer2 = new QTimer(this);
  630. timer3 = new QTimer(this);
  631. checkConnectTimer0 = new QTimer(this);
  632. m_zqthread = new ZQThread("", [this]() {
  633. while (true) {
  634. static bool first = true;
  635. bool connect = checkConnected();
  636. if (m_connected != connect || first) {
  637. first = false;
  638. m_connected = connect;
  639. emit doinui_signal(QFunction([this, connect]() {
  640. if (connect) {
  641. ui->DeviceConnectStateTB->setText("已连接");
  642. ui->DeviceConnectStateTB->setStyleSheet("color: green");
  643. displayInfo(true, "连接成功");
  644. } else {
  645. ui->DeviceConnectStateTB->setText("未连接");
  646. ui->DeviceConnectStateTB->setStyleSheet("color: red");
  647. }
  648. if (m_connected) {
  649. refreshPage();
  650. }
  651. }));
  652. }
  653. refreshReadonlyPage0();
  654. refreshReadonlyPage1();
  655. refreshReadonlyPage2();
  656. refreshReadonlyPage3();
  657. std::this_thread::sleep_for(std::chrono::milliseconds(1000));
  658. }
  659. });
  660. m_zqthread->start();
  661. // connect(timer0, &QTimer::timeout, this, [this]() { refreshReadonlyPage0(); });
  662. // connect(timer1, &QTimer::timeout, this, [this]() { refreshReadonlyPage1(); });
  663. // connect(timer2, &QTimer::timeout, this, [this]() { refreshReadonlyPage2(); });
  664. // connect(timer3, &QTimer::timeout, this, [this]() { refreshReadonlyPage3(); });
  665. // connect(checkConnectTimer0, &QTimer::timeout, this, [this]() { //
  666. // static bool connected = false;
  667. // bool connect = checkConnected();
  668. // if (connect) {
  669. // ui->DeviceConnectStateTB->setText("已连接");
  670. // ui->DeviceConnectStateTB->setStyleSheet("color: green");
  671. // } else {
  672. // ui->DeviceConnectStateTB->setText("未连接");
  673. // ui->DeviceConnectStateTB->setStyleSheet("color: red");
  674. // }
  675. // if (connected != connect) {
  676. // connected = connect;
  677. // if (connected) {
  678. // refreshPage();
  679. // }
  680. // }
  681. // });
  682. // timer0->setInterval(1100); // 每隔一秒触发一次
  683. // timer1->setInterval(1200); // 每隔一秒触发一次
  684. // timer2->setInterval(900); // 每隔一秒触发一次
  685. // timer3->setInterval(1000); // 每隔一秒触发一次
  686. // checkConnectTimer0->setInterval(100);
  687. // timer0->start();
  688. // timer1->start();
  689. // timer2->start();
  690. // timer3->start();
  691. // checkConnectTimer0->start();
  692. // m_clstc->regRawDataListener([this](uart_message_type_t type, uint8_t *data, size_t len) {
  693. // QString text;
  694. // if (type == kuart_raw_tx) {
  695. // text.append("TX: ");
  696. // for (size_t i = 0; i < len; i++) {
  697. // text.append(fmt("%02X ", data[i]));
  698. // }
  699. // } else if (type == kuart_raw_rx) {
  700. // text.append("RX: ");
  701. // for (size_t i = 0; i < len; i++) {
  702. // text.append(fmt("%02X ", data[i]));
  703. // }
  704. // }
  705. // emit doinui_signal(QFunction([this, text]() {
  706. // if (ui->instructionPreview->document()->lineCount() > 100) {
  707. // ui->instructionPreview->document()->clear();
  708. // }
  709. // ui->instructionPreview->append(text);
  710. // }));
  711. // });
  712. }
  713. void MainWindow::dumpLog(const char *fmt, ...) {
  714. va_list args;
  715. va_start(args, fmt);
  716. char buf[1024] = {0};
  717. vsnprintf(buf, sizeof(buf), fmt, args);
  718. // qDebug() << buf;
  719. va_end(args);
  720. QString text(buf);
  721. QString info;
  722. // zos_get_ticket
  723. info.append(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"));
  724. info.append(" [Info]:");
  725. info.append(text);
  726. static int id;
  727. // informationBrowser
  728. emit doinui_signal(QFunction([this, info]() {
  729. if (ui->instructionPreview->document()->lineCount() > 100) {
  730. ui->instructionPreview->document()->clear();
  731. }
  732. ui->instructionPreview->append(info);
  733. }));
  734. }
  735. void MainWindow::displayInfo(bool suc, QString info) {
  736. emit doinui_signal(QFunction([this, info, suc]() {
  737. static int cnt = 0;
  738. cnt++;
  739. QString _info;
  740. _info.append("[");
  741. _info.append(QString::number(cnt));
  742. _info.append("] ");
  743. _info.append(info);
  744. if (suc) {
  745. ui->informationBrowser->setStyleSheet("color: green");
  746. } else {
  747. ui->informationBrowser->setStyleSheet("color: red");
  748. }
  749. ui->informationBrowser->setText(_info);
  750. }));
  751. }
  752. MainWindow::~MainWindow() { delete ui; }