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.

807 lines
38 KiB

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